@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,576 @@
1
+ "use strict";
2
+
3
+ import { createElement, markActionAnchorSource } from "./RowElements.js";
4
+ import { applyTextWeight, applyValueSegments } from "./RowText.js";
5
+ const views = new WeakMap();
6
+ const columnSignatures = new WeakMap();
7
+ let sparklineId = 0;
8
+ const svgNamespace = 'http://www.w3.org/2000/svg';
9
+ const outlineStar = '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';
10
+ const solidStar = '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';
11
+ function columnsSignature(columns) {
12
+ let signature = columnSignatures.get(columns);
13
+ if (signature === undefined) {
14
+ signature = JSON.stringify(columns);
15
+ columnSignatures.set(columns, signature);
16
+ }
17
+ return signature;
18
+ }
19
+ function semanticCellShape(cell) {
20
+ if (cell.kind === 'asset') return {
21
+ key: cell.key,
22
+ kind: cell.kind,
23
+ leading: cell.leading,
24
+ badges: cell.badges,
25
+ hoverActionKey: cell.hoverActionKey,
26
+ lineGap: cell.lineGap,
27
+ secondaryBadges: cell.secondaryBadges,
28
+ hoverImages: cell.hoverImages,
29
+ primaryStyle: cell.title.style,
30
+ secondaryStyle: cell.secondary?.map(value => value.style),
31
+ hover: cell.hoverSecondary
32
+ };
33
+ if (cell.kind === 'favorite') return {
34
+ key: cell.key,
35
+ kind: cell.kind,
36
+ actionKey: cell.actionKey,
37
+ hoverActionKey: cell.hoverActionKey
38
+ };
39
+ if (cell.kind === 'sparkline') return {
40
+ key: cell.key,
41
+ kind: cell.kind,
42
+ width: cell.width,
43
+ height: cell.height
44
+ };
45
+ return {
46
+ key: cell.key,
47
+ kind: cell.kind,
48
+ partGap: cell.partGap,
49
+ primary: cell.primary.map(value => value.style),
50
+ secondary: cell.secondary?.map(value => value.style)
51
+ };
52
+ }
53
+ export function canPatchMarketTableValues(previous, next) {
54
+ const a = previous.webTable,
55
+ b = next.webTable;
56
+ return !!a && !!b && a.testID === b.testID && a.draggable === b.draggable && a.contextMenuActionKey === b.contextMenuActionKey && previous.height === next.height && previous.style === next.style && columnsSignature(a.columns) === columnsSignature(b.columns) && a.cells.length === b.cells.length && a.cells.every((cell, index) => JSON.stringify(semanticCellShape(cell)) === JSON.stringify(semanticCellShape(b.cells[index])));
57
+ }
58
+ function tone(value, secondary) {
59
+ return value === 'positive' ? 'var(--nl-positive)' : value === 'negative' ? 'var(--nl-negative)' : value === 'secondary' || value === undefined && secondary ? 'var(--nl-secondary)' : 'var(--nl-primary)';
60
+ }
61
+ function textPart(document, part, secondary) {
62
+ const element = createElement(document, 'span', undefined, part.text);
63
+ const size = part.style?.fontSize ?? (secondary ? 12 : 16),
64
+ height = part.style?.lineHeight ?? (secondary ? 16 : 24);
65
+ const weight = {
66
+ regular: 400,
67
+ medium: 500,
68
+ semibold: 600,
69
+ bold: 700
70
+ }[part.style?.fontWeight ?? (secondary ? 'regular' : 'medium')];
71
+ Object.assign(element.style, {
72
+ fontSize: `${size}px`,
73
+ lineHeight: `${height}px`,
74
+ fontWeight: String(weight),
75
+ color: part.style?.color ?? tone(part.tone, secondary),
76
+ minWidth: '0',
77
+ overflow: 'hidden',
78
+ textOverflow: 'ellipsis',
79
+ whiteSpace: 'nowrap'
80
+ });
81
+ applyTextWeight(element, weight);
82
+ if (part.segments?.length) applyValueSegments(element, part.segments, size, height, weight);
83
+ return element;
84
+ }
85
+ function line(document, parts, secondary, className) {
86
+ const element = createElement(document, 'span', className);
87
+ Object.assign(element.style, {
88
+ display: 'flex',
89
+ gap: '2px',
90
+ alignItems: 'center',
91
+ minWidth: '0',
92
+ overflow: 'hidden',
93
+ height: secondary ? '16px' : '24px',
94
+ flexShrink: '0'
95
+ });
96
+ parts?.forEach(part => element.appendChild(textPart(document, part, secondary)));
97
+ return element;
98
+ }
99
+ function action(element, key, label, slot) {
100
+ element.dataset.nativeListAction = key;
101
+ markActionAnchorSource(element, 'leadingAction', slot);
102
+ element.setAttribute('aria-label', label);
103
+ element.setAttribute('type', 'button');
104
+ Object.assign(element.style, {
105
+ border: '0',
106
+ padding: '4px',
107
+ background: 'transparent',
108
+ font: 'inherit',
109
+ display: 'inline-flex',
110
+ alignItems: 'center',
111
+ justifyContent: 'center',
112
+ cursor: 'pointer',
113
+ flexShrink: '0'
114
+ });
115
+ }
116
+ function icon(document, d, size) {
117
+ const svg = document.createElementNS(svgNamespace, 'svg');
118
+ svg.setAttribute('viewBox', '0 0 24 24');
119
+ svg.setAttribute('width', String(size));
120
+ svg.setAttribute('height', String(size));
121
+ svg.setAttribute('aria-hidden', 'true');
122
+ svg.setAttribute('fill', 'currentColor');
123
+ const path = document.createElementNS(svgNamespace, 'path');
124
+ path.setAttribute('d', d);
125
+ path.setAttribute('fill-rule', 'evenodd');
126
+ svg.appendChild(path);
127
+ return svg;
128
+ }
129
+ function drawSparkline(element, cell) {
130
+ element.replaceChildren();
131
+ if (cell.points.length < 2) return;
132
+ const svg = element.ownerDocument.createElementNS(svgNamespace, 'svg');
133
+ svg.setAttribute('width', String(cell.width));
134
+ svg.setAttribute('height', String(cell.height));
135
+ svg.setAttribute('viewBox', `0 0 ${cell.width} ${cell.height}`);
136
+ svg.setAttribute('aria-hidden', 'true');
137
+ const min = Math.min(...cell.points),
138
+ max = Math.max(...cell.points),
139
+ height = cell.height - 5,
140
+ step = cell.width / (cell.points.length - 1);
141
+ const y = value => max === min ? height / 2 : height - (value - min) * height / (max - min);
142
+ let d = '';
143
+ cell.points.forEach((point, index) => {
144
+ const x = index * step,
145
+ py = y(point);
146
+ if (index === 0) d = `M0 ${py}`;else if (index >= 2 && index < cell.points.length - 1) {
147
+ const previousX = (index - 1) * step,
148
+ previousY = y(cell.points[index - 1]),
149
+ beforeX = (index - 2) * step,
150
+ beforeY = y(cell.points[index - 2]),
151
+ nextX = (index + 1) * step,
152
+ nextY = y(cell.points[index + 1]);
153
+ d += ` C${previousX + (x - beforeX) * 0.1} ${Math.max(0, previousY + (py - beforeY) * 0.1)} ${x - (nextX - previousX) * 0.1} ${Math.max(0, py - (nextY - previousY) * 0.1)} ${x} ${py}`;
154
+ } else d += ` L${x} ${py}`;
155
+ });
156
+ const id = `nl-sparkline-${++sparklineId}`,
157
+ clipId = id + '-clip';
158
+ const defs = element.ownerDocument.createElementNS(svgNamespace, 'defs'),
159
+ gradient = element.ownerDocument.createElementNS(svgNamespace, 'linearGradient');
160
+ gradient.id = id;
161
+ gradient.setAttribute('gradientUnits', 'userSpaceOnUse');
162
+ gradient.setAttribute('x1', '0');
163
+ gradient.setAttribute('y1', '0');
164
+ gradient.setAttribute('x2', '0');
165
+ gradient.setAttribute('y2', String(height));
166
+ const start = element.ownerDocument.createElementNS(svgNamespace, 'stop');
167
+ start.setAttribute('offset', '0');
168
+ start.setAttribute('stop-color', cell.fillColor);
169
+ const end = element.ownerDocument.createElementNS(svgNamespace, 'stop');
170
+ end.setAttribute('offset', '1');
171
+ end.setAttribute('stop-color', cell.fillColor);
172
+ end.setAttribute('stop-opacity', '0');
173
+ gradient.append(start, end);
174
+ defs.appendChild(gradient);
175
+ const clip = element.ownerDocument.createElementNS(svgNamespace, 'clipPath');
176
+ clip.id = clipId;
177
+ const rect = element.ownerDocument.createElementNS(svgNamespace, 'rect');
178
+ rect.setAttribute('width', String(cell.width));
179
+ rect.setAttribute('height', String(cell.height - 1));
180
+ clip.appendChild(rect);
181
+ defs.appendChild(clip);
182
+ svg.appendChild(defs);
183
+ const outline = `${d} L${cell.width + step * 2} ${y(cell.points[cell.points.length - 1])} L${cell.width + step * 2} ${cell.height} L0 ${cell.height}`;
184
+ const group = element.ownerDocument.createElementNS(svgNamespace, 'g');
185
+ group.setAttribute('clip-path', `url(#${clipId})`);
186
+ const fill = element.ownerDocument.createElementNS(svgNamespace, 'path');
187
+ fill.setAttribute('d', outline + ' Z');
188
+ fill.setAttribute('fill', `url(#${id})`);
189
+ const stroke = element.ownerDocument.createElementNS(svgNamespace, 'path');
190
+ stroke.setAttribute('d', outline);
191
+ stroke.setAttribute('stroke', cell.strokeColor);
192
+ stroke.setAttribute('stroke-width', '1');
193
+ stroke.setAttribute('fill', 'none');
194
+ group.append(fill, stroke);
195
+ svg.appendChild(group);
196
+ element.appendChild(svg);
197
+ }
198
+ function updateCell(view, cell, primitives, index) {
199
+ const signature = JSON.stringify(cell);
200
+ if (view.signature === signature) return;
201
+ const element = view.element,
202
+ document = element.ownerDocument;
203
+ if (cell.kind === 'asset') {
204
+ const visualKey = JSON.stringify(cell.leading);
205
+ if (view.visualKey !== visualKey) {
206
+ if (view.visual) {
207
+ primitives.dispose(view.visual);
208
+ view.visual.remove();
209
+ }
210
+ view.visual = primitives.visual(cell.leading);
211
+ view.visualKey = visualKey;
212
+ if (view.visual) Object.assign(view.visual.style, {
213
+ width: '40px',
214
+ height: '40px',
215
+ flexBasis: '40px',
216
+ flexShrink: '0',
217
+ marginInlineEnd: '14px',
218
+ boxSizing: 'border-box',
219
+ border: cell.leading && 'borderColor' in cell.leading && cell.leading.borderColor ? `1px solid ${cell.leading.borderColor}` : '0'
220
+ });
221
+ if (view.visual) {
222
+ if (cell.leading && 'backgroundColor' in cell.leading && cell.leading.backgroundColor) view.visual.style.background = cell.leading.backgroundColor;
223
+ for (const child of [...view.visual.children]) {
224
+ if (child.classList.contains('ok-native-list-visual-main')) Object.assign(child.style, {
225
+ width: '100%',
226
+ height: '100%'
227
+ });
228
+ if (child.classList.contains('ok-native-list-visual-overlay') && cell.leading && 'borderColor' in cell.leading && cell.leading.borderColor) {
229
+ const style = child.style;
230
+ for (const edge of ['left', 'right', 'top', 'bottom']) if (style[edge]) style[edge] = `${Number.parseFloat(style[edge]) - 1}px`;
231
+ }
232
+ }
233
+ }
234
+ }
235
+ const assetShape = JSON.stringify(semanticCellShape(cell));
236
+ if (view.title && view.assetShape === assetShape) {
237
+ const primary = textPart(document, cell.title, false);
238
+ view.title.firstElementChild?.replaceWith(primary);
239
+ view.resting?.replaceChildren(...(cell.secondary ?? []).map(part => textPart(document, part, true)));
240
+ if (view.hover) {
241
+ const button = view.hover.querySelector('button');
242
+ for (const child of [...view.hover.children]) if (child !== button) child.remove();
243
+ for (const part of cell.hoverSecondary ?? []) view.hover.insertBefore(textPart(document, part, true), button);
244
+ }
245
+ view.signature = signature;
246
+ return;
247
+ }
248
+ view.hoverVisuals?.forEach(visual => primitives.dispose(visual));
249
+ view.hoverVisuals = [];
250
+ view.badgeVisuals?.forEach(visual => primitives.dispose(visual));
251
+ view.badgeVisuals = [];
252
+ view.assetShape = assetShape;
253
+ view.title = undefined;
254
+ view.resting = undefined;
255
+ view.hover = undefined;
256
+ for (const child of [...element.children]) if (child !== view.visual) child.remove();
257
+ if (view.visual) element.appendChild(view.visual);
258
+ const text = createElement(document, 'span');
259
+ Object.assign(text.style, {
260
+ display: 'flex',
261
+ flexDirection: 'column',
262
+ gap: `${cell.lineGap ?? 4}px`,
263
+ minWidth: '0',
264
+ flex: '1'
265
+ });
266
+ const title = line(document, [cell.title], false);
267
+ view.title = title;
268
+ title.style.gap = '4px';
269
+ cell.badges?.forEach((badge, slot) => {
270
+ const node = createElement(document, badge.actionKey ? 'button' : 'span', 'ok-native-list-market-badge', badge.text);
271
+ if (badge.actionKey) action(node, badge.actionKey, badge.accessibilityLabel ?? badge.text ?? '', slot);
272
+ node.style.color = badge.textColor ?? '';
273
+ node.style.backgroundColor = badge.backgroundColor ?? '';
274
+ if (badge.style) Object.assign(node.style, {
275
+ fontSize: `${badge.style.fontSize ?? 11}px`,
276
+ fontWeight: String({
277
+ regular: 400,
278
+ medium: 500,
279
+ semibold: 600,
280
+ bold: 700
281
+ }[badge.style.fontWeight ?? 'regular']),
282
+ lineHeight: `${badge.style.lineHeight ?? 16}px`,
283
+ height: `${badge.style.height ?? 16}px`,
284
+ paddingInline: `${badge.style.horizontalPadding ?? 5}px`
285
+ });
286
+ applyTextWeight(node, {
287
+ regular: 400,
288
+ medium: 500,
289
+ semibold: 600,
290
+ bold: 700
291
+ }[badge.style?.fontWeight ?? 'regular']);
292
+ if (badge.actionKey) node.dataset.nativeListHoverAction = 'true';
293
+ if (badge.icon) {
294
+ const visual = primitives.visual({
295
+ kind: 'image',
296
+ image: badge.icon,
297
+ shape: 'circle'
298
+ });
299
+ if (visual) {
300
+ Object.assign(node.style, {
301
+ height: `${badge.icon.height}px`,
302
+ padding: '0',
303
+ background: 'transparent'
304
+ });
305
+ Object.assign(visual.style, {
306
+ width: `${badge.icon.width}px`,
307
+ height: `${badge.icon.height}px`,
308
+ flexBasis: `${badge.icon.width}px`
309
+ });
310
+ for (const child of [...visual.children]) Object.assign(child.style, {
311
+ width: '100%',
312
+ height: '100%'
313
+ });
314
+ node.appendChild(visual);
315
+ view.badgeVisuals.push(visual);
316
+ }
317
+ }
318
+ if (badge.iconName === 'verified') {
319
+ Object.assign(node.style, {
320
+ height: '16px',
321
+ padding: '0',
322
+ background: 'transparent',
323
+ borderRadius: '0'
324
+ });
325
+ applyTextWeight(node, {
326
+ regular: 400,
327
+ medium: 500,
328
+ semibold: 600,
329
+ bold: 700
330
+ }[badge.style?.fontWeight ?? 'regular']);
331
+ if (badge.actionKey) node.dataset.nativeListHoverAction = 'true';
332
+ node.textContent = '';
333
+ const svg = icon(document, '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', 14);
334
+ node.appendChild(svg);
335
+ }
336
+ title.appendChild(node);
337
+ });
338
+ text.appendChild(title);
339
+ if (cell.secondary?.length || cell.hoverSecondary?.length) {
340
+ const height = cell.secondary?.[0]?.style?.lineHeight ?? cell.hoverSecondary?.[0]?.style?.lineHeight ?? 16;
341
+ const clip = createElement(document, 'span', 'ok-native-list-table-secondary');
342
+ clip.style.height = `${height}px`;
343
+ const track = createElement(document, 'span', 'ok-native-list-table-secondary-track');
344
+ track.style.setProperty('--nl-table-secondary-height', `${height}px`);
345
+ if (cell.secondary?.length) {
346
+ const resting = line(document, cell.secondary, true);
347
+ view.resting = resting;
348
+ resting.style.height = `${height}px`;
349
+ const restingFrame = createElement(document, 'span');
350
+ Object.assign(restingFrame.style, {
351
+ display: 'flex',
352
+ alignItems: 'center',
353
+ gap: '4px',
354
+ height: `${height}px`,
355
+ minWidth: '0'
356
+ });
357
+ cell.secondaryBadges?.forEach(badge => {
358
+ const node = createElement(document, 'span', 'ok-native-list-market-badge', badge.text);
359
+ Object.assign(node.style, {
360
+ fontSize: `${badge.style?.fontSize ?? 11}px`,
361
+ fontWeight: String({
362
+ regular: 400,
363
+ medium: 500,
364
+ semibold: 600,
365
+ bold: 700
366
+ }[badge.style?.fontWeight ?? 'regular']),
367
+ lineHeight: `${badge.style?.lineHeight ?? 12}px`,
368
+ height: `${badge.style?.height ?? 16}px`,
369
+ paddingInline: `${badge.style?.horizontalPadding ?? 4}px`
370
+ });
371
+ applyTextWeight(node, {
372
+ regular: 400,
373
+ medium: 500,
374
+ semibold: 600,
375
+ bold: 700
376
+ }[badge.style?.fontWeight ?? 'regular']);
377
+ restingFrame.appendChild(node);
378
+ });
379
+ restingFrame.appendChild(resting);
380
+ track.appendChild(restingFrame);
381
+ }
382
+ if (cell.hoverSecondary?.length) {
383
+ const hover = line(document, cell.hoverSecondary, true);
384
+ view.hover = hover;
385
+ hover.style.height = `${height}px`;
386
+ const hoverFrame = createElement(document, 'span');
387
+ Object.assign(hoverFrame.style, {
388
+ display: 'flex',
389
+ alignItems: 'center',
390
+ gap: cell.hoverActionKey ? '2px' : '4px',
391
+ height: `${height}px`,
392
+ minWidth: '0'
393
+ });
394
+ hoverFrame.appendChild(hover);
395
+ if (cell.hoverImages?.length) {
396
+ const group = createElement(document, 'span');
397
+ Object.assign(group.style, {
398
+ display: 'flex',
399
+ alignItems: 'center',
400
+ flexShrink: '0'
401
+ });
402
+ cell.hoverImages.forEach((image, i) => {
403
+ const visual = image ? primitives.visual({
404
+ kind: 'image',
405
+ image,
406
+ shape: 'circle'
407
+ }) : createElement(document, 'span', 'ok-native-list-visual');
408
+ if (visual) {
409
+ Object.assign(visual.style, {
410
+ width: '16px',
411
+ height: '16px',
412
+ flexBasis: '16px',
413
+ border: '1px solid var(--nl-row)',
414
+ boxSizing: 'border-box',
415
+ marginInlineEnd: i === cell.hoverImages.length - 1 ? '0' : '-4px',
416
+ zIndex: String(cell.hoverImages.length - i),
417
+ overflow: 'hidden'
418
+ });
419
+ for (const child of [...visual.children]) Object.assign(child.style, {
420
+ width: '100%',
421
+ height: '100%'
422
+ });
423
+ view.hoverVisuals.push(visual);
424
+ group.appendChild(visual);
425
+ }
426
+ });
427
+ hoverFrame.appendChild(group);
428
+ }
429
+ if (cell.hoverActionKey) {
430
+ const button = createElement(document, 'button');
431
+ action(button, cell.hoverActionKey, cell.hoverActionLabel ?? 'Copy address', index);
432
+ button.style.padding = '0';
433
+ button.style.color = 'var(--nl-icon-subdued)';
434
+ button.appendChild(icon(document, 'M21 17h-4v4H3V7h4V3h14zM5 19h10V9H5zM9 7h8v8h2V5H9z', 14));
435
+ hoverFrame.appendChild(button);
436
+ }
437
+ track.appendChild(hoverFrame);
438
+ if (cell.secondary?.length) clip.dataset.hasHover = 'true';
439
+ }
440
+ clip.appendChild(track);
441
+ text.appendChild(clip);
442
+ }
443
+ element.appendChild(text);
444
+ } else if (cell.kind === 'favorite') {
445
+ const button = element.querySelector('button') ?? createElement(document, 'button');
446
+ action(button, cell.actionKey, cell.accessibilityLabel, index);
447
+ button.setAttribute('aria-pressed', String(cell.active));
448
+ button.disabled = !!cell.disabled;
449
+ button.removeAttribute('title');
450
+ if (cell.hoverActionKey) button.dataset.nativeListHoverAction = cell.hoverActionKey;else delete button.dataset.nativeListHoverAction;
451
+ if (cell.testID) button.dataset.testid = cell.testID;else delete button.dataset.testid;
452
+ button.style.width = '24px';
453
+ button.style.height = '24px';
454
+ button.style.color = cell.active ? 'var(--nl-accent)' : 'var(--nl-icon-subdued)';
455
+ let svg = button.querySelector('svg');
456
+ if (!svg) {
457
+ svg = icon(document, cell.active ? solidStar : outlineStar, 16);
458
+ button.appendChild(svg);
459
+ }
460
+ svg.querySelector('path')?.setAttribute('d', cell.active ? solidStar : outlineStar);
461
+ if (!button.parentElement) element.appendChild(button);
462
+ } else if (cell.kind === 'sparkline') drawSparkline(element, cell);else {
463
+ element.replaceChildren();
464
+ const column = createElement(document, 'span');
465
+ Object.assign(column.style, {
466
+ display: 'flex',
467
+ flexDirection: 'column',
468
+ gap: '4px',
469
+ minWidth: '0',
470
+ width: '100%'
471
+ });
472
+ const primary = line(document, cell.primary, false);
473
+ primary.style.gap = `${cell.partGap ?? 2}px`;
474
+ column.appendChild(primary);
475
+ if (cell.secondary?.length) column.appendChild(line(document, cell.secondary, true));
476
+ element.appendChild(column);
477
+ }
478
+ view.signature = signature;
479
+ }
480
+ function bind(body, row, primitives) {
481
+ const state = views.get(body);
482
+ state.primitives = primitives;
483
+ const table = row.webTable;
484
+ if (table.testID) body.dataset.testid = table.testID;else delete body.dataset.testid;
485
+ const desired = new Set(table.columns.map(column => column.key));
486
+ state.cells.forEach((view, key) => {
487
+ if (!desired.has(key)) {
488
+ view.hoverVisuals?.forEach(visual => primitives.dispose(visual));
489
+ view.badgeVisuals?.forEach(visual => primitives.dispose(visual));
490
+ if (view.visual) primitives.dispose(view.visual);
491
+ view.element.remove();
492
+ state.cells.delete(key);
493
+ }
494
+ });
495
+ table.columns.forEach((column, index) => {
496
+ const cell = table.cells[index];
497
+ let view = state.cells.get(column.key);
498
+ if (view?.kind !== cell.kind) {
499
+ view?.hoverVisuals?.forEach(visual => primitives.dispose(visual));
500
+ view?.badgeVisuals?.forEach(visual => primitives.dispose(visual));
501
+ if (view?.visual) primitives.dispose(view.visual);
502
+ view?.element.remove();
503
+ state.cells.delete(column.key);
504
+ view = undefined;
505
+ }
506
+ if (!view) {
507
+ view = {
508
+ element: createElement(body.ownerDocument, 'span', 'ok-native-list-table-cell'),
509
+ kind: cell.kind,
510
+ signature: ''
511
+ };
512
+ view.element.dataset.columnKey = column.key;
513
+ state.cells.set(column.key, view);
514
+ }
515
+ const element = view.element;
516
+ Object.assign(element.style, {
517
+ display: 'flex',
518
+ boxSizing: 'border-box',
519
+ alignItems: 'center',
520
+ minWidth: `${column.minWidth ?? 0}px`,
521
+ width: column.width === undefined ? 'auto' : `${column.width}px`,
522
+ flex: column.flex !== undefined ? `${column.flex} 1 auto` : column.width === undefined ? '1 1 0px' : `0 0 ${column.width}px`,
523
+ paddingInlineStart: `${column.paddingStart ?? 0}px`,
524
+ paddingInlineEnd: `${column.paddingEnd ?? 0}px`,
525
+ justifyContent: column.alignment === 'end' ? 'flex-end' : column.alignment === 'center' ? 'center' : 'flex-start',
526
+ overflow: 'hidden',
527
+ height: '100%'
528
+ });
529
+ updateCell(view, cell, primitives, index);
530
+ body.appendChild(element);
531
+ });
532
+ }
533
+ function create(document, row, primitives) {
534
+ const body = createElement(document, 'div', 'ok-native-list-row ok-native-list-market-table');
535
+ body.dataset.nlRenderer = 'marketTable';
536
+ Object.assign(body.style, {
537
+ gap: '0',
538
+ padding: '0',
539
+ borderRadius: '12px'
540
+ });
541
+ views.set(body, {
542
+ cells: new Map(),
543
+ primitives
544
+ });
545
+ bind(body, row, primitives);
546
+ return body;
547
+ }
548
+ export function updateMarketTableValues(element, row) {
549
+ const body = element.querySelector('.ok-native-list-market-table');
550
+ const state = body ? views.get(body) : undefined;
551
+ if (!body || !state) return;
552
+ row.webTable.cells.forEach((cell, index) => {
553
+ const view = state.cells.get(cell.key);
554
+ if (view) updateCell(view, cell, state.primitives, index);
555
+ });
556
+ element.setAttribute('aria-label', row.accessibilityLabel ?? [row.title, row.price, row.change.text].join(', '));
557
+ }
558
+ export const marketTableRowRenderer = {
559
+ key: 'marketTable',
560
+ appliesSizePreset: () => false,
561
+ create,
562
+ bind,
563
+ measure: () => 72,
564
+ measureRendered: () => undefined,
565
+ recycle: body => {
566
+ const state = views.get(body);
567
+ state?.cells.forEach(view => {
568
+ if (view.visual) state.primitives.dispose(view.visual);
569
+ view.hoverVisuals?.forEach(visual => state.primitives.dispose(visual));
570
+ view.badgeVisuals?.forEach(visual => state.primitives.dispose(visual));
571
+ });
572
+ state?.cells.clear();
573
+ body.replaceChildren();
574
+ }
575
+ };
576
+ //# sourceMappingURL=MarketTableRowRenderer.js.map