@onekeyfe/react-native-native-list 6.7.0-alpha.327 → 6.7.0-alpha.335
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/SPEC.md +390 -9
- package/lib/module/NativeList.js +2 -0
- package/lib/module/NativeList.web.js +140 -29
- package/lib/module/validation.js +143 -34
- package/lib/module/web/NativeListWebEngine.js +356 -62
- package/lib/module/web/templates/ActivityRowRenderer.js +484 -5
- package/lib/module/web/templates/MarketRowRenderer.js +8 -3
- package/lib/module/web/templates/MarketTableRowRenderer.js +577 -0
- package/lib/module/web/templates/MediaTileRowRenderer.js +260 -5
- package/lib/module/web/templates/RowRendererRegistry.js +5 -3
- package/lib/module/web/templates/SectionHeaderRowRenderer.js +34 -1
- package/lib/typescript/src/NativeList.types.d.ts +11 -1
- package/lib/typescript/src/NativeList.web.d.ts +2 -2
- package/lib/typescript/src/models.d.ts +71 -1
- package/lib/typescript/src/web/NativeListWebEngine.d.ts +26 -1
- package/lib/typescript/src/web/templates/ActivityRowRenderer.d.ts +3 -3
- package/lib/typescript/src/web/templates/MarketTableRowRenderer.d.ts +17 -0
- package/lib/typescript/src/web/templates/MediaTileRowRenderer.d.ts +3 -3
- package/lib/typescript/src/web/templates/MessageRowRenderer.d.ts +1 -1
- package/lib/typescript/src/web/templates/RowRendererRegistry.d.ts +3 -1
- package/package.json +3 -3
- package/src/NativeList.tsx +2 -0
- package/src/NativeList.types.ts +12 -1
- package/src/NativeList.web.tsx +191 -38
- package/src/models.ts +93 -0
- package/src/validation.ts +348 -58
- package/src/web/NativeListWebEngine.ts +603 -95
- package/src/web/templates/ActivityRowRenderer.ts +723 -7
- package/src/web/templates/MarketRowRenderer.ts +19 -3
- package/src/web/templates/MarketTableRowRenderer.ts +755 -0
- package/src/web/templates/MediaTileRowRenderer.ts +313 -5
- package/src/web/templates/RowRendererRegistry.ts +10 -5
- package/src/web/templates/SectionHeaderRowRenderer.ts +42 -1
|
@@ -0,0 +1,577 @@
|
|
|
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
|
+
view.hover.parentElement?.querySelector('button')?.setAttribute('aria-label', cell.hoverActionLabel ?? 'Copy address');
|
|
243
|
+
for (const child of [...view.hover.children]) if (child !== button) child.remove();
|
|
244
|
+
for (const part of cell.hoverSecondary ?? []) view.hover.insertBefore(textPart(document, part, true), button);
|
|
245
|
+
}
|
|
246
|
+
view.signature = signature;
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
view.hoverVisuals?.forEach(visual => primitives.dispose(visual));
|
|
250
|
+
view.hoverVisuals = [];
|
|
251
|
+
view.badgeVisuals?.forEach(visual => primitives.dispose(visual));
|
|
252
|
+
view.badgeVisuals = [];
|
|
253
|
+
view.assetShape = assetShape;
|
|
254
|
+
view.title = undefined;
|
|
255
|
+
view.resting = undefined;
|
|
256
|
+
view.hover = undefined;
|
|
257
|
+
for (const child of [...element.children]) if (child !== view.visual) child.remove();
|
|
258
|
+
if (view.visual) element.appendChild(view.visual);
|
|
259
|
+
const text = createElement(document, 'span');
|
|
260
|
+
Object.assign(text.style, {
|
|
261
|
+
display: 'flex',
|
|
262
|
+
flexDirection: 'column',
|
|
263
|
+
gap: `${cell.lineGap ?? 4}px`,
|
|
264
|
+
minWidth: '0',
|
|
265
|
+
flex: '1'
|
|
266
|
+
});
|
|
267
|
+
const title = line(document, [cell.title], false);
|
|
268
|
+
view.title = title;
|
|
269
|
+
title.style.gap = '4px';
|
|
270
|
+
cell.badges?.forEach((badge, slot) => {
|
|
271
|
+
const node = createElement(document, badge.actionKey ? 'button' : 'span', 'ok-native-list-market-badge', badge.text);
|
|
272
|
+
if (badge.actionKey) action(node, badge.actionKey, badge.accessibilityLabel ?? badge.text ?? '', slot);
|
|
273
|
+
node.style.color = badge.textColor ?? '';
|
|
274
|
+
node.style.backgroundColor = badge.backgroundColor ?? '';
|
|
275
|
+
if (badge.style) Object.assign(node.style, {
|
|
276
|
+
fontSize: `${badge.style.fontSize ?? 11}px`,
|
|
277
|
+
fontWeight: String({
|
|
278
|
+
regular: 400,
|
|
279
|
+
medium: 500,
|
|
280
|
+
semibold: 600,
|
|
281
|
+
bold: 700
|
|
282
|
+
}[badge.style.fontWeight ?? 'regular']),
|
|
283
|
+
lineHeight: `${badge.style.lineHeight ?? 16}px`,
|
|
284
|
+
height: `${badge.style.height ?? 16}px`,
|
|
285
|
+
paddingInline: `${badge.style.horizontalPadding ?? 5}px`
|
|
286
|
+
});
|
|
287
|
+
applyTextWeight(node, {
|
|
288
|
+
regular: 400,
|
|
289
|
+
medium: 500,
|
|
290
|
+
semibold: 600,
|
|
291
|
+
bold: 700
|
|
292
|
+
}[badge.style?.fontWeight ?? 'regular']);
|
|
293
|
+
if (badge.actionKey) node.dataset.nativeListHoverAction = 'true';
|
|
294
|
+
if (badge.icon) {
|
|
295
|
+
const visual = primitives.visual({
|
|
296
|
+
kind: 'image',
|
|
297
|
+
image: badge.icon,
|
|
298
|
+
shape: 'circle'
|
|
299
|
+
});
|
|
300
|
+
if (visual) {
|
|
301
|
+
Object.assign(node.style, {
|
|
302
|
+
height: `${badge.icon.height}px`,
|
|
303
|
+
padding: '0',
|
|
304
|
+
background: 'transparent'
|
|
305
|
+
});
|
|
306
|
+
Object.assign(visual.style, {
|
|
307
|
+
width: `${badge.icon.width}px`,
|
|
308
|
+
height: `${badge.icon.height}px`,
|
|
309
|
+
flexBasis: `${badge.icon.width}px`
|
|
310
|
+
});
|
|
311
|
+
for (const child of [...visual.children]) Object.assign(child.style, {
|
|
312
|
+
width: '100%',
|
|
313
|
+
height: '100%'
|
|
314
|
+
});
|
|
315
|
+
node.appendChild(visual);
|
|
316
|
+
view.badgeVisuals.push(visual);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
if (badge.iconName === 'verified') {
|
|
320
|
+
Object.assign(node.style, {
|
|
321
|
+
height: '16px',
|
|
322
|
+
padding: '0',
|
|
323
|
+
background: 'transparent',
|
|
324
|
+
borderRadius: '0'
|
|
325
|
+
});
|
|
326
|
+
applyTextWeight(node, {
|
|
327
|
+
regular: 400,
|
|
328
|
+
medium: 500,
|
|
329
|
+
semibold: 600,
|
|
330
|
+
bold: 700
|
|
331
|
+
}[badge.style?.fontWeight ?? 'regular']);
|
|
332
|
+
if (badge.actionKey) node.dataset.nativeListHoverAction = 'true';
|
|
333
|
+
node.textContent = '';
|
|
334
|
+
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);
|
|
335
|
+
node.appendChild(svg);
|
|
336
|
+
}
|
|
337
|
+
title.appendChild(node);
|
|
338
|
+
});
|
|
339
|
+
text.appendChild(title);
|
|
340
|
+
if (cell.secondary?.length || cell.hoverSecondary?.length) {
|
|
341
|
+
const height = cell.secondary?.[0]?.style?.lineHeight ?? cell.hoverSecondary?.[0]?.style?.lineHeight ?? 16;
|
|
342
|
+
const clip = createElement(document, 'span', 'ok-native-list-table-secondary');
|
|
343
|
+
clip.style.height = `${height}px`;
|
|
344
|
+
const track = createElement(document, 'span', 'ok-native-list-table-secondary-track');
|
|
345
|
+
track.style.setProperty('--nl-table-secondary-height', `${height}px`);
|
|
346
|
+
if (cell.secondary?.length) {
|
|
347
|
+
const resting = line(document, cell.secondary, true);
|
|
348
|
+
view.resting = resting;
|
|
349
|
+
resting.style.height = `${height}px`;
|
|
350
|
+
const restingFrame = createElement(document, 'span');
|
|
351
|
+
Object.assign(restingFrame.style, {
|
|
352
|
+
display: 'flex',
|
|
353
|
+
alignItems: 'center',
|
|
354
|
+
gap: '4px',
|
|
355
|
+
height: `${height}px`,
|
|
356
|
+
minWidth: '0'
|
|
357
|
+
});
|
|
358
|
+
cell.secondaryBadges?.forEach(badge => {
|
|
359
|
+
const node = createElement(document, 'span', 'ok-native-list-market-badge', badge.text);
|
|
360
|
+
Object.assign(node.style, {
|
|
361
|
+
fontSize: `${badge.style?.fontSize ?? 11}px`,
|
|
362
|
+
fontWeight: String({
|
|
363
|
+
regular: 400,
|
|
364
|
+
medium: 500,
|
|
365
|
+
semibold: 600,
|
|
366
|
+
bold: 700
|
|
367
|
+
}[badge.style?.fontWeight ?? 'regular']),
|
|
368
|
+
lineHeight: `${badge.style?.lineHeight ?? 12}px`,
|
|
369
|
+
height: `${badge.style?.height ?? 16}px`,
|
|
370
|
+
paddingInline: `${badge.style?.horizontalPadding ?? 4}px`
|
|
371
|
+
});
|
|
372
|
+
applyTextWeight(node, {
|
|
373
|
+
regular: 400,
|
|
374
|
+
medium: 500,
|
|
375
|
+
semibold: 600,
|
|
376
|
+
bold: 700
|
|
377
|
+
}[badge.style?.fontWeight ?? 'regular']);
|
|
378
|
+
restingFrame.appendChild(node);
|
|
379
|
+
});
|
|
380
|
+
restingFrame.appendChild(resting);
|
|
381
|
+
track.appendChild(restingFrame);
|
|
382
|
+
}
|
|
383
|
+
if (cell.hoverSecondary?.length) {
|
|
384
|
+
const hover = line(document, cell.hoverSecondary, true);
|
|
385
|
+
view.hover = hover;
|
|
386
|
+
hover.style.height = `${height}px`;
|
|
387
|
+
const hoverFrame = createElement(document, 'span');
|
|
388
|
+
Object.assign(hoverFrame.style, {
|
|
389
|
+
display: 'flex',
|
|
390
|
+
alignItems: 'center',
|
|
391
|
+
gap: cell.hoverActionKey ? '2px' : '4px',
|
|
392
|
+
height: `${height}px`,
|
|
393
|
+
minWidth: '0'
|
|
394
|
+
});
|
|
395
|
+
hoverFrame.appendChild(hover);
|
|
396
|
+
if (cell.hoverImages?.length) {
|
|
397
|
+
const group = createElement(document, 'span');
|
|
398
|
+
Object.assign(group.style, {
|
|
399
|
+
display: 'flex',
|
|
400
|
+
alignItems: 'center',
|
|
401
|
+
flexShrink: '0'
|
|
402
|
+
});
|
|
403
|
+
cell.hoverImages.forEach((image, i) => {
|
|
404
|
+
const visual = image ? primitives.visual({
|
|
405
|
+
kind: 'image',
|
|
406
|
+
image,
|
|
407
|
+
shape: 'circle'
|
|
408
|
+
}) : createElement(document, 'span', 'ok-native-list-visual');
|
|
409
|
+
if (visual) {
|
|
410
|
+
Object.assign(visual.style, {
|
|
411
|
+
width: '16px',
|
|
412
|
+
height: '16px',
|
|
413
|
+
flexBasis: '16px',
|
|
414
|
+
border: '1px solid var(--nl-row)',
|
|
415
|
+
boxSizing: 'border-box',
|
|
416
|
+
marginInlineEnd: i === cell.hoverImages.length - 1 ? '0' : '-4px',
|
|
417
|
+
zIndex: String(cell.hoverImages.length - i),
|
|
418
|
+
overflow: 'hidden'
|
|
419
|
+
});
|
|
420
|
+
for (const child of [...visual.children]) Object.assign(child.style, {
|
|
421
|
+
width: '100%',
|
|
422
|
+
height: '100%'
|
|
423
|
+
});
|
|
424
|
+
view.hoverVisuals.push(visual);
|
|
425
|
+
group.appendChild(visual);
|
|
426
|
+
}
|
|
427
|
+
});
|
|
428
|
+
hoverFrame.appendChild(group);
|
|
429
|
+
}
|
|
430
|
+
if (cell.hoverActionKey) {
|
|
431
|
+
const button = createElement(document, 'button');
|
|
432
|
+
action(button, cell.hoverActionKey, cell.hoverActionLabel ?? 'Copy address', index);
|
|
433
|
+
button.style.padding = '0';
|
|
434
|
+
button.style.color = 'var(--nl-icon-subdued)';
|
|
435
|
+
button.appendChild(icon(document, 'M21 17h-4v4H3V7h4V3h14zM5 19h10V9H5zM9 7h8v8h2V5H9z', 14));
|
|
436
|
+
hoverFrame.appendChild(button);
|
|
437
|
+
}
|
|
438
|
+
track.appendChild(hoverFrame);
|
|
439
|
+
if (cell.secondary?.length) clip.dataset.hasHover = 'true';
|
|
440
|
+
}
|
|
441
|
+
clip.appendChild(track);
|
|
442
|
+
text.appendChild(clip);
|
|
443
|
+
}
|
|
444
|
+
element.appendChild(text);
|
|
445
|
+
} else if (cell.kind === 'favorite') {
|
|
446
|
+
const button = element.querySelector('button') ?? createElement(document, 'button');
|
|
447
|
+
action(button, cell.actionKey, cell.accessibilityLabel, index);
|
|
448
|
+
button.setAttribute('aria-pressed', String(cell.active));
|
|
449
|
+
button.disabled = !!cell.disabled;
|
|
450
|
+
button.removeAttribute('title');
|
|
451
|
+
if (cell.hoverActionKey) button.dataset.nativeListHoverAction = cell.hoverActionKey;else delete button.dataset.nativeListHoverAction;
|
|
452
|
+
if (cell.testID) button.dataset.testid = cell.testID;else delete button.dataset.testid;
|
|
453
|
+
button.style.width = '24px';
|
|
454
|
+
button.style.height = '24px';
|
|
455
|
+
button.style.color = cell.active ? 'var(--nl-accent)' : 'var(--nl-icon-subdued)';
|
|
456
|
+
let svg = button.querySelector('svg');
|
|
457
|
+
if (!svg) {
|
|
458
|
+
svg = icon(document, cell.active ? solidStar : outlineStar, 16);
|
|
459
|
+
button.appendChild(svg);
|
|
460
|
+
}
|
|
461
|
+
svg.querySelector('path')?.setAttribute('d', cell.active ? solidStar : outlineStar);
|
|
462
|
+
if (!button.parentElement) element.appendChild(button);
|
|
463
|
+
} else if (cell.kind === 'sparkline') drawSparkline(element, cell);else {
|
|
464
|
+
element.replaceChildren();
|
|
465
|
+
const column = createElement(document, 'span');
|
|
466
|
+
Object.assign(column.style, {
|
|
467
|
+
display: 'flex',
|
|
468
|
+
flexDirection: 'column',
|
|
469
|
+
gap: '4px',
|
|
470
|
+
minWidth: '0',
|
|
471
|
+
width: '100%'
|
|
472
|
+
});
|
|
473
|
+
const primary = line(document, cell.primary, false);
|
|
474
|
+
primary.style.gap = `${cell.partGap ?? 2}px`;
|
|
475
|
+
column.appendChild(primary);
|
|
476
|
+
if (cell.secondary?.length) column.appendChild(line(document, cell.secondary, true));
|
|
477
|
+
element.appendChild(column);
|
|
478
|
+
}
|
|
479
|
+
view.signature = signature;
|
|
480
|
+
}
|
|
481
|
+
function bind(body, row, primitives) {
|
|
482
|
+
const state = views.get(body);
|
|
483
|
+
state.primitives = primitives;
|
|
484
|
+
const table = row.webTable;
|
|
485
|
+
if (table.testID) body.dataset.testid = table.testID;else delete body.dataset.testid;
|
|
486
|
+
const desired = new Set(table.columns.map(column => column.key));
|
|
487
|
+
state.cells.forEach((view, key) => {
|
|
488
|
+
if (!desired.has(key)) {
|
|
489
|
+
view.hoverVisuals?.forEach(visual => primitives.dispose(visual));
|
|
490
|
+
view.badgeVisuals?.forEach(visual => primitives.dispose(visual));
|
|
491
|
+
if (view.visual) primitives.dispose(view.visual);
|
|
492
|
+
view.element.remove();
|
|
493
|
+
state.cells.delete(key);
|
|
494
|
+
}
|
|
495
|
+
});
|
|
496
|
+
table.columns.forEach((column, index) => {
|
|
497
|
+
const cell = table.cells[index];
|
|
498
|
+
let view = state.cells.get(column.key);
|
|
499
|
+
if (view?.kind !== cell.kind) {
|
|
500
|
+
view?.hoverVisuals?.forEach(visual => primitives.dispose(visual));
|
|
501
|
+
view?.badgeVisuals?.forEach(visual => primitives.dispose(visual));
|
|
502
|
+
if (view?.visual) primitives.dispose(view.visual);
|
|
503
|
+
view?.element.remove();
|
|
504
|
+
state.cells.delete(column.key);
|
|
505
|
+
view = undefined;
|
|
506
|
+
}
|
|
507
|
+
if (!view) {
|
|
508
|
+
view = {
|
|
509
|
+
element: createElement(body.ownerDocument, 'span', 'ok-native-list-table-cell'),
|
|
510
|
+
kind: cell.kind,
|
|
511
|
+
signature: ''
|
|
512
|
+
};
|
|
513
|
+
view.element.dataset.columnKey = column.key;
|
|
514
|
+
state.cells.set(column.key, view);
|
|
515
|
+
}
|
|
516
|
+
const element = view.element;
|
|
517
|
+
Object.assign(element.style, {
|
|
518
|
+
display: 'flex',
|
|
519
|
+
boxSizing: 'border-box',
|
|
520
|
+
alignItems: 'center',
|
|
521
|
+
minWidth: `${column.minWidth ?? 0}px`,
|
|
522
|
+
width: column.width === undefined ? 'auto' : `${column.width}px`,
|
|
523
|
+
flex: column.flex !== undefined ? `${column.flex} 1 auto` : column.width === undefined ? '1 1 0px' : `0 0 ${column.width}px`,
|
|
524
|
+
paddingInlineStart: `${column.paddingStart ?? 0}px`,
|
|
525
|
+
paddingInlineEnd: `${column.paddingEnd ?? 0}px`,
|
|
526
|
+
justifyContent: column.alignment === 'end' ? 'flex-end' : column.alignment === 'center' ? 'center' : 'flex-start',
|
|
527
|
+
overflow: 'hidden',
|
|
528
|
+
height: '100%'
|
|
529
|
+
});
|
|
530
|
+
updateCell(view, cell, primitives, index);
|
|
531
|
+
body.appendChild(element);
|
|
532
|
+
});
|
|
533
|
+
}
|
|
534
|
+
function create(document, row, primitives) {
|
|
535
|
+
const body = createElement(document, 'div', 'ok-native-list-row ok-native-list-market-table');
|
|
536
|
+
body.dataset.nlRenderer = 'marketTable';
|
|
537
|
+
Object.assign(body.style, {
|
|
538
|
+
gap: '0',
|
|
539
|
+
padding: '0',
|
|
540
|
+
borderRadius: '12px'
|
|
541
|
+
});
|
|
542
|
+
views.set(body, {
|
|
543
|
+
cells: new Map(),
|
|
544
|
+
primitives
|
|
545
|
+
});
|
|
546
|
+
bind(body, row, primitives);
|
|
547
|
+
return body;
|
|
548
|
+
}
|
|
549
|
+
export function updateMarketTableValues(element, row) {
|
|
550
|
+
const body = element.querySelector('.ok-native-list-market-table');
|
|
551
|
+
const state = body ? views.get(body) : undefined;
|
|
552
|
+
if (!body || !state) return;
|
|
553
|
+
row.webTable.cells.forEach((cell, index) => {
|
|
554
|
+
const view = state.cells.get(cell.key);
|
|
555
|
+
if (view) updateCell(view, cell, state.primitives, index);
|
|
556
|
+
});
|
|
557
|
+
element.setAttribute('aria-label', row.accessibilityLabel ?? [row.title, row.price, row.change.text].join(', '));
|
|
558
|
+
}
|
|
559
|
+
export const marketTableRowRenderer = {
|
|
560
|
+
key: 'marketTable',
|
|
561
|
+
appliesSizePreset: () => false,
|
|
562
|
+
create,
|
|
563
|
+
bind,
|
|
564
|
+
measure: () => 72,
|
|
565
|
+
measureRendered: () => undefined,
|
|
566
|
+
recycle: body => {
|
|
567
|
+
const state = views.get(body);
|
|
568
|
+
state?.cells.forEach(view => {
|
|
569
|
+
if (view.visual) state.primitives.dispose(view.visual);
|
|
570
|
+
view.hoverVisuals?.forEach(visual => state.primitives.dispose(visual));
|
|
571
|
+
view.badgeVisuals?.forEach(visual => state.primitives.dispose(visual));
|
|
572
|
+
});
|
|
573
|
+
state?.cells.clear();
|
|
574
|
+
body.replaceChildren();
|
|
575
|
+
}
|
|
576
|
+
};
|
|
577
|
+
//# sourceMappingURL=MarketTableRowRenderer.js.map
|