Skip to content

Commit 73d6d1c

Browse files
added html attrs to code export
1 parent 2f14d2b commit 73d6d1c

File tree

4 files changed

+73
-74
lines changed

4 files changed

+73
-74
lines changed

src/components/CodePreview.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class CodePreview extends Component<Props> {
2020
{/* <SortChildren /> */}
2121
<div
2222
style={{
23-
width: '500px',
23+
width: '800px',
2424
height: '290px',
2525
direction: 'rtl',
2626
paddingLeft: '20px',

src/components/HTMLComponentPanel.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class HTMLComponentPanel extends Component {
4040
disableRipple
4141
classes={{ root: classes.tabRoot, selected: classes.tabSelected }}
4242
label="Add HTML elements"
43+
style={{ cursor: 'default' }}
4344
/>
4445
<Grid container spacing={8} align="center">
4546
<Grid item xs={4}>

src/components/HtmlAttr.jsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ const styles = theme => ({
1919
},
2020
cssLabel: {
2121
color: 'white',
22-
'&$cssFocused': {
23-
color: 'green',
24-
},
22+
},
23+
cssFocused: {
24+
color: 'green',
2525
},
2626
input: {
2727
color: '#fff',
@@ -68,7 +68,7 @@ class HtmlAttr extends Component {
6868

6969
const HtmlForm = HTMLelements[focusChildType].attributes.map((attr, i) => (
7070
<Grid container spacing={0} key={i} style={{ marginTop: '10px', marginRight: '20px' }}>
71-
<Grid item xs={1.5}>
71+
<Grid item xs={2}>
7272
<TextField
7373
InputLabelProps={{
7474
classes: {

src/utils/componentRender.util.ts

Lines changed: 67 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,84 @@
1-
import { ComponentInt, ChildInt, ChildrenInt, PropInt } from "./Interfaces";
2-
import cloneDeep from "./cloneDeep";
1+
import {
2+
ComponentInt, ComponentsInt, ChildInt, ChildrenInt, PropInt,
3+
} from './Interfaces';
4+
import cloneDeep from './cloneDeep';
35

4-
const componentRender = (component: ComponentInt, data: any) => {
6+
const componentRender = (component: ComponentInt, components: ComponentsInt) => {
57
const {
68
// stateful,
79
// id,
810
// position,
911
childrenArray,
1012
title,
11-
props
13+
props,
1214
}: {
13-
childrenArray: ChildrenInt;
14-
title: string;
15-
props: PropInt[];
15+
childrenArray: ChildrenInt;
16+
title: string;
17+
props: PropInt[];
1618
} = component;
1719

1820
function typeSwitcher(type: string) {
1921
switch (type) {
20-
case "string":
21-
return "string";
22-
case "number":
23-
return "number";
24-
case "object":
25-
return "object";
26-
case "array":
27-
return "any[]";
28-
case "bool":
29-
return "boolean";
30-
case "function":
31-
return "() => any";
22+
case 'string':
23+
return 'string';
24+
case 'number':
25+
return 'number';
26+
case 'object':
27+
return 'object';
28+
case 'array':
29+
return 'any[]';
30+
case 'bool':
31+
return 'boolean';
32+
case 'function':
33+
return '() => any';
3234
// case 'symbol':
3335
// return 'string';
34-
case "node":
35-
return "string";
36-
case "element":
37-
return "string";
38-
case "tuple":
39-
return "[any]";
40-
case "enum":
41-
return "{}";
42-
case "any":
43-
return "any";
36+
case 'node':
37+
return 'string';
38+
case 'element':
39+
return 'string';
40+
case 'tuple':
41+
return '[any]';
42+
case 'enum':
43+
return '{}';
44+
case 'any':
45+
return 'any';
4446
default:
45-
return "any";
47+
return 'any';
4648
}
4749
}
4850

4951
function propDrillTextGenerator(child: ChildInt) {
50-
if (child.childType === "COMP") {
51-
return data
52+
if (child.childType === 'COMP') {
53+
return components
5254
.find((c: any) => c.id === child.childComponentId)
5355
.props.map((prop: PropInt) => `${prop.key}={${prop.value}}`)
54-
.join(" ");
56+
.join(' ');
5557
}
56-
return "";
58+
if (child.childType === 'HTML') {
59+
const keys: string[] = Object.keys(child.HTMLInfo);
60+
return keys.map(key => `${key}={${child.HTMLInfo[key]}}`).join(' ');
61+
}
62+
return '';
5763
}
5864

5965
function componentNameGenerator(child: ChildInt) {
60-
if (child.childType === "HTML") {
66+
if (child.childType === 'HTML') {
6167
switch (child.componentName) {
62-
case "Image":
63-
return "img";
64-
case "Form":
65-
return "form";
66-
case "Button":
67-
return "button";
68-
case "Link":
68+
case 'Image':
69+
return 'img';
70+
case 'Form':
71+
return 'form';
72+
case 'Button':
73+
return 'button';
74+
case 'Link':
6975
return 'a href=""';
70-
case "List":
71-
return "ul";
72-
case "Paragraph":
73-
return "p";
76+
case 'List':
77+
return 'ul';
78+
case 'Paragraph':
79+
return 'p';
7480
default:
75-
return "div";
81+
return 'div';
7682
}
7783
} else {
7884
return child.componentName;
@@ -120,38 +126,30 @@ const componentRender = (component: ComponentInt, data: any) => {
120126
return `
121127
import React from 'react';
122128
${childrenArray
123-
.filter(child => child.childType !== "HTML")
124-
.map(
125-
child =>
126-
`import ${child.componentName} from './${child.componentName}.tsx'`
127-
)
128-
.reduce((acc: Array<string>, child) => {
129-
if (!acc.includes(child)) {
130-
acc.push(child);
131-
return acc;
132-
}
129+
.filter(child => child.childType !== 'HTML')
130+
.map(child => `import ${child.componentName} from './${child.componentName}.tsx'`)
131+
.reduce((acc: Array<string>, child) => {
132+
if (!acc.includes(child)) {
133+
acc.push(child);
133134
return acc;
134-
}, [])
135-
.join("\n")}
135+
}
136+
return acc;
137+
}, [])
138+
.join('\n')}
136139
137140
type Props = {
138-
${props.map(prop => `${prop.key}: ${typeSwitcher(prop.type)}`).join("\n")}
141+
${props.map(prop => `${prop.key}: ${typeSwitcher(prop.type)}`).join('\n')}
139142
}
140143
141144
const ${title} = (props: Props) => {
142-
const {${props.map(el => el.key).join(",\n")}} = props
145+
const {${props.map(el => el.key).join(',\n')}} = props
143146
144147
return (
145148
<div>
146149
${cloneDeep(childrenArray)
147-
.sort((a, b) => a.childSort - b.childSort)
148-
.map(
149-
child =>
150-
`<${componentNameGenerator(child)} ${propDrillTextGenerator(
151-
child
152-
)}/>`
153-
)
154-
.join("\n")}
150+
.sort((a, b) => a.childSort - b.childSort)
151+
.map(child => `<${componentNameGenerator(child)} ${propDrillTextGenerator(child)}/>`)
152+
.join('\n')}
155153
</div>
156154
);
157155
}

0 commit comments

Comments
 (0)