-
Notifications
You must be signed in to change notification settings - Fork 343
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(metaComponent): add capability of add custom metaComponents
- Loading branch information
1 parent
439992b
commit c7efc41
Showing
20 changed files
with
429 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<template> | ||
<span>我是自定义的 meta input</span> | ||
<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: 'MetaInput', | ||
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { addMetaComponents } from '@opentiny/tiny-engine-entry' | ||
import MetaInput from './MetaInput.vue' | ||
|
||
export default () => { | ||
addMetaComponents([ | ||
{ | ||
name: 'meta-input-custom', | ||
component: MetaInput | ||
} | ||
]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { MetaComponents } from '@opentiny/tiny-engine-common' | ||
import { addMetaComponents } from '@opentiny/tiny-engine-entry' | ||
// 后续默认 metaComponent 都由这个package 提供,抽空 tiny-engine-common 中的 metacomponent | ||
import * as defaultMetaComponents from '@opentiny/tiny-engine-meta-components' | ||
|
||
/** | ||
* 注册TinyEngine默认的 metaComponents | ||
*/ | ||
export const registerMetaComponents = () => { | ||
const { MetaInput, MetaSelect, ...otherComponents } = MetaComponents | ||
|
||
addMetaComponents(Object.entries(otherComponents).map(([name, component]) => ({ name, component }))) | ||
addMetaComponents(Object.values(defaultMetaComponents)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# entry(暂定) | ||
|
||
|
||
## metaComponents | ||
|
||
往设计器添加 metaComponent,满足右侧属性面板属性设置器自定义组件的需求 | ||
|
||
### addMetaComponents | ||
|
||
```javascript | ||
addMetaComponents([ | ||
{ | ||
name: 'MetaInput', | ||
component: MetaInput | ||
}, | ||
{ | ||
name: 'MetaSelect', | ||
component: MetaSelect | ||
} | ||
]) | ||
``` | ||
|
||
### getMetaComponent | ||
|
||
```javascript | ||
getMetaComponent('MetaInput') | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const metaComponentsMap = new Map() | ||
|
||
export const addMetaComponents = (components) => { | ||
if (Array.isArray(components)) { | ||
for (const { name, component } of components) { | ||
metaComponentsMap.set(name, component) | ||
} | ||
} | ||
} | ||
|
||
export const getMetaComponent = (name) => { | ||
return metaComponentsMap.get(name) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# TinyEngine 的 meta component 组件 | ||
|
||
右侧属性面板配置物料属性的组件。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"name": "@opentiny/tiny-engine-meta-components", | ||
"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:*" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { default as MetaInput } from './meta-input' | ||
export { default as MetaSelect } from './meta-select' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: 'MetaInput', | ||
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import MetaInput from './MetaInput.vue' | ||
|
||
export default { | ||
name: 'MetaInput', | ||
component: MetaInput | ||
} |
Oops, something went wrong.