@@ -41,7 +41,7 @@ Description:
41
41
@click =" createComponent"
42
42
:disabled =" !componentNameInputValue.trim()"
43
43
/>
44
- <ImportComponent v-if =" activeComponent === ''" />
44
+ <ImportComponent v-if =" activeComponent === ''" @imported = " createComponent " />
45
45
46
46
</div >
47
47
</template >
@@ -64,6 +64,8 @@ export default {
64
64
" selectedElementList" ,
65
65
" activeComponent" ,
66
66
" activeHTML" ,
67
+ " userActions" ,
68
+ " userState" ,
67
69
]),
68
70
componentNameInputValue: {
69
71
get () {
@@ -85,13 +87,32 @@ export default {
85
87
" addNestedNoActive" ,
86
88
" editComponentName" ,
87
89
" openProject" ,
90
+ " createAction" ,
91
+ " createState" ,
88
92
]),
89
93
90
- createComponent () {
91
- if (! this .componentNameInputValue .replace (/ [^ a-z0-9 -_. ] / gi , " " )) {
94
+ createComponent (importObj ) {
95
+ let imported = false ;
96
+ if (importObj .hasOwnProperty (' componentName' )){
97
+ imported = true ;
98
+ // Check if state and actions on import exist in the store. If not, add them.
99
+ for (let i = 0 ; i < importObj .actions .length ; i++ ){
100
+ if (! this .userActions .includes (importObj .actions [i])){
101
+ this .createAction (importObj .actions [i])
102
+ }
103
+ }
104
+ for (let i = 0 ; i < importObj .state .length ; i++ ){
105
+ if (! this .userState .includes (importObj .state [i])){
106
+ this .createState (importObj .state [i])
107
+ }
108
+ }
109
+ }
110
+
111
+ if (! this .componentNameInputValue .replace (/ [^ a-z0-9 -_. ] / gi , " " ) && imported === false ) {
92
112
event .preventDefault ();
93
113
return false ;
94
114
}
115
+
95
116
// boilerplate properties for each component upon creation
96
117
const component = {
97
118
componentName: this .componentNameInputValue .replace (
@@ -111,13 +132,20 @@ export default {
111
132
parent: {},
112
133
isActive: false ,
113
134
};
114
- console .log (component .htmlList )
135
+
136
+ if (imported === true ){
137
+ component .componentName = importObj .componentName ;
138
+ component .htmlList = importObj .htmlList ;
139
+ component .actions = importObj .actions ;
140
+ component .state = importObj .state ;
141
+ component .props = importObj .props ;
142
+ }
143
+
115
144
if (! this .componentMap [component .componentName ]) {
116
145
this .registerComponent (component);
117
146
this .setActiveComponent (component .componentName );
118
147
}
119
148
120
- console .log (this .$store .state );
121
149
},
122
150
},
123
151
};
0 commit comments