2019-11-01 23:32:53 +08:00
|
|
|
import {
|
|
|
|
createRenderer,
|
2020-02-14 14:30:08 +08:00
|
|
|
createHydrationRenderer,
|
2019-11-01 23:32:53 +08:00
|
|
|
warn,
|
2020-01-24 04:05:38 +08:00
|
|
|
RootRenderFunction,
|
2020-02-14 14:30:08 +08:00
|
|
|
CreateAppFunction,
|
2020-02-15 01:33:32 +08:00
|
|
|
Renderer,
|
|
|
|
HydrationRenderer,
|
|
|
|
App,
|
|
|
|
RootHydrateFunction
|
2019-11-01 23:32:53 +08:00
|
|
|
} from '@vue/runtime-core'
|
2019-06-20 21:28:37 +08:00
|
|
|
import { nodeOps } from './nodeOps'
|
2020-06-30 23:23:09 +08:00
|
|
|
import { patchProp, forcePatchProp } from './patchProp'
|
2019-10-22 04:25:16 +08:00
|
|
|
// Importing from the compiler, will be tree-shaken in prod
|
2020-06-11 04:54:23 +08:00
|
|
|
import { isFunction, isString, isHTMLTag, isSVGTag, extend } from '@vue/shared'
|
2018-09-19 23:35:38 +08:00
|
|
|
|
2020-05-02 04:14:30 +08:00
|
|
|
declare module '@vue/reactivity' {
|
|
|
|
export interface RefUnwrapBailTypes {
|
|
|
|
// Note: if updating this, also update `types/refBail.d.ts`.
|
|
|
|
runtimeDOMBailTypes: Node | Window
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-30 23:23:09 +08:00
|
|
|
const rendererOptions = extend({ patchProp, forcePatchProp }, nodeOps)
|
2020-02-14 14:30:08 +08:00
|
|
|
|
|
|
|
// lazy create the renderer - this makes core renderer logic tree-shakable
|
|
|
|
// in case the user only imports reactivity utilities from Vue.
|
2020-02-15 01:33:32 +08:00
|
|
|
let renderer: Renderer | HydrationRenderer
|
2020-02-14 14:30:08 +08:00
|
|
|
|
|
|
|
let enabledHydration = false
|
|
|
|
|
|
|
|
function ensureRenderer() {
|
|
|
|
return renderer || (renderer = createRenderer(rendererOptions))
|
|
|
|
}
|
|
|
|
|
|
|
|
function ensureHydrationRenderer() {
|
|
|
|
renderer = enabledHydration
|
|
|
|
? renderer
|
|
|
|
: createHydrationRenderer(rendererOptions)
|
|
|
|
enabledHydration = true
|
2020-02-15 01:33:32 +08:00
|
|
|
return renderer as HydrationRenderer
|
2020-02-14 14:30:08 +08:00
|
|
|
}
|
2019-09-03 04:09:34 +08:00
|
|
|
|
2019-11-01 23:32:53 +08:00
|
|
|
// use explicit type casts here to avoid import() calls in rolled-up d.ts
|
2020-02-14 14:30:08 +08:00
|
|
|
export const render = ((...args) => {
|
|
|
|
ensureRenderer().render(...args)
|
2020-03-23 23:08:22 +08:00
|
|
|
}) as RootRenderFunction<Element>
|
2020-02-14 14:30:08 +08:00
|
|
|
|
|
|
|
export const hydrate = ((...args) => {
|
|
|
|
ensureHydrationRenderer().hydrate(...args)
|
2020-02-15 01:33:32 +08:00
|
|
|
}) as RootHydrateFunction
|
2019-11-01 23:32:53 +08:00
|
|
|
|
2020-02-14 14:30:08 +08:00
|
|
|
export const createApp = ((...args) => {
|
|
|
|
const app = ensureRenderer().createApp(...args)
|
2019-10-25 09:58:34 +08:00
|
|
|
|
|
|
|
if (__DEV__) {
|
2020-02-14 14:30:08 +08:00
|
|
|
injectNativeTagCheck(app)
|
2019-10-25 09:58:34 +08:00
|
|
|
}
|
|
|
|
|
2020-01-24 04:05:38 +08:00
|
|
|
const { mount } = app
|
2020-02-14 14:30:08 +08:00
|
|
|
app.mount = (containerOrSelector: Element | string): any => {
|
|
|
|
const container = normalizeContainer(containerOrSelector)
|
|
|
|
if (!container) return
|
2020-01-24 10:01:56 +08:00
|
|
|
const component = app._component
|
2020-03-12 04:39:26 +08:00
|
|
|
if (!isFunction(component) && !component.render && !component.template) {
|
2019-10-25 09:58:34 +08:00
|
|
|
component.template = container.innerHTML
|
|
|
|
}
|
2020-02-14 14:30:08 +08:00
|
|
|
// clear content before mounting
|
|
|
|
container.innerHTML = ''
|
2020-04-01 06:13:59 +08:00
|
|
|
const proxy = mount(container)
|
|
|
|
container.removeAttribute('v-cloak')
|
|
|
|
return proxy
|
2020-02-14 14:30:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return app
|
|
|
|
}) as CreateAppFunction<Element>
|
|
|
|
|
|
|
|
export const createSSRApp = ((...args) => {
|
|
|
|
const app = ensureHydrationRenderer().createApp(...args)
|
|
|
|
|
|
|
|
if (__DEV__) {
|
|
|
|
injectNativeTagCheck(app)
|
|
|
|
}
|
|
|
|
|
|
|
|
const { mount } = app
|
|
|
|
app.mount = (containerOrSelector: Element | string): any => {
|
|
|
|
const container = normalizeContainer(containerOrSelector)
|
|
|
|
if (container) {
|
|
|
|
return mount(container, true)
|
2020-02-14 12:31:03 +08:00
|
|
|
}
|
2020-01-17 01:23:47 +08:00
|
|
|
}
|
|
|
|
|
2019-10-15 03:36:30 +08:00
|
|
|
return app
|
2020-02-14 14:30:08 +08:00
|
|
|
}) as CreateAppFunction<Element>
|
|
|
|
|
|
|
|
function injectNativeTagCheck(app: App) {
|
|
|
|
// Inject `isNativeTag`
|
|
|
|
// this is used for component name validation (dev only)
|
|
|
|
Object.defineProperty(app.config, 'isNativeTag', {
|
|
|
|
value: (tag: string) => isHTMLTag(tag) || isSVGTag(tag),
|
|
|
|
writable: false
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
function normalizeContainer(container: Element | string): Element | null {
|
|
|
|
if (isString(container)) {
|
|
|
|
const res = document.querySelector(container)
|
|
|
|
if (__DEV__ && !res) {
|
|
|
|
warn(`Failed to mount app: mount target selector returned null.`)
|
|
|
|
}
|
|
|
|
return res
|
|
|
|
}
|
|
|
|
return container
|
2019-10-15 03:36:30 +08:00
|
|
|
}
|
|
|
|
|
2020-05-01 05:04:35 +08:00
|
|
|
// DOM-only components
|
|
|
|
export { Transition, TransitionProps } from './components/Transition'
|
|
|
|
export {
|
|
|
|
TransitionGroup,
|
|
|
|
TransitionGroupProps
|
|
|
|
} from './components/TransitionGroup'
|
|
|
|
|
|
|
|
// **Internal** DOM-only runtime directive helpers
|
2019-10-11 06:02:51 +08:00
|
|
|
export {
|
|
|
|
vModelText,
|
|
|
|
vModelCheckbox,
|
|
|
|
vModelRadio,
|
|
|
|
vModelSelect,
|
|
|
|
vModelDynamic
|
|
|
|
} from './directives/vModel'
|
2019-10-19 04:20:45 +08:00
|
|
|
export { withModifiers, withKeys } from './directives/vOn'
|
2019-11-29 07:41:01 +08:00
|
|
|
export { vShow } from './directives/vShow'
|
2019-10-14 12:33:23 +08:00
|
|
|
|
2018-09-20 09:51:21 +08:00
|
|
|
// re-export everything from core
|
2019-08-20 21:58:10 +08:00
|
|
|
// h, Component, reactivity API, nextTick, flags & types
|
2018-10-27 03:44:50 +08:00
|
|
|
export * from '@vue/runtime-core'
|