@player-ui/player
Version:
47 lines • 2.1 kB
TypeScript
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;
}
/**
* 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: {
/**
* 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], Record<string, any>>;
/**
* 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 | null | undefined, object], Record<string, any>>;
parseNode: SyncBailHook<[obj: object, nodeType: Node.ChildrenTypes, parseOptions: ParseObjectOptions, childOptions?: ParseObjectChildOptions | undefined], Node.Node | Node.Child[], Record<string, any>>;
};
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