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

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 (148) hide show
  1. package/android/src/main/java/com/onekey/nativelist/HybridNativeList.kt +14 -1
  2. package/android/src/main/java/com/onekey/nativelist/NativeListAccessoryStack.kt +245 -9
  3. package/android/src/main/java/com/onekey/nativelist/NativeListActivityDetailsView.kt +35 -7
  4. package/android/src/main/java/com/onekey/nativelist/NativeListActivityRenderer.kt +25 -3
  5. package/android/src/main/java/com/onekey/nativelist/NativeListAdapter.kt +17 -1
  6. package/android/src/main/java/com/onekey/nativelist/NativeListButtonGroupRenderer.kt +102 -0
  7. package/android/src/main/java/com/onekey/nativelist/NativeListContainerSlotAdapter.kt +12 -0
  8. package/android/src/main/java/com/onekey/nativelist/NativeListDataRowRenderer.kt +102 -7
  9. package/android/src/main/java/com/onekey/nativelist/NativeListIdentityRenderer.kt +225 -11
  10. package/android/src/main/java/com/onekey/nativelist/NativeListLeadingVisual.kt +147 -33
  11. package/android/src/main/java/com/onekey/nativelist/NativeListMarketRenderer.kt +92 -28
  12. package/android/src/main/java/com/onekey/nativelist/NativeListMessageRenderer.kt +25 -0
  13. package/android/src/main/java/com/onekey/nativelist/NativeListModels.kt +149 -3
  14. package/android/src/main/java/com/onekey/nativelist/NativeListPrimitives.kt +51 -0
  15. package/android/src/main/java/com/onekey/nativelist/NativeListRendererRegistry.kt +2 -0
  16. package/android/src/main/java/com/onekey/nativelist/NativeListRendererRowView.kt +2 -0
  17. package/android/src/main/java/com/onekey/nativelist/NativeListResolvedText.kt +3 -2
  18. package/android/src/main/java/com/onekey/nativelist/NativeListSectionHeaderRenderer.kt +69 -0
  19. package/android/src/main/java/com/onekey/nativelist/NativeListTextView.kt +55 -1
  20. package/android/src/main/java/com/onekey/nativelist/NativeListView.kt +1953 -117
  21. package/android/src/test/java/com/margelo/nitro/nativelist/NativeListActivityHostClipPolicyTest.kt +35 -0
  22. package/android/src/test/java/com/margelo/nitro/nativelist/NativeListIdentityTrailingAxisTest.kt +36 -0
  23. package/android/src/test/java/com/margelo/nitro/nativelist/NativeListLeadingSlotFrameTest.kt +68 -0
  24. package/android/src/test/java/com/margelo/nitro/nativelist/NativeListLeadingVisualClipPolicyTest.kt +44 -0
  25. package/android/src/test/java/com/margelo/nitro/nativelist/NativeListPressPolicyTest.kt +10 -0
  26. package/docs/ROW_TEMPLATES.md +70 -11
  27. package/docs/SPEC.md +1235 -20
  28. package/docs/STYLE_SPEC.md +6 -0
  29. package/ios/HybridNativeList.swift +21 -2
  30. package/ios/NativeListAccessoryStack.swift +235 -39
  31. package/ios/NativeListActivityDetailsView.swift +30 -11
  32. package/ios/NativeListActivityRenderer.swift +8 -2
  33. package/ios/NativeListButtonGroupRenderer.swift +89 -0
  34. package/ios/NativeListDataRowRenderer.swift +155 -27
  35. package/ios/NativeListDesignAssets.swift +9 -0
  36. package/ios/NativeListIdentityRenderer.swift +239 -31
  37. package/ios/NativeListLeadingVisual.swift +119 -22
  38. package/ios/NativeListMarketRenderer.swift +113 -18
  39. package/ios/NativeListMessageRenderer.swift +34 -1
  40. package/ios/NativeListModels.swift +42 -2
  41. package/ios/NativeListRendererRegistry.swift +1 -0
  42. package/ios/NativeListResolvedText.swift +2 -1
  43. package/ios/NativeListRowHost.swift +14 -0
  44. package/ios/NativeListSectionHeaderRenderer.swift +88 -0
  45. package/ios/RNCNativeListView.swift +1052 -58
  46. package/ios/Resources/NativeListIcons.xcassets/onekey_crypto_coin_outline.imageset/Contents.json +15 -0
  47. package/ios/Resources/NativeListIcons.xcassets/onekey_crypto_coin_outline.imageset/icon.svg +4 -0
  48. package/ios/Resources/NativeListIcons.xcassets/onekey_document2.imageset/Contents.json +1 -0
  49. package/ios/Resources/NativeListIcons.xcassets/onekey_document2.imageset/icon.svg +1 -0
  50. package/ios/Resources/NativeListIcons.xcassets/onekey_dot_ver_solid.imageset/Contents.json +1 -0
  51. package/ios/Resources/NativeListIcons.xcassets/onekey_dot_ver_solid.imageset/icon.svg +1 -0
  52. package/ios/Resources/NativeListIcons.xcassets/onekey_gas_solid.imageset/Contents.json +15 -0
  53. package/ios/Resources/NativeListIcons.xcassets/onekey_gas_solid.imageset/icon.svg +3 -0
  54. package/ios/Resources/NativeListIcons.xcassets/onekey_plus_large.imageset/Contents.json +1 -0
  55. package/ios/Resources/NativeListIcons.xcassets/onekey_plus_large.imageset/icon.svg +1 -0
  56. package/ios/Resources/NativeListIcons.xcassets/onekey_refresh_ccw_outline.imageset/Contents.json +15 -0
  57. package/ios/Resources/NativeListIcons.xcassets/onekey_refresh_ccw_outline.imageset/icon.svg +3 -0
  58. package/ios/Resources/NativeListIcons.xcassets/onekey_ticket.imageset/Contents.json +1 -0
  59. package/ios/Resources/NativeListIcons.xcassets/onekey_ticket.imageset/icon.svg +1 -0
  60. package/ios/Resources/NativeListIcons.xcassets/onekey_wallet.imageset/Contents.json +1 -0
  61. package/ios/Resources/NativeListIcons.xcassets/onekey_wallet.imageset/icon.svg +1 -0
  62. package/ios/tests/NativeListAccessoryStackTests.swift +89 -0
  63. package/ios/tests/NativeListActivityPresentationTests.swift +153 -0
  64. package/ios/tests/NativeListIdentityTitleIconLayoutTests.swift +81 -0
  65. package/ios/tests/NativeListLeadingVisualPairBackdropTests.swift +50 -0
  66. package/ios/tests/NativeListLifecycleTests.swift +2789 -3
  67. package/ios/tests/NativeListMarketMetricsTests.swift +117 -0
  68. package/lib/module/NativeList.js +223 -36
  69. package/lib/module/NativeList.web.js +260 -33
  70. package/lib/module/index.js +1 -1
  71. package/lib/module/models.js +3 -0
  72. package/lib/module/selection.js +1 -1
  73. package/lib/module/validation.js +1386 -81
  74. package/lib/module/web/NativeListWebEngine.js +914 -80
  75. package/lib/module/web/templates/ActivityRowRenderer.js +487 -7
  76. package/lib/module/web/templates/ButtonGroupRowRenderer.js +47 -0
  77. package/lib/module/web/templates/DataRowRenderer.js +40 -5
  78. package/lib/module/web/templates/IdentityRowRenderer.js +145 -5
  79. package/lib/module/web/templates/MarketRowRenderer.js +8 -3
  80. package/lib/module/web/templates/MarketTableRowRenderer.js +577 -0
  81. package/lib/module/web/templates/MediaTileRowRenderer.js +260 -5
  82. package/lib/module/web/templates/MessageRowRenderer.js +18 -2
  83. package/lib/module/web/templates/RowContainerStyle.js +1 -0
  84. package/lib/module/web/templates/RowRendererRegistry.js +8 -3
  85. package/lib/module/web/templates/SectionHeaderRowRenderer.js +70 -3
  86. package/lib/nitrogen/generated/android/c++/JHybridNativeListSpec.cpp +26 -0
  87. package/lib/nitrogen/generated/android/c++/JHybridNativeListSpec.hpp +4 -0
  88. package/lib/nitrogen/generated/android/c++/views/JHybridNativeListStateUpdater.cpp +10 -0
  89. package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/HybridNativeListSpec.kt +20 -0
  90. package/lib/nitrogen/generated/ios/c++/HybridNativeListSpecSwift.hpp +14 -0
  91. package/lib/nitrogen/generated/ios/c++/views/HybridNativeListComponent.mm +12 -0
  92. package/lib/nitrogen/generated/ios/swift/HybridNativeListSpec.swift +2 -0
  93. package/lib/nitrogen/generated/ios/swift/HybridNativeListSpec_cxx.swift +43 -0
  94. package/lib/nitrogen/generated/shared/c++/HybridNativeListSpec.cpp +4 -0
  95. package/lib/nitrogen/generated/shared/c++/HybridNativeListSpec.hpp +4 -0
  96. package/lib/nitrogen/generated/shared/c++/views/HybridNativeListComponent.cpp +4 -0
  97. package/lib/nitrogen/generated/shared/c++/views/HybridNativeListComponent.hpp +6 -0
  98. package/lib/nitrogen/generated/shared/json/NativeListConfig.json +2 -0
  99. package/lib/typescript/src/NativeList.d.ts +3 -3
  100. package/lib/typescript/src/NativeList.nitro.d.ts +2 -0
  101. package/lib/typescript/src/NativeList.types.d.ts +29 -1
  102. package/lib/typescript/src/NativeList.web.d.ts +2 -2
  103. package/lib/typescript/src/index.d.ts +2 -2
  104. package/lib/typescript/src/models.d.ts +196 -17
  105. package/lib/typescript/src/validation.d.ts +20 -0
  106. package/lib/typescript/src/web/NativeListWebEngine.d.ts +58 -1
  107. package/lib/typescript/src/web/templates/ActivityRowRenderer.d.ts +3 -3
  108. package/lib/typescript/src/web/templates/ButtonGroupRowRenderer.d.ts +14 -0
  109. package/lib/typescript/src/web/templates/IdentityRowRenderer.d.ts +1 -1
  110. package/lib/typescript/src/web/templates/MarketTableRowRenderer.d.ts +17 -0
  111. package/lib/typescript/src/web/templates/MediaTileRowRenderer.d.ts +3 -3
  112. package/lib/typescript/src/web/templates/MessageRowRenderer.d.ts +10 -4
  113. package/lib/typescript/src/web/templates/RowRendererRegistry.d.ts +3 -1
  114. package/nitrogen/generated/android/c++/JHybridNativeListSpec.cpp +26 -0
  115. package/nitrogen/generated/android/c++/JHybridNativeListSpec.hpp +4 -0
  116. package/nitrogen/generated/android/c++/views/JHybridNativeListStateUpdater.cpp +10 -0
  117. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/HybridNativeListSpec.kt +20 -0
  118. package/nitrogen/generated/ios/c++/HybridNativeListSpecSwift.hpp +14 -0
  119. package/nitrogen/generated/ios/c++/views/HybridNativeListComponent.mm +12 -0
  120. package/nitrogen/generated/ios/swift/HybridNativeListSpec.swift +2 -0
  121. package/nitrogen/generated/ios/swift/HybridNativeListSpec_cxx.swift +43 -0
  122. package/nitrogen/generated/shared/c++/HybridNativeListSpec.cpp +4 -0
  123. package/nitrogen/generated/shared/c++/HybridNativeListSpec.hpp +4 -0
  124. package/nitrogen/generated/shared/c++/views/HybridNativeListComponent.cpp +4 -0
  125. package/nitrogen/generated/shared/c++/views/HybridNativeListComponent.hpp +6 -0
  126. package/nitrogen/generated/shared/json/NativeListConfig.json +2 -0
  127. package/package.json +3 -3
  128. package/react-native-native-list.podspec +1 -0
  129. package/src/NativeList.nitro.ts +2 -0
  130. package/src/NativeList.tsx +418 -89
  131. package/src/NativeList.types.ts +34 -1
  132. package/src/NativeList.web.tsx +417 -66
  133. package/src/index.ts +2 -0
  134. package/src/models.ts +355 -143
  135. package/src/selection.ts +1 -0
  136. package/src/validation.ts +3315 -166
  137. package/src/web/NativeListWebEngine.ts +1473 -113
  138. package/src/web/templates/ActivityRowRenderer.ts +732 -8
  139. package/src/web/templates/ButtonGroupRowRenderer.ts +58 -0
  140. package/src/web/templates/DataRowRenderer.ts +93 -20
  141. package/src/web/templates/IdentityRowRenderer.ts +217 -6
  142. package/src/web/templates/MarketRowRenderer.ts +19 -3
  143. package/src/web/templates/MarketTableRowRenderer.ts +755 -0
  144. package/src/web/templates/MediaTileRowRenderer.ts +313 -5
  145. package/src/web/templates/MessageRowRenderer.ts +23 -7
  146. package/src/web/templates/RowContainerStyle.ts +2 -0
  147. package/src/web/templates/RowRendererRegistry.ts +21 -6
  148. package/src/web/templates/SectionHeaderRowRenderer.ts +89 -5
