@onekeyfe/react-native-native-list 6.7.0-alpha.327 → 6.7.0-alpha.336

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 +390 -9
  2. package/lib/module/NativeList.js +2 -0
  3. package/lib/module/NativeList.web.js +140 -29
  4. package/lib/module/validation.js +143 -34
  5. package/lib/module/web/NativeListWebEngine.js +356 -62
  6. package/lib/module/web/templates/ActivityRowRenderer.js +484 -5
  7. package/lib/module/web/templates/MarketRowRenderer.js +8 -3
  8. package/lib/module/web/templates/MarketTableRowRenderer.js +577 -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 +191 -38
  25. package/src/models.ts +93 -0
  26. package/src/validation.ts +348 -58
  27. package/src/web/NativeListWebEngine.ts +603 -95
  28. package/src/web/templates/ActivityRowRenderer.ts +723 -7
  29. package/src/web/templates/MarketRowRenderer.ts +19 -3
  30. package/src/web/templates/MarketTableRowRenderer.ts +755 -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
@@ -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 bind(body: HTMLElement, row: ActivityRow, primitives: RowPrimitives) {
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 create(
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
- bind(body, row, primitives);
138
+ bindLegacy(body, row, primitives);
134
139
  return body;
135
140
  }
136
- function recycle(body: HTMLElement) {
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,724 @@ 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
+ visuals: {
183
+ node: HTMLElement;
184
+ style: RowVisualStyle;
185
+ background: string;
186
+ loaded: boolean;
187
+ fallback?: HTMLElement;
188
+ fallbackStyle?: RowVisualStyle;
189
+ }[];
190
+ primitives: RowPrimitives;
191
+ };
192
+ const histories = new WeakMap<HTMLElement, HistoryViews>();
193
+ const isHistory = (row: ActivityRow) =>
194
+ row.presentation !== undefined || row.amounts !== undefined;
195
+ const ellipsis =
196
+ 'min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;';
197
+ function valueText(
198
+ node: HTMLElement,
199
+ text: string | undefined,
200
+ segments: ActivityAmount['textSegments'],
201
+ size: number,
202
+ line: number,
203
+ weight: number
204
+ ) {
205
+ node.textContent = text ?? '';
206
+ applyTextWeight(node, weight);
207
+ applyValueSegments(node, segments, size, line, weight);
208
+ }
209
+ function createHistory(body: HTMLElement, primitives: RowPrimitives) {
210
+ const document = body.ownerDocument;
211
+ const node = (name: string) =>
212
+ createElement(document, 'div', `ok-native-list-history-${name}`);
213
+ const content = node('content');
214
+ const identity = node('identity');
215
+ const visual = node('visual');
216
+ const text = node('text');
217
+ const titleLine = node('title-line');
218
+ const title = tagSlot(node('title'), 'title');
219
+ const badges = node('badges');
220
+ const description = node('description');
221
+ description.dataset.nlSlot = 'description';
222
+ const descriptionTime = createElement(document, 'span');
223
+ const descriptionDot = createElement(document, 'span', undefined, '•');
224
+ const descriptionAddress = createElement(
225
+ document,
226
+ 'button'
227
+ ) as HTMLButtonElement;
228
+ descriptionAddress.type = 'button';
229
+ description.append(descriptionTime, descriptionDot, descriptionAddress);
230
+ const amounts = node('amounts');
231
+ const fee = node('fee');
232
+ const feeLabel = node('fee-label');
233
+ const feeValues = node('fee-values');
234
+ const feePrimary = node('fee-primary');
235
+ const feeSecondary = node('fee-secondary');
236
+ const actions = node('actions');
237
+ titleLine.append(title, badges);
238
+ text.append(titleLine, description);
239
+ identity.append(visual, text);
240
+ feeValues.append(feePrimary, feeSecondary);
241
+ fee.append(feeLabel, feeValues);
242
+ content.append(identity, amounts, fee);
243
+ body.replaceChildren(content, actions);
244
+ const v: HistoryViews = {
245
+ content,
246
+ identity,
247
+ visual,
248
+ text,
249
+ titleLine,
250
+ title,
251
+ badges,
252
+ description,
253
+ descriptionTime,
254
+ descriptionDot,
255
+ descriptionAddress,
256
+ amounts,
257
+ amountRows: new Map(),
258
+ fee,
259
+ feeLabel,
260
+ feeValues,
261
+ feePrimary,
262
+ feeSecondary,
263
+ actions,
264
+ actionButtons: new Map(),
265
+ visualKey: '',
266
+ visuals: [],
267
+ primitives,
268
+ };
269
+ histories.set(body, v);
270
+ return v;
271
+ }
272
+ const historyIconPaths: Readonly<Record<string, readonly string[]>> = {
273
+ ArrowTopOutline: [
274
+ 'M19.414 10 18 11.414l-5-5V21h-2V6.414l-5 5L4.586 10 12 2.586z',
275
+ ],
276
+ ArrowBottomOutline: [
277
+ 'm13 17.586 5-5L19.414 14 12 21.414 4.586 14 6 12.586l5 5V3h2z',
278
+ ],
279
+ SwitchHorOutline: [
280
+ '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',
281
+ ],
282
+ CoinsOutline: [
283
+ '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',
284
+ ],
285
+ ShieldCheckDoneOutline: [
286
+ 'M15.914 9.75 11 14.664 8.086 11.75 9.5 10.336l1.5 1.5 3.5-3.5z',
287
+ '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',
288
+ ],
289
+ UnlockedOutline: [
290
+ 'M13 18h-2v-5h2z',
291
+ 'M12 2a5 5 0 0 1 5 5h-2a3 3 0 0 0-6 0v2h11v13H4V9h3V7a5 5 0 0 1 5-5M6 20h12v-9H6z',
292
+ ],
293
+ Document2Outline: [
294
+ 'M12 16H8v-2h4zm4-4H8v-2h8zm0-4H8V6h8z',
295
+ 'M20 22H4V2h16zM6 20h12V4H6z',
296
+ ],
297
+ CryptoCoinOutline: [
298
+ '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',
299
+ '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',
300
+ ],
301
+ ImageSquareWavesOutline: [
302
+ 'M14.25 7a2 2 0 1 1 0 4 2 2 0 0 1 0-4',
303
+ 'M21 21H3V3h18zM5 16.414V19h12.586L14 15.414l-2 2-4-4zm0-2.828 3-3 4 4 2-2 5 5V5H5z',
304
+ ],
305
+ DotHorOutline: ['M6 14H2v-4h4zm8 0h-4v-4h4zm8 0h-4v-4h4z'],
306
+ };
307
+ function historyIcon(
308
+ node: HTMLElement,
309
+ source: LeadingVisual | undefined,
310
+ size: number
311
+ ) {
312
+ const name =
313
+ source?.kind === 'icon'
314
+ ? source.name
315
+ : source?.kind === 'token'
316
+ ? source.fallbackIcon?.name
317
+ : undefined;
318
+ const paths = name && historyIconPaths[name];
319
+ if (!paths) return;
320
+ const placeholder = node.querySelector<HTMLElement>(
321
+ '.ok-native-list-visual-fallback'
322
+ );
323
+ if (!placeholder && source && 'image' in source && source.image) return;
324
+ const fallback = placeholder ?? node;
325
+ Object.assign(fallback.style, {
326
+ display: 'flex',
327
+ alignItems: 'center',
328
+ justifyContent: 'center',
329
+ width: '100%',
330
+ height: '100%',
331
+ });
332
+ if (source?.kind === 'icon' && source.tintColor)
333
+ fallback.style.color = source.tintColor;
334
+ else if (source && 'fallbackIcon' in source && source.fallbackIcon?.tintColor)
335
+ fallback.style.color = source.fallbackIcon.tintColor;
336
+ const svg = node.ownerDocument.createElementNS(
337
+ 'http://www.w3.org/2000/svg',
338
+ 'svg'
339
+ );
340
+ svg.setAttribute('viewBox', '0 0 24 24');
341
+ svg.setAttribute('width', String(size));
342
+ svg.setAttribute('height', String(size));
343
+ svg.setAttribute('fill', 'currentColor');
344
+ svg.setAttribute('aria-hidden', 'true');
345
+ for (const d of paths) {
346
+ const path = node.ownerDocument.createElementNS(
347
+ 'http://www.w3.org/2000/svg',
348
+ 'path'
349
+ );
350
+ path.setAttribute('d', d);
351
+ path.setAttribute('fill-rule', 'evenodd');
352
+ svg.append(path);
353
+ }
354
+ fallback.replaceChildren(svg);
355
+ }
356
+ function bindHistory(
357
+ body: HTMLElement,
358
+ row: ActivityRow,
359
+ primitives: RowPrimitives
360
+ ) {
361
+ const v = histories.get(body) ?? createHistory(body, primitives);
362
+ v.primitives = primitives;
363
+ const table = row.presentation === 'table';
364
+ const footer = Boolean(row.footerActions?.length);
365
+ body.className = 'ok-native-list-row ok-native-list-history';
366
+ body.style.cssText = '';
367
+ body.removeAttribute('data-nl-container-background');
368
+ body.removeAttribute('data-nl-container-border');
369
+ Object.assign(body.style, {
370
+ display: 'flex',
371
+ flexDirection: 'column',
372
+ alignItems: 'stretch',
373
+ justifyContent: 'flex-start',
374
+ width: 'calc(100% - 16px)',
375
+ margin: '0 8px',
376
+ padding: `${table ? 12 : 8}px 12px`,
377
+ height:
378
+ !table && !footer && row.height !== 60 ? 'calc(100% - 8px)' : '100%',
379
+ borderRadius: '12px',
380
+ gap: '8px',
381
+ });
382
+ Object.assign(v.content.style, {
383
+ display: 'flex',
384
+ alignItems: 'center',
385
+ gap: '12px',
386
+ minWidth: '0',
387
+ width: '100%',
388
+ });
389
+ Object.assign(v.identity.style, {
390
+ display: 'flex',
391
+ alignItems: 'center',
392
+ gap: '12px',
393
+ minWidth: '0',
394
+ flex: '1 1 0',
395
+ });
396
+ Object.assign(v.visual.style, {
397
+ position: 'relative',
398
+ width: '40px',
399
+ height: '40px',
400
+ flex: '0 0 40px',
401
+ });
402
+ const visualKey = JSON.stringify([
403
+ row.key,
404
+ row.leading,
405
+ row.secondaryLeading,
406
+ ]);
407
+ if (v.visualKey !== visualKey) {
408
+ Array.from(v.visual.children).forEach((n) =>
409
+ primitives.dispose(n as HTMLElement)
410
+ );
411
+ v.visual.replaceChildren();
412
+ v.visuals = [];
413
+ const sources = [row.leading, row.secondaryLeading].filter(Boolean);
414
+ sources.forEach((source) => {
415
+ const visual = primitives.visual(source);
416
+ if (!visual) return;
417
+ historyIcon(visual, source, table || sources.length > 1 ? 24 : 28);
418
+ const retained = {
419
+ node: visual,
420
+ style: new RowVisualStyle(visual),
421
+ background: visual.style.background,
422
+ loaded: false,
423
+ };
424
+ // Only placeholder-backed sources restore their frame background on load.
425
+ const image = source && 'image' in source ? source.image : undefined;
426
+ if (image?.loadingStrategy && image.loadingStrategy !== 'none') {
427
+ visual
428
+ .querySelector('.ok-native-list-visual-main')
429
+ ?.addEventListener('load', () => {
430
+ retained.background =
431
+ source && 'backgroundColor' in source && source.backgroundColor
432
+ ? source.backgroundColor
433
+ : 'transparent';
434
+ retained.loaded = true;
435
+ });
436
+ }
437
+ v.visuals.push(retained);
438
+ v.visual.append(visual);
439
+ });
440
+ v.visualKey = visualKey;
441
+ }
442
+ const sources = [row.leading, row.secondaryLeading].filter(Boolean);
443
+ v.visuals.forEach((retained, index) => {
444
+ const { node: visual, style, background, loaded } = retained;
445
+ const source = sources[index];
446
+ const previousToken = visual.querySelector<HTMLElement>(
447
+ ':scope > .ok-native-list-history-token'
448
+ );
449
+ if (previousToken) {
450
+ visual.append(...Array.from(previousToken.children));
451
+ previousToken.remove();
452
+ }
453
+ const currentFallback = visual.querySelector<HTMLElement>(
454
+ ':scope > .ok-native-list-visual-fallback:not(.ok-native-list-visual-corner)'
455
+ );
456
+ if (currentFallback && retained.fallback !== currentFallback) {
457
+ retained.fallback = currentFallback;
458
+ retained.fallbackStyle = new RowVisualStyle(currentFallback);
459
+ }
460
+ // A terminal image error creates a new fallback node after the factory bind.
461
+ retained.fallbackStyle?.restore();
462
+ const size = sources.length > 1 ? (index ? 28 : 24) : 40;
463
+ style.apply(row.style?.image, size, size, 0);
464
+ Object.assign(visual.style, {
465
+ background,
466
+ position: '',
467
+ left: '',
468
+ top: '',
469
+ });
470
+ const svg = visual.querySelector<SVGElement>(
471
+ '.ok-native-list-visual-fallback > svg'
472
+ );
473
+ if (svg) {
474
+ const iconSize = String(table || sources.length > 1 ? 24 : 28);
475
+ svg.setAttribute('width', iconSize);
476
+ svg.setAttribute('height', iconSize);
477
+ }
478
+ Object.assign(visual.style, {
479
+ display: 'inline-flex',
480
+ alignItems: 'center',
481
+ justifyContent: 'center',
482
+ });
483
+ if (sources.length > 1)
484
+ Object.assign(visual.style, {
485
+ position: 'absolute',
486
+ left: index ? '12px' : '0',
487
+ top: index ? '12px' : '0',
488
+ border: index ? '2px solid var(--nl-row)' : '0',
489
+ boxSizing: 'border-box',
490
+ });
491
+ if (!table && sources.length > 1) {
492
+ const token = visual.ownerDocument.createElement('span');
493
+ token.className = 'ok-native-list-history-token';
494
+ Object.assign(token.style, {
495
+ display: 'flex',
496
+ alignItems: 'center',
497
+ justifyContent: 'center',
498
+ position: 'relative',
499
+ width: '24px',
500
+ height: '24px',
501
+ flex: '0 0 24px',
502
+ borderRadius: 'inherit',
503
+ boxSizing: 'border-box',
504
+ overflow: 'hidden',
505
+ background:
506
+ source && 'backgroundColor' in source
507
+ ? source.backgroundColor ?? ''
508
+ : '',
509
+ border:
510
+ source && 'borderColor' in source && source.borderColor
511
+ ? `1px solid ${source.borderColor}`
512
+ : '0',
513
+ });
514
+ token.append(
515
+ ...Array.from(visual.children).filter(
516
+ (child) => !child.classList.contains('ok-native-list-visual-corner')
517
+ )
518
+ );
519
+ const fallback = token.querySelector<HTMLElement>(
520
+ ':scope > .ok-native-list-visual-fallback'
521
+ );
522
+ if (fallback) {
523
+ fallback.style.width = '24px';
524
+ fallback.style.height = '24px';
525
+ fallback.style.flexShrink = '0';
526
+ }
527
+ const mainImage = token.querySelector<HTMLImageElement>(
528
+ ':scope > .ok-native-list-visual-main'
529
+ );
530
+ if (mainImage) {
531
+ mainImage.style.width = '100%';
532
+ mainImage.style.height = '100%';
533
+ }
534
+ visual.append(token);
535
+ }
536
+ if (table) {
537
+ visual.style.background = loaded
538
+ ? background
539
+ : source && 'backgroundColor' in source && source.backgroundColor
540
+ ? source.backgroundColor
541
+ : 'var(--nl-strong)';
542
+ const borderColor =
543
+ source && 'borderColor' in source && source.borderColor
544
+ ? source.borderColor
545
+ : 'var(--nl-separator)';
546
+ visual.style.border = `1px solid ${borderColor}`;
547
+ visual.style.boxSizing = 'border-box';
548
+ } else if (sources.length === 1 && source?.kind === 'token') {
549
+ visual.style.border = source.borderColor
550
+ ? `1px solid ${source.borderColor}`
551
+ : '0';
552
+ visual.style.boxSizing = 'border-box';
553
+ const mainImage = visual.querySelector<HTMLImageElement>(
554
+ ':scope > .ok-native-list-visual-main'
555
+ );
556
+ if (mainImage) {
557
+ mainImage.style.width = '100%';
558
+ mainImage.style.height = '100%';
559
+ }
560
+ }
561
+ });
562
+ Object.assign(v.text.style, {
563
+ minWidth: '0',
564
+ flex: '1 1 auto',
565
+ display: 'flex',
566
+ flexDirection: 'column',
567
+ gap: table ? '4px' : '0',
568
+ });
569
+ Object.assign(v.titleLine.style, {
570
+ display: 'flex',
571
+ alignItems: 'center',
572
+ minWidth: '0',
573
+ });
574
+ v.title.style.cssText =
575
+ ellipsis +
576
+ `font-size:${table ? 14 : 16}px;line-height:${
577
+ table ? 20 : 24
578
+ }px;font-weight:500;`;
579
+ v.title.textContent = row.title;
580
+ applyTextWeight(v.title, 500);
581
+ if (row.style?.title) primitives.textStyle(v.title, row.style.title);
582
+ v.badges.style.cssText = 'display:flex;flex:0 0 auto;gap:8px;margin-left:8px';
583
+ v.badges.replaceChildren();
584
+ for (const badge of row.badges ?? []) {
585
+ const element = createElement(
586
+ body.ownerDocument,
587
+ 'span',
588
+ 'ok-native-list-badge',
589
+ badge.text
590
+ );
591
+ element.dataset.tone = badge.tone ?? '';
592
+ element.style.cssText =
593
+ 'height:20px;font-size:12px;line-height:16px;padding:2px 8px;border-radius:4px;box-sizing:border-box';
594
+ applyTextWeight(element, 500);
595
+ if (badge.tone === 'neutral')
596
+ Object.assign(element.style, {
597
+ background: 'var(--nl-strong)',
598
+ color: 'var(--nl-secondary)',
599
+ });
600
+ if (badge.tone === 'warning')
601
+ Object.assign(element.style, {
602
+ background:
603
+ 'var(--nl-caution-background,color-mix(in srgb,var(--nl-caution) 12%,transparent))',
604
+ color: 'var(--nl-caution)',
605
+ });
606
+ v.badges.append(element);
607
+ }
608
+ v.badges.style.display = row.badges?.length ? 'flex' : 'none';
609
+ v.description.style.cssText =
610
+ ellipsis +
611
+ '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;';
612
+ applyTextWeight(v.description, 400);
613
+ const split = row.description?.indexOf(' • ') ?? -1;
614
+ v.descriptionTime.textContent =
615
+ split >= 0 ? row.description!.slice(0, split) : '';
616
+ v.descriptionTime.style.display = split >= 0 ? 'inline' : 'none';
617
+ v.descriptionTime.style.flexShrink = '0';
618
+ v.descriptionDot.style.cssText = `flex-shrink:0;margin:0 4px;display:${
619
+ split >= 0 ? 'inline' : 'none'
620
+ }`;
621
+ v.descriptionAddress.style.cssText =
622
+ ellipsis +
623
+ 'appearance:none;display:block;max-width:100%;border:0;padding:0;background:transparent;text-align:left;color:inherit;font:inherit;font-variant-numeric:inherit;';
624
+ v.descriptionAddress.textContent =
625
+ split >= 0 ? row.description!.slice(split + 3) : row.description ?? '';
626
+ v.description.style.display = row.description ? 'flex' : 'none';
627
+ v.descriptionAddress.tabIndex = row.descriptionActionKey ? 0 : -1;
628
+ if (row.descriptionActionKey) {
629
+ v.descriptionAddress.dataset.nativeListAction = row.descriptionActionKey;
630
+ markActionAnchorSource(v.descriptionAddress, 'description');
631
+ v.descriptionAddress.style.cursor = 'pointer';
632
+ } else {
633
+ delete v.descriptionAddress.dataset.nativeListAction;
634
+ delete v.descriptionAddress.dataset.nativeListAnchorSource;
635
+ v.descriptionAddress.style.cursor = 'inherit';
636
+ }
637
+ if (row.style?.description)
638
+ primitives.textStyle(v.description, row.style.description);
639
+ v.description.style.display = row.description ? 'flex' : 'none';
640
+ Object.assign(v.amounts.style, {
641
+ display: 'flex',
642
+ flexDirection: 'column',
643
+ minWidth: '0',
644
+ gap: table ? '4px' : '0',
645
+ flex: table ? '1 1 0' : '0 1 auto',
646
+ maxWidth: table ? '50%' : '50%',
647
+ alignItems: table ? 'stretch' : 'flex-end',
648
+ alignSelf: table ? 'stretch' : 'center',
649
+ });
650
+ const amountKeys = new Set<string>();
651
+ for (const amount of row.amounts ?? []) {
652
+ amountKeys.add(amount.key);
653
+ let view = v.amountRows.get(amount.key);
654
+ if (!view) {
655
+ const element = createElement(body.ownerDocument, 'div');
656
+ const primary = tagSlot(
657
+ createElement(body.ownerDocument, 'span'),
658
+ 'primaryAmount'
659
+ );
660
+ const secondary = tagSlot(
661
+ createElement(body.ownerDocument, 'span'),
662
+ 'secondaryAmount'
663
+ );
664
+ element.append(primary, secondary);
665
+ view = { element, primary, secondary, visualKey: '' };
666
+ v.amountRows.set(amount.key, view);
667
+ }
668
+ view.element.style.cssText = `display:flex;align-items:center;gap:4px;min-width:0;max-width:100%;${
669
+ table ? '' : 'justify-content:flex-end;'
670
+ }`;
671
+ const secondary = amount.tone === 'secondary';
672
+ const size = table || secondary ? 14 : 16;
673
+ const line = table || secondary ? 20 : 24;
674
+ const weight = table || secondary ? 400 : 500;
675
+ view.primary.style.cssText =
676
+ ellipsis +
677
+ `font-size:${size}px;line-height:${line}px;font-weight:${weight};color:${
678
+ amount.tone === 'positive'
679
+ ? 'var(--nl-positive)'
680
+ : amount.tone === 'negative'
681
+ ? 'var(--nl-negative)'
682
+ : secondary
683
+ ? 'var(--nl-secondary)'
684
+ : 'var(--nl-primary)'
685
+ };`;
686
+ valueText(
687
+ view.primary,
688
+ amount.text,
689
+ amount.textSegments,
690
+ size,
691
+ line,
692
+ weight
693
+ );
694
+ const roleStyle = secondary
695
+ ? row.style?.secondaryAmount
696
+ : row.style?.primaryAmount;
697
+ if (roleStyle) primitives.textStyle(view.primary, roleStyle);
698
+ view.secondary.style.cssText =
699
+ ellipsis +
700
+ 'font-size:14px;line-height:20px;font-weight:400;color:var(--nl-secondary);';
701
+ valueText(
702
+ view.secondary,
703
+ amount.secondaryText,
704
+ amount.secondaryTextSegments,
705
+ 14,
706
+ 20,
707
+ 400
708
+ );
709
+ view.secondary.hidden = !table || !amount.secondaryText;
710
+ const amountVisualKey = JSON.stringify(table ? amount.leading : undefined);
711
+ if (view.visualKey !== amountVisualKey) {
712
+ if (view.visual) {
713
+ primitives.dispose(view.visual);
714
+ view.visual.remove();
715
+ }
716
+ view.visual = table ? primitives.visual(amount.leading) : undefined;
717
+ if (view.visual) {
718
+ new RowVisualStyle(view.visual).apply(
719
+ { width: 20, height: 20 },
720
+ 20,
721
+ 20,
722
+ 0
723
+ );
724
+ historyIcon(view.visual, amount.leading, 16);
725
+ if (amount.leading?.kind === 'token' && amount.leading.image) {
726
+ view.visual.style.border = amount.leading.borderColor
727
+ ? `1px solid ${amount.leading.borderColor}`
728
+ : '0';
729
+ view.visual.style.boxSizing = 'border-box';
730
+ }
731
+ view.element.prepend(view.visual);
732
+ }
733
+ view.visualKey = amountVisualKey;
734
+ }
735
+ v.amounts.append(view.element);
736
+ }
737
+ for (const [key, view] of v.amountRows) {
738
+ if (!amountKeys.has(key)) {
739
+ if (view.visual) primitives.dispose(view.visual);
740
+ view.element.remove();
741
+ v.amountRows.delete(key);
742
+ }
743
+ }
744
+ v.fee.style.cssText =
745
+ 'display:flex;flex-direction:column;flex:.6 1 0;min-width:0;gap:4px';
746
+ v.fee.hidden = !table || !row.fee;
747
+ v.fee.style.display = table && row.fee ? 'flex' : 'none';
748
+ v.fee.style.opacity = row.fee?.hidden ? '0' : '1';
749
+ v.feeLabel.style.cssText =
750
+ 'font-size:14px;line-height:20px;color:var(--nl-secondary);';
751
+ v.feeLabel.textContent = row.fee?.label ?? '';
752
+ applyTextWeight(v.feeLabel, 400);
753
+ v.feeValues.style.cssText =
754
+ 'display:flex;align-items:center;gap:4px;min-width:0';
755
+ v.feePrimary.style.cssText =
756
+ ellipsis + 'font-size:14px;line-height:20px;font-weight:400;';
757
+ v.feeSecondary.style.cssText =
758
+ ellipsis +
759
+ 'font-size:14px;line-height:20px;font-weight:400;color:var(--nl-secondary);';
760
+ valueText(
761
+ v.feePrimary,
762
+ row.fee?.primary,
763
+ row.fee?.primaryTextSegments,
764
+ 14,
765
+ 20,
766
+ 400
767
+ );
768
+ valueText(
769
+ v.feeSecondary,
770
+ row.fee?.secondary,
771
+ row.fee?.secondaryTextSegments,
772
+ 14,
773
+ 20,
774
+ 400
775
+ );
776
+ v.actions.style.cssText =
777
+ 'display:flex;gap:12px;padding-left:52px;padding-bottom:4px;';
778
+ v.actions.style.display = footer ? 'flex' : 'none';
779
+ const actionKeys = new Set<string>();
780
+ for (const [index, action] of (row.footerActions ?? []).entries()) {
781
+ actionKeys.add(action.key);
782
+ let button = v.actionButtons.get(action.key);
783
+ if (!button) {
784
+ button = createElement(
785
+ body.ownerDocument,
786
+ 'button',
787
+ 'ok-native-list-action-button'
788
+ ) as HTMLButtonElement;
789
+ button.type = 'button';
790
+ v.actionButtons.set(action.key, button);
791
+ }
792
+ if (button.textContent !== action.label) button.textContent = action.label;
793
+ button.toggleAttribute('disabled', Boolean(action.disabled));
794
+ button.dataset.nativeListAction = action.key;
795
+ markActionAnchorSource(button, 'footerAction', index);
796
+ button.style.cssText =
797
+ '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;';
798
+ applyTextWeight(button, 500);
799
+ if (action.tone === 'primary')
800
+ Object.assign(button.style, {
801
+ background: 'var(--nl-primary)',
802
+ color: 'var(--nl-inverse-text)',
803
+ });
804
+ if (v.actions.children[index] !== button)
805
+ v.actions.insertBefore(button, v.actions.children[index] ?? null);
806
+ }
807
+ for (const [key, button] of v.actionButtons) {
808
+ if (!actionKeys.has(key)) {
809
+ button.remove();
810
+ v.actionButtons.delete(key);
811
+ }
812
+ }
813
+ }
814
+ function recycle(body: HTMLElement) {
815
+ const v = histories.get(body);
816
+ if (v) {
817
+ Array.from(v.visual.children).forEach((n) =>
818
+ v.primitives.dispose(n as HTMLElement)
819
+ );
820
+ for (const view of v.amountRows.values())
821
+ if (view.visual) v.primitives.dispose(view.visual);
822
+ histories.delete(body);
823
+ }
824
+ recycleLegacy(body);
825
+ views.delete(body);
826
+ }
827
+ function bind(body: HTMLElement, row: ActivityRow, primitives: RowPrimitives) {
828
+ if (isHistory(row)) {
829
+ if (views.has(body)) {
830
+ recycleLegacy(body);
831
+ views.delete(body);
832
+ }
833
+ bindHistory(body, row, primitives);
834
+ } else {
835
+ if (histories.has(body)) recycle(body);
836
+ if (!views.has(body)) {
837
+ const initial = createLegacy(body.ownerDocument, row, primitives);
838
+ body.replaceChildren(...Array.from(initial.childNodes));
839
+ body.className = initial.className;
840
+ views.set(body, views.get(initial)!);
841
+ views.delete(initial);
842
+ }
843
+ bindLegacy(body, row, primitives);
844
+ }
845
+ }
846
+ function create(
847
+ document: Document,
848
+ row: ActivityRow,
849
+ primitives: RowPrimitives
850
+ ) {
851
+ const body = document.createElement('div');
852
+ body.dataset.nlRenderer = 'activity';
853
+ bind(body, row, primitives);
854
+ return body;
855
+ }
148
856
  export const activityRowRenderer = {
149
857
  key: 'activity' as const,
150
858
  create,
151
859
  bind,
152
860
  recycle,
153
- measure: (row: ActivityRow, _width: number) =>
154
- row.footerActions?.length ? 100 : 60,
861
+ measure: (row: ActivityRow, _width: number) => {
862
+ if (!isHistory(row)) return row.footerActions?.length ? 100 : 60;
863
+ const extra =
864
+ row.presentation === 'table'
865
+ ? Math.max(0, (row.amounts?.length ?? 0) - 2) * 24
866
+ : 0;
867
+ if (row.footerActions?.length)
868
+ return (row.presentation === 'table' ? 68 : 60) + extra + 42;
869
+ return 68 + extra;
870
+ },
155
871
  measureRendered: (
156
872
  _body: HTMLElement,
157
873
  _row: ActivityRow