2023-05-01 11:56:30 +00:00
|
|
|
import { h } from 'vue'
|
2022-03-14 10:47:24 +00:00
|
|
|
import type { Component } from 'vue'
|
2023-03-08 21:13:06 +00:00
|
|
|
// eslint-disable-next-line
|
|
|
|
import { isString, isPromise, isArray } from '@vue/shared'
|
2022-03-14 10:47:24 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal utility
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
export const _wrapIf = (component: Component, props: any, slots: any) => {
|
2023-05-01 11:56:30 +00:00
|
|
|
props = props === true ? {} : props
|
|
|
|
return { default: () => props ? h(component, props, slots) : slots.default?.() }
|
2022-03-14 10:47:24 +00:00
|
|
|
}
|
2023-03-08 21:13:06 +00:00
|
|
|
|
|
|
|
// eslint-disable-next-line no-use-before-define
|
|
|
|
export type SSRBuffer = SSRBufferItem[] & { hasAsync?: boolean }
|
|
|
|
export type SSRBufferItem = string | SSRBuffer | Promise<SSRBuffer>
|
|
|
|
|
|
|
|
/**
|
|
|
|
* create buffer retrieved from @vue/server-renderer
|
|
|
|
*
|
|
|
|
* @see https://github.com/vuejs/core/blob/9617dd4b2abc07a5dc40de6e5b759e851b4d0da1/packages/server-renderer/src/render.ts#L57
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
export function createBuffer () {
|
|
|
|
let appendable = false
|
|
|
|
const buffer: SSRBuffer = []
|
|
|
|
return {
|
|
|
|
getBuffer (): SSRBuffer {
|
|
|
|
return buffer
|
|
|
|
},
|
|
|
|
push (item: SSRBufferItem) {
|
|
|
|
const isStringItem = isString(item)
|
|
|
|
if (appendable && isStringItem) {
|
|
|
|
buffer[buffer.length - 1] += item as string
|
|
|
|
} else {
|
|
|
|
buffer.push(item)
|
|
|
|
}
|
|
|
|
appendable = isStringItem
|
|
|
|
if (isPromise(item) || (isArray(item) && item.hasAsync)) {
|
|
|
|
buffer.hasAsync = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|