2019-11-01 15:32:53 +00:00
|
|
|
import {
|
|
|
|
createRenderer,
|
2020-02-14 06:30:08 +00:00
|
|
|
createHydrationRenderer,
|
2019-11-01 15:32:53 +00:00
|
|
|
warn,
|
2020-01-23 20:05:38 +00:00
|
|
|
RootRenderFunction,
|
2020-02-14 06:30:08 +00:00
|
|
|
CreateAppFunction,
|
2020-02-14 17:33:32 +00:00
|
|
|
Renderer,
|
|
|
|
HydrationRenderer,
|
|
|
|
App,
|
2021-02-24 21:18:55 +00:00
|
|
|
RootHydrateFunction,
|
2021-04-05 21:09:22 +00:00
|
|
|
isRuntimeOnly,
|
|
|
|
warnDeprecation,
|
|
|
|
DeprecationTypes
|
2019-11-01 15:32:53 +00:00
|
|
|
} from '@vue/runtime-core'
|
2019-06-20 13:28:37 +00:00
|
|
|
import { nodeOps } from './nodeOps'
|
2020-06-30 15:23:09 +00:00
|
|
|
import { patchProp, forcePatchProp } from './patchProp'
|
2019-10-21 20:25:16 +00:00
|
|
|
// Importing from the compiler, will be tree-shaken in prod
|
2021-04-05 21:09:22 +00:00
|
|
|
import { isFunction, isString, isHTMLTag, isSVGTag, extend } from '@vue/shared'
|
2018-09-19 15:35:38 +00:00
|
|
|
|
2020-05-01 20:14:30 +00:00
|
|
|
declare module '@vue/reactivity' {
|
|
|
|
export interface RefUnwrapBailTypes {
|
|
|
|
// Note: if updating this, also update `types/refBail.d.ts`.
|
|
|
|
runtimeDOMBailTypes: Node | Window
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-30 15:23:09 +00:00
|
|
|
const rendererOptions = extend({ patchProp, forcePatchProp }, nodeOps)
|
2020-02-14 06:30:08 +00:00
|
|
|
|
|
|
|
// lazy create the renderer - this makes core renderer logic tree-shakable
|
|
|
|
// in case the user only imports reactivity utilities from Vue.
|
2020-07-13 16:44:37 +00:00
|
|
|
let renderer: Renderer<Element> | HydrationRenderer
|
2020-02-14 06:30:08 +00:00
|
|
|
|
|
|
|
let enabledHydration = false
|
|
|
|
|
|
|
|
function ensureRenderer() {
|
2020-07-13 16:44:37 +00:00
|
|
|
return renderer || (renderer = createRenderer<Node, Element>(rendererOptions))
|
2020-02-14 06:30:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function ensureHydrationRenderer() {
|
|
|
|
renderer = enabledHydration
|
|
|
|
? renderer
|
|
|
|
: createHydrationRenderer(rendererOptions)
|
|
|
|
enabledHydration = true
|
2020-02-14 17:33:32 +00:00
|
|
|
return renderer as HydrationRenderer
|
2020-02-14 06:30:08 +00:00
|
|
|
}
|
2019-09-02 20:09:34 +00:00
|
|
|
|
2019-11-01 15:32:53 +00:00
|
|
|
// use explicit type casts here to avoid import() calls in rolled-up d.ts
|
2020-02-14 06:30:08 +00:00
|
|
|
export const render = ((...args) => {
|
|
|
|
ensureRenderer().render(...args)
|
2020-03-23 15:08:22 +00:00
|
|
|
}) as RootRenderFunction<Element>
|
2020-02-14 06:30:08 +00:00
|
|
|
|
|
|
|
export const hydrate = ((...args) => {
|
|
|
|
ensureHydrationRenderer().hydrate(...args)
|
2020-02-14 17:33:32 +00:00
|
|
|
}) as RootHydrateFunction
|
2019-11-01 15:32:53 +00:00
|
|
|
|
2020-02-14 06:30:08 +00:00
|
|
|
export const createApp = ((...args) => {
|
|
|
|
const app = ensureRenderer().createApp(...args)
|
2019-10-25 01:58:34 +00:00
|
|
|
|
|
|
|
if (__DEV__) {
|
2020-02-14 06:30:08 +00:00
|
|
|
injectNativeTagCheck(app)
|
2021-02-24 21:18:55 +00:00
|
|
|
injectCustomElementCheck(app)
|
2019-10-25 01:58:34 +00:00
|
|
|
}
|
|
|
|
|
2020-01-23 20:05:38 +00:00
|
|
|
const { mount } = app
|
2020-12-04 21:51:38 +00:00
|
|
|
app.mount = (containerOrSelector: Element | ShadowRoot | string): any => {
|
2020-02-14 06:30:08 +00:00
|
|
|
const container = normalizeContainer(containerOrSelector)
|
|
|
|
if (!container) return
|
2021-04-03 15:55:44 +00:00
|
|
|
|
2020-01-24 02:01:56 +00:00
|
|
|
const component = app._component
|
2020-03-11 20:39:26 +00:00
|
|
|
if (!isFunction(component) && !component.render && !component.template) {
|
2021-04-03 15:55:44 +00:00
|
|
|
// __UNSAFE__
|
|
|
|
// Reason: potential execution of JS expressions in in-DOM template.
|
|
|
|
// The user must make sure the in-DOM template is trusted. If it's
|
|
|
|
// rendered by the server, the template should not contain any user data.
|
2019-10-25 01:58:34 +00:00
|
|
|
component.template = container.innerHTML
|
2021-04-05 15:54:35 +00:00
|
|
|
// 2.x compat check
|
|
|
|
if (__COMPAT__ && __DEV__) {
|
|
|
|
for (let i = 0; i < container.attributes.length; i++) {
|
|
|
|
const attr = container.attributes[i]
|
|
|
|
if (attr.name !== 'v-cloak' && /^(v-|:|@)/.test(attr.name)) {
|
2021-04-05 22:13:29 +00:00
|
|
|
warnDeprecation(DeprecationTypes.GLOBAL_DOM_TEMPLATE_MOUNT)
|
2021-04-05 15:54:35 +00:00
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-10-25 01:58:34 +00:00
|
|
|
}
|
2021-04-05 15:54:35 +00:00
|
|
|
|
2020-02-14 06:30:08 +00:00
|
|
|
// clear content before mounting
|
|
|
|
container.innerHTML = ''
|
2021-03-01 16:51:32 +00:00
|
|
|
const proxy = mount(container, false, container instanceof SVGElement)
|
2020-12-04 21:51:38 +00:00
|
|
|
if (container instanceof Element) {
|
|
|
|
container.removeAttribute('v-cloak')
|
|
|
|
container.setAttribute('data-v-app', '')
|
|
|
|
}
|
2020-03-31 22:13:59 +00:00
|
|
|
return proxy
|
2020-02-14 06:30:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return app
|
|
|
|
}) as CreateAppFunction<Element>
|
|
|
|
|
|
|
|
export const createSSRApp = ((...args) => {
|
|
|
|
const app = ensureHydrationRenderer().createApp(...args)
|
|
|
|
|
|
|
|
if (__DEV__) {
|
|
|
|
injectNativeTagCheck(app)
|
2021-02-24 21:18:55 +00:00
|
|
|
injectCustomElementCheck(app)
|
2020-02-14 06:30:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const { mount } = app
|
2020-12-04 21:51:38 +00:00
|
|
|
app.mount = (containerOrSelector: Element | ShadowRoot | string): any => {
|
2020-02-14 06:30:08 +00:00
|
|
|
const container = normalizeContainer(containerOrSelector)
|
|
|
|
if (container) {
|
2021-03-01 16:51:32 +00:00
|
|
|
return mount(container, true, container instanceof SVGElement)
|
2020-02-14 04:31:03 +00:00
|
|
|
}
|
2020-01-16 17:23:47 +00:00
|
|
|
}
|
|
|
|
|
2019-10-14 19:36:30 +00:00
|
|
|
return app
|
2020-02-14 06:30:08 +00: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
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-02-24 21:18:55 +00:00
|
|
|
// dev only
|
|
|
|
function injectCustomElementCheck(app: App) {
|
|
|
|
if (isRuntimeOnly()) {
|
|
|
|
const value = app.config.isCustomElement
|
|
|
|
Object.defineProperty(app.config, 'isCustomElement', {
|
|
|
|
get() {
|
|
|
|
return value
|
|
|
|
},
|
|
|
|
set() {
|
|
|
|
warn(
|
|
|
|
`The \`isCustomElement\` config option is only respected when using the runtime compiler.` +
|
|
|
|
`If you are using the runtime-only build, \`isCustomElement\` must be passed to \`@vue/compiler-dom\` in the build setup instead` +
|
|
|
|
`- for example, via the \`compilerOptions\` option in vue-loader: https://vue-loader.vuejs.org/options.html#compileroptions.`
|
|
|
|
)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-04 21:51:38 +00:00
|
|
|
function normalizeContainer(
|
|
|
|
container: Element | ShadowRoot | string
|
|
|
|
): Element | null {
|
2020-02-14 06:30:08 +00:00
|
|
|
if (isString(container)) {
|
|
|
|
const res = document.querySelector(container)
|
|
|
|
if (__DEV__ && !res) {
|
2020-12-04 23:25:13 +00:00
|
|
|
warn(
|
|
|
|
`Failed to mount app: mount target selector "${container}" returned null.`
|
|
|
|
)
|
2020-02-14 06:30:08 +00:00
|
|
|
}
|
|
|
|
return res
|
|
|
|
}
|
2020-12-04 21:51:38 +00:00
|
|
|
if (
|
|
|
|
__DEV__ &&
|
2021-02-03 18:10:27 +00:00
|
|
|
container instanceof window.ShadowRoot &&
|
2020-12-04 21:51:38 +00:00
|
|
|
container.mode === 'closed'
|
|
|
|
) {
|
|
|
|
warn(
|
|
|
|
`mounting on a ShadowRoot with \`{mode: "closed"}\` may lead to unpredictable bugs`
|
|
|
|
)
|
|
|
|
}
|
|
|
|
return container as any
|
2019-10-14 19:36:30 +00:00
|
|
|
}
|
|
|
|
|
2020-07-09 20:25:29 +00:00
|
|
|
// SFC CSS utilities
|
2020-07-12 22:04:09 +00:00
|
|
|
export { useCssModule } from './helpers/useCssModule'
|
|
|
|
export { useCssVars } from './helpers/useCssVars'
|
2020-07-09 20:25:29 +00:00
|
|
|
|
2020-04-30 21:04:35 +00:00
|
|
|
// DOM-only components
|
|
|
|
export { Transition, TransitionProps } from './components/Transition'
|
|
|
|
export {
|
|
|
|
TransitionGroup,
|
|
|
|
TransitionGroupProps
|
|
|
|
} from './components/TransitionGroup'
|
|
|
|
|
|
|
|
// **Internal** DOM-only runtime directive helpers
|
2019-10-10 22:02:51 +00:00
|
|
|
export {
|
|
|
|
vModelText,
|
|
|
|
vModelCheckbox,
|
|
|
|
vModelRadio,
|
|
|
|
vModelSelect,
|
|
|
|
vModelDynamic
|
|
|
|
} from './directives/vModel'
|
2019-10-18 20:20:45 +00:00
|
|
|
export { withModifiers, withKeys } from './directives/vOn'
|
2019-11-28 23:41:01 +00:00
|
|
|
export { vShow } from './directives/vShow'
|
2019-10-14 04:33:23 +00:00
|
|
|
|
2018-09-20 01:51:21 +00:00
|
|
|
// re-export everything from core
|
2019-08-20 13:58:10 +00:00
|
|
|
// h, Component, reactivity API, nextTick, flags & types
|
2018-10-26 19:44:50 +00:00
|
|
|
export * from '@vue/runtime-core'
|