vue3-yuanma/packages/runtime-dom/src/index.ts

88 lines
2.3 KiB
TypeScript
Raw Normal View History

2019-11-01 15:32:53 +00:00
import {
createRenderer,
warn,
RootRenderFunction,
CreateAppFunction
2019-11-01 15:32:53 +00:00
} from '@vue/runtime-core'
2019-06-20 13:28:37 +00:00
import { nodeOps } from './nodeOps'
import { patchProp } from './patchProp'
// Importing from the compiler, will be tree-shaken in prod
import { isFunction, isString, isHTMLTag, isSVGTag } from '@vue/shared'
2018-09-19 15:35:38 +00:00
2020-02-13 22:47:00 +00:00
const {
render: baseRender,
hydrate: baseHydrate,
createApp: baseCreateApp
} = createRenderer({
2019-06-20 13:28:37 +00:00
patchProp,
...nodeOps
2019-09-06 20:58:32 +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
export const render = baseRender as RootRenderFunction<Node, Element>
2020-02-13 22:47:00 +00:00
export const hydrate = baseHydrate as RootRenderFunction<Node, Element>
2019-11-01 15:32:53 +00:00
export const createApp: CreateAppFunction<Element> = (...args) => {
const app = baseCreateApp(...args)
if (__DEV__) {
// 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
})
}
const { mount } = app
2020-02-14 04:31:03 +00:00
app.mount = (container: Element | string): any => {
if (isString(container)) {
container = document.querySelector(container)!
if (!container) {
__DEV__ &&
warn(`Failed to mount app: mount target selector returned null.`)
return
}
}
const component = app._component
if (
__RUNTIME_COMPILE__ &&
!isFunction(component) &&
!component.render &&
!component.template
) {
component.template = container.innerHTML
}
2020-02-14 04:31:03 +00:00
const isHydrate = container.hasAttribute('data-server-rendered')
if (!isHydrate) {
// clear content before mounting
container.innerHTML = ''
}
return mount(container, isHydrate)
}
return app
}
2019-11-28 23:41:01 +00:00
// DOM-only runtime directive helpers
2019-10-10 22:02:51 +00:00
export {
vModelText,
vModelCheckbox,
vModelRadio,
vModelSelect,
vModelDynamic
} from './directives/vModel'
export { withModifiers, withKeys } from './directives/vOn'
2019-11-28 23:41:01 +00:00
export { vShow } from './directives/vShow'
// DOM-only components
2019-11-24 21:00:46 +00:00
export { Transition, TransitionProps } from './components/Transition'
2019-11-28 23:41:01 +00:00
export {
TransitionGroup,
TransitionGroupProps
} from './components/TransitionGroup'
// 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'