@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.
- package/docs/SPEC.md +365 -9
- package/lib/module/NativeList.js +2 -0
- package/lib/module/NativeList.web.js +135 -29
- package/lib/module/validation.js +143 -34
- package/lib/module/web/NativeListWebEngine.js +353 -62
- package/lib/module/web/templates/ActivityRowRenderer.js +432 -5
- package/lib/module/web/templates/MarketRowRenderer.js +8 -3
- package/lib/module/web/templates/MarketTableRowRenderer.js +576 -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 +183 -38
- package/src/models.ts +93 -0
- package/src/validation.ts +348 -58
- package/src/web/NativeListWebEngine.ts +600 -95
- package/src/web/templates/ActivityRowRenderer.ts +656 -7
- package/src/web/templates/MarketRowRenderer.ts +19 -3
- package/src/web/templates/MarketTableRowRenderer.ts +752 -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
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type { ActivityRow } from '../../models';
|
|
1
|
+
import type { ActivityAmount, ActivityRow, LeadingVisual } from '../../models';
|
|
2
2
|
import { createElement, tagSlot, markActionAnchorSource } from './RowElements';
|
|
3
3
|
import { RowVisualStyle, type RowPrimitives } from './RowVisual';
|
|
4
|
+
import { applyTextWeight, applyValueSegments } from './RowText';
|
|
4
5
|
type Views = {
|
|
5
6
|
column: HTMLElement;
|
|
6
7
|
fields: Record<string, HTMLElement>;
|
|
@@ -12,7 +13,11 @@ type Views = {
|
|
|
12
13
|
primitives: RowPrimitives;
|
|
13
14
|
};
|
|
14
15
|
const views = new WeakMap<HTMLElement, Views>();
|
|
15
|
-
function
|
|
16
|
+
function bindLegacy(
|
|
17
|
+
body: HTMLElement,
|
|
18
|
+
row: ActivityRow,
|
|
19
|
+
primitives: RowPrimitives
|
|
20
|
+
) {
|
|
16
21
|
const v = views.get(body)!;
|
|
17
22
|
v.primitives = primitives;
|
|
18
23
|
body.style.cssText = '';
|
|
@@ -81,7 +86,7 @@ function bind(body: HTMLElement, row: ActivityRow, primitives: RowPrimitives) {
|
|
|
81
86
|
v.actions.appendChild(button);
|
|
82
87
|
});
|
|
83
88
|
}
|
|
84
|
-
function
|
|
89
|
+
function createLegacy(
|
|
85
90
|
document: Document,
|
|
86
91
|
row: ActivityRow,
|
|
87
92
|
primitives: RowPrimitives
|
|
@@ -130,10 +135,10 @@ function create(
|
|
|
130
135
|
visualKey: '',
|
|
131
136
|
primitives,
|
|
132
137
|
});
|
|
133
|
-
|
|
138
|
+
bindLegacy(body, row, primitives);
|
|
134
139
|
return body;
|
|
135
140
|
}
|
|
136
|
-
function
|
|
141
|
+
function recycleLegacy(body: HTMLElement) {
|
|
137
142
|
const v = views.get(body);
|
|
138
143
|
if (!v) return;
|
|
139
144
|
v.visuals.forEach((node) => {
|
|
@@ -145,13 +150,657 @@ function recycle(body: HTMLElement) {
|
|
|
145
150
|
v.visualKey = '';
|
|
146
151
|
v.actions.replaceChildren();
|
|
147
152
|
}
|
|
153
|
+
type AmountViews = {
|
|
154
|
+
element: HTMLElement;
|
|
155
|
+
primary: HTMLElement;
|
|
156
|
+
secondary: HTMLElement;
|
|
157
|
+
visual?: HTMLElement;
|
|
158
|
+
visualKey: string;
|
|
159
|
+
};
|
|
160
|
+
type HistoryViews = {
|
|
161
|
+
content: HTMLElement;
|
|
162
|
+
identity: HTMLElement;
|
|
163
|
+
visual: HTMLElement;
|
|
164
|
+
text: HTMLElement;
|
|
165
|
+
titleLine: HTMLElement;
|
|
166
|
+
title: HTMLElement;
|
|
167
|
+
badges: HTMLElement;
|
|
168
|
+
description: HTMLElement;
|
|
169
|
+
descriptionTime: HTMLElement;
|
|
170
|
+
descriptionDot: HTMLElement;
|
|
171
|
+
descriptionAddress: HTMLButtonElement;
|
|
172
|
+
amounts: HTMLElement;
|
|
173
|
+
amountRows: Map<string, AmountViews>;
|
|
174
|
+
fee: HTMLElement;
|
|
175
|
+
feeLabel: HTMLElement;
|
|
176
|
+
feeValues: HTMLElement;
|
|
177
|
+
feePrimary: HTMLElement;
|
|
178
|
+
feeSecondary: HTMLElement;
|
|
179
|
+
actions: HTMLElement;
|
|
180
|
+
actionButtons: Map<string, HTMLButtonElement>;
|
|
181
|
+
visualKey: string;
|
|
182
|
+
primitives: RowPrimitives;
|
|
183
|
+
};
|
|
184
|
+
const histories = new WeakMap<HTMLElement, HistoryViews>();
|
|
185
|
+
const isHistory = (row: ActivityRow) =>
|
|
186
|
+
row.presentation !== undefined || row.amounts !== undefined;
|
|
187
|
+
const ellipsis =
|
|
188
|
+
'min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;';
|
|
189
|
+
function valueText(
|
|
190
|
+
node: HTMLElement,
|
|
191
|
+
text: string | undefined,
|
|
192
|
+
segments: ActivityAmount['textSegments'],
|
|
193
|
+
size: number,
|
|
194
|
+
line: number,
|
|
195
|
+
weight: number
|
|
196
|
+
) {
|
|
197
|
+
node.textContent = text ?? '';
|
|
198
|
+
applyTextWeight(node, weight);
|
|
199
|
+
applyValueSegments(node, segments, size, line, weight);
|
|
200
|
+
}
|
|
201
|
+
function createHistory(body: HTMLElement, primitives: RowPrimitives) {
|
|
202
|
+
const document = body.ownerDocument;
|
|
203
|
+
const node = (name: string) =>
|
|
204
|
+
createElement(document, 'div', `ok-native-list-history-${name}`);
|
|
205
|
+
const content = node('content');
|
|
206
|
+
const identity = node('identity');
|
|
207
|
+
const visual = node('visual');
|
|
208
|
+
const text = node('text');
|
|
209
|
+
const titleLine = node('title-line');
|
|
210
|
+
const title = tagSlot(node('title'), 'title');
|
|
211
|
+
const badges = node('badges');
|
|
212
|
+
const description = node('description');
|
|
213
|
+
description.dataset.nlSlot = 'description';
|
|
214
|
+
const descriptionTime = createElement(document, 'span');
|
|
215
|
+
const descriptionDot = createElement(document, 'span', undefined, '•');
|
|
216
|
+
const descriptionAddress = createElement(
|
|
217
|
+
document,
|
|
218
|
+
'button'
|
|
219
|
+
) as HTMLButtonElement;
|
|
220
|
+
descriptionAddress.type = 'button';
|
|
221
|
+
description.append(descriptionTime, descriptionDot, descriptionAddress);
|
|
222
|
+
const amounts = node('amounts');
|
|
223
|
+
const fee = node('fee');
|
|
224
|
+
const feeLabel = node('fee-label');
|
|
225
|
+
const feeValues = node('fee-values');
|
|
226
|
+
const feePrimary = node('fee-primary');
|
|
227
|
+
const feeSecondary = node('fee-secondary');
|
|
228
|
+
const actions = node('actions');
|
|
229
|
+
titleLine.append(title, badges);
|
|
230
|
+
text.append(titleLine, description);
|
|
231
|
+
identity.append(visual, text);
|
|
232
|
+
feeValues.append(feePrimary, feeSecondary);
|
|
233
|
+
fee.append(feeLabel, feeValues);
|
|
234
|
+
content.append(identity, amounts, fee);
|
|
235
|
+
body.replaceChildren(content, actions);
|
|
236
|
+
const v: HistoryViews = {
|
|
237
|
+
content,
|
|
238
|
+
identity,
|
|
239
|
+
visual,
|
|
240
|
+
text,
|
|
241
|
+
titleLine,
|
|
242
|
+
title,
|
|
243
|
+
badges,
|
|
244
|
+
description,
|
|
245
|
+
descriptionTime,
|
|
246
|
+
descriptionDot,
|
|
247
|
+
descriptionAddress,
|
|
248
|
+
amounts,
|
|
249
|
+
amountRows: new Map(),
|
|
250
|
+
fee,
|
|
251
|
+
feeLabel,
|
|
252
|
+
feeValues,
|
|
253
|
+
feePrimary,
|
|
254
|
+
feeSecondary,
|
|
255
|
+
actions,
|
|
256
|
+
actionButtons: new Map(),
|
|
257
|
+
visualKey: '',
|
|
258
|
+
primitives,
|
|
259
|
+
};
|
|
260
|
+
histories.set(body, v);
|
|
261
|
+
return v;
|
|
262
|
+
}
|
|
263
|
+
const historyIconPaths: Readonly<Record<string, readonly string[]>> = {
|
|
264
|
+
ArrowTopOutline: [
|
|
265
|
+
'M19.414 10 18 11.414l-5-5V21h-2V6.414l-5 5L4.586 10 12 2.586z',
|
|
266
|
+
],
|
|
267
|
+
ArrowBottomOutline: [
|
|
268
|
+
'm13 17.586 5-5L19.414 14 12 21.414 4.586 14 6 12.586l5 5V3h2z',
|
|
269
|
+
],
|
|
270
|
+
SwitchHorOutline: [
|
|
271
|
+
'm9.414 13-3 3H21v2H6.414l3 3L8 22.414 2.586 17 8 11.586zm12-6L16 12.414 14.586 11l3-3H3V6h14.586l-3-3L16 1.586z',
|
|
272
|
+
],
|
|
273
|
+
CoinsOutline: [
|
|
274
|
+
'M9 3a7 7 0 0 1 6.328 4.008 7 7 0 1 1-6.657 9.983A7 7 0 0 1 9 3m5.718 6.008a5 5 0 1 0 .566 9.985 5 5 0 0 0-.566-9.985M9 5a5 5 0 0 0-.941 9.91 7 7 0 0 1 5.11-7.667A4.99 4.99 0 0 0 8.999 5Z',
|
|
275
|
+
],
|
|
276
|
+
ShieldCheckDoneOutline: [
|
|
277
|
+
'M15.914 9.75 11 14.664 8.086 11.75 9.5 10.336l1.5 1.5 3.5-3.5z',
|
|
278
|
+
'M12.325 2.055 21 5.036v6.876c0 2.807-1.149 4.83-2.813 6.404-1.615 1.53-3.745 2.66-5.712 3.722l-.475.256-.475-.256c-1.967-1.061-4.097-2.192-5.713-3.722C4.15 16.741 3 14.72 3 11.912V5.036l8.675-2.981.325-.113zM5 6.463v5.45c0 2.165.851 3.686 2.188 4.951 1.275 1.208 2.965 2.154 4.812 3.154 1.847-1 3.537-1.946 4.813-3.154C18.148 15.6 19 14.078 19 11.912v-5.45l-7-2.405z',
|
|
279
|
+
],
|
|
280
|
+
UnlockedOutline: [
|
|
281
|
+
'M13 18h-2v-5h2z',
|
|
282
|
+
'M12 2a5 5 0 0 1 5 5h-2a3 3 0 0 0-6 0v2h11v13H4V9h3V7a5 5 0 0 1 5-5M6 20h12v-9H6z',
|
|
283
|
+
],
|
|
284
|
+
Document2Outline: [
|
|
285
|
+
'M12 16H8v-2h4zm4-4H8v-2h8zm0-4H8V6h8z',
|
|
286
|
+
'M20 22H4V2h16zM6 20h12V4H6z',
|
|
287
|
+
],
|
|
288
|
+
CryptoCoinOutline: [
|
|
289
|
+
'M11 16.387a4.5 4.5 0 0 1 0-8.775V6h2v1.613a4.5 4.5 0 0 1 2.856 2.067l-1.712 1.032a2.5 2.5 0 1 0 0 2.576l1.712 1.032A4.5 4.5 0 0 1 13 16.386V18h-2z',
|
|
290
|
+
'M22 12c0 5.523-4.477 10-10 10S2 17.523 2 12 6.477 2 12 2s10 4.477 10 10m-2 0a8 8 0 1 0-16 0 8 8 0 0 0 16 0',
|
|
291
|
+
],
|
|
292
|
+
ImageSquareWavesOutline: [
|
|
293
|
+
'M14.25 7a2 2 0 1 1 0 4 2 2 0 0 1 0-4',
|
|
294
|
+
'M21 21H3V3h18zM5 16.414V19h12.586L14 15.414l-2 2-4-4zm0-2.828 3-3 4 4 2-2 5 5V5H5z',
|
|
295
|
+
],
|
|
296
|
+
DotHorOutline: ['M6 14H2v-4h4zm8 0h-4v-4h4zm8 0h-4v-4h4z'],
|
|
297
|
+
};
|
|
298
|
+
function historyIcon(
|
|
299
|
+
node: HTMLElement,
|
|
300
|
+
source: LeadingVisual | undefined,
|
|
301
|
+
size: number
|
|
302
|
+
) {
|
|
303
|
+
const name =
|
|
304
|
+
source?.kind === 'icon'
|
|
305
|
+
? source.name
|
|
306
|
+
: source?.kind === 'token'
|
|
307
|
+
? source.fallbackIcon?.name
|
|
308
|
+
: undefined;
|
|
309
|
+
const paths = name && historyIconPaths[name];
|
|
310
|
+
if (!paths) return;
|
|
311
|
+
const placeholder = node.querySelector<HTMLElement>(
|
|
312
|
+
'.ok-native-list-visual-fallback'
|
|
313
|
+
);
|
|
314
|
+
if (!placeholder && source && 'image' in source && source.image) return;
|
|
315
|
+
const fallback = placeholder ?? node;
|
|
316
|
+
Object.assign(fallback.style, {
|
|
317
|
+
display: 'flex',
|
|
318
|
+
alignItems: 'center',
|
|
319
|
+
justifyContent: 'center',
|
|
320
|
+
width: '100%',
|
|
321
|
+
height: '100%',
|
|
322
|
+
});
|
|
323
|
+
if (source?.kind === 'icon' && source.tintColor)
|
|
324
|
+
fallback.style.color = source.tintColor;
|
|
325
|
+
else if (source && 'fallbackIcon' in source && source.fallbackIcon?.tintColor)
|
|
326
|
+
fallback.style.color = source.fallbackIcon.tintColor;
|
|
327
|
+
const svg = node.ownerDocument.createElementNS(
|
|
328
|
+
'http://www.w3.org/2000/svg',
|
|
329
|
+
'svg'
|
|
330
|
+
);
|
|
331
|
+
svg.setAttribute('viewBox', '0 0 24 24');
|
|
332
|
+
svg.setAttribute('width', String(size));
|
|
333
|
+
svg.setAttribute('height', String(size));
|
|
334
|
+
svg.setAttribute('fill', 'currentColor');
|
|
335
|
+
svg.setAttribute('aria-hidden', 'true');
|
|
336
|
+
for (const d of paths) {
|
|
337
|
+
const path = node.ownerDocument.createElementNS(
|
|
338
|
+
'http://www.w3.org/2000/svg',
|
|
339
|
+
'path'
|
|
340
|
+
);
|
|
341
|
+
path.setAttribute('d', d);
|
|
342
|
+
path.setAttribute('fill-rule', 'evenodd');
|
|
343
|
+
svg.append(path);
|
|
344
|
+
}
|
|
345
|
+
fallback.replaceChildren(svg);
|
|
346
|
+
}
|
|
347
|
+
function bindHistory(
|
|
348
|
+
body: HTMLElement,
|
|
349
|
+
row: ActivityRow,
|
|
350
|
+
primitives: RowPrimitives
|
|
351
|
+
) {
|
|
352
|
+
const v = histories.get(body) ?? createHistory(body, primitives);
|
|
353
|
+
v.primitives = primitives;
|
|
354
|
+
const table = row.presentation === 'table';
|
|
355
|
+
const footer = Boolean(row.footerActions?.length);
|
|
356
|
+
body.className = 'ok-native-list-row ok-native-list-history';
|
|
357
|
+
body.style.cssText = '';
|
|
358
|
+
body.removeAttribute('data-nl-container-background');
|
|
359
|
+
body.removeAttribute('data-nl-container-border');
|
|
360
|
+
Object.assign(body.style, {
|
|
361
|
+
display: 'flex',
|
|
362
|
+
flexDirection: 'column',
|
|
363
|
+
alignItems: 'stretch',
|
|
364
|
+
justifyContent: 'flex-start',
|
|
365
|
+
width: 'calc(100% - 16px)',
|
|
366
|
+
margin: '0 8px',
|
|
367
|
+
padding: `${table ? 12 : 8}px 12px`,
|
|
368
|
+
height:
|
|
369
|
+
!table && !footer && row.height !== 60 ? 'calc(100% - 8px)' : '100%',
|
|
370
|
+
borderRadius: '12px',
|
|
371
|
+
gap: '8px',
|
|
372
|
+
});
|
|
373
|
+
Object.assign(v.content.style, {
|
|
374
|
+
display: 'flex',
|
|
375
|
+
alignItems: 'center',
|
|
376
|
+
gap: '12px',
|
|
377
|
+
minWidth: '0',
|
|
378
|
+
width: '100%',
|
|
379
|
+
});
|
|
380
|
+
Object.assign(v.identity.style, {
|
|
381
|
+
display: 'flex',
|
|
382
|
+
alignItems: 'center',
|
|
383
|
+
gap: '12px',
|
|
384
|
+
minWidth: '0',
|
|
385
|
+
flex: '1 1 0',
|
|
386
|
+
});
|
|
387
|
+
Object.assign(v.visual.style, {
|
|
388
|
+
position: 'relative',
|
|
389
|
+
width: '40px',
|
|
390
|
+
height: '40px',
|
|
391
|
+
flex: '0 0 40px',
|
|
392
|
+
});
|
|
393
|
+
const visualKey = JSON.stringify([
|
|
394
|
+
row.key,
|
|
395
|
+
row.leading,
|
|
396
|
+
row.secondaryLeading,
|
|
397
|
+
]);
|
|
398
|
+
if (v.visualKey !== visualKey) {
|
|
399
|
+
Array.from(v.visual.children).forEach((n) =>
|
|
400
|
+
primitives.dispose(n as HTMLElement)
|
|
401
|
+
);
|
|
402
|
+
v.visual.replaceChildren();
|
|
403
|
+
const sources = [row.leading, row.secondaryLeading].filter(Boolean);
|
|
404
|
+
sources.forEach((source, index) => {
|
|
405
|
+
const visual = primitives.visual(source);
|
|
406
|
+
if (!visual) return;
|
|
407
|
+
const size = sources.length > 1 ? (index ? 28 : 24) : 40;
|
|
408
|
+
new RowVisualStyle(visual).apply(row.style?.image, size, size, 0);
|
|
409
|
+
Object.assign(visual.style, {
|
|
410
|
+
display: 'inline-flex',
|
|
411
|
+
alignItems: 'center',
|
|
412
|
+
justifyContent: 'center',
|
|
413
|
+
});
|
|
414
|
+
if (sources.length > 1)
|
|
415
|
+
Object.assign(visual.style, {
|
|
416
|
+
position: 'absolute',
|
|
417
|
+
left: index ? '12px' : '0',
|
|
418
|
+
top: index ? '12px' : '0',
|
|
419
|
+
border: index ? '2px solid var(--nl-row)' : '0',
|
|
420
|
+
boxSizing: 'border-box',
|
|
421
|
+
});
|
|
422
|
+
historyIcon(visual, source, table || sources.length > 1 ? 24 : 28);
|
|
423
|
+
if (!table && sources.length > 1) {
|
|
424
|
+
const token = visual.ownerDocument.createElement('span');
|
|
425
|
+
Object.assign(token.style, {
|
|
426
|
+
display: 'flex',
|
|
427
|
+
alignItems: 'center',
|
|
428
|
+
justifyContent: 'center',
|
|
429
|
+
position: 'relative',
|
|
430
|
+
width: '24px',
|
|
431
|
+
height: '24px',
|
|
432
|
+
flex: '0 0 24px',
|
|
433
|
+
borderRadius: 'inherit',
|
|
434
|
+
boxSizing: 'border-box',
|
|
435
|
+
overflow: 'hidden',
|
|
436
|
+
background:
|
|
437
|
+
source && 'backgroundColor' in source
|
|
438
|
+
? source.backgroundColor ?? ''
|
|
439
|
+
: '',
|
|
440
|
+
border:
|
|
441
|
+
source && 'borderColor' in source && source.borderColor
|
|
442
|
+
? `1px solid ${source.borderColor}`
|
|
443
|
+
: '0',
|
|
444
|
+
});
|
|
445
|
+
token.append(
|
|
446
|
+
...Array.from(visual.children).filter(
|
|
447
|
+
(child) => !child.classList.contains('ok-native-list-visual-corner')
|
|
448
|
+
)
|
|
449
|
+
);
|
|
450
|
+
const fallback = token.querySelector<HTMLElement>(
|
|
451
|
+
':scope > .ok-native-list-visual-fallback'
|
|
452
|
+
);
|
|
453
|
+
if (fallback) {
|
|
454
|
+
fallback.style.width = '24px';
|
|
455
|
+
fallback.style.height = '24px';
|
|
456
|
+
fallback.style.flexShrink = '0';
|
|
457
|
+
}
|
|
458
|
+
const mainImage = token.querySelector<HTMLImageElement>(
|
|
459
|
+
':scope > .ok-native-list-visual-main'
|
|
460
|
+
);
|
|
461
|
+
if (mainImage) {
|
|
462
|
+
mainImage.style.width = '100%';
|
|
463
|
+
mainImage.style.height = '100%';
|
|
464
|
+
}
|
|
465
|
+
visual.append(token);
|
|
466
|
+
}
|
|
467
|
+
if (table) {
|
|
468
|
+
visual.style.background =
|
|
469
|
+
source && 'backgroundColor' in source && source.backgroundColor
|
|
470
|
+
? source.backgroundColor
|
|
471
|
+
: 'var(--nl-strong)';
|
|
472
|
+
const borderColor =
|
|
473
|
+
source && 'borderColor' in source && source.borderColor
|
|
474
|
+
? source.borderColor
|
|
475
|
+
: 'var(--nl-separator)';
|
|
476
|
+
visual.style.border = `1px solid ${borderColor}`;
|
|
477
|
+
visual.style.boxSizing = 'border-box';
|
|
478
|
+
} else if (sources.length === 1 && source?.kind === 'token') {
|
|
479
|
+
visual.style.border = source.borderColor
|
|
480
|
+
? `1px solid ${source.borderColor}`
|
|
481
|
+
: '0';
|
|
482
|
+
visual.style.boxSizing = 'border-box';
|
|
483
|
+
const mainImage = visual.querySelector<HTMLImageElement>(
|
|
484
|
+
':scope > .ok-native-list-visual-main'
|
|
485
|
+
);
|
|
486
|
+
if (mainImage) {
|
|
487
|
+
mainImage.style.width = '100%';
|
|
488
|
+
mainImage.style.height = '100%';
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
v.visual.append(visual);
|
|
492
|
+
});
|
|
493
|
+
v.visualKey = visualKey;
|
|
494
|
+
}
|
|
495
|
+
Object.assign(v.text.style, {
|
|
496
|
+
minWidth: '0',
|
|
497
|
+
flex: '1 1 auto',
|
|
498
|
+
display: 'flex',
|
|
499
|
+
flexDirection: 'column',
|
|
500
|
+
gap: table ? '4px' : '0',
|
|
501
|
+
});
|
|
502
|
+
Object.assign(v.titleLine.style, {
|
|
503
|
+
display: 'flex',
|
|
504
|
+
alignItems: 'center',
|
|
505
|
+
minWidth: '0',
|
|
506
|
+
});
|
|
507
|
+
v.title.style.cssText =
|
|
508
|
+
ellipsis +
|
|
509
|
+
`font-size:${table ? 14 : 16}px;line-height:${
|
|
510
|
+
table ? 20 : 24
|
|
511
|
+
}px;font-weight:500;`;
|
|
512
|
+
v.title.textContent = row.title;
|
|
513
|
+
applyTextWeight(v.title, 500);
|
|
514
|
+
if (row.style?.title) primitives.textStyle(v.title, row.style.title);
|
|
515
|
+
v.badges.style.cssText = 'display:flex;flex:0 0 auto;gap:8px;margin-left:8px';
|
|
516
|
+
v.badges.replaceChildren();
|
|
517
|
+
for (const badge of row.badges ?? []) {
|
|
518
|
+
const element = createElement(
|
|
519
|
+
body.ownerDocument,
|
|
520
|
+
'span',
|
|
521
|
+
'ok-native-list-badge',
|
|
522
|
+
badge.text
|
|
523
|
+
);
|
|
524
|
+
element.dataset.tone = badge.tone ?? '';
|
|
525
|
+
element.style.cssText =
|
|
526
|
+
'height:20px;font-size:12px;line-height:16px;padding:2px 8px;border-radius:4px;box-sizing:border-box';
|
|
527
|
+
applyTextWeight(element, 500);
|
|
528
|
+
if (badge.tone === 'neutral')
|
|
529
|
+
Object.assign(element.style, {
|
|
530
|
+
background: 'var(--nl-strong)',
|
|
531
|
+
color: 'var(--nl-secondary)',
|
|
532
|
+
});
|
|
533
|
+
if (badge.tone === 'warning')
|
|
534
|
+
Object.assign(element.style, {
|
|
535
|
+
background:
|
|
536
|
+
'var(--nl-caution-background,color-mix(in srgb,var(--nl-caution) 12%,transparent))',
|
|
537
|
+
color: 'var(--nl-caution)',
|
|
538
|
+
});
|
|
539
|
+
v.badges.append(element);
|
|
540
|
+
}
|
|
541
|
+
v.badges.style.display = row.badges?.length ? 'flex' : 'none';
|
|
542
|
+
v.description.style.cssText =
|
|
543
|
+
ellipsis +
|
|
544
|
+
'display:flex;max-width:100%;color:var(--nl-secondary);font-family:inherit;font-size:14px;line-height:20px;font-weight:400;font-variant-numeric:tabular-nums;';
|
|
545
|
+
applyTextWeight(v.description, 400);
|
|
546
|
+
const split = row.description?.indexOf(' • ') ?? -1;
|
|
547
|
+
v.descriptionTime.textContent =
|
|
548
|
+
split >= 0 ? row.description!.slice(0, split) : '';
|
|
549
|
+
v.descriptionTime.style.display = split >= 0 ? 'inline' : 'none';
|
|
550
|
+
v.descriptionTime.style.flexShrink = '0';
|
|
551
|
+
v.descriptionDot.style.cssText = `flex-shrink:0;margin:0 4px;display:${
|
|
552
|
+
split >= 0 ? 'inline' : 'none'
|
|
553
|
+
}`;
|
|
554
|
+
v.descriptionAddress.style.cssText =
|
|
555
|
+
ellipsis +
|
|
556
|
+
'appearance:none;display:block;max-width:100%;border:0;padding:0;background:transparent;text-align:left;color:inherit;font:inherit;font-variant-numeric:inherit;';
|
|
557
|
+
v.descriptionAddress.textContent =
|
|
558
|
+
split >= 0 ? row.description!.slice(split + 3) : row.description ?? '';
|
|
559
|
+
v.description.style.display = row.description ? 'flex' : 'none';
|
|
560
|
+
v.descriptionAddress.tabIndex = row.descriptionActionKey ? 0 : -1;
|
|
561
|
+
if (row.descriptionActionKey) {
|
|
562
|
+
v.descriptionAddress.dataset.nativeListAction = row.descriptionActionKey;
|
|
563
|
+
markActionAnchorSource(v.descriptionAddress, 'description');
|
|
564
|
+
v.descriptionAddress.style.cursor = 'pointer';
|
|
565
|
+
} else {
|
|
566
|
+
delete v.descriptionAddress.dataset.nativeListAction;
|
|
567
|
+
delete v.descriptionAddress.dataset.nativeListAnchorSource;
|
|
568
|
+
v.descriptionAddress.style.cursor = 'inherit';
|
|
569
|
+
}
|
|
570
|
+
if (row.style?.description)
|
|
571
|
+
primitives.textStyle(v.description, row.style.description);
|
|
572
|
+
v.description.style.display = row.description ? 'flex' : 'none';
|
|
573
|
+
Object.assign(v.amounts.style, {
|
|
574
|
+
display: 'flex',
|
|
575
|
+
flexDirection: 'column',
|
|
576
|
+
minWidth: '0',
|
|
577
|
+
gap: table ? '4px' : '0',
|
|
578
|
+
flex: table ? '1 1 0' : '0 1 auto',
|
|
579
|
+
maxWidth: table ? '50%' : '50%',
|
|
580
|
+
alignItems: table ? 'stretch' : 'flex-end',
|
|
581
|
+
alignSelf: table ? 'stretch' : 'center',
|
|
582
|
+
});
|
|
583
|
+
const amountKeys = new Set<string>();
|
|
584
|
+
for (const amount of row.amounts ?? []) {
|
|
585
|
+
amountKeys.add(amount.key);
|
|
586
|
+
let view = v.amountRows.get(amount.key);
|
|
587
|
+
if (!view) {
|
|
588
|
+
const element = createElement(body.ownerDocument, 'div');
|
|
589
|
+
const primary = tagSlot(
|
|
590
|
+
createElement(body.ownerDocument, 'span'),
|
|
591
|
+
'primaryAmount'
|
|
592
|
+
);
|
|
593
|
+
const secondary = tagSlot(
|
|
594
|
+
createElement(body.ownerDocument, 'span'),
|
|
595
|
+
'secondaryAmount'
|
|
596
|
+
);
|
|
597
|
+
element.append(primary, secondary);
|
|
598
|
+
view = { element, primary, secondary, visualKey: '' };
|
|
599
|
+
v.amountRows.set(amount.key, view);
|
|
600
|
+
}
|
|
601
|
+
view.element.style.cssText = `display:flex;align-items:center;gap:4px;min-width:0;max-width:100%;${
|
|
602
|
+
table ? '' : 'justify-content:flex-end;'
|
|
603
|
+
}`;
|
|
604
|
+
const secondary = amount.tone === 'secondary';
|
|
605
|
+
const size = table || secondary ? 14 : 16;
|
|
606
|
+
const line = table || secondary ? 20 : 24;
|
|
607
|
+
const weight = table || secondary ? 400 : 500;
|
|
608
|
+
view.primary.style.cssText =
|
|
609
|
+
ellipsis +
|
|
610
|
+
`font-size:${size}px;line-height:${line}px;font-weight:${weight};color:${
|
|
611
|
+
amount.tone === 'positive'
|
|
612
|
+
? 'var(--nl-positive)'
|
|
613
|
+
: amount.tone === 'negative'
|
|
614
|
+
? 'var(--nl-negative)'
|
|
615
|
+
: secondary
|
|
616
|
+
? 'var(--nl-secondary)'
|
|
617
|
+
: 'var(--nl-primary)'
|
|
618
|
+
};`;
|
|
619
|
+
valueText(
|
|
620
|
+
view.primary,
|
|
621
|
+
amount.text,
|
|
622
|
+
amount.textSegments,
|
|
623
|
+
size,
|
|
624
|
+
line,
|
|
625
|
+
weight
|
|
626
|
+
);
|
|
627
|
+
const roleStyle = secondary
|
|
628
|
+
? row.style?.secondaryAmount
|
|
629
|
+
: row.style?.primaryAmount;
|
|
630
|
+
if (roleStyle) primitives.textStyle(view.primary, roleStyle);
|
|
631
|
+
view.secondary.style.cssText =
|
|
632
|
+
ellipsis +
|
|
633
|
+
'font-size:14px;line-height:20px;font-weight:400;color:var(--nl-secondary);';
|
|
634
|
+
valueText(
|
|
635
|
+
view.secondary,
|
|
636
|
+
amount.secondaryText,
|
|
637
|
+
amount.secondaryTextSegments,
|
|
638
|
+
14,
|
|
639
|
+
20,
|
|
640
|
+
400
|
|
641
|
+
);
|
|
642
|
+
view.secondary.hidden = !table || !amount.secondaryText;
|
|
643
|
+
const amountVisualKey = JSON.stringify(table ? amount.leading : undefined);
|
|
644
|
+
if (view.visualKey !== amountVisualKey) {
|
|
645
|
+
if (view.visual) {
|
|
646
|
+
primitives.dispose(view.visual);
|
|
647
|
+
view.visual.remove();
|
|
648
|
+
}
|
|
649
|
+
view.visual = table ? primitives.visual(amount.leading) : undefined;
|
|
650
|
+
if (view.visual) {
|
|
651
|
+
new RowVisualStyle(view.visual).apply(
|
|
652
|
+
{ width: 20, height: 20 },
|
|
653
|
+
20,
|
|
654
|
+
20,
|
|
655
|
+
0
|
|
656
|
+
);
|
|
657
|
+
historyIcon(view.visual, amount.leading, 16);
|
|
658
|
+
if (amount.leading?.kind === 'token' && amount.leading.image) {
|
|
659
|
+
view.visual.style.border = amount.leading.borderColor
|
|
660
|
+
? `1px solid ${amount.leading.borderColor}`
|
|
661
|
+
: '0';
|
|
662
|
+
view.visual.style.boxSizing = 'border-box';
|
|
663
|
+
}
|
|
664
|
+
view.element.prepend(view.visual);
|
|
665
|
+
}
|
|
666
|
+
view.visualKey = amountVisualKey;
|
|
667
|
+
}
|
|
668
|
+
v.amounts.append(view.element);
|
|
669
|
+
}
|
|
670
|
+
for (const [key, view] of v.amountRows) {
|
|
671
|
+
if (!amountKeys.has(key)) {
|
|
672
|
+
if (view.visual) primitives.dispose(view.visual);
|
|
673
|
+
view.element.remove();
|
|
674
|
+
v.amountRows.delete(key);
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
v.fee.style.cssText =
|
|
678
|
+
'display:flex;flex-direction:column;flex:.6 1 0;min-width:0;gap:4px';
|
|
679
|
+
v.fee.hidden = !table || !row.fee;
|
|
680
|
+
v.fee.style.display = table && row.fee ? 'flex' : 'none';
|
|
681
|
+
v.fee.style.opacity = row.fee?.hidden ? '0' : '1';
|
|
682
|
+
v.feeLabel.style.cssText =
|
|
683
|
+
'font-size:14px;line-height:20px;color:var(--nl-secondary);';
|
|
684
|
+
v.feeLabel.textContent = row.fee?.label ?? '';
|
|
685
|
+
applyTextWeight(v.feeLabel, 400);
|
|
686
|
+
v.feeValues.style.cssText =
|
|
687
|
+
'display:flex;align-items:center;gap:4px;min-width:0';
|
|
688
|
+
v.feePrimary.style.cssText =
|
|
689
|
+
ellipsis + 'font-size:14px;line-height:20px;font-weight:400;';
|
|
690
|
+
v.feeSecondary.style.cssText =
|
|
691
|
+
ellipsis +
|
|
692
|
+
'font-size:14px;line-height:20px;font-weight:400;color:var(--nl-secondary);';
|
|
693
|
+
valueText(
|
|
694
|
+
v.feePrimary,
|
|
695
|
+
row.fee?.primary,
|
|
696
|
+
row.fee?.primaryTextSegments,
|
|
697
|
+
14,
|
|
698
|
+
20,
|
|
699
|
+
400
|
|
700
|
+
);
|
|
701
|
+
valueText(
|
|
702
|
+
v.feeSecondary,
|
|
703
|
+
row.fee?.secondary,
|
|
704
|
+
row.fee?.secondaryTextSegments,
|
|
705
|
+
14,
|
|
706
|
+
20,
|
|
707
|
+
400
|
|
708
|
+
);
|
|
709
|
+
v.actions.style.cssText =
|
|
710
|
+
'display:flex;gap:12px;padding-left:52px;padding-bottom:4px;';
|
|
711
|
+
v.actions.style.display = footer ? 'flex' : 'none';
|
|
712
|
+
const actionKeys = new Set<string>();
|
|
713
|
+
for (const [index, action] of (row.footerActions ?? []).entries()) {
|
|
714
|
+
actionKeys.add(action.key);
|
|
715
|
+
let button = v.actionButtons.get(action.key);
|
|
716
|
+
if (!button) {
|
|
717
|
+
button = createElement(
|
|
718
|
+
body.ownerDocument,
|
|
719
|
+
'button',
|
|
720
|
+
'ok-native-list-action-button'
|
|
721
|
+
) as HTMLButtonElement;
|
|
722
|
+
button.type = 'button';
|
|
723
|
+
v.actionButtons.set(action.key, button);
|
|
724
|
+
}
|
|
725
|
+
if (button.textContent !== action.label) button.textContent = action.label;
|
|
726
|
+
button.toggleAttribute('disabled', Boolean(action.disabled));
|
|
727
|
+
button.dataset.nativeListAction = action.key;
|
|
728
|
+
markActionAnchorSource(button, 'footerAction', index);
|
|
729
|
+
button.style.cssText =
|
|
730
|
+
'font-family:inherit;font-size:14px;line-height:20px;font-weight:500;padding:4px 10px;border:1px solid transparent;border-radius:8px;background:var(--nl-strong);color:var(--nl-primary);white-space:nowrap;';
|
|
731
|
+
applyTextWeight(button, 500);
|
|
732
|
+
if (action.tone === 'primary')
|
|
733
|
+
Object.assign(button.style, {
|
|
734
|
+
background: 'var(--nl-primary)',
|
|
735
|
+
color: 'var(--nl-inverse-text)',
|
|
736
|
+
});
|
|
737
|
+
if (v.actions.children[index] !== button)
|
|
738
|
+
v.actions.insertBefore(button, v.actions.children[index] ?? null);
|
|
739
|
+
}
|
|
740
|
+
for (const [key, button] of v.actionButtons) {
|
|
741
|
+
if (!actionKeys.has(key)) {
|
|
742
|
+
button.remove();
|
|
743
|
+
v.actionButtons.delete(key);
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
function recycle(body: HTMLElement) {
|
|
748
|
+
const v = histories.get(body);
|
|
749
|
+
if (v) {
|
|
750
|
+
Array.from(v.visual.children).forEach((n) =>
|
|
751
|
+
v.primitives.dispose(n as HTMLElement)
|
|
752
|
+
);
|
|
753
|
+
for (const view of v.amountRows.values())
|
|
754
|
+
if (view.visual) v.primitives.dispose(view.visual);
|
|
755
|
+
histories.delete(body);
|
|
756
|
+
}
|
|
757
|
+
recycleLegacy(body);
|
|
758
|
+
views.delete(body);
|
|
759
|
+
}
|
|
760
|
+
function bind(body: HTMLElement, row: ActivityRow, primitives: RowPrimitives) {
|
|
761
|
+
if (isHistory(row)) {
|
|
762
|
+
if (views.has(body)) {
|
|
763
|
+
recycleLegacy(body);
|
|
764
|
+
views.delete(body);
|
|
765
|
+
}
|
|
766
|
+
bindHistory(body, row, primitives);
|
|
767
|
+
} else {
|
|
768
|
+
if (histories.has(body)) recycle(body);
|
|
769
|
+
if (!views.has(body)) {
|
|
770
|
+
const initial = createLegacy(body.ownerDocument, row, primitives);
|
|
771
|
+
body.replaceChildren(...Array.from(initial.childNodes));
|
|
772
|
+
body.className = initial.className;
|
|
773
|
+
views.set(body, views.get(initial)!);
|
|
774
|
+
views.delete(initial);
|
|
775
|
+
}
|
|
776
|
+
bindLegacy(body, row, primitives);
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
function create(
|
|
780
|
+
document: Document,
|
|
781
|
+
row: ActivityRow,
|
|
782
|
+
primitives: RowPrimitives
|
|
783
|
+
) {
|
|
784
|
+
const body = document.createElement('div');
|
|
785
|
+
body.dataset.nlRenderer = 'activity';
|
|
786
|
+
bind(body, row, primitives);
|
|
787
|
+
return body;
|
|
788
|
+
}
|
|
148
789
|
export const activityRowRenderer = {
|
|
149
790
|
key: 'activity' as const,
|
|
150
791
|
create,
|
|
151
792
|
bind,
|
|
152
793
|
recycle,
|
|
153
|
-
measure: (row: ActivityRow, _width: number) =>
|
|
154
|
-
row.footerActions?.length ? 100 : 60
|
|
794
|
+
measure: (row: ActivityRow, _width: number) => {
|
|
795
|
+
if (!isHistory(row)) return row.footerActions?.length ? 100 : 60;
|
|
796
|
+
const extra =
|
|
797
|
+
row.presentation === 'table'
|
|
798
|
+
? Math.max(0, (row.amounts?.length ?? 0) - 2) * 24
|
|
799
|
+
: 0;
|
|
800
|
+
if (row.footerActions?.length)
|
|
801
|
+
return (row.presentation === 'table' ? 68 : 60) + extra + 42;
|
|
802
|
+
return 68 + extra;
|
|
803
|
+
},
|
|
155
804
|
measureRendered: (
|
|
156
805
|
_body: HTMLElement,
|
|
157
806
|
_row: ActivityRow
|