| 1 |
<script lang="ts"> |
| 2 |
export type {MyDetail} from '@lit-internal/test-element-a/detail-type.js'; |
| 3 |
export type {EventSubclass} from '@lit-internal/test-element-a/element-events.js'; |
| 4 |
export type {SpecialEvent} from '@lit-internal/test-element-a/special-event.js'; |
| 5 |
export type {TemplateResult} from 'lit'; |
| 6 |
</script> |
| 7 |
<script setup lang="ts"> |
| 8 |
import {h, useSlots, reactive} from 'vue'; |
| 9 |
import {assignSlotNodes, Slots} from '@lit-labs/vue-utils/wrapper-utils.js'; |
| 10 |
import '@lit-internal/test-element-a/element-events.js'; |
| 11 |
import {MyDetail} from '@lit-internal/test-element-a/detail-type.js'; |
| 12 |
import {EventSubclass} from '@lit-internal/test-element-a/element-events.js'; |
| 13 |
import {SpecialEvent} from '@lit-internal/test-element-a/special-event.js'; |
| 14 |
import {TemplateResult} from 'lit'; |
| 15 |
|
| 16 |
export interface Props { |
| 17 |
foo?: string | undefined; |
| 18 |
} |
| 19 |
|
| 20 |
const vueProps = defineProps<Props>(); |
| 21 |
|
| 22 |
const defaults = reactive({} as Props); |
| 23 |
const vDefaults = { |
| 24 |
created(el: any) { |
| 25 |
for (const p in vueProps) { |
| 26 |
defaults[p as keyof Props] = el[p]; |
| 27 |
} |
| 28 |
}, |
| 29 |
}; |
| 30 |
|
| 31 |
let hasRendered = false; |
| 32 |
|
| 33 |
const emit = defineEmits<{ |
| 34 |
(e: 'string-custom-event', payload: CustomEvent<string>): void; |
| 35 |
(e: 'number-custom-event', payload: CustomEvent<number>): void; |
| 36 |
(e: 'my-detail-custom-event', payload: CustomEvent<MyDetail>): void; |
| 37 |
(e: 'event-subclass', payload: EventSubclass): void; |
| 38 |
(e: 'special-event', payload: SpecialEvent): void; |
| 39 |
( |
| 40 |
e: 'template-result-custom-event', |
| 41 |
payload: CustomEvent<TemplateResult> |
| 42 |
): void; |
| 43 |
}>(); |
| 44 |
|
| 45 |
const slots = useSlots() as Slots; |
| 46 |
|
| 47 |
const render = () => { |
| 48 |
const eventProps = { |
| 49 |
onStringCustomEvent: (event: CustomEvent<string>) => |
| 50 |
emit('string-custom-event', event as CustomEvent<string>), |
| 51 |
onNumberCustomEvent: (event: CustomEvent<number>) => |
| 52 |
emit('number-custom-event', event as CustomEvent<number>), |
| 53 |
onMyDetailCustomEvent: (event: CustomEvent<MyDetail>) => |
| 54 |
emit('my-detail-custom-event', event as CustomEvent<MyDetail>), |
| 55 |
onEventSubclass: (event: EventSubclass) => |
| 56 |
emit('event-subclass', event as EventSubclass), |
| 57 |
onSpecialEvent: (event: SpecialEvent) => |
| 58 |
emit('special-event', event as SpecialEvent), |
| 59 |
onTemplateResultCustomEvent: (event: CustomEvent<TemplateResult>) => |
| 60 |
emit( |
| 61 |
'template-result-custom-event', |
| 62 |
event as CustomEvent<TemplateResult> |
| 63 |
), |
| 64 |
}; |
| 65 |
const props = eventProps as typeof eventProps & Props; |
| 66 |
|
| 67 |
for (const p in vueProps) { |
| 68 |
const v = vueProps[p as keyof Props]; |
| 69 |
if (v !== undefined || hasRendered) { |
| 70 |
(props[p as keyof Props] as unknown) = v ?? defaults[p as keyof Props]; |
| 71 |
} |
| 72 |
} |
| 73 |
|
| 74 |
hasRendered = true; |
| 75 |
|
| 76 |
return h('element-events', props, assignSlotNodes(slots)); |
| 77 |
}; |
| 78 |
</script> |
| 79 |
<template><render v-defaults /></template> |