UNPKG

@morlz/composition-api

Version:

Provide logic composition capabilities for Vue.

48 lines (47 loc) 2.63 kB
import Vue, { VueConstructor, VNode, ComponentOptions as Vue2ComponentOptions } from 'vue'; import { ComponentPropsOptions, ExtractPropTypes } from './componentProps'; import { UnwrapRef } from '../reactivity'; import { HasDefined } from '../types/basic'; export declare type Data = { [key: string]: unknown; }; export declare type ComponentInstance = InstanceType<VueConstructor>; export 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>, UnwrapRef<RawBindings>, ExtractPropTypes<PropsOptions, false>>; }; declare type VueProxy<PropsOptions, RawBindings> = Vue2ComponentOptions<Vue, UnwrapRef<RawBindings>, never, never, PropsOptions, ExtractPropTypes<PropsOptions, false>> & VueConstructorProxy<PropsOptions, RawBindings>; export interface SetupContext<Style = any> { readonly attrs: Record<string, string>; readonly slots: { [key: string]: (...args: any[]) => VNode[]; }; readonly parent: ComponentInstance | null; readonly root: ComponentInstance; readonly listeners: { [key: string]: Function; }; readonly style: Style; emit(event: string, ...args: any[]): void; } export declare type SetupFunction<Props, RawBindings> = (this: void, props: Props, ctx: SetupContext) => RawBindings | (() => VNode | null); interface ComponentOptionsWithProps<PropsOptions = ComponentPropsOptions, RawBindings = Data, Props = ExtractPropTypes<PropsOptions>> { props?: PropsOptions; setup?: SetupFunction<Props, RawBindings>; } interface ComponentOptionsWithoutProps<Props = never, RawBindings = Data> { props?: undefined; setup?: SetupFunction<Props, RawBindings>; } export declare function createComponent<RawBindings>(options: ComponentOptionsWithoutProps<never, RawBindings>): VueProxy<never, RawBindings>; export declare function createComponent<Props, RawBindings = Data, PropsOptions extends ComponentPropsOptions = ComponentPropsOptions>(options: (HasDefined<Props> extends true ? ComponentOptionsWithProps<PropsOptions, RawBindings, Props> : ComponentOptionsWithProps<PropsOptions, RawBindings>) & Omit<Vue2ComponentOptions<Vue>, keyof ComponentOptionsWithProps<never, never>>): VueProxy<PropsOptions, RawBindings>; export {};