Skip to content

Commit d3d2ea8

Browse files
committed
import component is started, not complete.
Co-authored-by: Kerolos Nesem <[email protected]>
1 parent a62148d commit d3d2ea8

File tree

5 files changed

+171
-15
lines changed

5 files changed

+171
-15
lines changed

src/components/ComponentDisplay.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ export default {
167167
activeComponentData() {
168168
// Must deep clone this so we are not directly mutating state
169169
// return this.activeComponentObj;
170+
console.log(this.activeComponentObj)
170171
return cloneDeep(this.activeComponentObj);
171172
},
172173
options() {

src/components/home_sidebar_items/ComponentTab/CreateComponent.vue

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,27 +41,23 @@ Description:
4141
@click="createComponent"
4242
:disabled="!componentNameInputValue.trim()"
4343
/>
44+
<ImportComponent v-if="activeComponent === ''" />
4445

45-
<q-btn
46-
v-if="activeComponent === ''"
47-
id="import-component-btn"
48-
color="secondary"
49-
label="Import Component"
50-
@click="click"
51-
/>
5246
</div>
5347
</template>
5448

5549
<script>
5650
import Icons from "./Icons.vue";
5751
import ParentMultiselect from "./ParentMultiselect.vue";
52+
import ImportComponent from "./ImportComponent.vue"
5853
import { mapState, mapActions } from "vuex";
5954
export default {
6055
name: "HomeSidebar",
6156
components: {
6257
Icons,
6358
ParentMultiselect,
64-
},
59+
ImportComponent
60+
},
6561
computed: {
6662
...mapState([
6763
"componentMap",
@@ -88,10 +84,9 @@ export default {
8884
"addNestedHTML",
8985
"addNestedNoActive",
9086
"editComponentName",
87+
"openProject",
9188
]),
92-
click() {
93-
console.log("click");
94-
},
89+
9590
createComponent() {
9691
if (!this.componentNameInputValue.replace(/[^a-z0-9-_.]/gi, "")) {
9792
event.preventDefault();
@@ -116,6 +111,7 @@ export default {
116111
parent: {},
117112
isActive: false,
118113
};
114+
console.log(component.htmlList)
119115
if (!this.componentMap[component.componentName]) {
120116
this.registerComponent(component);
121117
this.setActiveComponent(component.componentName);
Lines changed: 156 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,159 @@
1+
<template>
2+
<q-btn
3+
id="import-component-btn"
4+
color="secondary"
5+
label="Import Component"
6+
@click="importComponent"
7+
/>
8+
</template>
9+
110
<script>
2-
import { defineComponent } from "@vue/composition-api";
11+
export default {
12+
methods: {
13+
importComponent() {
14+
ipcRenderer
15+
.invoke("openProject", {
16+
properties: ["openProject"],
17+
filters: [
18+
{
19+
name: "Vue Files",
20+
extensions: ["vue"],
21+
},
22+
],
23+
})
24+
.then((res) => this.openVueFile(res.filePaths))
25+
.catch((err) => console.log(err));
26+
},
27+
28+
openVueFile(data) {
29+
if (data === undefined) return;
30+
let vueFile = fs.readFileSync(data[0], "utf8");
31+
const importObj = {
32+
htmlList: []
33+
};
34+
35+
const htmlElementMap = { //OverVue state management only handles these HTML tags.
36+
div: ["<div>", "</div>"],
37+
button: ["<button>", "</button>"],
38+
form: ["<form>", "</form>"],
39+
img: ["<img>", ""],
40+
link: ['<a href="#"/>', ""],
41+
list: ["<li>", "</li>"],
42+
paragraph: ["<p>", "</p>"],
43+
"list-ol": ["<ol>", "</ol>"],
44+
"list-ul": ["<ul>", "</ul>"],
45+
input: ["<input />", ""],
46+
navbar: ["<nav>", "</nav>"],
47+
};
48+
49+
let htmlList = [];
50+
let htmlString = vueFile.substring(vueFile.indexOf('<template >')+10, vueFile.indexOf('</template>'));
51+
let scriptString = vueFile.substring(vueFile.indexOf(`<script>`)+8, vueFile.indexOf(`/script>`)-1)
52+
htmlParser(htmlString);
53+
createHTMLList(htmlList);
54+
55+
function htmlParser(htmlString){
56+
if (!htmlString){return}
57+
//remove new lines and tabs from HTML
58+
htmlString = htmlString.replaceAll('\n', '').replaceAll('\t', '')
59+
//find index for the first < and > in the string
60+
let openTag = htmlString.indexOf('<')
61+
let closeTag = htmlString.indexOf('>')
62+
63+
//push the substring wrapped by < and > into the helper func
64+
pushElement(htmlString.substring(openTag+1, closeTag))
65+
66+
//recursively call htmlParser on the remainder of the string
67+
return htmlParser(htmlString.substring(closeTag+1))
68+
}
69+
70+
function pushElement(substring){
71+
for (const elem in htmlElementMap){
72+
for (let i = 0; i < htmlElementMap[elem].length; i++){
73+
//if the htmlElementMap[elem][index] matches the substring, push it into the output array
74+
if (htmlElementMap[elem][i].indexOf(substring) !== -1){
75+
htmlList.push(htmlElementMap[elem][i])
76+
break; //exit, or else div will match with /div, for example.
77+
}
78+
}
79+
}
80+
}
81+
82+
function createHTMLList (htmlList){
83+
let currentOpen = null;
84+
for (let i = 0; i < htmlList.length; i++){
85+
const elemText = htmlList[i].substring(1,htmlList[i].length-1);
86+
87+
}
88+
}
89+
90+
console.log(importObj)
91+
92+
93+
}
94+
}
95+
}
96+
97+
//img, link, input do NOT need closing tags -- cannot have children either
98+
99+
100+
//for props, it's
101+
102+
//Trying to target obj property without a key
103+
//string.slice(indexof({),indexof(:))
3104

4-
export default defineComponent({
5-
setup() {},
6-
});
105+
function parsingStringToProps (str){
106+
107+
//Split the strings into an array
108+
//look for the last '{' in the string
109+
//look for the first ':' after the last '{'
110+
//save the string in between as a first prop
111+
112+
//if after ':' there's a ',' look for ':'
113+
// save the string in between as a second prop
114+
115+
//if after ':' there's a ',' invoke the second function in search for the third prop, etc..
116+
// save the string in between as third prop
117+
}
118+
/*
119+
//
120+
data () {
121+
return {
122+
123+
TestPropForImport: "PLACEHOLDER FOR VALUE",
124+
}
125+
},
126+
127+
*/
128+
129+
//for state it's
130+
/*
131+
132+
computed: {
133+
...mapState([
134+
"TestStateForImport",
135+
]),
136+
},
137+
*/
138+
139+
140+
//for actions it's
141+
/*
142+
143+
methods: {
144+
...mapActions([
145+
"TestActionForImport",
146+
]),
147+
},
148+
149+
*/
150+
151+
152+
7153
</script>
154+
155+
156+
157+
158+
159+

src/store/actions.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,12 @@ const actions = {
273273
commit(types.SET_ROUTES, payload.routes);
274274
},
275275

276+
[types.importComponent]: ({ commit }, payload) => {
277+
//import component
278+
console.log('inside import component action')
279+
console.log(payload)
280+
},
281+
276282
// Add project
277283
[types.addProject]: ({ commit }, payload) => {
278284
commit(types.ADD_PROJECT, payload);

src/store/types.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ export const deletePropsFromComponent = 'deletePropsFromComponent'
9393
export const deleteSelectedElement = 'deleteSelectedElement'
9494
export const deleteStateFromComponent = 'deleteStateFromComponent'
9595
export const editComponentName = 'editComponentName'
96+
export const importComponent = 'importComponent'
9697
export const importImage = 'importImage'
9798
export const incrementProjectId = 'incrementProjectId'
9899
export const openProject = 'openProject'

0 commit comments

Comments
 (0)