UNPKG

@player-ui/player

Version:

63 lines 2.53 kB
import { SyncBailHook, SyncWaterfallHook } from "tapable-ts"; import type { AnyAssetType, Node } from "./types"; import { NodeType } from "./types"; export * from "./types"; export * from "./utils"; export declare const EMPTY_NODE: Node.Empty; export interface ParseObjectOptions { /** how nested the templated is */ templateDepth?: number; } export interface ParseObjectChildOptions { key: string; path: Node.PathSegment[]; parentObj: object; } export type ParserHooks = { /** * A hook to interact with an object _before_ parsing it into an AST * * @param value - The object we're are about to parse * @returns - A new value to parse. * If undefined, the original value is used. * If null, we stop parsing this node. */ onParseObject: SyncWaterfallHook<[object, NodeType]>; /** * A callback to interact with an AST _after_ we parse it into the AST * * @param value - The object we parsed * @param node - The AST node we generated * @returns - A new AST node to use * If undefined, the original value is used. * If null, we ignore this node all together */ onCreateASTNode: SyncWaterfallHook<[Node.Node | undefined | null, object]>; /** A hook to call when parsing an object into an AST node * * @param obj - The object we're are about to parse * @param nodeType - The type of node we're parsing * @param parseOptions - Additional options when parsing * @param childOptions - Additional options that are populated when the node being parsed is a child of another node * @returns - A new AST node to use * If undefined, the original value is used. * If null, we ignore this node all together */ parseNode: SyncBailHook<[ obj: object, nodeType: Node.ChildrenTypes, parseOptions: ParseObjectOptions, childOptions?: ParseObjectChildOptions ], Node.Node | Node.Child[]>; }; /** * The Parser is the way to take an incoming view from the user and parse it into an AST. * It provides a few ways to interact with the parsing, including mutating an object before and after creation of an AST node */ export declare class Parser { readonly hooks: ParserHooks; parseView(value: AnyAssetType): Node.View; createASTNode(node: Node.Node | null, value: any): Node.Node | null; parseObject(obj: object, type?: Node.ChildrenTypes, options?: ParseObjectOptions): Node.Node | null; } //# sourceMappingURL=index.d.ts.map