Skip to content

Commit d8f731b

Browse files
committed
feat(RichRenderers): Parse more UI elements
YouTube is currently A/B testing a new You/Library page that uses RichShelf nodes instead of Shelf. There are no major visual changes, other than the page being much more responsive due to how RichShelf is styled.
1 parent 9694a48 commit d8f731b

File tree

2 files changed

+39
-9
lines changed

2 files changed

+39
-9
lines changed

src/parser/classes/RichSection.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,17 @@ import { Parser, type RawNode } from '../index.js';
44
export default class RichSection extends YTNode {
55
static type = 'RichSection';
66

7-
content: YTNode;
7+
public content: YTNode;
8+
public full_bleed: boolean;
9+
public target_id?: string;
810

911
constructor(data: RawNode) {
1012
super();
1113
this.content = Parser.parseItem(data.content);
14+
this.full_bleed = !!data.fullBleed;
15+
16+
if ('targetId' in data) {
17+
this.target_id = data.targetId;
18+
}
1219
}
1320
}

src/parser/classes/RichShelf.ts

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,50 @@
1-
import { YTNode, type ObservedArray } from '../helpers.js';
1+
import { type ObservedArray, YTNode } from '../helpers.js';
22
import { Parser, type RawNode } from '../index.js';
33
import NavigationEndpoint from './NavigationEndpoint.js';
44
import Text from './misc/Text.js';
55

66
export default class RichShelf extends YTNode {
77
static type = 'RichShelf';
88

9-
title: Text;
10-
contents: ObservedArray<YTNode>;
11-
endpoint?: NavigationEndpoint;
12-
subtitle?: Text;
13-
9+
public title: Text;
10+
public contents: ObservedArray<YTNode>;
11+
public endpoint?: NavigationEndpoint;
12+
public subtitle?: Text;
13+
public is_expanded: boolean;
14+
public is_bottom_divider_hidden: boolean;
15+
public is_top_divider_hidden: boolean;
16+
public layout_sizing?: 'RICH_GRID_LAYOUT_SIZING_UNSPECIFIED'
17+
| 'RICH_GRID_LAYOUT_SIZING_STANDARD'
18+
| 'RICH_GRID_LAYOUT_SIZING_COMPACT'
19+
| 'RICH_GRID_LAYOUT_SIZING_EXTRA_COMPACT'
20+
| 'RICH_GRID_LAYOUT_SIZING_TINY';
21+
public menu: YTNode | null;
22+
public next_button: YTNode | null;
23+
public previous_button: YTNode | null;
24+
1425
constructor(data: RawNode) {
1526
super();
1627
this.title = new Text(data.title);
1728
this.contents = Parser.parseArray(data.contents);
1829

19-
if (Reflect.has(data, 'endpoint')) {
30+
this.is_expanded = !!data.is_expanded;
31+
this.is_bottom_divider_hidden = !!data.isBottomDividerHidden;
32+
this.is_top_divider_hidden = !!data.isTopDividerHidden;
33+
34+
if ('endpoint' in data) {
2035
this.endpoint = new NavigationEndpoint(data.endpoint);
2136
}
2237

23-
if (Reflect.has(data, 'subtitle')) {
38+
if ('subtitle' in data) {
2439
this.subtitle = new Text(data.subtitle);
2540
}
41+
42+
if ('layoutSizing' in data) {
43+
this.layout_sizing = data.layoutSizing;
44+
}
45+
46+
this.menu = Parser.parseItem(data.menu);
47+
this.next_button = Parser.parseItem(data.nextButton);
48+
this.previous_button = Parser.parseItem(data.previousButton);
2649
}
2750
}

0 commit comments

Comments
 (0)