1 | import { Vue, CreateElement, CombinedVueInstance } from "./vue";
|
2 | import { VNode, VNodeData, VNodeDirective, NormalizedScopedSlot } from "./vnode";
|
3 |
|
4 | type Constructor = {
|
5 | new (...args: any[]): any;
|
6 | }
|
7 |
|
8 |
|
9 |
|
10 | export type Component<Data=DefaultData<never>, Methods=DefaultMethods<never>, Computed=DefaultComputed, Props=DefaultProps> =
|
11 | | typeof Vue
|
12 | | FunctionalComponentOptions<Props>
|
13 | | ComponentOptions<never, Data, Methods, Computed, Props>
|
14 |
|
15 | interface EsModuleComponent {
|
16 | default: Component
|
17 | }
|
18 |
|
19 | export type AsyncComponent<Data=DefaultData<never>, Methods=DefaultMethods<never>, Computed=DefaultComputed, Props=DefaultProps>
|
20 | = AsyncComponentPromise<Data, Methods, Computed, Props>
|
21 | | AsyncComponentFactory<Data, Methods, Computed, Props>
|
22 |
|
23 | export type AsyncComponentPromise<Data=DefaultData<never>, Methods=DefaultMethods<never>, Computed=DefaultComputed, Props=DefaultProps> = (
|
24 | resolve: (component: Component<Data, Methods, Computed, Props>) => void,
|
25 | reject: (reason?: any) => void
|
26 | ) => Promise<Component | EsModuleComponent> | void;
|
27 |
|
28 | export type AsyncComponentFactory<Data=DefaultData<never>, Methods=DefaultMethods<never>, Computed=DefaultComputed, Props=DefaultProps> = () => {
|
29 | component: AsyncComponentPromise<Data, Methods, Computed, Props>;
|
30 | loading?: Component | EsModuleComponent;
|
31 | error?: Component | EsModuleComponent;
|
32 | delay?: number;
|
33 | timeout?: number;
|
34 | }
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 | export type Accessors<T> = {
|
43 | [K in keyof T]: (() => T[K]) | ComputedOptions<T[K]>
|
44 | }
|
45 |
|
46 | type DataDef<Data, Props, V> = Data | ((this: Readonly<Props> & V) => Data)
|
47 | /**
|
48 | * This type should be used when an array of strings is used for a component's `props` value.
|
49 | */
|
50 | export type ThisTypedComponentOptionsWithArrayProps<V extends Vue, Data, Methods, Computed, PropNames extends string> =
|
51 | object &
|
52 | ComponentOptions<V, DataDef<Data, Record<PropNames, any>, V>, Methods, Computed, PropNames[], Record<PropNames, any>> &
|
53 | ThisType<CombinedVueInstance<V, Data, Methods, Computed, Readonly<Record<PropNames, any>>>>;
|
54 |
|
55 | /**
|
56 | * This type should be used when an object mapped to `PropOptions` is used for a component's `props` value.
|
57 | */
|
58 | export type ThisTypedComponentOptionsWithRecordProps<V extends Vue, Data, Methods, Computed, Props> =
|
59 | object &
|
60 | ComponentOptions<V, DataDef<Data, Props, V>, Methods, Computed, RecordPropsDefinition<Props>, Props> &
|
61 | ThisType<CombinedVueInstance<V, Data, Methods, Computed, Readonly<Props>>>;
|
62 |
|
63 | type DefaultData<V> = object | ((this: V) => object);
|
64 | type DefaultProps = Record<string, any>;
|
65 | type DefaultMethods<V> = { [key: string]: (this: V, ...args: any[]) => any };
|
66 | type DefaultComputed = { [key: string]: any };
|
67 | export interface ComponentOptions<
|
68 | V extends Vue,
|
69 | Data=DefaultData<V>,
|
70 | Methods=DefaultMethods<V>,
|
71 | Computed=DefaultComputed,
|
72 | PropsDef=PropsDefinition<DefaultProps>,
|
73 | Props=DefaultProps> {
|
74 | data?: Data;
|
75 | props?: PropsDef;
|
76 | propsData?: object;
|
77 | computed?: Accessors<Computed>;
|
78 | methods?: Methods;
|
79 | watch?: Record<string, WatchOptionsWithHandler<any> | WatchHandler<any> | string>;
|
80 |
|
81 | el?: Element | string;
|
82 | template?: string;
|
83 |
|
84 | render?(createElement: CreateElement, hack: RenderContext<Props>): VNode;
|
85 | renderError?(createElement: CreateElement, err: Error): VNode;
|
86 | staticRenderFns?: ((createElement: CreateElement) => VNode)[];
|
87 |
|
88 | beforeCreate?(this: V): void;
|
89 | created?(): void;
|
90 | beforeDestroy?(): void;
|
91 | destroyed?(): void;
|
92 | beforeMount?(): void;
|
93 | mounted?(): void;
|
94 | beforeUpdate?(): void;
|
95 | updated?(): void;
|
96 | activated?(): void;
|
97 | deactivated?(): void;
|
98 | errorCaptured?(err: Error, vm: Vue, info: string): boolean | void;
|
99 | serverPrefetch?(this: V): Promise<void>;
|
100 |
|
101 | directives?: { [key: string]: DirectiveFunction | DirectiveOptions };
|
102 | components?: { [key: string]: Component<any, any, any, any> | AsyncComponent<any, any, any, any> };
|
103 | transitions?: { [key: string]: object };
|
104 | filters?: { [key: string]: Function };
|
105 |
|
106 | provide?: object | (() => object);
|
107 | inject?: InjectOptions;
|
108 |
|
109 | model?: {
|
110 | prop?: string;
|
111 | event?: string;
|
112 | };
|
113 |
|
114 | parent?: Vue;
|
115 | mixins?: (ComponentOptions<Vue> | typeof Vue)[];
|
116 | name?: string;
|
117 | // TODO: support properly inferred 'extends'
|
118 | extends?: ComponentOptions<Vue> | typeof Vue;
|
119 | delimiters?: [string, string];
|
120 | comments?: boolean;
|
121 | inheritAttrs?: boolean;
|
122 | }
|
123 |
|
124 | export interface FunctionalComponentOptions<Props = DefaultProps, PropDefs = PropsDefinition<Props>> {
|
125 | name?: string;
|
126 | props?: PropDefs;
|
127 | model?: {
|
128 | prop?: string;
|
129 | event?: string;
|
130 | };
|
131 | inject?: InjectOptions;
|
132 | functional: boolean;
|
133 | render?(this: undefined, createElement: CreateElement, context: RenderContext<Props>): VNode | VNode[];
|
134 | }
|
135 |
|
136 | export interface RenderContext<Props=DefaultProps> {
|
137 | props: Props;
|
138 | children: VNode[];
|
139 | slots(): any;
|
140 | data: VNodeData;
|
141 | parent: Vue;
|
142 | listeners: { [key: string]: Function | Function[] };
|
143 | scopedSlots: { [key: string]: NormalizedScopedSlot };
|
144 | injections: any
|
145 | }
|
146 |
|
147 | export type Prop<T> = { (): T } | { new(...args: any[]): T & object }
|
148 |
|
149 | export type PropType<T> = Prop<T> | Prop<T>[];
|
150 |
|
151 | export type PropValidator<T> = PropOptions<T> | PropType<T>;
|
152 |
|
153 | export interface PropOptions<T=any> {
|
154 | type?: PropType<T>;
|
155 | required?: boolean;
|
156 | default?: T | null | undefined | (() => T | null | undefined);
|
157 | validator?(value: T): boolean;
|
158 | }
|
159 |
|
160 | export type RecordPropsDefinition<T> = {
|
161 | [K in keyof T]: PropValidator<T[K]>
|
162 | }
|
163 | export type ArrayPropsDefinition<T> = (keyof T)[];
|
164 | export type PropsDefinition<T> = ArrayPropsDefinition<T> | RecordPropsDefinition<T>;
|
165 |
|
166 | export interface ComputedOptions<T> {
|
167 | get?(): T;
|
168 | set?(value: T): void;
|
169 | cache?: boolean;
|
170 | }
|
171 |
|
172 | export type WatchHandler<T> = (val: T, oldVal: T) => void;
|
173 |
|
174 | export interface WatchOptions {
|
175 | deep?: boolean;
|
176 | immediate?: boolean;
|
177 | }
|
178 |
|
179 | export interface WatchOptionsWithHandler<T> extends WatchOptions {
|
180 | handler: WatchHandler<T>;
|
181 | }
|
182 |
|
183 | export interface DirectiveBinding extends Readonly<VNodeDirective> {
|
184 | readonly modifiers: { [key: string]: boolean };
|
185 | }
|
186 |
|
187 | export type DirectiveFunction = (
|
188 | el: HTMLElement,
|
189 | binding: DirectiveBinding,
|
190 | vnode: VNode,
|
191 | oldVnode: VNode
|
192 | ) => void;
|
193 |
|
194 | export interface DirectiveOptions {
|
195 | bind?: DirectiveFunction;
|
196 | inserted?: DirectiveFunction;
|
197 | update?: DirectiveFunction;
|
198 | componentUpdated?: DirectiveFunction;
|
199 | unbind?: DirectiveFunction;
|
200 | }
|
201 |
|
202 | export type InjectKey = string | symbol;
|
203 |
|
204 | export type InjectOptions = {
|
205 | [key: string]: InjectKey | { from?: InjectKey, default?: any }
|
206 | } | string[];
|