|
@@ -1,14 +1,16 @@
|
|
|
-import { isFunction, isObject } from '@vue/shared'
|
|
|
|
|
|
|
+import { NO, isFunction, isObject } from '@vue/shared'
|
|
|
import {
|
|
import {
|
|
|
type Component,
|
|
type Component,
|
|
|
type ComponentInternalInstance,
|
|
type ComponentInternalInstance,
|
|
|
createComponentInstance,
|
|
createComponentInstance,
|
|
|
|
|
+ validateComponentName,
|
|
|
} from './component'
|
|
} from './component'
|
|
|
import { warn } from './warning'
|
|
import { warn } from './warning'
|
|
|
-import { version } from '.'
|
|
|
|
|
|
|
+import { type Directive, version } from '.'
|
|
|
import { render, setupComponent, unmountComponent } from './apiRender'
|
|
import { render, setupComponent, unmountComponent } from './apiRender'
|
|
|
import type { InjectionKey } from './apiInject'
|
|
import type { InjectionKey } from './apiInject'
|
|
|
import type { RawProps } from './componentProps'
|
|
import type { RawProps } from './componentProps'
|
|
|
|
|
+import { validateDirectiveName } from './directives'
|
|
|
|
|
|
|
|
export function createVaporApp(
|
|
export function createVaporApp(
|
|
|
rootComponent: Component,
|
|
rootComponent: Component,
|
|
@@ -60,6 +62,35 @@ export function createVaporApp(
|
|
|
return app
|
|
return app
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
|
|
+ component(name: string, component?: Component): any {
|
|
|
|
|
+ if (__DEV__) {
|
|
|
|
|
+ validateComponentName(name, context.config)
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!component) {
|
|
|
|
|
+ return context.components[name]
|
|
|
|
|
+ }
|
|
|
|
|
+ if (__DEV__ && context.components[name]) {
|
|
|
|
|
+ warn(`Component "${name}" has already been registered in target app.`)
|
|
|
|
|
+ }
|
|
|
|
|
+ context.components[name] = component
|
|
|
|
|
+ return app
|
|
|
|
|
+ },
|
|
|
|
|
+
|
|
|
|
|
+ directive(name: string, directive?: Directive) {
|
|
|
|
|
+ if (__DEV__) {
|
|
|
|
|
+ validateDirectiveName(name)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (!directive) {
|
|
|
|
|
+ return context.directives[name] as any
|
|
|
|
|
+ }
|
|
|
|
|
+ if (__DEV__ && context.directives[name]) {
|
|
|
|
|
+ warn(`Directive "${name}" has already been registered in target app.`)
|
|
|
|
|
+ }
|
|
|
|
|
+ context.directives[name] = directive
|
|
|
|
|
+ return app
|
|
|
|
|
+ },
|
|
|
|
|
+
|
|
|
mount(rootContainer): any {
|
|
mount(rootContainer): any {
|
|
|
if (!instance) {
|
|
if (!instance) {
|
|
|
instance = createComponentInstance(
|
|
instance = createComponentInstance(
|
|
@@ -119,11 +150,14 @@ export function createAppContext(): AppContext {
|
|
|
return {
|
|
return {
|
|
|
app: null as any,
|
|
app: null as any,
|
|
|
config: {
|
|
config: {
|
|
|
|
|
+ isNativeTag: NO,
|
|
|
errorHandler: undefined,
|
|
errorHandler: undefined,
|
|
|
warnHandler: undefined,
|
|
warnHandler: undefined,
|
|
|
globalProperties: {},
|
|
globalProperties: {},
|
|
|
},
|
|
},
|
|
|
provides: Object.create(null),
|
|
provides: Object.create(null),
|
|
|
|
|
+ components: {},
|
|
|
|
|
+ directives: {},
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -151,6 +185,11 @@ export interface App {
|
|
|
): this
|
|
): this
|
|
|
use<Options>(plugin: Plugin<Options>, options: Options): this
|
|
use<Options>(plugin: Plugin<Options>, options: Options): this
|
|
|
|
|
|
|
|
|
|
+ component(name: string): Component | undefined
|
|
|
|
|
+ component<T extends Component>(name: string, component: T): this
|
|
|
|
|
+ directive<T = any, V = any>(name: string): Directive<T, V> | undefined
|
|
|
|
|
+ directive<T = any, V = any>(name: string, directive: Directive<T, V>): this
|
|
|
|
|
+
|
|
|
mount(
|
|
mount(
|
|
|
rootContainer: ParentNode | string,
|
|
rootContainer: ParentNode | string,
|
|
|
isHydrate?: boolean,
|
|
isHydrate?: boolean,
|
|
@@ -163,6 +202,9 @@ export interface App {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
export interface AppConfig {
|
|
export interface AppConfig {
|
|
|
|
|
+ // @private
|
|
|
|
|
+ readonly isNativeTag: (tag: string) => boolean
|
|
|
|
|
+
|
|
|
errorHandler?: (
|
|
errorHandler?: (
|
|
|
err: unknown,
|
|
err: unknown,
|
|
|
instance: ComponentInternalInstance | null,
|
|
instance: ComponentInternalInstance | null,
|
|
@@ -180,6 +222,17 @@ export interface AppContext {
|
|
|
app: App // for devtools
|
|
app: App // for devtools
|
|
|
config: AppConfig
|
|
config: AppConfig
|
|
|
provides: Record<string | symbol, any>
|
|
provides: Record<string | symbol, any>
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Resolved component registry, only for components with mixins or extends
|
|
|
|
|
+ * @internal
|
|
|
|
|
+ */
|
|
|
|
|
+ components: Record<string, Component>
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Resolved directive registry, only for components with mixins or extends
|
|
|
|
|
+ * @internal
|
|
|
|
|
+ */
|
|
|
|
|
+ directives: Record<string, Directive>
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|