Skip to content

Commit

Permalink
feat: add shortcutProps to support shortcut themes; !#zh: 增加 shortcut…
Browse files Browse the repository at this point in the history
…Props 以支持快捷面板定制化/主题化
  • Loading branch information
ly525 committed Jun 10, 2020
1 parent cf70307 commit 1070215
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
9 changes: 7 additions & 2 deletions front-end/h5/src/components/core/editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,16 @@ export default {
* !#zh 点击插件,copy 其基础数据到组件树(中间画布)
* #!en click the plugin shortcut, create new Element with the plugin's meta data
* pluginInfo {Object}: 插件列表中的基础数据, {name}=pluginInfo
*
* shortcutItem: PluginListItem = {
name: String,
shortcutProps: {}
}
*/
clone ({ name }) {
clone (shortcutItem) {
this.elementManager({
type: 'add',
value: { name }
value: shortcutItem
})
},
/**
Expand Down
12 changes: 9 additions & 3 deletions front-end/h5/src/components/core/models/element.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ class Element {
if (typeof ele.pluginProps === 'object') {
return cloneObj({ ...ele.pluginProps, uuid: this.uuid })
}
return this.getDefaultPluginProps(ele.props || {})
return this.getDefaultPluginProps(ele.props, ele.shortcutProps)
}

// init prop of plugin
getDefaultPluginProps (props) {
const pluginProps = {
getDefaultPluginProps (props = {}, shortcutProps) {
let pluginProps = {
uuid: this.uuid
}
Object.keys(props).forEach(key => {
Expand All @@ -70,6 +70,12 @@ class Element {
const defaultValue = props[key].default
pluginProps[key] = typeof defaultValue === 'function' ? defaultValue() : defaultValue
})

pluginProps = {
...pluginProps,
...shortcutProps
}

return pluginProps
}

Expand Down
1 change: 1 addition & 0 deletions front-end/h5/src/store/modules/element.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const mutations = {
switch (type) {
case 'add':
const vm = getVM(value.name)
vm.$options.shortcutProps = value.shortcutProps
const element = new Element(vm.$options)
elements.push(element)
break
Expand Down

0 comments on commit 1070215

Please sign in to comment.