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

Refactor: split renderer #888

Draft
wants to merge 30 commits into
base: refactor/develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
8055d3c
refactor: split renderer package
yy-wow Oct 24, 2024
e12ae04
fix: miss file
yy-wow Oct 24, 2024
80b514e
refactor: split renderer package
yy-wow Oct 30, 2024
eec6840
fix: import path
yy-wow Oct 30, 2024
b6df90b
fix: remove unused api
yy-wow Oct 30, 2024
2b692b2
feat: 增加画布特征判断
yy-wow Oct 30, 2024
a1778ad
fix: builtin name
yy-wow Oct 30, 2024
c76693b
fix: package.json
yy-wow Oct 30, 2024
391069c
fix: viteConfig
yy-wow Oct 30, 2024
d3ff581
fix: viteConfig
yy-wow Oct 30, 2024
965730b
fix: review
yy-wow Oct 30, 2024
3f7efcd
doc: README
yy-wow Oct 30, 2024
a9c5c65
fix: README
yy-wow Nov 1, 2024
948b741
fix: 渲染器接收参数
yy-wow Nov 4, 2024
2f96bf3
doc: update README
yy-wow Nov 4, 2024
3658f57
doc: update README
yy-wow Nov 4, 2024
a37a30b
fix: package dependencies
yy-wow Nov 4, 2024
cff6056
Merge branch 'refactor/develop' into refactor/split-renderer
yy-wow Nov 5, 2024
88dcaa0
fix: build error
yy-wow Nov 5, 2024
f75edeb
Merge branch 'refactor/develop' into refactor/split-renderer
yy-wow Nov 8, 2024
23028c7
Merge branch 'refactor/develop' into refactor/split-renderer
yy-wow Nov 11, 2024
622f4ca
fix: revert canvasFlag
yy-wow Nov 11, 2024
c370fbf
fix: remove props
yy-wow Nov 11, 2024
0097246
fix: README
yy-wow Nov 11, 2024
af1dc68
Merge branch 'refactor/develop' into refactor/split-renderer
yy-wow Nov 13, 2024
40d3b16
feat: add generate context function
yy-wow Nov 14, 2024
1eac4d0
feat: export generateContext
yy-wow Nov 15, 2024
8a17eb5
fix: generate context
yy-wow Nov 15, 2024
ee61ad6
fix: state reactive
yy-wow Nov 22, 2024
e629c68
fix: vite config
yy-wow Nov 22, 2024
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
1 change: 1 addition & 0 deletions jsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"@opentiny/tiny-engine": ["packages/design-core/index.js"],
"@opentiny/tiny-engine-meta-register": ["packages/register/src/index.js"],
"@opentiny/tiny-engine-canvas": ["packages/canvas/src/index.js"],
"@opentiny/tiny-engine-renderer": ["packages/renderer/src/index.js"],
"@opentiny/tiny-engine-plugin-materials": ["packages/plugins/materials/index"],
"@opentiny/tiny-engine-plugin-state": ["packages/plugins/state/index"],
"@opentiny/tiny-engine-plugin-script": ["packages/plugins/script/index"],
Expand Down
8 changes: 0 additions & 8 deletions mockServer/src/mock/get/app-center/v1/apps/schema/918.json
Original file line number Diff line number Diff line change
Expand Up @@ -2130,14 +2130,6 @@
"main": ""
}
},
{
"name": "npm",
"type": "function",
"content": {
"type": "JSFunction",
"value": "''"
}
},
{
"name": "Pager",
"type": "npm",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const getDevAlias = (useSourceAlias) => {
'@opentiny/tiny-engine-http': path.resolve(basePath, 'packages/http/src/index.js'),
'@opentiny/tiny-engine-canvas': path.resolve(basePath, 'packages/canvas/index.js'),
'@opentiny/tiny-engine-canvas/render': path.resolve(basePath, 'packages/canvas/render/index.js'),
'@opentiny/tiny-engine-renderer': path.resolve(basePath, 'packages/renderer/src/index.js'),
'@opentiny/tiny-engine-utils': path.resolve(basePath, 'packages/utils/src/index.js'),
'@opentiny/tiny-engine-webcomponent-core': path.resolve(basePath, 'packages/webcomponent/src/lib.js'),
'@opentiny/tiny-engine-i18n-host': path.resolve(basePath, 'packages/i18n/src/lib.js'),
Expand Down
34 changes: 24 additions & 10 deletions packages/canvas/container/src/CanvasContainer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,16 @@ export default {
}
}

const isCanvasEvent = (event, handler) => {
const canvasFlag = canvasApi.getRenderer().getCanvasFlag()

if (!canvasFlag) {
return
}

return handler(event)
}

const canvasReady = ({ detail }) => {
if (iframe.value) {
// 设置monitor报错埋点
Expand All @@ -131,15 +141,17 @@ export default {

// 以下是内部iframe监听的事件
win.addEventListener('mousedown', (event) => {
// html元素使用scroll和mouseup事件处理
if (event.target === doc.documentElement) {
isScrolling = false
return
}

insertPosition.value = false
setCurrentNode(event)
target.value = event.target
isCanvasEvent(event, (e) => {
// html元素使用scroll和mouseup事件处理
if (e.target === doc.documentElement) {
isScrolling = false
return
}

insertPosition.value = false
setCurrentNode(e)
target.value = e.target
})
})

win.addEventListener('scroll', () => {
Expand Down Expand Up @@ -168,7 +180,9 @@ export default {
})

win.addEventListener('mousemove', (ev) => {
dragMove(ev, true)
isCanvasEvent(ev, (e) => {
dragMove(e, true)
})
})

// 阻止浏览器默认的右键菜单功能
Expand Down
4 changes: 2 additions & 2 deletions packages/canvas/container/src/container.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
} from '../../common'
import { useCanvas, useLayout, useResource, useTranslate, useMaterial } from '@opentiny/tiny-engine-meta-register'
import { isVsCodeEnv } from '@opentiny/tiny-engine-common/js/environments'
import Builtin from '../../render/src/builtin/builtin.json' //TODO 画布内外应该分开
import { BuiltinBundle } from '@opentiny/tiny-engine-renderer'

export const POSITION = Object.freeze({
TOP: 'top',
Expand Down Expand Up @@ -895,7 +895,7 @@ export const canvasApi = {
getGlobalState,
getDocument,
canvasDispatch,
Builtin,
BuiltinBundle,
setDataSourceMap: (...args) => {
return canvasState.renderer.setDataSourceMap(...args)
},
Expand Down
11 changes: 6 additions & 5 deletions packages/canvas/render/src/lowcode.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@

import { getCurrentInstance, nextTick, provide, inject } from 'vue'
import { I18nInjectionKey } from 'vue-i18n'
import { api } from './RenderMain'
import { collectionMethodsMap, generateFn, globalNotify } from './render'
import { api } from '@opentiny/tiny-engine-renderer'

const { getCollectionMethodsMap, generateFn, globalNotify, getUtils, getDataSourceMap } = api

export const lowcodeWrap = (props, context) => {
const global = {}
Expand Down Expand Up @@ -49,10 +50,10 @@ export const lowcodeWrap = (props, context) => {
location: { get: location },
history: { get: history },
utils: {
get: api.getUtils
get: getUtils
},
bridge: { get: () => ({}) },
dataSourceMap: { get: api.getDataSourceMap },
dataSourceMap: { get: getDataSourceMap },
$: { get: () => ref }
})

Expand All @@ -61,7 +62,7 @@ export const lowcodeWrap = (props, context) => {
const fnName = fn.name
if (fn.toString().includes('return this')) {
return () => global
} else if (fnName && collectionMethodsMap[fnName.slice(0, -1)]) {
} else if (fnName && getCollectionMethodsMap()[fnName.slice(0, -1)]) {
// 这里区块打包的时候会在方法名称后面多加一个字符串,所以此处需要截取下函数名称
fn.realName = fnName.slice(0, -1)
return generateFn(fn)
Expand Down
2 changes: 1 addition & 1 deletion packages/canvas/render/src/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import { createApp } from 'vue'
import { addScript, addStyle, dynamicImportComponents, updateDependencies } from '../../common'
import TinyI18nHost, { I18nInjectionKey } from '@opentiny/tiny-engine-common/js/i18n'
import Main, { api } from './RenderMain'
import Main, { api } from '@opentiny/tiny-engine-renderer'
yy-wow marked this conversation as resolved.
Show resolved Hide resolved
import lowcode from './lowcode'
import { supportUmdBlock } from './supportUmdBlock'

Expand Down
6 changes: 5 additions & 1 deletion packages/canvas/render/src/supportUmdBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import * as TinyVueIcon from '@opentiny/vue-icon'
import TinyVue from '@opentiny/vue'
import TinyI18nHost from '@opentiny/tiny-engine-common/js/i18n'
import { camelize, capitalize } from '@vue/shared'
import { blockSlotDataMap, getComponent } from './render'
import { api } from '@opentiny/tiny-engine-renderer'

const { getBlockSlotDataMap, getComponent } = api

// 和 @opentiny/tiny-engine-block-build 打包umd方式相适配
export function supportUmdBlock() {
Expand Down Expand Up @@ -33,6 +35,8 @@ export function supportUmdBlock() {

// 如果是作用域插槽,则获取作用域插槽传递过来的参数
if (slotData) {
const blockSlotDataMap = getBlockSlotDataMap()

yy-wow marked this conversation as resolved.
Show resolved Hide resolved
if (blockSlotDataMap[blockName]) {
blockSlotDataMap[blockName][slotName] = slotData
} else {
Expand Down
4 changes: 2 additions & 2 deletions packages/plugins/materials/src/composable/useMaterial.js
Original file line number Diff line number Diff line change
Expand Up @@ -399,9 +399,9 @@ const updateCanvasDependencies = (blocks) => {
}

const initBuiltinMaterial = () => {
const { Builtin } = useCanvas().canvasApi.value
const { BuiltinBundle } = useCanvas().canvasApi.value
// 添加画布物料
addMaterials(Builtin.data.materials)
addMaterials(BuiltinBundle.data.materials)
// 添加builtin-component NPM包物料
addMaterials(BuiltinComponentMaterials)
}
Expand Down
42 changes: 42 additions & 0 deletions packages/renderer/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* Copyright (c) 2023 - present TinyEngine Authors.
* Copyright (c) 2023 - present Huawei Cloud Computing Technologies Co., Ltd.
*
* Use of this source code is governed by an MIT-style license.
*
* THE OPEN SOURCE SOFTWARE IN THIS PRODUCT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL,
* BUT WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR
* A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS.
*
*/

module.exports = {
env: {
browser: true,
es2015: true,
node: true,
jest: true
},
extends: ['eslint:recommended', 'plugin:vue/vue3-essential'],
parser: 'vue-eslint-parser',
parserOptions: {
parser: '@babel/eslint-parser',
ecmaVersion: 'latest',
sourceType: 'module',
requireConfigFile: false,
babelOptions: {
parserOpts: {
plugins: ['jsx']
}
}
},
plugins: ['vue'],
rules: {
'no-console': 'error',
'no-debugger': 'error',
'space-before-function-paren': 'off',
'vue/multi-word-component-names': 'off',
'no-use-before-define': 'error',
'no-unused-vars': ['error', { ignoreRestSiblings: true, varsIgnorePattern: '^_', argsIgnorePattern: '^_' }]
}
}
24 changes: 24 additions & 0 deletions packages/renderer/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
29 changes: 29 additions & 0 deletions packages/renderer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# tiny-engine-renderer

## Introduction

A Vue3 renderer for tiny-engine.

## Usage

```javascript
// xxx.vue
import { h } from 'vue'
import Main, { api } from '@opentiny/tiny-engine-renderer'

export default {
render() {
// utils
api.setUtils(utils)
// globalState
api.setGlobalState(globalState)
// dataSource
api.setDataSourceMap(dataSourceList)
// schema
api.setSchema(schema)

return h(Main)
}
}
```

28 changes: 28 additions & 0 deletions packages/renderer/README.zh-CN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# tiny-engine-renderer

## 简介

基于 Vue 3 的低代码渲染引擎。

## 用法

```javascript
// xxx.vue
import { h } from 'vue'
import Main, { api } from '@opentiny/tiny-engine-renderer'

export default {
render() {
// 工具类
api.setUtils(utils)
// 全局状态
api.setGlobalState(globalState)
// 数据源
api.setDataSourceMap(dataSourceList)
// 页面schema
api.setSchema(schema)

return h(Main)
}
}
```
yy-wow marked this conversation as resolved.
Show resolved Hide resolved
61 changes: 61 additions & 0 deletions packages/renderer/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"name": "@opentiny/tiny-engine-renderer",
"version": "2.0.0-alpha.4",
"publishConfig": {
"access": "public"
},
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview"
},
"main": "dist/index.js",
"module": "dist/index.js",
"files": [
"dist"
],
"exports": {
".": {
"import": "./dist/index.js"
}
},
"repository": {
"type": "git",
"url": "https://github.com/opentiny/tiny-engine",
"directory": "packages/renderer"
},
"bugs": {
"url": "https://github.com/opentiny/tiny-engine/issues"
},
"author": "OpenTiny Team",
"license": "MIT",
"homepage": "https://opentiny.design/tiny-engine",
"type": "module",
"dependencies": {
"@babel/core": "7.18.13",
"@opentiny/tiny-engine-builtin-component": "workspace:*",
"@opentiny/tiny-engine-common": "workspace:*",
"@opentiny/tiny-engine-http": "workspace:*",
"@opentiny/tiny-engine-i18n-host": "workspace:*",
"@opentiny/tiny-engine-meta-register": "workspace:*",
"@opentiny/tiny-engine-utils": "workspace:*",
"@opentiny/tiny-engine-webcomponent-core": "workspace:*",
"@vue/babel-plugin-jsx": "1.1.1",
"@vue/shared": "^3.3.4",
"@vueuse/core": "^9.6.0"
},
yy-wow marked this conversation as resolved.
Show resolved Hide resolved
"devDependencies": {
"@opentiny/tiny-engine-vite-plugin-meta-comments": "workspace:*",
"@vitejs/plugin-vue": "^5.1.2",
"@vitejs/plugin-vue-jsx": "^4.0.1",
"rollup-plugin-polyfill-node": "^0.13.0",
"vite": "^5.4.2"
},
"peerDependencies": {
"@opentiny/vue": "^3.14.0",
"@opentiny/vue-icon": "^3.14.0",
"@opentiny/vue-renderless": "^3.14.0",
"vue": "^3.4.15",
"vue-i18n": "^9.9.0"
}
}
14 changes: 14 additions & 0 deletions packages/renderer/src/CanvasEmpty.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<template>
<p class="empty-text">从左侧面板拖入组件,以构建页面</p>
</template>

<style lang="less" scoped>
.empty-text {
position: absolute;
top: 250px;
left: 50%;
transform: translate(-50%);
color: #808080;
font-size: 12px;
}
</style>
Loading
Loading