Skip to content

Commit

Permalink
feat(Parser): Implement utility class to parse rendererContext
Browse files Browse the repository at this point in the history
This field is found in most of the newer view model nodes. It can contain accessibility labels, text, commands or nothing but logging info.
  • Loading branch information
LuanRT committed Dec 31, 2024
1 parent a602a31 commit 3a11b99
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/parser/classes/misc/RendererContext.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import type { RawNode } from '../../types/index.js';
import NavigationEndpoint from '../NavigationEndpoint.js';

export type CommandContext = {
on_tap?: NavigationEndpoint;
};

export type AccessibilityContext = {
label?: string;
};

export default class RendererContext {
public command_context: CommandContext;
public accessibility_context: AccessibilityContext;

constructor(data: RawNode) {
this.command_context = {};
this.accessibility_context = {};

if (Reflect.has(data, 'commandContext')) {
if (Reflect.has(data.commandContext, 'onTap')) {
this.command_context.on_tap = new NavigationEndpoint(data.commandContext.onTap);
}
}

if (Reflect.has(data, 'accessibilityContext')) {
if (Reflect.has(data.accessibilityContext, 'label')) {
this.accessibility_context.label = data.accessibilityContext.label;
}
}
}
}
1 change: 1 addition & 0 deletions src/parser/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export { default as Author } from './classes/misc/Author.js';
export { default as ChildElement } from './classes/misc/ChildElement.js';
export { default as EmojiRun } from './classes/misc/EmojiRun.js';
export { default as Format } from './classes/misc/Format.js';
export { default as RendererContext } from './classes/misc/RendererContext.js';
export { default as Text } from './classes/misc/Text.js';
export { default as TextRun } from './classes/misc/TextRun.js';
export { default as Thumbnail } from './classes/misc/Thumbnail.js';
Expand Down

0 comments on commit 3a11b99

Please sign in to comment.