1
1
import Vue from 'vue'
2
2
import { mapState , mapActions } from 'vuex'
3
- import { getVM } from '../../../../utils/element'
3
+ import { getVM , getComponentsForPropsEditor } from '../../../../utils/element'
4
4
5
5
export default {
6
6
data : ( ) => ( {
@@ -10,12 +10,22 @@ export default {
10
10
layout : {
11
11
type : String ,
12
12
default : 'horizontal'
13
+ } ,
14
+ // 优先级更高的当前编辑元素
15
+ realEditingElement : {
16
+ type : Object ,
17
+ default : ( ) => null
13
18
}
14
19
} ,
15
20
computed : {
16
- ...mapState ( 'editor' , [ 'editingElement' , 'editingElementEditorConfig' ] ) ,
21
+ ...mapState ( 'editor' , {
22
+ stateEditingElement : state => state . editingElement
23
+ } ) ,
17
24
customEditorName ( ) {
18
25
return `${ this . editingElement . name } -custom-editor`
26
+ } ,
27
+ editingElement ( ) {
28
+ return this . realEditingElement || this . stateEditingElement
19
29
}
20
30
} ,
21
31
methods : {
@@ -42,11 +52,10 @@ export default {
42
52
* 将插件属性的 自定义增强编辑器注入 属性编辑面板中
43
53
*/
44
54
mixinEnhancedPropsEditor ( editingElement ) {
45
- if ( ! this . editingElementEditorConfig || ! this . editingElementEditorConfig . components ) return
46
- const { components } = this . editingElementEditorConfig
47
- for ( const key in components ) {
55
+ if ( ! this . componentsForPropsEditor ) return
56
+ for ( const key in this . componentsForPropsEditor ) {
48
57
if ( this . $options . components [ key ] ) return
49
- this . $options . components [ key ] = components [ key ]
58
+ this . $options . components [ key ] = this . componentsForPropsEditor [ key ]
50
59
}
51
60
} ,
52
61
/**
@@ -81,7 +90,7 @@ export default {
81
90
// editingElement.pluginProps[propKey] = e.target ? e.target.value : e
82
91
// }
83
92
change ( e ) {
84
- // TODO fixme: update plugin props in vuex with dispatch
93
+ // TODO fixme: update plugin props in vuex with dispatch
85
94
editingElement . pluginProps [ propKey ] = e . target ? e . target . value : e
86
95
}
87
96
}
@@ -140,6 +149,9 @@ export default {
140
149
return this . renderPropsEditorPanel ( h , ele )
141
150
} ,
142
151
created ( ) {
143
- window . getEditorApp . $on ( 'setEditingElement' , this . loadCustomEditorForPlugin )
152
+ window . getEditorApp . $on ( 'setEditingElement' , ( ele ) => {
153
+ this . loadCustomEditorForPlugin ( )
154
+ this . componentsForPropsEditor = getComponentsForPropsEditor ( ele . name )
155
+ } )
144
156
}
145
157
}
0 commit comments