Skip to content

Commit 23b9fc3

Browse files
authored
Merge pull request #5 from oslabs-beta/exportTypescript
Export typescript
2 parents a62148d + 1c13a64 commit 23b9fc3

File tree

12 files changed

+87
-73
lines changed

12 files changed

+87
-73
lines changed

TestExport/Test.vue

Lines changed: 0 additions & 19 deletions
This file was deleted.

TestExport2/Test.vue

Lines changed: 0 additions & 19 deletions
This file was deleted.

TestExport3/Test.vue

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/components/ComponentDisplay.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ export default {
158158
"componentChildrenMultiselectValue",
159159
"imagePath",
160160
"activeComponentObj",
161+
"exportAsTypescript",
161162
]),
162163
// used in VueDraggableResizeable component
163164
activeRouteArray() {

src/components/ExportComponentMixin.vue

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ export default {
116116
else imports += "mapActions";
117117
imports += ' } from "vuex"\n';
118118
}
119+
// if Typescript toggle is on, import defineComponent
120+
if (this.exportAsTypescript === "on") {
121+
imports += 'import { defineComponent } from "vue";\n';
122+
}
119123
// add imports for children
120124
children.forEach((name) => {
121125
imports += `import ${name} from '@/components/${name}.vue';\n`;
@@ -161,15 +165,27 @@ export default {
161165
methods += " },\n";
162166
}
163167
// concat all code within script tags
164-
let output = "\n\n<script>\n";
165-
output += imports + "\nexport default {\n name: '" + componentName + "'";
168+
// if exportAsTypescript is on, out should be <script lang="ts">
169+
let output;
170+
if (this.exportAsTypescript === 'on') {
171+
output = "\n\n<script lang='ts'>\n";
172+
output += imports + "\nexport default defineComponent ({\n name: '" + componentName + "'";
173+
} else {
174+
output = "\n\n<script>\n";
175+
output += imports + "\nexport default {\n name: '" + componentName + "'";
176+
}
166177
output += ",\n components: {\n";
167178
output += childrenComponentNames + " },\n";
168179
output += data;
169180
output += computed;
170181
output += methods;
171182
// eslint-disable-next-line no-useless-escape
172-
output += "};\n<\/script>";
183+
if (this.exportAsTypescript === 'on') {
184+
output += "});\n<\/script>";
185+
186+
} else {
187+
output += "};\n<\/script>";
188+
}
173189
return output;
174190
},
175191
/**

src/components/dashboard_items/CodeSnippet.vue

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export default {
4545
},
4646
computed: {
4747
// needs access to current component aka activeComponent
48-
...mapState(["componentMap", "activeComponent", "activeComponentObj"]),
48+
...mapState(["componentMap", "activeComponent", "activeComponentObj", "exportAsTypescript"]),
4949
code: function () {
5050
let computedCode = "Your component boilerplate will be displayed here.";
5151
if (this.activeComponent) {
@@ -172,7 +172,12 @@ export default {
172172
imports += "mapState, mapActions";
173173
} else if (this.activeComponentObj.state.length) imports += "mapState";
174174
else imports += "mapActions";
175-
imports += ' } from "vuex"\n';
175+
imports += ' } from "vuex";\n';
176+
}
177+
178+
// if Typescript toggle is on, import defineComponent
179+
if (this.exportAsTypescript === "on") {
180+
imports += 'import { defineComponent } from "vue";\n';
176181
}
177182
178183
// add imports for children
@@ -223,15 +228,28 @@ export default {
223228
}
224229
225230
// concat all code within script tags
226-
let output = "\n\n<script>\n";
227-
output += imports + "\nexport default {\n name: " + componentName;
231+
// if exportAsTypescript is on, out should be <script lang="ts">
232+
let output;
233+
if (this.exportAsTypescript === 'on') {
234+
output = "\n\n<script lang='ts'>\n";
235+
output += imports + "\nexport default defineComponent ({\n name: '" + componentName + "';";
236+
} else {
237+
output = "\n\n<script>\n";
238+
output += imports + "\nexport default {\n name: '" + componentName + "';";
239+
}
228240
output += ",\n components: {\n";
229241
output += childrenComponentNames + " },\n";
230242
output += data;
231243
output += computed;
232244
output += methods;
245+
246+
if (this.exportAsTypescript === 'on') {
247+
output += "});\n<\/script>\n\n<style scoped>\n</style>"
248+
249+
} else {
250+
output += "};\n<\/script>\n\n<style scoped>\n</style>"
251+
}
233252
// eslint-disable-next-line no-useless-escape
234-
output += "};\n<\/script>\n\n<style scoped>\n</style>";
235253
// add props/data
236254
237255
// eslint-disable-next-line no-useless-escape

src/components/home_sidebar_items/ComponentTab/ComponentState.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export default {
9898
]),
9999
// Prevent Delete on changes to searchable multiselet
100100
stopDelete(e) {
101-
if (e.code === "Backspce") e.stopPropogation();
101+
if (e.code === "Backspace") e.stopPropogation();
102102
},
103103
// adds a state to the currently selected component
104104
addStateToComp() {

src/components/home_sidebar_items/ComponentTab/EditDeleteComponents.vue

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ export default {
186186
"activeComponent",
187187
"activeComponentObj",
188188
"componentMap",
189+
"exportAsTypescript",
189190
]),
190191
191192
activeRouteDisplay() {
@@ -274,6 +275,11 @@ export default {
274275
}
275276
},
276277
278+
// Delete prop
279+
deleteProp(prop) {
280+
this.$store.dispatch('deletePropsFromComponent', prop);
281+
},
282+
277283
// changes layer of active component
278284
handleLayer(e) {
279285
e.preventDefault();

src/layouts/MyLayout.vue

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ Description:
1717
></i>
1818
</q-btn>
1919
<q-toolbar-title> OverVue </q-toolbar-title>
20+
<label for="typescript" style="margin-right: 10px;">
21+
<input type="checkbox" name="typescript" id="typescript" :value="exportAsTypescript" @change="syncTypescriptFlag" />
22+
Use Typescript
23+
</label>
2024
<SlackLoginWindow />
2125
<div></div>
2226
<i
@@ -113,6 +117,7 @@ import OpenProjectComponent from "../components/file_system_interface/OpenProjec
113117
import SlackLoginWindow from "../components/slack_login/SlackLoginWindow.vue";
114118
import ComponentTab from "../components/home_sidebar_items/ComponentTab/ComponentTab.vue";
115119
import StoreTab from "../components/home_sidebar_items/StoreTab/StoreTab.vue";
120+
import { mapState } from "vuex";
116121
117122
export default {
118123
// Passed down from App.vue
@@ -133,6 +138,11 @@ export default {
133138
ComponentTab,
134139
StoreTab,
135140
},
141+
computed: {
142+
...mapState([
143+
"exportAsTypescript"
144+
]),
145+
},
136146
methods: {
137147
undo() {
138148
// this.$router.app.$children[0].undo();
@@ -142,6 +152,15 @@ export default {
142152
redo() {
143153
this.$emit("redo");
144154
},
155+
syncTypescriptFlag(e) {
156+
let checkboxValue;
157+
if (e.target.value === "off") {
158+
checkboxValue = "on"
159+
} else {
160+
checkboxValue = "off"
161+
}
162+
this.$store.commit('EXPORT_AS_TYPESCRIPT', checkboxValue);
163+
},
145164
},
146165
};
147166
</script>

src/store/mutations.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ const mutations = {
8989

9090
// *** VUEX *** //////////////////////////////////////////////
9191

92+
93+
[types.EXPORT_AS_TYPESCRIPT]: (state, payload) => {
94+
state.exportAsTypescript = payload;
95+
},
96+
9297
[types.CREATE_ACTION]: (state, payload) => {
9398
state.userActions.push(payload);
9499
state.userActions.sort();
@@ -99,7 +104,7 @@ const mutations = {
99104
},
100105

101106
[types.ADD_ACTION_TO_COMPONENT]: (state, payload) => {
102-
const active = state.activeComponentObj;
107+
const active = state.componentMap[state.activeComponent];
103108

104109
if (!active.actions) {
105110
active.actions = payload;
@@ -133,7 +138,7 @@ const mutations = {
133138
},
134139

135140
[types.ADD_PROPS_TO_COMPONENT]: (state, payload) => {
136-
const active = state.activeComponentObj;
141+
const active = state.componentMap[state.activeComponent];
137142

138143
if (!active.props) {
139144
active.props = payload;
@@ -164,7 +169,8 @@ const mutations = {
164169
},
165170

166171
[types.ADD_STATE_TO_COMPONENT]: (state, payload) => {
167-
const active = state.activeComponentObj;
172+
// const active = state.activeComponentObj;
173+
const active = state.componentMap[state.activeComponent];
168174

169175
if (!state.activeComponentObj.state) {
170176
state.activeComponentObj.state = payload;
@@ -187,7 +193,7 @@ const mutations = {
187193
},
188194

189195
[types.DELETE_ACTION_FROM_COMPONENT]: (state, payload) => {
190-
const temp = state.activeComponentObj;
196+
const temp = state.componentMap[state.activeComponent];
191197
const newArray = [];
192198
temp.actions.forEach((element) => {
193199
if (element !== payload) newArray.push(element);
@@ -198,7 +204,7 @@ const mutations = {
198204
},
199205

200206
[types.DELETE_PROPS_FROM_COMPONENT]: (state, payload) => {
201-
const temp = state.activeComponentObj;
207+
const temp = state.componentMap[state.activeComponent];
202208
const newArray = [];
203209
temp.props.forEach((element) => {
204210
if (element !== payload) newArray.push(element);
@@ -209,7 +215,7 @@ const mutations = {
209215
},
210216

211217
[types.DELETE_STATE_FROM_COMPONENT]: (state, payload) => {
212-
const temp = state.activeComponentObj;
218+
const temp = state.componentMap[state.activeComponent];
213219
const newArray = [];
214220
temp.state.forEach((element) => {
215221
if (element !== payload) newArray.push(element);

0 commit comments

Comments
 (0)