2020-06-27 00:25:07 -04:00
|
|
|
import { ComponentInternalInstance, Slots } from 'vue'
|
2020-06-26 18:09:47 +03:00
|
|
|
import { Props, PushFn, renderVNodeChildren } from '../render'
|
2020-02-05 21:04:40 -05:00
|
|
|
|
|
|
|
export type SSRSlots = Record<string, SSRSlot>
|
|
|
|
export type SSRSlot = (
|
|
|
|
props: Props,
|
|
|
|
push: PushFn,
|
2020-02-06 17:45:34 -05:00
|
|
|
parentComponent: ComponentInternalInstance | null,
|
|
|
|
scopeId: string | null
|
2020-02-05 21:04:40 -05:00
|
|
|
) => void
|
|
|
|
|
2020-02-06 12:07:25 -05:00
|
|
|
export function ssrRenderSlot(
|
2020-02-05 21:04:40 -05:00
|
|
|
slots: Slots | SSRSlots,
|
|
|
|
slotName: string,
|
|
|
|
slotProps: Props,
|
|
|
|
fallbackRenderFn: (() => void) | null,
|
|
|
|
push: PushFn,
|
2020-02-16 01:41:20 +03:00
|
|
|
parentComponent: ComponentInternalInstance
|
2020-02-05 21:04:40 -05:00
|
|
|
) {
|
2020-03-12 22:19:41 -04:00
|
|
|
// template-compiled slots are always rendered as fragments
|
2020-03-13 11:55:04 -04:00
|
|
|
push(`<!--[-->`)
|
2020-02-05 21:04:40 -05:00
|
|
|
const slotFn = slots[slotName]
|
|
|
|
if (slotFn) {
|
2020-06-27 00:25:07 -04:00
|
|
|
const scopeId = parentComponent && parentComponent.type.__scopeId
|
|
|
|
const ret = slotFn(
|
|
|
|
slotProps,
|
|
|
|
push,
|
|
|
|
parentComponent,
|
|
|
|
scopeId ? ` ${scopeId}-s` : ``
|
|
|
|
)
|
|
|
|
if (Array.isArray(ret)) {
|
2020-02-05 21:04:40 -05:00
|
|
|
// normal slot
|
2020-06-27 00:25:07 -04:00
|
|
|
renderVNodeChildren(push, ret, parentComponent)
|
2020-02-05 21:04:40 -05:00
|
|
|
}
|
|
|
|
} else if (fallbackRenderFn) {
|
|
|
|
fallbackRenderFn()
|
|
|
|
}
|
2020-03-13 11:55:04 -04:00
|
|
|
push(`<!--]-->`)
|
2020-02-05 21:04:40 -05:00
|
|
|
}
|