UNPKG

vue-function-api-sd

Version:

Provide logic composition capabilities for Vue.

42 lines (41 loc) 2.1 kB
import { VueConstructor, VNode, ComponentOptions as Vue2ComponentOptions } from 'vue'; import { ComponentPropsOptions, ExtractPropTypes } from './componentProps'; import { UnwrapValue } from '../wrappers'; export declare type Data = { [key: string]: unknown; }; export declare type ComponentInstance = InstanceType<VueConstructor>; declare type ComponentRenderProxy<P = {}, S = {}, PublicProps = P> = { $data: S; $props: PublicProps; $attrs: Data; $refs: Data; $slots: Data; $root: ComponentInstance | null; $parent: ComponentInstance | null; $emit: (event: string, ...args: unknown[]) => void; } & P & S; declare type VueConstructorProxy<PropsOptions, RawBindings> = { new (): ComponentRenderProxy<ExtractPropTypes<PropsOptions>, UnwrapValue<RawBindings>, ExtractPropTypes<PropsOptions, false>>; }; declare type VueProxy<PropsOptions, RawBindings> = Vue2ComponentOptions<never, UnwrapValue<RawBindings>, never, never, PropsOptions, ExtractPropTypes<PropsOptions, false>> & VueConstructorProxy<PropsOptions, RawBindings>; export interface SetupContext { readonly parent: ComponentInstance; readonly root: ComponentInstance; readonly refs: { [key: string]: ComponentInstance | Element | ComponentInstance[] | Element[]; }; readonly slots: { [key: string]: VNode[] | undefined; }; readonly attrs: Record<string, string>; emit(event: string, ...args: any[]): void; } declare type RenderFunction<Props> = (props: Props, ctx: SetupContext) => VNode; export declare type SetupFunction<Props, RawBindings> = (this: void, props: Props, ctx: SetupContext) => RawBindings | RenderFunction<Props>; export interface ComponentOptions<PropsOptions = ComponentPropsOptions, RawBindings = Data, Props = ExtractPropTypes<PropsOptions>> { props?: PropsOptions; setup?: SetupFunction<Props, RawBindings>; } export declare function createComponent<PropsOptions, RawBindings>(options: ComponentOptions<PropsOptions, RawBindings>): VueProxy<PropsOptions, RawBindings>; export {};