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

feat: add capability of add custom metaComponents #528

Merged
merged 8 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
3 changes: 2 additions & 1 deletion designer-demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"vue": "^3.4.21",
"@opentiny/tiny-engine": "workspace:^",
"@opentiny/tiny-engine-entry": "workspace:^",
"@opentiny/tiny-engine-canvas": "workspace:^"
"@opentiny/tiny-engine-canvas": "workspace:^",
"@opentiny/tiny-engine-configurator": "workspace:*"
},
"devDependencies": {
"@vitejs/plugin-vue": "^5.0.4",
Expand Down
63 changes: 63 additions & 0 deletions designer-demo/src/MyInputConfigurator.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<template>
<span>我是自定义的 meta input</span>
wenmine marked this conversation as resolved.
Show resolved Hide resolved
<tiny-input v-model="value" :type="type" :placeholder="placeholder" :rows="rows" @update:modelValue="change">
</tiny-input>
</template>

<script>
import { ref } from 'vue'
import { Input } from '@opentiny/vue'

export default {
name: 'MyInputConfigurator',
components: {
TinyInput: Input
},
props: {
modelValue: {
type: String
},
type: {
type: String
},
placeholder: {
type: String
},
suffixIcons: {
type: Array,
default: () => []
},
dataType: {
type: String
},
rows: {
type: Number,
default: 10
}
},
emits: ['update:modelValue'],
setup(props, { emit }) {
const value = ref(props.modelValue)

const change = (val) => {
emit('update:modelValue', props.dataType === 'Array' ? val.split(',') : val)
}

return {
value,
change
}
}
}
</script>

<style lang="less" scoped>
.tiny-svg-size {
margin-left: 10px;
font-size: 16px;
&:hover {
cursor: pointer;
color: var(--ti-lowcode-dialog-font-color);
}
}
</style>
11 changes: 11 additions & 0 deletions designer-demo/src/configurators.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { InputConfigurator, SelectConfigurator } from '@opentiny/tiny-engine-configurator'
import MyInputConfigurator from './MyInputConfigurator.vue'

export const configurators = [
{
name: 'MyInputConfigurator',
component: MyInputConfigurator
},
InputConfigurator,
SelectConfigurator
]
3 changes: 2 additions & 1 deletion designer-demo/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@
// 导入@opentiny/tiny-engine时,内部的依赖包也会逐个导入,可能会执行useComplie,此时需要templateHashMap。所以需要先执行一次defineEntry
import { registry } from './defineEntry.js'
import { init } from '@opentiny/tiny-engine'
import { configurators } from './configurators.js'

init({ registry })
init({ registry, configurators })
10 changes: 5 additions & 5 deletions packages/builtinComponent/src/meta/CanvasCol.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"cols": 12,
"rules": [],
"widget": {
"component": "MetaInput",
"component": "InputConfigurator",
"props": {}
}
},
Expand All @@ -72,7 +72,7 @@
"cols": 12,
"rules": [],
"widget": {
"component": "MetaInput",
"component": "InputConfigurator",
"props": {}
}
},
Expand All @@ -88,7 +88,7 @@
"cols": 12,
"rules": [],
"widget": {
"component": "MetaInput",
"component": "InputConfigurator",
"props": {}
}
},
Expand All @@ -104,7 +104,7 @@
"cols": 12,
"rules": [],
"widget": {
"component": "MetaSelect",
"component": "SelectConfigurator",
"props": {
"options": [
{ "value": "flex-start", "label": "头部对齐" },
Expand All @@ -128,7 +128,7 @@
"cols": 12,
"rules": [],
"widget": {
"component": "MetaSelect",
"component": "SelectConfigurator",
"props": {
"options": [
{ "value": "flex-start", "label": "头部对齐" },
Expand Down
10 changes: 5 additions & 5 deletions packages/builtinComponent/src/meta/CanvasRow.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"cols": 12,
"rules": [],
"widget": {
"component": "MetaInput",
"component": "InputConfigurator",
"props": {}
}
},
Expand All @@ -50,7 +50,7 @@
"cols": 12,
"rules": [],
"widget": {
"component": "MetaInput",
"component": "InputConfigurator",
"props": {}
}
},
Expand All @@ -66,7 +66,7 @@
"cols": 12,
"rules": [],
"widget": {
"component": "MetaInput",
"component": "InputConfigurator",
"props": {}
}
},
Expand All @@ -82,7 +82,7 @@
"cols": 12,
"rules": [],
"widget": {
"component": "MetaSelect",
"component": "SelectConfigurator",
"props": {
"options": [
{ "value": "flex-start", "label": "头部对齐" },
Expand All @@ -106,7 +106,7 @@
"cols": 12,
"rules": [],
"widget": {
"component": "MetaSelect",
"component": "SelectConfigurator",
"props": {
"options": [
{ "value": "flex-start", "label": "头部对齐" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"cols": 12,
"rules": [],
"widget": {
"component": "MetaInput",
"component": "InputConfigurator",
"props": {}
}
}
Expand Down
6 changes: 3 additions & 3 deletions packages/canvas/src/components/builtin/builtin.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
},
"cols": 12,
"widget": {
"component": "MetaInput",
"component": "InputConfigurator",
"props": {}
}
},
Expand Down Expand Up @@ -256,7 +256,7 @@
"cols": 12,
"rules": [],
"widget": {
"component": "MetaInput",
"component": "InputConfigurator",
"props": {
"type": "textarea",
"autosize": true
Expand Down Expand Up @@ -399,7 +399,7 @@
"cols": 12,
"rules": [],
"widget": {
"component": "MetaInput",
"component": "InputConfigurator",
"props": {}
}
}
Expand Down
14 changes: 8 additions & 6 deletions packages/common/component/ConfigItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ import MultiTypeSelector from './MultiTypeSelector.vue'
import { useHistory, useProperties, useResource, useLayout, useCanvas } from '@opentiny/tiny-engine-controller'
import { generateFunction } from '@opentiny/tiny-engine-controller/utils'
import { SCHEMA_DATA_TYPE, PAGE_STATUS, TYPES } from '@opentiny/tiny-engine-controller/js/constants'
import { getMetaComponent } from '@opentiny/tiny-engine-entry'

const hasRule = (required, rules) => {
if (required) {
Expand Down Expand Up @@ -201,13 +202,14 @@ export default {
(props.property?.label?.text?.[locale.value] ?? props.property?.label?.text)
)
const isLinked = computed(() => Boolean(props.property.linked))
const component = computed(() =>
multiType.value
const component = computed(() => {
// TODO: 需要弄清楚 props.metaComponents[widget.value.component] 是什么场景
return multiType.value
? MultiTypeSelector
: props.metaComponents[widget.value.component] ||
MetaComponents[widget.value.component] ||
MetaComponents['MetaInput']
)
: getMetaComponent(widget.value.component) ||
props.metaComponents[widget.value.component] ||
zzcr marked this conversation as resolved.
Show resolved Hide resolved
getMetaComponent('MetaInput')
wenmine marked this conversation as resolved.
Show resolved Hide resolved
})
const bindValue = computed(() => {
let value = props.property?.widget?.props?.modelValue

Expand Down
3 changes: 1 addition & 2 deletions packages/common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,7 @@ export const MetaComponents = {
MetaIpSection,
MetaRelatedEditor,
MetaRelatedColumns,
MetaTableColumns,
SearchEmpty
MetaTableColumns
}

export {
Expand Down
3 changes: 3 additions & 0 deletions packages/configurator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# TinyEngine 的 meta component 组件
wenmine marked this conversation as resolved.
Show resolved Hide resolved

右侧属性面板配置物料属性的组件。
29 changes: 29 additions & 0 deletions packages/configurator/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "@opentiny/tiny-engine-configurator",
"version": "1.0.0",
"description": "",
"main": "dist/index.js",
"module": "dist/index.js",
"type": "module",
"scripts": {
"build": "vite build",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "OpenTiny Team",
"license": "MIT",
"bugs": {
"url": "https://github.com/opentiny/tiny-engine/issues"
},
"homepage": "https://opentiny.design/tiny-engine",
"devDependencies": {
"vite": "^4.3.7"
},
"peerDependencies": {
"@opentiny/vue": "^3.14.0",
"vue": "^3.4.15"
},
"dependencies": {
"@opentiny/tiny-engine-controller": "workspace:*"
}
}
2 changes: 2 additions & 0 deletions packages/configurator/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { default as InputConfigurator } from './input-configurator'
export { default as SelectConfigurator } from './select-configurator'
72 changes: 72 additions & 0 deletions packages/configurator/src/input-configurator/InputConfigurator.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<template>
<tiny-input v-model="value" :type="type" :placeholder="placeholder" :rows="rows" @update:modelValue="change">
<template #suffix>
<div v-for="item in suffixIcons" :key="item.icon">
<svg-icon v-if="item.icon" :name="item.icon" class="tiny-svg-size" @click="item.onClick.action"></svg-icon>
</div>
</template>
</tiny-input>
</template>

<script>
import { ref, watchEffect } from 'vue'
import { Input } from '@opentiny/vue'
import { useProperties } from '@opentiny/tiny-engine-controller'

export default {
name: 'InputConfigurator',
components: {
TinyInput: Input
},
props: {
modelValue: {
type: String
},
type: {
type: String
},
placeholder: {
type: String
},
suffixIcons: {
type: Array,
default: () => []
},
dataType: {
type: String
},
rows: {
type: Number,
default: 10
}
},
emits: ['update:modelValue'],
setup(props, { emit }) {
const value = ref(props.modelValue)

const change = (val) => {
emit('update:modelValue', props.dataType === 'Array' ? val.split(',') : val)
}

watchEffect(() => {
value.value = useProperties().translateProp(props.modelValue)
})

return {
value,
change
}
}
}
</script>

<style lang="less" scoped>
.tiny-svg-size {
margin-left: 10px;
font-size: 16px;
&:hover {
cursor: pointer;
color: var(--ti-lowcode-dialog-font-color);
}
}
</style>
6 changes: 6 additions & 0 deletions packages/configurator/src/input-configurator/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import InputConfigurator from './InputConfigurator.vue'

export default {
name: 'InputConfigurator',
component: InputConfigurator
}
Loading