@onekeyfe/react-native-native-list 6.8.0-24 → 6.8.0-26

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.
@@ -1,4 +1,4 @@
1
- import { applyTextWeight } from './RowText';
1
+ import { applyTextWeight, fontWeight } from './RowText';
2
2
  import { applyTabularNumbers, hasExplicitRowHeight } from './RowElements';
3
3
  import type {
4
4
  IdentityRow,
@@ -30,6 +30,81 @@ function toneColor(
30
30
  if (tone === 'secondary') return 'var(--nl-secondary)';
31
31
  return fallback === 'secondary' ? 'var(--nl-secondary)' : 'var(--nl-primary)';
32
32
  }
33
+ // Hidden from sight, still read: the runs themselves are hidden from
34
+ // assistive technology in favor of `title`.
35
+ const VISUALLY_HIDDEN: Partial<CSSStyleDeclaration> = {
36
+ position: 'absolute',
37
+ width: '1px',
38
+ height: '1px',
39
+ overflow: 'hidden',
40
+ clip: 'rect(0 0 0 0)',
41
+ whiteSpace: 'nowrap',
42
+ };
43
+ function appendTitleRuns(
44
+ document: Document,
45
+ target: HTMLElement,
46
+ row: IdentityRow
47
+ ): void {
48
+ const runs = createElement(
49
+ document,
50
+ 'span',
51
+ 'ok-native-list-identity-title-runs'
52
+ );
53
+ runs.setAttribute('aria-hidden', 'true');
54
+ Object.assign(runs.style, {
55
+ display: 'flex',
56
+ flex: '1 1 auto',
57
+ minWidth: '0',
58
+ maxWidth: '100%',
59
+ overflow: 'hidden',
60
+ });
61
+ row.titleSegments?.forEach((segment) => {
62
+ const run = createElement(
63
+ document,
64
+ 'span',
65
+ 'ok-native-list-identity-title-run',
66
+ // A run is one line on every platform: `white-space: pre` would turn a
67
+ // hard break into a second line here.
68
+ segment.text.replace(/\r\n|[\r\n]/g, ' ')
69
+ );
70
+ // Only the shrinking run gives up width; a cap is a share of the line.
71
+ Object.assign(run.style, {
72
+ flex: segment.shrink ? '0 1 auto' : '0 0 auto',
73
+ minWidth: segment.shrink ? '0' : '',
74
+ maxWidth:
75
+ segment.maxWidthRatio === undefined
76
+ ? ''
77
+ : `${segment.maxWidthRatio * 100}%`,
78
+ overflow: 'hidden',
79
+ textOverflow: 'ellipsis',
80
+ whiteSpace: 'pre',
81
+ });
82
+ if (segment.tone)
83
+ run.style.color =
84
+ segment.tone === 'secondary'
85
+ ? 'var(--nl-secondary)'
86
+ : 'var(--nl-primary)';
87
+ if (segment.fontWeight === 'medium') {
88
+ run.style.fontWeight = '500';
89
+ run.style.fontFamily = 'var(--nl-font-medium)';
90
+ } else if (segment.fontWeight === 'regular') {
91
+ run.style.fontWeight = '400';
92
+ run.style.fontFamily = 'var(--nl-font-regular)';
93
+ }
94
+ setData(run, 'tone', segment.tone);
95
+ runs.appendChild(run);
96
+ });
97
+ const spoken = createElement(
98
+ document,
99
+ 'span',
100
+ 'ok-native-list-identity-title-spoken',
101
+ row.title
102
+ );
103
+ Object.assign(spoken.style, VISUALLY_HIDDEN);
104
+ target.replaceChildren(runs, spoken);
105
+ target.style.display = 'flex';
106
+ target.style.minWidth = '0';
107
+ }
33
108
  function appendAccessories(
34
109
  parent: HTMLElement,
35
110
  document: Document,
@@ -217,6 +292,18 @@ function createIdentityRow(
217
292
  fragment.appendChild(document.createTextNode(row.title.slice(offset)));
218
293
  textTarget.prepend(fragment);
219
294
  }
295
+ // The runs replace the plain title, except where `title` itself is
296
+ // highlighted or shown in the wallet sidebar.
297
+ const hasTitleRuns =
298
+ !!row.titleSegments?.length &&
299
+ presentation !== 'walletSidebar' &&
300
+ !row.titleMatch?.length;
301
+ if (hasTitleRuns) {
302
+ const textTarget =
303
+ titleElement.querySelector<HTMLElement>('[data-nl-slot="title"]') ??
304
+ titleElement;
305
+ appendTitleRuns(document, textTarget, row);
306
+ }
220
307
  if (row.subtitleSegments?.length) {
221
308
  column.querySelector('.ok-native-list-secondary')?.remove();
222
309
  const segments = createElement(
@@ -413,6 +500,69 @@ function createIdentityRow(
413
500
  badges.style.minWidth = '0';
414
501
  }
415
502
  }
503
+ if (hasTitleRuns) {
504
+ // The runs fill what the title line leaves, so a ratio is a share of
505
+ // that width and title accessories sit at the line's end.
506
+ const runs = titleElement.querySelector<HTMLElement>(
507
+ '.ok-native-list-identity-title-runs'
508
+ );
509
+ for (
510
+ let node = runs?.parentElement;
511
+ node && node !== titleElement;
512
+ node = node.parentElement
513
+ ) {
514
+ node.style.display = 'flex';
515
+ node.style.flex = '1 1 auto';
516
+ node.style.minWidth = '0';
517
+ }
518
+ titleElement.style.display = 'flex';
519
+ titleElement.style.alignItems = 'center';
520
+ }
521
+ if (row.titleLeadingIcon && presentation !== 'walletSidebar') {
522
+ const descriptor = row.titleLeadingIcon;
523
+ if (titleElement.hasAttribute('data-nl-slot')) {
524
+ // Keep the glyph out of the title slot that text styles apply to.
525
+ const titleText = tagSlot(
526
+ createElement(document, 'span', 'ok-native-list-identity-title-text'),
527
+ 'title'
528
+ );
529
+ while (titleElement.firstChild)
530
+ titleText.appendChild(titleElement.firstChild);
531
+ if (hasTitleRuns) {
532
+ titleText.style.display = 'flex';
533
+ // Created after the loop above gave the runs' ancestors their share:
534
+ // without it a ratio would be a share of the text's own width.
535
+ titleText.style.flex = '1 1 auto';
536
+ titleText.style.minWidth = '0';
537
+ }
538
+ titleElement.removeAttribute('data-nl-slot');
539
+ titleElement.appendChild(titleText);
540
+ }
541
+ // A label makes the passive glyph an image with that name.
542
+ const icon = primitives.iconAction(
543
+ descriptor.name,
544
+ undefined,
545
+ undefined,
546
+ descriptor.tintColor,
547
+ descriptor.accessibilityLabel
548
+ );
549
+ icon.className = 'ok-native-list-identity-title-leading-icon';
550
+ if (!descriptor.accessibilityLabel)
551
+ icon.setAttribute('aria-hidden', 'true');
552
+ // The slot is 16px. Host artwork comes at 24px, and a name without
553
+ // artwork leaves the slot empty rather than a text glyph.
554
+ const artwork = icon.querySelector('svg');
555
+ if (artwork) {
556
+ artwork.setAttribute('width', '16');
557
+ artwork.setAttribute('height', '16');
558
+ } else icon.textContent = '';
559
+ titleElement.style.display = 'flex';
560
+ titleElement.style.alignItems = 'center';
561
+ // 6px to the title, whatever gap the title line already has.
562
+ const lineGap = Number.parseFloat(titleElement.style.gap || '0') || 0;
563
+ icon.style.marginInlineEnd = `${Math.max(0, 6 - lineGap)}px`;
564
+ titleElement.prepend(icon);
565
+ }
416
566
  if (presentation === 'walletSidebar' && row.badges?.length) {
417
567
  const badges = createElement(
418
568
  document,
@@ -425,6 +575,7 @@ function createIdentityRow(
425
575
  column.appendChild(badges);
426
576
  }
427
577
  for (const key of ['title', 'subtitle'] as const) {
578
+ if (key === 'title' && hasTitleRuns) continue;
428
579
  const lines = row.style?.[key]?.lines ?? row[`${key}Lines`];
429
580
  if (lines !== undefined)
430
581
  column
@@ -581,10 +732,42 @@ function applyIdentityStyle(body: HTMLElement, row: IdentityRow) {
581
732
  body
582
733
  .querySelectorAll<HTMLElement>('[data-nl-slot="' + key + '"]')
583
734
  .forEach((element) => {
584
- applyTextStyleToSlot(element, slotStyle);
735
+ if (
736
+ key === 'title' &&
737
+ element.querySelector('.ok-native-list-identity-title-runs')
738
+ )
739
+ applyTitleStyleToRuns(element, slotStyle);
740
+ else applyTextStyleToSlot(element, slotStyle);
585
741
  });
586
742
  });
587
743
  }
744
+ // With runs, `style.title` only sets what a run inherits: a run that names its
745
+ // tone or weight keeps it, and the runs stay on one line whatever `lines` says.
746
+ function applyTitleStyleToRuns(
747
+ slot: HTMLElement,
748
+ style: NativeListTextStyle
749
+ ): void {
750
+ if (style.fontSize !== undefined)
751
+ slot.style.fontSize = String(style.fontSize) + 'px';
752
+ if (style.lineHeight !== undefined)
753
+ slot.style.lineHeight = String(style.lineHeight) + 'px';
754
+ if (style.fontWeight !== undefined)
755
+ applyTextWeight(slot, String(fontWeight(style.fontWeight, 400)));
756
+ if (style.color !== undefined) slot.style.color = style.color;
757
+ if (style.tabularNumbers !== undefined)
758
+ slot.style.fontVariantNumeric = style.tabularNumbers
759
+ ? 'tabular-nums'
760
+ : 'proportional-nums';
761
+ if (style.letterSpacing !== undefined)
762
+ slot.style.letterSpacing = String(style.letterSpacing) + 'px';
763
+ // Paint only, as for a plain title: the line keeps its place in the layout.
764
+ if (style.offsetY !== undefined) {
765
+ const runs = slot.querySelector<HTMLElement>(
766
+ '.ok-native-list-identity-title-runs'
767
+ );
768
+ if (runs) runs.style.transform = `translateY(${style.offsetY}px)`;
769
+ }
770
+ }
588
771
  type Views = {
589
772
  visual?: {
590
773
  key: string;