UNPKG

@player-ui/player

Version:

101 lines 4.61 kB
import type { Flow as FlowType } from "@player-ui/types"; import { SyncHook, SyncWaterfallHook } from "tapable-ts"; import type { Logger } from "./logger"; import { TapableLogger } from "./logger"; import { ExpressionEvaluator } from "./expressions"; import { SchemaController } from "./schema"; import { BindingParser } from "./binding"; import type { ViewInstance } from "./view"; import { ConstantsController, ViewController, DataController, ValidationController, FlowController } from "./controllers"; import type { PlayerFlowState, CompletedState } from "./types"; export interface PlayerPlugin { /** * Unique identifier of the plugin. * Enables the plugin to be retrievable from Player. */ symbol?: symbol; /** The name of the plugin */ name: string; /** * Use this to tap into Player hooks */ apply: (player: Player) => void; } export interface ExtendedPlayerPlugin<Assets = void, Views = void, Expressions = void, DataTypes = void> { } export interface PlayerConfigOptions { /** A set of plugins to load */ plugins?: PlayerPlugin[]; /** A logger to use */ logger?: Logger; } export interface PlayerInfo { /** Version of the running player */ version: string; /** Hash of the HEAD commit used to build the current version */ commit: string; } /** * This is it. */ export declare class Player { static readonly info: PlayerInfo; readonly logger: TapableLogger; readonly constantsController: ConstantsController; private config; private state; readonly hooks: { /** The hook that fires every time we create a new flowController (a new Content blob is passed in) */ flowController: SyncHook<[FlowController], Record<string, any>>; /** The hook that updates/handles views */ viewController: SyncHook<[ViewController], Record<string, any>>; /** A hook called every-time there's a new view. This is equivalent to the view hook on the view-controller */ view: SyncHook<[ViewInstance], Record<string, any>>; /** Called when an expression evaluator was created */ expressionEvaluator: SyncHook<[ExpressionEvaluator], Record<string, any>>; /** The hook that creates and manages data */ dataController: SyncHook<[DataController], Record<string, any>>; /** Called after the schema is created for a flow */ schema: SyncHook<[SchemaController], Record<string, any>>; /** Manages validations (schema and x-field ) */ validationController: SyncHook<[ValidationController], Record<string, any>>; /** Manages parsing binding */ bindingParser: SyncHook<[BindingParser], Record<string, any>>; /** A that's called for state changes in the flow execution */ state: SyncHook<[PlayerFlowState], Record<string, any>>; /** A hook to access the current flow */ onStart: SyncHook<[FlowType<import("@player-ui/types").Asset<string>>], Record<string, any>>; /** A hook for when the flow ends either in success or failure */ onEnd: SyncHook<[], Record<string, any>>; /** Mutate the Content flow before starting */ resolveFlowContent: SyncWaterfallHook<[FlowType<import("@player-ui/types").Asset<string>>], Record<string, any>>; }; constructor(config?: PlayerConfigOptions); /** Returns currently registered plugins */ getPlugins(): PlayerPlugin[]; /** Find instance of [Plugin] that has been registered to Player */ findPlugin<Plugin extends PlayerPlugin>(symbol: symbol): Plugin | undefined; /** Retrieve an instance of [Plugin] and conditionally invoke [apply] if it exists */ applyTo<Plugin extends PlayerPlugin>(symbol: symbol, apply: (plugin: Plugin) => void): void; /** Register and apply [Plugin] if one with the same symbol is not already registered. */ registerPlugin(plugin: PlayerPlugin): void; /** Returns the current version of the running player */ getVersion(): string; /** Returns the git commit used to build Player version */ getCommit(): string; /** * Fetch the current state of Player. * It will return either `not-started`, `in-progress`, `completed` * with some extra data in each */ getState(): PlayerFlowState; /** * A private means of setting the state of Player * Calls the hooks for subscribers to listen for this event */ private setState; /** Start Player with the given flow */ private setupFlow; start(payload: FlowType): Promise<CompletedState>; } //# sourceMappingURL=player.d.ts.map