@@ -0,0 +1,755 @@
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
+ view.hover.parentElement
348
+ ?.querySelector('button')
349
+ ?.setAttribute('aria-label', cell.hoverActionLabel ?? 'Copy address');
350
+ for (const child of [...view.hover.children])
351
+ if (child !== button) child.remove();
352
+ for (const part of cell.hoverSecondary ?? [])
353
+ view.hover.insertBefore(textPart(document, part, true), button);
354
+ }
355
+ view.signature = signature;
356
+ return;
357
+ }
358
+ view.hoverVisuals?.forEach((visual) => primitives.dispose(visual));
359
+ view.hoverVisuals = [];
360
+ view.badgeVisuals?.forEach((visual) => primitives.dispose(visual));
361
+ view.badgeVisuals = [];
362
+ view.assetShape = assetShape;
363
+ view.title = undefined;
364
+ view.resting = undefined;
365
+ view.hover = undefined;
366
+ for (const child of [...element.children])
367
+ if (child !== view.visual) child.remove();
368
+ if (view.visual) element.appendChild(view.visual);
369
+ const text = createElement(document, 'span');
370
+ Object.assign(text.style, {
371
+ display: 'flex',
372
+ flexDirection: 'column',
373
+ gap: `${cell.lineGap ?? 4}px`,
374
+ minWidth: '0',
375
+ flex: '1',
376
+ });
377
+ const title = line(document, [cell.title], false);
378
+ view.title = title;
379
+ title.style.gap = '4px';
380
+ cell.badges?.forEach((badge, slot) => {
381
+ const node = createElement(
382
+ document,
383
+ badge.actionKey ? 'button' : 'span',
384
+ 'ok-native-list-market-badge',
385
+ badge.text
386
+ );
387
+ if (badge.actionKey)
388
+ action(
389
+ node,
390
+ badge.actionKey,
391
+ badge.accessibilityLabel ?? badge.text ?? '',
392
+ slot
393
+ );
394
+ node.style.color = badge.textColor ?? '';
395
+ node.style.backgroundColor = badge.backgroundColor ?? '';
396
+ if (badge.style)
397
+ Object.assign(node.style, {
398
+ fontSize: `${badge.style.fontSize ?? 11}px`,
399
+ fontWeight: String(
400
+ { regular: 400, medium: 500, semibold: 600, bold: 700 }[
401
+ badge.style.fontWeight ?? 'regular'
402
+ ]
403
+ ),
404
+ lineHeight: `${badge.style.lineHeight ?? 16}px`,
405
+ height: `${badge.style.height ?? 16}px`,
406
+ paddingInline: `${badge.style.horizontalPadding ?? 5}px`,
407
+ });
408
+ applyTextWeight(
409
+ node,
410
+ { regular: 400, medium: 500, semibold: 600, bold: 700 }[
411
+ badge.style?.fontWeight ?? 'regular'
412
+ ]
413
+ );
414
+ if (badge.actionKey) node.dataset.nativeListHoverAction = 'true';
415
+ if (badge.icon) {
416
+ const visual = primitives.visual({
417
+ kind: 'image',
418
+ image: badge.icon,
419
+ shape: 'circle',
420
+ });
421
+ if (visual) {
422
+ Object.assign(node.style, {
423
+ height: `${badge.icon.height}px`,
424
+ padding: '0',
425
+ background: 'transparent',
426
+ });
427
+ Object.assign(visual.style, {
428
+ width: `${badge.icon.width}px`,
429
+ height: `${badge.icon.height}px`,
430
+ flexBasis: `${badge.icon.width}px`,
431
+ });
432
+ for (const child of [...visual.children])
433
+ Object.assign((child as HTMLElement).style, {
434
+ width: '100%',
435
+ height: '100%',
436
+ });
437
+ node.appendChild(visual);
438
+ view.badgeVisuals!.push(visual);
439
+ }
440
+ }
441
+ if (badge.iconName === 'verified') {
442
+ Object.assign(node.style, {
443
+ height: '16px',
444
+ padding: '0',
445
+ background: 'transparent',
446
+ borderRadius: '0',
447
+ });
448
+ applyTextWeight(
449
+ node,
450
+ { regular: 400, medium: 500, semibold: 600, bold: 700 }[
451
+ badge.style?.fontWeight ?? 'regular'
452
+ ]
453
+ );
454
+ if (badge.actionKey) node.dataset.nativeListHoverAction = 'true';
455
+ node.textContent = '';
456
+ const svg = icon(
457
+ document,
458
+ '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',
459
+ 14
460
+ );
461
+ node.appendChild(svg);
462
+ }
463
+ title.appendChild(node);
464
+ });
465
+ text.appendChild(title);
466
+ if (cell.secondary?.length || cell.hoverSecondary?.length) {
467
+ const height =
468
+ cell.secondary?.[0]?.style?.lineHeight ??
469
+ cell.hoverSecondary?.[0]?.style?.lineHeight ??
470
+ 16;
471
+ const clip = createElement(
472
+ document,
473
+ 'span',
474
+ 'ok-native-list-table-secondary'
475
+ );
476
+ clip.style.height = `${height}px`;
477
+ const track = createElement(
478
+ document,
479
+ 'span',
480
+ 'ok-native-list-table-secondary-track'
481
+ );
482
+ track.style.setProperty('--nl-table-secondary-height', `${height}px`);
483
+ if (cell.secondary?.length) {
484
+ const resting = line(document, cell.secondary, true);
485
+ view.resting = resting;
486
+ resting.style.height = `${height}px`;
487
+ const restingFrame = createElement(document, 'span');
488
+ Object.assign(restingFrame.style, {
489
+ display: 'flex',
490
+ alignItems: 'center',
491
+ gap: '4px',
492
+ height: `${height}px`,
493
+ minWidth: '0',
494
+ });
495
+ cell.secondaryBadges?.forEach((badge) => {
496
+ const node = createElement(
497
+ document,
498
+ 'span',
499
+ 'ok-native-list-market-badge',
500
+ badge.text
501
+ );
502
+ Object.assign(node.style, {
503
+ fontSize: `${badge.style?.fontSize ?? 11}px`,
504
+ fontWeight: String(
505
+ { regular: 400, medium: 500, semibold: 600, bold: 700 }[
506
+ badge.style?.fontWeight ?? 'regular'
507
+ ]
508
+ ),
509
+ lineHeight: `${badge.style?.lineHeight ?? 12}px`,
510
+ height: `${badge.style?.height ?? 16}px`,
511
+ paddingInline: `${badge.style?.horizontalPadding ?? 4}px`,
512
+ });
513
+ applyTextWeight(
514
+ node,
515
+ { regular: 400, medium: 500, semibold: 600, bold: 700 }[
516
+ badge.style?.fontWeight ?? 'regular'
517
+ ]
518
+ );
519
+ restingFrame.appendChild(node);
520
+ });
521
+ restingFrame.appendChild(resting);
522
+ track.appendChild(restingFrame);
523
+ }
524
+ if (cell.hoverSecondary?.length) {
525
+ const hover = line(document, cell.hoverSecondary, true);
526
+ view.hover = hover;
527
+ hover.style.height = `${height}px`;
528
+ const hoverFrame = createElement(document, 'span');
529
+ Object.assign(hoverFrame.style, {
530
+ display: 'flex',
531
+ alignItems: 'center',
532
+ gap: cell.hoverActionKey ? '2px' : '4px',
533
+ height: `${height}px`,
534
+ minWidth: '0',
535
+ });
536
+ hoverFrame.appendChild(hover);
537
+ if (cell.hoverImages?.length) {
538
+ const group = createElement(document, 'span');
539
+ Object.assign(group.style, {
540
+ display: 'flex',
541
+ alignItems: 'center',
542
+ flexShrink: '0',
543
+ });
544
+ cell.hoverImages.forEach((image, i) => {
545
+ const visual = image
546
+ ? primitives.visual({ kind: 'image', image, shape: 'circle' })
547
+ : createElement(document, 'span', 'ok-native-list-visual');
548
+ if (visual) {
549
+ Object.assign(visual.style, {
550
+ width: '16px',
551
+ height: '16px',
552
+ flexBasis: '16px',
553
+ border: '1px solid var(--nl-row)',
554
+ boxSizing: 'border-box',
555
+ marginInlineEnd:
556
+ i === cell.hoverImages!.length - 1 ? '0' : '-4px',
557
+ zIndex: String(cell.hoverImages!.length - i),
558
+ overflow: 'hidden',
559
+ });
560
+ for (const child of [...visual.children])
561
+ Object.assign((child as HTMLElement).style, {
562
+ width: '100%',
563
+ height: '100%',
564
+ });
565
+ view.hoverVisuals!.push(visual);
566
+ group.appendChild(visual);
567
+ }
568
+ });
569
+ hoverFrame.appendChild(group);
570
+ }
571
+ if (cell.hoverActionKey) {
572
+ const button = createElement(document, 'button');
573
+ action(
574
+ button,
575
+ cell.hoverActionKey,
576
+ cell.hoverActionLabel ?? 'Copy address',
577
+ index
578
+ );
579
+ button.style.padding = '0';
580
+ button.style.color = 'var(--nl-icon-subdued)';
581
+ button.appendChild(
582
+ icon(
583
+ document,
584
+ 'M21 17h-4v4H3V7h4V3h14zM5 19h10V9H5zM9 7h8v8h2V5H9z',
585
+ 14
586
+ )
587
+ );
588
+ hoverFrame.appendChild(button);
589
+ }
590
+ track.appendChild(hoverFrame);
591
+ if (cell.secondary?.length) clip.dataset.hasHover = 'true';
592
+ }
593
+ clip.appendChild(track);
594
+ text.appendChild(clip);
595
+ }
596
+ element.appendChild(text);
597
+ } else if (cell.kind === 'favorite') {
598
+ const button =
599
+ element.querySelector('button') ?? createElement(document, 'button');
600
+ action(button, cell.actionKey, cell.accessibilityLabel, index);
601
+ button.setAttribute('aria-pressed', String(cell.active));
602
+ (button as HTMLButtonElement).disabled = !!cell.disabled;
603
+ button.removeAttribute('title');
604
+ if (cell.hoverActionKey)
605
+ button.dataset.nativeListHoverAction = cell.hoverActionKey;
606
+ else delete button.dataset.nativeListHoverAction;
607
+ if (cell.testID) button.dataset.testid = cell.testID;
608
+ else delete button.dataset.testid;
609
+ button.style.width = '24px';
610
+ button.style.height = '24px';
611
+ button.style.color = cell.active
612
+ ? 'var(--nl-accent)'
613
+ : 'var(--nl-icon-subdued)';
614
+ let svg = button.querySelector('svg');
615
+ if (!svg) {
616
+ svg = icon(document, cell.active ? solidStar : outlineStar, 16);
617
+ button.appendChild(svg);
618
+ }
619
+ svg
620
+ .querySelector('path')
621
+ ?.setAttribute('d', cell.active ? solidStar : outlineStar);
622
+ if (!button.parentElement) element.appendChild(button);
623
+ } else if (cell.kind === 'sparkline') drawSparkline(element, cell);
624
+ else {
625
+ element.replaceChildren();
626
+ const column = createElement(document, 'span');
627
+ Object.assign(column.style, {
628
+ display: 'flex',
629
+ flexDirection: 'column',
630
+ gap: '4px',
631
+ minWidth: '0',
632
+ width: '100%',
633
+ });
634
+ const primary = line(document, cell.primary, false);
635
+ primary.style.gap = `${cell.partGap ?? 2}px`;
636
+ column.appendChild(primary);
637
+ if (cell.secondary?.length)
638
+ column.appendChild(line(document, cell.secondary, true));
639
+ element.appendChild(column);
640
+ }
641
+ view.signature = signature;
642
+ }
643
+ function bind(body: HTMLElement, row: MarketRow, primitives: RowPrimitives) {
644
+ const state = views.get(body)!;
645
+ state.primitives = primitives;
646
+ const table = row.webTable!;
647
+ if (table.testID) body.dataset.testid = table.testID;
648
+ else delete body.dataset.testid;
649
+ const desired = new Set(table.columns.map((column) => column.key));
650
+ state.cells.forEach((view, key) => {
651
+ if (!desired.has(key)) {
652
+ view.hoverVisuals?.forEach((visual) => primitives.dispose(visual));
653
+ view.badgeVisuals?.forEach((visual) => primitives.dispose(visual));
654
+ if (view.visual) primitives.dispose(view.visual);
655
+ view.element.remove();
656
+ state.cells.delete(key);
657
+ }
658
+ });
659
+ table.columns.forEach((column, index) => {
660
+ const cell = table.cells[index];
661
+ let view = state.cells.get(column.key);
662
+ if (view?.kind !== cell.kind) {
663
+ view?.hoverVisuals?.forEach((visual) => primitives.dispose(visual));
664
+ view?.badgeVisuals?.forEach((visual) => primitives.dispose(visual));
665
+ if (view?.visual) primitives.dispose(view.visual);
666
+ view?.element.remove();
667
+ state.cells.delete(column.key);
668
+ view = undefined;
669
+ }
670
+ if (!view) {
671
+ view = {
672
+ element: createElement(
673
+ body.ownerDocument,
674
+ 'span',
675
+ 'ok-native-list-table-cell'
676
+ ),
677
+ kind: cell.kind,
678
+ signature: '',
679
+ };
680
+ view.element.dataset.columnKey = column.key;
681
+ state.cells.set(column.key, view);
682
+ }
683
+ const element = view.element;
684
+ Object.assign(element.style, {
685
+ display: 'flex',
686
+ boxSizing: 'border-box',
687
+ alignItems: 'center',
688
+ minWidth: `${column.minWidth ?? 0}px`,
689
+ width: column.width === undefined ? 'auto' : `${column.width}px`,
690
+ flex:
691
+ column.flex !== undefined
692
+ ? `${column.flex} 1 auto`
693
+ : column.width === undefined
694
+ ? '1 1 0px'
695
+ : `0 0 ${column.width}px`,
696
+ paddingInlineStart: `${column.paddingStart ?? 0}px`,
697
+ paddingInlineEnd: `${column.paddingEnd ?? 0}px`,
698
+ justifyContent:
699
+ column.alignment === 'end'
700
+ ? 'flex-end'
701
+ : column.alignment === 'center'
702
+ ? 'center'
703
+ : 'flex-start',
704
+ overflow: 'hidden',
705
+ height: '100%',
706
+ });
707
+ updateCell(view, cell, primitives, index);
708
+ body.appendChild(element);
709
+ });
710
+ }
711
+ function create(document: Document, row: MarketRow, primitives: RowPrimitives) {
712
+ const body = createElement(
713
+ document,
714
+ 'div',
715
+ 'ok-native-list-row ok-native-list-market-table'
716
+ );
717
+ body.dataset.nlRenderer = 'marketTable';
718
+ Object.assign(body.style, { gap: '0', padding: '0', borderRadius: '12px' });
719
+ views.set(body, { cells: new Map(), primitives });
720
+ bind(body, row, primitives);
721
+ return body;
722
+ }
723
+ export function updateMarketTableValues(element: HTMLElement, row: MarketRow) {
724
+ const body = element.querySelector<HTMLElement>(
725
+ '.ok-native-list-market-table'
726
+ );
727
+ const state = body ? views.get(body) : undefined;
728
+ if (!body || !state) return;
729
+ row.webTable!.cells.forEach((cell, index) => {
730
+ const view = state.cells.get(cell.key);
731
+ if (view) updateCell(view, cell, state.primitives, index);
732
+ });
733
+ element.setAttribute(
734
+ 'aria-label',
735
+ row.accessibilityLabel ?? [row.title, row.price, row.change.text].join(', ')
736
+ );
737
+ }
738
+ export const marketTableRowRenderer = {
739
+ key: 'marketTable',
740
+ appliesSizePreset: () => false,
741
+ create,
742
+ bind,
743
+ measure: () => 72,
744
+ measureRendered: () => undefined,
745
+ recycle: (body: HTMLElement) => {
746
+ const state = views.get(body);
747
+ state?.cells.forEach((view) => {
748
+ if (view.visual) state.primitives.dispose(view.visual);
749
+ view.hoverVisuals?.forEach((visual) => state.primitives.dispose(visual));
750
+ view.badgeVisuals?.forEach((visual) => state.primitives.dispose(visual));
751
+ });
752
+ state?.cells.clear();
753
+ body.replaceChildren();
754
+ },
755
+ };