mirror of https://github.com/vuejs/core.git
feat(custom-element): support passing custom-element-specific options via 2nd argument of defineCustomElement
This commit is contained in:
parent
56c76a8b05
commit
60a88a2b12
|
@ -898,16 +898,20 @@ describe('defineCustomElement', () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
const toggle = ref(true)
|
const toggle = ref(true)
|
||||||
const ES = defineCustomElement({
|
const ES = defineCustomElement(
|
||||||
shadowRoot: false,
|
{
|
||||||
render() {
|
render() {
|
||||||
return [
|
return [
|
||||||
renderSlot(this.$slots, 'default'),
|
renderSlot(this.$slots, 'default'),
|
||||||
toggle.value ? renderSlot(this.$slots, 'named') : null,
|
toggle.value ? renderSlot(this.$slots, 'named') : null,
|
||||||
renderSlot(this.$slots, 'omitted', {}, () => [h('div', 'fallback')]),
|
renderSlot(this.$slots, 'omitted', {}, () => [
|
||||||
]
|
h('div', 'fallback'),
|
||||||
|
]),
|
||||||
|
]
|
||||||
|
},
|
||||||
},
|
},
|
||||||
})
|
{ shadowRoot: false },
|
||||||
|
)
|
||||||
customElements.define('my-el-shadowroot-false-slots', ES)
|
customElements.define('my-el-shadowroot-false-slots', ES)
|
||||||
|
|
||||||
test('should render slots', async () => {
|
test('should render slots', async () => {
|
||||||
|
|
|
@ -141,6 +141,7 @@ export function defineCustomElement<
|
||||||
Exposed
|
Exposed
|
||||||
>
|
>
|
||||||
>,
|
>,
|
||||||
|
extraOptions?: CustomElementOptions,
|
||||||
): VueElementConstructor<ResolvedProps>
|
): VueElementConstructor<ResolvedProps>
|
||||||
|
|
||||||
// overload 3: defining a custom element from the returned value of
|
// overload 3: defining a custom element from the returned value of
|
||||||
|
@ -149,6 +150,7 @@ export function defineCustomElement<
|
||||||
T extends DefineComponent<any, any, any, any>,
|
T extends DefineComponent<any, any, any, any>,
|
||||||
>(
|
>(
|
||||||
options: T,
|
options: T,
|
||||||
|
extraOptions?: CustomElementOptions,
|
||||||
): VueElementConstructor<
|
): VueElementConstructor<
|
||||||
T extends DefineComponent<infer P, any, any, any>
|
T extends DefineComponent<infer P, any, any, any>
|
||||||
? ExtractPropTypes<P>
|
? ExtractPropTypes<P>
|
||||||
|
@ -165,6 +167,7 @@ export function defineCustomElement(
|
||||||
hydrate?: RootHydrateFunction,
|
hydrate?: RootHydrateFunction,
|
||||||
): VueElementConstructor {
|
): VueElementConstructor {
|
||||||
const Comp = defineComponent(options, extraOptions) as any
|
const Comp = defineComponent(options, extraOptions) as any
|
||||||
|
if (isPlainObject(Comp)) extend(Comp, extraOptions)
|
||||||
class VueCustomElement extends VueElement {
|
class VueCustomElement extends VueElement {
|
||||||
static def = Comp
|
static def = Comp
|
||||||
constructor(initialProps?: Record<string, any>) {
|
constructor(initialProps?: Record<string, any>) {
|
||||||
|
|
|
@ -245,6 +245,7 @@ export {
|
||||||
useShadowRoot,
|
useShadowRoot,
|
||||||
VueElement,
|
VueElement,
|
||||||
type VueElementConstructor,
|
type VueElementConstructor,
|
||||||
|
type CustomElementOptions,
|
||||||
} from './apiCustomElement'
|
} from './apiCustomElement'
|
||||||
|
|
||||||
// SFC CSS utilities
|
// SFC CSS utilities
|
||||||
|
|
Loading…
Reference in New Issue