feat(runtime-dom): defineCustomElement

This commit is contained in:
Evan You
2021-07-12 15:32:38 -04:00
parent 42ace9577d
commit 8610e1c9e2
8 changed files with 546 additions and 14 deletions

View File

@@ -279,12 +279,15 @@ export interface ComponentInternalInstance {
* @internal
*/
emitsOptions: ObjectEmitsOptions | null
/**
* resolved inheritAttrs options
* @internal
*/
inheritAttrs?: boolean
/**
* is custom element?
*/
isCE?: boolean
// the rest are only for stateful components ---------------------------------
@@ -519,6 +522,11 @@ export function createComponentInstance(
instance.root = parent ? parent.root : instance
instance.emit = emit.bind(null, instance)
// apply custom element special handling
if (vnode.ce) {
vnode.ce(instance)
}
return instance
}

View File

@@ -1,6 +1,9 @@
import { Data } from '../component'
import { Slots, RawSlots } from '../componentSlots'
import { ContextualRenderFn } from '../componentRenderContext'
import {
ContextualRenderFn,
currentRenderingInstance
} from '../componentRenderContext'
import { Comment, isVNode } from '../vnode'
import {
VNodeArrayChildren,
@@ -11,6 +14,7 @@ import {
} from '../vnode'
import { PatchFlags, SlotFlags } from '@vue/shared'
import { warn } from '../warning'
import { createVNode } from '@vue/runtime-core'
/**
* Compiler runtime helper for rendering `<slot/>`
@@ -25,6 +29,14 @@ export function renderSlot(
fallback?: () => VNodeArrayChildren,
noSlotted?: boolean
): VNode {
if (currentRenderingInstance!.isCE) {
return createVNode(
'slot',
name === 'default' ? null : { name },
fallback && fallback()
)
}
let slot = slots[name]
if (__DEV__ && slot && slot.length > 1) {

View File

@@ -25,7 +25,7 @@ import { isAsyncWrapper } from './apiAsyncComponent'
export type RootHydrateFunction = (
vnode: VNode<Node, Element>,
container: Element
container: Element | ShadowRoot
) => void
const enum DOMNodeTypes {

View File

@@ -93,7 +93,7 @@ export interface Renderer<HostElement = RendererElement> {
createApp: CreateAppFunction<HostElement>
}
export interface HydrationRenderer extends Renderer<Element> {
export interface HydrationRenderer extends Renderer<Element | ShadowRoot> {
hydrate: RootHydrateFunction
}

View File

@@ -136,11 +136,6 @@ export interface VNode<
*/
[ReactiveFlags.SKIP]: true
/**
* @internal __COMPAT__ only
*/
isCompatRoot?: true
type: VNodeTypes
props: (VNodeProps & ExtraProps) | null
key: string | number | null
@@ -155,6 +150,7 @@ export interface VNode<
* - Slot fragment vnodes with :slotted SFC styles.
* - Component vnodes (during patch/hydration) so that its root node can
* inherit the component's slotScopeIds
* @internal
*/
slotScopeIds: string[] | null
children: VNodeNormalizedChildren
@@ -167,24 +163,50 @@ export interface VNode<
anchor: HostNode | null // fragment anchor
target: HostElement | null // teleport target
targetAnchor: HostNode | null // teleport target anchor
staticCount?: number // number of elements contained in a static vnode
/**
* number of elements contained in a static vnode
* @internal
*/
staticCount: number
// suspense
suspense: SuspenseBoundary | null
/**
* @internal
*/
ssContent: VNode | null
/**
* @internal
*/
ssFallback: VNode | null
// optimization only
shapeFlag: number
patchFlag: number
/**
* @internal
*/
dynamicProps: string[] | null
/**
* @internal
*/
dynamicChildren: VNode[] | null
// application root node only
appContext: AppContext | null
// v-for memo
/**
* @internal attached by v-memo
*/
memo?: any[]
/**
* @internal __COMPAT__ only
*/
isCompatRoot?: true
/**
* @internal custom element interception hook
*/
ce?: (instance: ComponentInternalInstance) => void
}
// Since v-if and v-for are the two possible ways node structure can dynamically