@onekeyfe/react-native-native-list 6.8.0-25 → 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.
- package/android/src/main/java/com/onekey/nativelist/NativeListActivityDetailsView.kt +12 -1
- package/android/src/main/java/com/onekey/nativelist/NativeListIdentityRenderer.kt +96 -3
- package/android/src/main/java/com/onekey/nativelist/NativeListPrimitives.kt +6 -3
- package/android/src/main/java/com/onekey/nativelist/NativeListTitleSegmentLayout.kt +71 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListTitleSegmentsView.kt +126 -0
- package/android/src/test/java/com/margelo/nitro/nativelist/NativeListTitleSegmentLayoutTest.kt +130 -0
- package/docs/ROW_TEMPLATES.md +8 -1
- package/docs/SPEC.md +122 -3
- package/ios/NativeListActivityDetailsView.swift +45 -1
- package/ios/NativeListIdentityRenderer.swift +109 -8
- package/ios/NativeListTitleSegmentLayout.swift +72 -0
- package/ios/NativeListTitleSegmentsLabel.swift +92 -0
- package/ios/tests/NativeListActivityPresentationTests.swift +137 -0
- package/ios/tests/NativeListIdentityTitleIconLayoutTests.swift +155 -0
- package/lib/module/models.js +2 -0
- package/lib/module/validation.js +77 -5
- package/lib/module/web/NativeListWebEngine.js +1 -1
- package/lib/module/web/templates/IdentityRowRenderer.js +122 -2
- package/lib/typescript/src/models.d.ts +21 -1
- package/package.json +1 -1
- package/src/models.ts +23 -0
- package/src/validation.ts +129 -2
- package/src/web/NativeListWebEngine.ts +1 -1
- package/src/web/templates/IdentityRowRenderer.ts +185 -2
|
@@ -400,6 +400,18 @@ export type RowBase = Readonly<{
|
|
|
400
400
|
accessibilityLabel?: string;
|
|
401
401
|
separator?: boolean;
|
|
402
402
|
}>;
|
|
403
|
+
/** One run of an identity title line; see docs/SPEC.md. */
|
|
404
|
+
export type IdentityTitleSegment = Readonly<{
|
|
405
|
+
text: string;
|
|
406
|
+
/** Omitted: the title color. */
|
|
407
|
+
tone?: 'primary' | 'secondary';
|
|
408
|
+
/** Omitted: the title weight. */
|
|
409
|
+
fontWeight?: 'regular' | 'medium';
|
|
410
|
+
/** The one run that gives up width when the line is too narrow. */
|
|
411
|
+
shrink?: boolean;
|
|
412
|
+
/** Caps the run at this fraction of the title line, within (0, 1]. */
|
|
413
|
+
maxWidthRatio?: number;
|
|
414
|
+
}>;
|
|
403
415
|
export type IdentityRow = RowBase & Readonly<{
|
|
404
416
|
type: 'identity';
|
|
405
417
|
/** Opt in to content-based height; explicit row/container height still wins. */
|
|
@@ -434,6 +446,14 @@ export type IdentityRow = RowBase & Readonly<{
|
|
|
434
446
|
}>;
|
|
435
447
|
/** Web-only additional help icon after titleIcon. */
|
|
436
448
|
secondaryTitleIcon?: IdentityRow['titleIcon'];
|
|
449
|
+
/** Runs drawn in place of `title`, which stays the spoken label. */
|
|
450
|
+
titleSegments?: readonly IdentityTitleSegment[];
|
|
451
|
+
/** 16-point glyph before the title; decorative unless labelled. */
|
|
452
|
+
titleLeadingIcon?: Readonly<{
|
|
453
|
+
name: string;
|
|
454
|
+
tintColor?: string;
|
|
455
|
+
accessibilityLabel?: string;
|
|
456
|
+
}>;
|
|
437
457
|
/** Circular image after title icons; image dimensions must be square, 1...40. */
|
|
438
458
|
titleImage?: Readonly<{
|
|
439
459
|
image: ImageSource;
|
|
@@ -911,7 +931,7 @@ export type PatchClearableChanges<Row, Keys extends keyof Row> = Readonly<{
|
|
|
911
931
|
export type RowPatch = Readonly<{
|
|
912
932
|
type: 'identity';
|
|
913
933
|
key: string;
|
|
914
|
-
changes: PatchClearableChanges<IdentityRow, CommonPatchFields | 'title' | 'titleSuffixes' | 'titleIcon' | 'secondaryTitleIcon' | 'titleImage' | 'subtitle' | 'subtitleLines' | 'collapseEmptyTrailing' | 'contentHeight' | 'longPressActionKey' | 'tertiary' | 'tertiaryTone' | 'badges' | 'trailing' | 'leading' | 'leadingAction' | 'titleMatch' | 'titleActionKey' | 'titleActionOnHover' | 'subtitleSegments'>;
|
|
934
|
+
changes: PatchClearableChanges<IdentityRow, CommonPatchFields | 'title' | 'titleSuffixes' | 'titleIcon' | 'secondaryTitleIcon' | 'titleImage' | 'titleSegments' | 'titleLeadingIcon' | 'subtitle' | 'subtitleLines' | 'collapseEmptyTrailing' | 'contentHeight' | 'longPressActionKey' | 'tertiary' | 'tertiaryTone' | 'badges' | 'trailing' | 'leading' | 'leadingAction' | 'titleMatch' | 'titleActionKey' | 'titleActionOnHover' | 'subtitleSegments'>;
|
|
915
935
|
}> | Readonly<{
|
|
916
936
|
type: 'rail';
|
|
917
937
|
key: string;
|
package/package.json
CHANGED
package/src/models.ts
CHANGED
|
@@ -519,6 +519,19 @@ export type RowBase = Readonly<{
|
|
|
519
519
|
separator?: boolean;
|
|
520
520
|
}>;
|
|
521
521
|
|
|
522
|
+
/** One run of an identity title line; see docs/SPEC.md. */
|
|
523
|
+
export type IdentityTitleSegment = Readonly<{
|
|
524
|
+
text: string;
|
|
525
|
+
/** Omitted: the title color. */
|
|
526
|
+
tone?: 'primary' | 'secondary';
|
|
527
|
+
/** Omitted: the title weight. */
|
|
528
|
+
fontWeight?: 'regular' | 'medium';
|
|
529
|
+
/** The one run that gives up width when the line is too narrow. */
|
|
530
|
+
shrink?: boolean;
|
|
531
|
+
/** Caps the run at this fraction of the title line, within (0, 1]. */
|
|
532
|
+
maxWidthRatio?: number;
|
|
533
|
+
}>;
|
|
534
|
+
|
|
522
535
|
export type IdentityRow = RowBase &
|
|
523
536
|
Readonly<{
|
|
524
537
|
type: 'identity';
|
|
@@ -550,6 +563,14 @@ export type IdentityRow = RowBase &
|
|
|
550
563
|
}>;
|
|
551
564
|
/** Web-only additional help icon after titleIcon. */
|
|
552
565
|
secondaryTitleIcon?: IdentityRow['titleIcon'];
|
|
566
|
+
/** Runs drawn in place of `title`, which stays the spoken label. */
|
|
567
|
+
titleSegments?: readonly IdentityTitleSegment[];
|
|
568
|
+
/** 16-point glyph before the title; decorative unless labelled. */
|
|
569
|
+
titleLeadingIcon?: Readonly<{
|
|
570
|
+
name: string;
|
|
571
|
+
tintColor?: string;
|
|
572
|
+
accessibilityLabel?: string;
|
|
573
|
+
}>;
|
|
553
574
|
/** Circular image after title icons; image dimensions must be square, 1...40. */
|
|
554
575
|
titleImage?: Readonly<{
|
|
555
576
|
image: ImageSource;
|
|
@@ -1124,6 +1145,8 @@ export type RowPatch =
|
|
|
1124
1145
|
| 'titleIcon'
|
|
1125
1146
|
| 'secondaryTitleIcon'
|
|
1126
1147
|
| 'titleImage'
|
|
1148
|
+
| 'titleSegments'
|
|
1149
|
+
| 'titleLeadingIcon'
|
|
1127
1150
|
| 'subtitle'
|
|
1128
1151
|
| 'subtitleLines'
|
|
1129
1152
|
| 'collapseEmptyTrailing'
|
package/src/validation.ts
CHANGED
|
@@ -1357,6 +1357,110 @@ function assertButtonGroup(
|
|
|
1357
1357
|
});
|
|
1358
1358
|
}
|
|
1359
1359
|
|
|
1360
|
+
const MAX_TITLE_SEGMENTS = 4;
|
|
1361
|
+
const HEX_COLOR_PATTERN = /^#[0-9a-f]{6}([0-9a-f]{2})?$/i;
|
|
1362
|
+
|
|
1363
|
+
function assertTitleSegments(value: unknown, path: string): void {
|
|
1364
|
+
if (
|
|
1365
|
+
!Array.isArray(value) ||
|
|
1366
|
+
value.length === 0 ||
|
|
1367
|
+
value.length > MAX_TITLE_SEGMENTS
|
|
1368
|
+
)
|
|
1369
|
+
fail(path, `must hold 1...${MAX_TITLE_SEGMENTS} segments`);
|
|
1370
|
+
let shrinking = 0;
|
|
1371
|
+
// Array.from also visits holes, so a sparse list is rejected here and the
|
|
1372
|
+
// production sanitizer drops it before protocol validation walks it.
|
|
1373
|
+
Array.from(value as readonly unknown[]).forEach((item, index) => {
|
|
1374
|
+
const segmentPath = `${path}[${index}]`;
|
|
1375
|
+
const segment = protocolObject(item, segmentPath);
|
|
1376
|
+
assertUnknownKeys(
|
|
1377
|
+
segment,
|
|
1378
|
+
['text', 'tone', 'fontWeight', 'shrink', 'maxWidthRatio'],
|
|
1379
|
+
segmentPath,
|
|
1380
|
+
'title segment key'
|
|
1381
|
+
);
|
|
1382
|
+
const { text, tone, fontWeight, shrink, maxWidthRatio } = segment;
|
|
1383
|
+
if (typeof text !== 'string' || !text.trim())
|
|
1384
|
+
fail(`${segmentPath}.text`, 'must be non-blank');
|
|
1385
|
+
assertText(text, `${segmentPath}.text`);
|
|
1386
|
+
if (tone !== undefined && tone !== 'primary' && tone !== 'secondary')
|
|
1387
|
+
fail(`${segmentPath}.tone`, 'must be primary or secondary');
|
|
1388
|
+
if (
|
|
1389
|
+
fontWeight !== undefined &&
|
|
1390
|
+
fontWeight !== 'regular' &&
|
|
1391
|
+
fontWeight !== 'medium'
|
|
1392
|
+
)
|
|
1393
|
+
fail(`${segmentPath}.fontWeight`, 'must be regular or medium');
|
|
1394
|
+
if (shrink !== undefined && typeof shrink !== 'boolean')
|
|
1395
|
+
fail(`${segmentPath}.shrink`, 'must be a boolean');
|
|
1396
|
+
if (shrink) shrinking += 1;
|
|
1397
|
+
if (
|
|
1398
|
+
maxWidthRatio !== undefined &&
|
|
1399
|
+
(typeof maxWidthRatio !== 'number' ||
|
|
1400
|
+
!Number.isFinite(maxWidthRatio) ||
|
|
1401
|
+
maxWidthRatio <= 0 ||
|
|
1402
|
+
maxWidthRatio > 1)
|
|
1403
|
+
)
|
|
1404
|
+
fail(`${segmentPath}.maxWidthRatio`, 'must be finite within (0, 1]');
|
|
1405
|
+
});
|
|
1406
|
+
if (shrinking > 1) fail(path, 'allows at most one shrinking segment');
|
|
1407
|
+
}
|
|
1408
|
+
|
|
1409
|
+
function assertTitleLeadingIcon(value: unknown, path: string): void {
|
|
1410
|
+
const icon = protocolObject(value, path);
|
|
1411
|
+
assertUnknownKeys(
|
|
1412
|
+
icon,
|
|
1413
|
+
['name', 'tintColor', 'accessibilityLabel'],
|
|
1414
|
+
path,
|
|
1415
|
+
'title leading icon key'
|
|
1416
|
+
);
|
|
1417
|
+
const { name, tintColor, accessibilityLabel } = icon;
|
|
1418
|
+
if (typeof name !== 'string' || !name.trim())
|
|
1419
|
+
fail(`${path}.name`, 'must be non-blank');
|
|
1420
|
+
if (
|
|
1421
|
+
tintColor !== undefined &&
|
|
1422
|
+
(typeof tintColor !== 'string' || !HEX_COLOR_PATTERN.test(tintColor))
|
|
1423
|
+
)
|
|
1424
|
+
fail(`${path}.tintColor`, 'must be #RRGGBB or #RRGGBBAA');
|
|
1425
|
+
if (
|
|
1426
|
+
accessibilityLabel !== undefined &&
|
|
1427
|
+
typeof accessibilityLabel !== 'string'
|
|
1428
|
+
)
|
|
1429
|
+
fail(`${path}.accessibilityLabel`, 'must be a string');
|
|
1430
|
+
}
|
|
1431
|
+
|
|
1432
|
+
function assertIdentityTitleRuns(
|
|
1433
|
+
row: Pick<
|
|
1434
|
+
IdentityRow,
|
|
1435
|
+
'titleSegments' | 'titleLeadingIcon' | 'titleMatch' | 'presentation'
|
|
1436
|
+
>,
|
|
1437
|
+
path: string
|
|
1438
|
+
): void {
|
|
1439
|
+
if (row.titleSegments !== undefined) {
|
|
1440
|
+
assertTitleSegments(row.titleSegments, `${path}.titleSegments`);
|
|
1441
|
+
// titleMatch ranges index `title`, which the runs replace on screen.
|
|
1442
|
+
if (row.titleMatch?.length)
|
|
1443
|
+
fail(`${path}.titleMatch`, 'cannot be combined with titleSegments');
|
|
1444
|
+
if (row.presentation === 'walletSidebar')
|
|
1445
|
+
fail(`${path}.titleSegments`, 'is not supported with walletSidebar');
|
|
1446
|
+
}
|
|
1447
|
+
if (row.titleLeadingIcon !== undefined) {
|
|
1448
|
+
assertTitleLeadingIcon(row.titleLeadingIcon, `${path}.titleLeadingIcon`);
|
|
1449
|
+
if (row.presentation === 'walletSidebar')
|
|
1450
|
+
fail(`${path}.titleLeadingIcon`, 'is not supported with walletSidebar');
|
|
1451
|
+
}
|
|
1452
|
+
}
|
|
1453
|
+
|
|
1454
|
+
/** Production keeps decorative title runs only when they pass the rules. */
|
|
1455
|
+
function passesTitleRunRules(check: () => void): boolean {
|
|
1456
|
+
try {
|
|
1457
|
+
check();
|
|
1458
|
+
return true;
|
|
1459
|
+
} catch {
|
|
1460
|
+
return false;
|
|
1461
|
+
}
|
|
1462
|
+
}
|
|
1463
|
+
|
|
1360
1464
|
// A passive label: its text and two caller colors, with no action or style slot.
|
|
1361
1465
|
function assertWebLeadingBadge(value: unknown, path: string): void {
|
|
1362
1466
|
if (value === undefined) return;
|
|
@@ -1892,6 +1996,7 @@ function assertRow(
|
|
|
1892
1996
|
);
|
|
1893
1997
|
});
|
|
1894
1998
|
assertIdentityExtras(row, path);
|
|
1999
|
+
assertIdentityTitleRuns(row, path);
|
|
1895
2000
|
assertText(row.subtitle, `${path}.subtitle`);
|
|
1896
2001
|
// OneKey patch: selector text segments truncate independently.
|
|
1897
2002
|
row.subtitleSegments?.forEach((segment, segmentIndex) => {
|
|
@@ -2485,6 +2590,8 @@ const ROW_FIELDS: Readonly<Record<string, readonly string[]>> = {
|
|
|
2485
2590
|
'titleIcon',
|
|
2486
2591
|
'secondaryTitleIcon',
|
|
2487
2592
|
'titleImage',
|
|
2593
|
+
'titleSegments',
|
|
2594
|
+
'titleLeadingIcon',
|
|
2488
2595
|
'subtitle',
|
|
2489
2596
|
'tertiary',
|
|
2490
2597
|
'tertiaryTone',
|
|
@@ -2664,6 +2771,8 @@ const PATCH_FIELDS: Readonly<Record<string, readonly string[]>> = {
|
|
|
2664
2771
|
'titleIcon',
|
|
2665
2772
|
'secondaryTitleIcon',
|
|
2666
2773
|
'titleImage',
|
|
2774
|
+
'titleSegments',
|
|
2775
|
+
'titleLeadingIcon',
|
|
2667
2776
|
'subtitle',
|
|
2668
2777
|
'tertiary',
|
|
2669
2778
|
'tertiaryTone',
|
|
@@ -2797,6 +2906,7 @@ function protocolKey(value: unknown, path: string): void {
|
|
|
2797
2906
|
const PROTOCOL_ARRAY_FIELDS = new Set([
|
|
2798
2907
|
'columns',
|
|
2799
2908
|
'titleSuffixes',
|
|
2909
|
+
'titleSegments',
|
|
2800
2910
|
'cells',
|
|
2801
2911
|
'points',
|
|
2802
2912
|
'images',
|
|
@@ -3042,7 +3152,10 @@ function assertRowProtocol(row: RowModel, path: string): void {
|
|
|
3042
3152
|
if (row.height !== undefined && row.height < 0)
|
|
3043
3153
|
fail(`${path}.height`, 'must be non-negative');
|
|
3044
3154
|
if (row.type === 'identity') {
|
|
3045
|
-
if (isDevelopment())
|
|
3155
|
+
if (isDevelopment()) {
|
|
3156
|
+
assertIdentityExtras(row, path);
|
|
3157
|
+
assertIdentityTitleRuns(row, path);
|
|
3158
|
+
}
|
|
3046
3159
|
if (row.titleSuffixes !== undefined && !Array.isArray(row.titleSuffixes))
|
|
3047
3160
|
fail(`${path}.titleSuffixes`, 'must be an array');
|
|
3048
3161
|
row.titleSuffixes?.forEach((suffix, index) => {
|
|
@@ -3660,6 +3773,14 @@ const NESTED_DECORATION_FIELDS: Readonly<Record<string, readonly string[]>> = {
|
|
|
3660
3773
|
|
|
3661
3774
|
function sanitizeDecoration(value: unknown, field: string): unknown {
|
|
3662
3775
|
if (value === undefined || value === null) return undefined;
|
|
3776
|
+
if (field === 'titleSegments')
|
|
3777
|
+
return passesTitleRunRules(() => assertTitleSegments(value, field))
|
|
3778
|
+
? value
|
|
3779
|
+
: undefined;
|
|
3780
|
+
if (field === 'titleLeadingIcon')
|
|
3781
|
+
return passesTitleRunRules(() => assertTitleLeadingIcon(value, field))
|
|
3782
|
+
? value
|
|
3783
|
+
: undefined;
|
|
3663
3784
|
// All or nothing: a badge without valid text and both colors is dropped, and
|
|
3664
3785
|
// only its three declared fields are kept.
|
|
3665
3786
|
if (field === 'webLeadingBadge') {
|
|
@@ -4445,6 +4566,8 @@ function assertPatchChanges(patch: PatchValues, index: number): void {
|
|
|
4445
4566
|
);
|
|
4446
4567
|
});
|
|
4447
4568
|
assertIdentityExtras(patch.changes, path);
|
|
4569
|
+
// A null clear never reaches here; a replacement follows the row rules.
|
|
4570
|
+
assertIdentityTitleRuns(patch.changes, path);
|
|
4448
4571
|
assertText(patch.changes.subtitle, `${path}.subtitle`);
|
|
4449
4572
|
assertText(patch.changes.tertiary, `${path}.tertiary`);
|
|
4450
4573
|
if (
|
|
@@ -4735,7 +4858,11 @@ function normalizePatch(patch: RowPatch, index: number): RowPatch | undefined {
|
|
|
4735
4858
|
? sanitizeMarketMetrics(normalized)
|
|
4736
4859
|
: sanitizeDecoration(normalized, field);
|
|
4737
4860
|
if (canonical !== undefined) changes[field] = canonical;
|
|
4738
|
-
|
|
4861
|
+
// A rejected title decoration clears the old one instead of leaving it drawn.
|
|
4862
|
+
else if (
|
|
4863
|
+
['titleImage', 'titleSegments', 'titleLeadingIcon'].includes(field)
|
|
4864
|
+
)
|
|
4865
|
+
changes[field] = null;
|
|
4739
4866
|
}
|
|
4740
4867
|
if (
|
|
4741
4868
|
patch.type === 'market' &&
|
|
@@ -883,7 +883,7 @@ export const WEB_LIST_CSS = `
|
|
|
883
883
|
.ok-native-list-icon-button.ok-native-list-tertiary-icon{box-sizing:border-box;flex:0 0 38px;width:38px;height:38px;margin:-7px;padding:6px;border:1px solid transparent;border-radius:9999px;color:var(--nl-icon-subdued);background:transparent}.ok-native-list-icon-button.ok-native-list-tertiary-icon:hover:not(:disabled){background:var(--nl-hover)}.ok-native-list-icon-button.ok-native-list-tertiary-icon:active:not(:disabled){background:var(--nl-pressed)}.ok-native-list-icon-button.ok-native-list-tertiary-icon:disabled{opacity:.4;cursor:default}
|
|
884
884
|
.ok-native-list-action-glyph{display:inline-flex;width:24px;height:24px;align-items:center;justify-content:center}
|
|
885
885
|
.ok-native-list-icon-button.ok-native-list-tertiary-icon:focus-visible:not(:disabled){outline:2px solid var(--nl-accent)}
|
|
886
|
-
.ok-native-list-identity-title-icon{flex:0 0 20px;width:20px;height:20px;display:inline-flex;align-items:center;justify-content:center;color:var(--nl-icon);font-size:20px}.ok-native-list-identity-title-text{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
886
|
+
.ok-native-list-identity-title-icon{flex:0 0 20px;width:20px;height:20px;display:inline-flex;align-items:center;justify-content:center;color:var(--nl-icon);font-size:20px}.ok-native-list-identity-title-leading-icon{flex:0 0 16px;width:16px;height:16px;display:inline-flex;align-items:center;justify-content:center;color:var(--nl-icon-subdued);font-size:16px}.ok-native-list-identity-title-text{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
887
887
|
.ok-native-list-account-row .ok-native-list-visual,.ok-native-list-account-action-row .ok-native-list-visual{width:32px;height:32px;flex-basis:32px}.ok-native-list-account-row .ok-native-list-visual>img,.ok-native-list-account-row .ok-native-list-visual-main,.ok-native-list-account-action-row .ok-native-list-visual>img,.ok-native-list-account-action-row .ok-native-list-visual-main{width:32px;height:32px}.ok-native-list-account-row .ok-native-list-visual>.ok-native-list-visual-corner{width:20px;height:20px;padding:2px}.ok-native-list-account-action-row .ok-native-list-visual{border-radius:8px!important}.ok-native-list-wallet-row .ok-native-list-title{color:var(--nl-secondary);font-size:12px;line-height:16px;font-weight:400;font-family:var(--nl-font-regular)}.ok-native-list-item[data-native-list-selected="true"]>.ok-native-list-wallet-row .ok-native-list-title{color:var(--nl-primary)}.ok-native-list-account-row .ok-native-list-title{font-size:16px;line-height:20px;font-weight:400;font-family:var(--nl-font-regular)}.ok-native-list-account-row .ok-native-list-secondary{font-size:14px;line-height:20px;font-weight:400;font-family:var(--nl-font-regular)}
|
|
888
888
|
.ok-native-list-flex{display:flex;flex:1;min-width:0;flex-direction:column;justify-content:center}.ok-native-list-title{font-size:15px;line-height:20px;font-weight:600;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;font-family:var(--nl-font-semibold)}.ok-native-list-secondary{font-size:13px;line-height:18px;color:var(--nl-secondary);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.ok-native-list-tertiary{color:var(--nl-secondary)}.ok-native-list-info{color:var(--nl-info)}
|
|
889
889
|
.ok-native-list-identity-row .ok-native-list-title,.ok-native-list-identity-row .ok-native-list-amounts>span:first-child{font-size:16px;line-height:20px}.ok-native-list-identity-row .ok-native-list-secondary{font-size:14px;line-height:20px}
|
|
@@ -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
|
-
|
|
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;
|