2022-05-27 09:26:55 +00:00
|
|
|
import { Vue, CreateElement, CombinedVueInstance } from './vue'
|
|
|
|
import { VNode, VNodeData, VNodeDirective, NormalizedScopedSlot } from './vnode'
|
2022-06-01 13:55:33 +00:00
|
|
|
import { SetupContext } from './v3-setup-context'
|
|
|
|
import { DebuggerEvent } from './v3-generated'
|
2022-07-05 02:12:21 +00:00
|
|
|
import { DefineComponent } from './v3-define-component'
|
2022-08-18 07:56:37 +00:00
|
|
|
import { ComponentOptionsMixin } from './v3-component-options'
|
2022-10-11 03:51:05 +00:00
|
|
|
import { ObjectDirective, FunctionDirective } from './v3-directive'
|
2016-08-23 19:01:30 +00:00
|
|
|
|
|
|
|
type Constructor = {
|
2022-05-27 09:26:55 +00:00
|
|
|
new (...args: any[]): any
|
2016-08-23 19:01:30 +00:00
|
|
|
}
|
|
|
|
|
2017-10-06 18:45:14 +00:00
|
|
|
// we don't support infer props in async component
|
2018-01-03 06:33:48 +00:00
|
|
|
// N.B. ComponentOptions<V> is contravariant, the default generic should be bottom type
|
2022-05-27 09:26:55 +00:00
|
|
|
export type Component<
|
|
|
|
Data = DefaultData<never>,
|
|
|
|
Methods = DefaultMethods<never>,
|
|
|
|
Computed = DefaultComputed,
|
|
|
|
Props = DefaultProps,
|
|
|
|
SetupBindings = {}
|
|
|
|
> =
|
2017-10-06 18:45:14 +00:00
|
|
|
| typeof Vue
|
|
|
|
| FunctionalComponentOptions<Props>
|
2022-05-27 09:26:55 +00:00
|
|
|
| ComponentOptions<never, Data, Methods, Computed, Props, SetupBindings>
|
2022-07-08 07:15:22 +00:00
|
|
|
| DefineComponent<any, any, any, any, any, any, any, any, any, any, any>
|
2017-09-05 19:25:16 +00:00
|
|
|
|
2021-06-03 13:13:33 +00:00
|
|
|
type EsModule<T> = T | { default: T }
|
|
|
|
|
2022-05-27 09:26:55 +00:00
|
|
|
type ImportedComponent<
|
|
|
|
Data = DefaultData<never>,
|
|
|
|
Methods = DefaultMethods<never>,
|
|
|
|
Computed = DefaultComputed,
|
|
|
|
Props = DefaultProps,
|
|
|
|
SetupBindings = {}
|
|
|
|
> = EsModule<Component<Data, Methods, Computed, Props, SetupBindings>>
|
|
|
|
|
|
|
|
export type AsyncComponent<
|
|
|
|
Data = DefaultData<never>,
|
|
|
|
Methods = DefaultMethods<never>,
|
|
|
|
Computed = DefaultComputed,
|
|
|
|
Props = DefaultProps,
|
|
|
|
SetupBindings = {}
|
|
|
|
> =
|
|
|
|
| AsyncComponentPromise<Data, Methods, Computed, Props, SetupBindings>
|
|
|
|
| AsyncComponentFactory<Data, Methods, Computed, Props, SetupBindings>
|
|
|
|
|
|
|
|
export type AsyncComponentPromise<
|
|
|
|
Data = DefaultData<never>,
|
|
|
|
Methods = DefaultMethods<never>,
|
|
|
|
Computed = DefaultComputed,
|
|
|
|
Props = DefaultProps,
|
|
|
|
SetupBindings = {}
|
|
|
|
> = (
|
|
|
|
resolve: (
|
|
|
|
component: Component<Data, Methods, Computed, Props, SetupBindings>
|
|
|
|
) => void,
|
2016-09-30 17:57:38 +00:00
|
|
|
reject: (reason?: any) => void
|
2022-05-27 09:26:55 +00:00
|
|
|
) => Promise<
|
|
|
|
ImportedComponent<Data, Methods, Computed, Props, SetupBindings>
|
|
|
|
> | void
|
|
|
|
|
|
|
|
export type AsyncComponentFactory<
|
|
|
|
Data = DefaultData<never>,
|
|
|
|
Methods = DefaultMethods<never>,
|
|
|
|
Computed = DefaultComputed,
|
|
|
|
Props = DefaultProps,
|
|
|
|
SetupBindings = {}
|
|
|
|
> = () => {
|
|
|
|
component: Promise<
|
|
|
|
ImportedComponent<Data, Methods, Computed, Props, SetupBindings>
|
|
|
|
>
|
|
|
|
loading?: ImportedComponent
|
|
|
|
error?: ImportedComponent
|
|
|
|
delay?: number
|
|
|
|
timeout?: number
|
2018-12-05 23:00:56 +00:00
|
|
|
}
|
|
|
|
|
2017-10-06 18:45:14 +00:00
|
|
|
/**
|
|
|
|
* When the `Computed` type parameter on `ComponentOptions` is inferred,
|
|
|
|
* it should have a property with the return type of every get-accessor.
|
|
|
|
* Since there isn't a way to query for the return type of a function, we allow TypeScript
|
|
|
|
* to infer from the shape of `Accessors<Computed>` and work backwards.
|
|
|
|
*/
|
|
|
|
export type Accessors<T> = {
|
|
|
|
[K in keyof T]: (() => T[K]) | ComputedOptions<T[K]>
|
|
|
|
}
|
2016-09-30 17:57:38 +00:00
|
|
|
|
2018-03-08 18:55:52 +00:00
|
|
|
type DataDef<Data, Props, V> = Data | ((this: Readonly<Props> & V) => Data)
|
2017-10-06 18:45:14 +00:00
|
|
|
/**
|
|
|
|
* This type should be used when an array of strings is used for a component's `props` value.
|
|
|
|
*/
|
2022-05-27 09:26:55 +00:00
|
|
|
export type ThisTypedComponentOptionsWithArrayProps<
|
|
|
|
V extends Vue,
|
|
|
|
Data,
|
|
|
|
Methods,
|
|
|
|
Computed,
|
|
|
|
PropNames extends string,
|
2022-08-18 07:56:37 +00:00
|
|
|
SetupBindings,
|
2022-08-22 02:28:39 +00:00
|
|
|
Mixin extends ComponentOptionsMixin,
|
|
|
|
Extends extends ComponentOptionsMixin
|
2022-05-27 09:26:55 +00:00
|
|
|
> = object &
|
|
|
|
ComponentOptions<
|
|
|
|
V,
|
|
|
|
DataDef<Data, Record<PropNames, any>, V>,
|
|
|
|
Methods,
|
|
|
|
Computed,
|
|
|
|
PropNames[],
|
|
|
|
Record<PropNames, any>,
|
2022-08-18 07:56:37 +00:00
|
|
|
SetupBindings,
|
|
|
|
Mixin,
|
|
|
|
Extends
|
2022-05-27 09:26:55 +00:00
|
|
|
> &
|
|
|
|
ThisType<
|
|
|
|
CombinedVueInstance<
|
|
|
|
V,
|
|
|
|
Data,
|
|
|
|
Methods,
|
|
|
|
Computed,
|
|
|
|
Readonly<Record<PropNames, any>>,
|
2022-08-18 07:56:37 +00:00
|
|
|
SetupBindings,
|
|
|
|
Mixin,
|
|
|
|
Extends
|
2022-05-27 09:26:55 +00:00
|
|
|
>
|
|
|
|
>
|
2017-10-06 18:45:14 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This type should be used when an object mapped to `PropOptions` is used for a component's `props` value.
|
|
|
|
*/
|
2022-05-27 09:26:55 +00:00
|
|
|
export type ThisTypedComponentOptionsWithRecordProps<
|
|
|
|
V extends Vue,
|
|
|
|
Data,
|
|
|
|
Methods,
|
|
|
|
Computed,
|
|
|
|
Props,
|
2022-08-18 07:56:37 +00:00
|
|
|
SetupBindings,
|
2022-08-22 02:28:39 +00:00
|
|
|
Mixin extends ComponentOptionsMixin,
|
|
|
|
Extends extends ComponentOptionsMixin
|
2022-05-27 09:26:55 +00:00
|
|
|
> = object &
|
|
|
|
ComponentOptions<
|
|
|
|
V,
|
|
|
|
DataDef<Data, Props, V>,
|
|
|
|
Methods,
|
|
|
|
Computed,
|
|
|
|
RecordPropsDefinition<Props>,
|
|
|
|
Props,
|
2022-08-18 07:56:37 +00:00
|
|
|
SetupBindings,
|
|
|
|
Mixin,
|
|
|
|
Extends
|
2022-05-27 09:26:55 +00:00
|
|
|
> &
|
|
|
|
ThisType<
|
|
|
|
CombinedVueInstance<
|
|
|
|
V,
|
|
|
|
Data,
|
|
|
|
Methods,
|
|
|
|
Computed,
|
|
|
|
Readonly<Props>,
|
2022-08-18 07:56:37 +00:00
|
|
|
SetupBindings,
|
|
|
|
Mixin,
|
|
|
|
Extends
|
2022-05-27 09:26:55 +00:00
|
|
|
>
|
|
|
|
>
|
|
|
|
|
|
|
|
type DefaultData<V> = object | ((this: V) => object)
|
|
|
|
type DefaultProps = Record<string, any>
|
|
|
|
type DefaultMethods<V> = { [key: string]: (this: V, ...args: any[]) => any }
|
|
|
|
type DefaultComputed = { [key: string]: any }
|
|
|
|
|
2017-10-06 18:45:14 +00:00
|
|
|
export interface ComponentOptions<
|
|
|
|
V extends Vue,
|
2022-05-27 09:26:55 +00:00
|
|
|
Data = DefaultData<V>,
|
|
|
|
Methods = DefaultMethods<V>,
|
|
|
|
Computed = DefaultComputed,
|
|
|
|
PropsDef = PropsDefinition<DefaultProps>,
|
|
|
|
Props = DefaultProps,
|
2022-08-18 07:56:37 +00:00
|
|
|
RawBindings = {},
|
|
|
|
Mixin extends ComponentOptionsMixin = ComponentOptionsMixin,
|
|
|
|
Extends extends ComponentOptionsMixin = ComponentOptionsMixin
|
2022-05-27 09:26:55 +00:00
|
|
|
> {
|
|
|
|
data?: Data
|
|
|
|
props?: PropsDef
|
|
|
|
propsData?: object
|
|
|
|
computed?: Accessors<Computed>
|
|
|
|
methods?: Methods
|
2022-10-11 06:43:33 +00:00
|
|
|
watch?: Record<string, WatchOptionsWithHandler<any> | WatchHandler<any> | Array<WatchOptionsWithHandler<any> | WatchHandler<any>>>
|
2022-05-27 09:26:55 +00:00
|
|
|
|
|
|
|
setup?: (
|
|
|
|
this: void,
|
|
|
|
props: Props,
|
|
|
|
ctx: SetupContext
|
|
|
|
) => Promise<RawBindings> | RawBindings | ((h: CreateElement) => VNode) | void
|
|
|
|
|
|
|
|
el?: Element | string
|
|
|
|
template?: string
|
2018-12-01 04:58:58 +00:00
|
|
|
// hack is for functional component type inference, should not be used in user code
|
2022-07-05 02:12:21 +00:00
|
|
|
render?(
|
|
|
|
createElement: CreateElement,
|
|
|
|
hack: RenderContext<Props>
|
|
|
|
): VNode | null | void
|
2022-05-27 09:26:55 +00:00
|
|
|
renderError?(createElement: CreateElement, err: Error): VNode
|
|
|
|
staticRenderFns?: ((createElement: CreateElement) => VNode)[]
|
|
|
|
|
|
|
|
beforeCreate?(this: V): void
|
|
|
|
created?(): void
|
|
|
|
beforeDestroy?(): void
|
|
|
|
destroyed?(): void
|
|
|
|
beforeMount?(): void
|
|
|
|
mounted?(): void
|
|
|
|
beforeUpdate?(): void
|
|
|
|
updated?(): void
|
|
|
|
activated?(): void
|
|
|
|
deactivated?(): void
|
|
|
|
errorCaptured?(err: Error, vm: Vue, info: string): boolean | void
|
2023-10-23 06:58:47 +00:00
|
|
|
serverPrefetch?(): Promise<void>
|
2022-05-29 08:01:38 +00:00
|
|
|
renderTracked?(e: DebuggerEvent): void
|
|
|
|
renderTriggerd?(e: DebuggerEvent): void
|
2022-05-27 09:26:55 +00:00
|
|
|
|
|
|
|
directives?: { [key: string]: DirectiveFunction | DirectiveOptions }
|
|
|
|
components?: {
|
|
|
|
[key: string]:
|
2022-07-08 07:15:22 +00:00
|
|
|
| {}
|
|
|
|
| Component<any, any, any, any, any>
|
2022-05-27 09:26:55 +00:00
|
|
|
| AsyncComponent<any, any, any, any>
|
|
|
|
}
|
|
|
|
transitions?: { [key: string]: object }
|
|
|
|
filters?: { [key: string]: Function }
|
|
|
|
|
|
|
|
provide?: object | (() => object)
|
|
|
|
inject?: InjectOptions
|
2017-02-22 03:35:50 +00:00
|
|
|
|
|
|
|
model?: {
|
2022-05-27 09:26:55 +00:00
|
|
|
prop?: string
|
|
|
|
event?: string
|
|
|
|
}
|
2017-02-22 03:35:50 +00:00
|
|
|
|
2022-05-27 09:26:55 +00:00
|
|
|
parent?: Vue
|
2022-08-18 07:56:37 +00:00
|
|
|
mixins?: (Mixin | ComponentOptions<Vue> | typeof Vue)[]
|
2022-05-27 09:26:55 +00:00
|
|
|
name?: string
|
2022-07-12 09:39:45 +00:00
|
|
|
// for SFC auto name inference w/ ts-loader check
|
|
|
|
__name?: string
|
2017-10-06 18:45:14 +00:00
|
|
|
// TODO: support properly inferred 'extends'
|
2022-08-18 07:56:37 +00:00
|
|
|
extends?: Extends | ComponentOptions<Vue> | typeof Vue
|
2022-05-27 09:26:55 +00:00
|
|
|
delimiters?: [string, string]
|
|
|
|
comments?: boolean
|
|
|
|
inheritAttrs?: boolean
|
2016-08-23 19:01:30 +00:00
|
|
|
}
|
|
|
|
|
2022-05-27 09:26:55 +00:00
|
|
|
export interface FunctionalComponentOptions<
|
|
|
|
Props = DefaultProps,
|
|
|
|
PropDefs = PropsDefinition<Props>
|
|
|
|
> {
|
|
|
|
name?: string
|
|
|
|
props?: PropDefs
|
2018-10-24 17:03:48 +00:00
|
|
|
model?: {
|
2022-05-27 09:26:55 +00:00
|
|
|
prop?: string
|
|
|
|
event?: string
|
|
|
|
}
|
|
|
|
inject?: InjectOptions
|
|
|
|
functional: boolean
|
|
|
|
render?(
|
|
|
|
this: undefined,
|
|
|
|
createElement: CreateElement,
|
|
|
|
context: RenderContext<Props>
|
|
|
|
): VNode | VNode[]
|
2016-09-05 10:53:34 +00:00
|
|
|
}
|
|
|
|
|
2022-05-27 09:26:55 +00:00
|
|
|
export interface RenderContext<Props = DefaultProps> {
|
|
|
|
props: Props
|
|
|
|
children: VNode[]
|
|
|
|
slots(): any
|
|
|
|
data: VNodeData
|
|
|
|
parent: Vue
|
|
|
|
listeners: { [key: string]: Function | Function[] }
|
|
|
|
scopedSlots: { [key: string]: NormalizedScopedSlot }
|
2017-04-05 06:36:15 +00:00
|
|
|
injections: any
|
2016-09-05 10:53:34 +00:00
|
|
|
}
|
|
|
|
|
2022-06-01 14:12:02 +00:00
|
|
|
export type Prop<T> =
|
|
|
|
| { (): T }
|
|
|
|
| { new (...args: never[]): T & object }
|
|
|
|
| { new (...args: string[]): Function }
|
|
|
|
|
|
|
|
export type PropType<T> = Prop<T> | Prop<T>[]
|
2018-12-05 22:50:13 +00:00
|
|
|
|
2022-05-27 09:26:55 +00:00
|
|
|
export type PropValidator<T> = PropOptions<T> | PropType<T>
|
2017-10-06 18:45:14 +00:00
|
|
|
|
2022-06-01 14:12:02 +00:00
|
|
|
export interface PropOptions<T = any> {
|
|
|
|
type?: PropType<T>
|
|
|
|
required?: boolean
|
|
|
|
default?: T | null | undefined | (() => T | null | undefined)
|
|
|
|
validator?(value: unknown): boolean
|
|
|
|
}
|
|
|
|
|
2017-10-06 18:45:14 +00:00
|
|
|
export type RecordPropsDefinition<T> = {
|
|
|
|
[K in keyof T]: PropValidator<T[K]>
|
|
|
|
}
|
2022-05-27 09:26:55 +00:00
|
|
|
export type ArrayPropsDefinition<T> = (keyof T)[]
|
|
|
|
export type PropsDefinition<T> =
|
|
|
|
| ArrayPropsDefinition<T>
|
|
|
|
| RecordPropsDefinition<T>
|
2017-10-06 18:45:14 +00:00
|
|
|
|
|
|
|
export interface ComputedOptions<T> {
|
2022-05-27 09:26:55 +00:00
|
|
|
get?(): T
|
|
|
|
set?(value: T): void
|
|
|
|
cache?: boolean
|
2016-08-23 19:01:30 +00:00
|
|
|
}
|
|
|
|
|
2022-05-27 09:26:55 +00:00
|
|
|
export type WatchHandler<T> = string | ((val: T, oldVal: T) => void)
|
2016-08-23 19:01:30 +00:00
|
|
|
|
|
|
|
export interface WatchOptions {
|
2022-05-27 09:26:55 +00:00
|
|
|
deep?: boolean
|
|
|
|
immediate?: boolean
|
2016-08-23 19:01:30 +00:00
|
|
|
}
|
|
|
|
|
2017-10-06 18:45:14 +00:00
|
|
|
export interface WatchOptionsWithHandler<T> extends WatchOptions {
|
2022-05-27 09:26:55 +00:00
|
|
|
handler: WatchHandler<T>
|
2017-10-06 18:45:14 +00:00
|
|
|
}
|
|
|
|
|
2018-10-22 20:09:23 +00:00
|
|
|
export interface DirectiveBinding extends Readonly<VNodeDirective> {
|
2022-05-27 09:26:55 +00:00
|
|
|
readonly modifiers: { [key: string]: boolean }
|
2018-10-22 20:09:23 +00:00
|
|
|
}
|
|
|
|
|
2022-10-11 03:51:05 +00:00
|
|
|
/**
|
|
|
|
* @deprecated use {@link FunctionDirective} instead
|
|
|
|
*/
|
2016-08-23 19:01:30 +00:00
|
|
|
export type DirectiveFunction = (
|
|
|
|
el: HTMLElement,
|
2018-10-22 20:09:23 +00:00
|
|
|
binding: DirectiveBinding,
|
2016-08-23 19:01:30 +00:00
|
|
|
vnode: VNode,
|
|
|
|
oldVnode: VNode
|
2022-05-27 09:26:55 +00:00
|
|
|
) => void
|
2016-08-23 19:01:30 +00:00
|
|
|
|
2022-10-11 03:51:05 +00:00
|
|
|
/**
|
|
|
|
* @deprecated use {@link ObjectDirective} instead
|
|
|
|
*/
|
2016-08-23 19:01:30 +00:00
|
|
|
export interface DirectiveOptions {
|
2022-05-27 09:26:55 +00:00
|
|
|
bind?: DirectiveFunction
|
|
|
|
inserted?: DirectiveFunction
|
|
|
|
update?: DirectiveFunction
|
|
|
|
componentUpdated?: DirectiveFunction
|
|
|
|
unbind?: DirectiveFunction
|
2016-08-23 19:01:30 +00:00
|
|
|
}
|
2017-10-06 21:41:54 +00:00
|
|
|
|
2022-05-27 09:26:55 +00:00
|
|
|
export type InjectKey = string | symbol
|
2017-10-06 21:41:54 +00:00
|
|
|
|
2022-05-27 09:26:55 +00:00
|
|
|
export type InjectOptions =
|
|
|
|
| {
|
|
|
|
[key: string]: InjectKey | { from?: InjectKey; default?: any }
|
|
|
|
}
|
|
|
|
| string[]
|