Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unibuy/yy #3

Merged
merged 4 commits into from
Jul 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 41 additions & 17 deletions packages/canvas/render/src/RenderMain.js
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,42 @@ const setSchema = async (data) => {

const getNode = (id, parent) => (id ? getNodeById(id, parent) : schema)

let canvasRenderer = null

const defaultRenderer = function() {
// 渲染画布增加根节点,与出码和预览保持一致
const rootChildrenSchema = {
componentName: 'div',
props: schema.props,
children: schema.children
}

return h(
'tiny-i18n-host',
{
locale: 'zh_CN',
key: refreshKey.value,
ref: 'page',
className: 'design-page'
},
schema.children?.length ? h(renderer, { schema: rootChildrenSchema, parent: schema }) : [h(CanvasEmpty)]
)
}

const getRenderer = () => canvasRenderer || defaultRenderer

const setRenderer = (fn) => {
canvasRenderer = fn
}

let rendererMounted

const getRendererMounted = () => rendererMounted || function() {}

const setRendererMounted = (fn) => {
rendererMounted = fn
}

export default {
setup() {
provide('rootSchema', schema)
Expand Down Expand Up @@ -376,23 +412,7 @@ export default {
)
},
render() {
// 渲染画布增加根节点,与出码和预览保持一致
const rootChildrenSchema = {
componentName: 'div',
props: schema.props,
children: schema.children
}

return h(
'tiny-i18n-host',
{
locale: 'zh_CN',
key: refreshKey.value,
ref: 'page',
className: 'design-page'
},
schema.children?.length ? h(renderer, { schema: rootChildrenSchema, parent: schema }) : [h(CanvasEmpty)]
)
return getRenderer().call(this)
}
}

Expand Down Expand Up @@ -424,4 +444,8 @@ export const api = {
setDataSourceMap,
setGlobalState,
setNode,
getRenderer,
setRenderer,
getRendererMounted,
setRendererMounted
}