Skip to content

Commit 5d05d00

Browse files
added html attrs to code export
1 parent 4cd830c commit 5d05d00

File tree

4 files changed

+63
-64
lines changed

4 files changed

+63
-64
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} alignItems="baseline" align="stretch">
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',
@@ -66,7 +66,7 @@ class HtmlAttr extends Component {
6666

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

src/utils/componentRender.util.ts

Lines changed: 57 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
import { ComponentInt, ChildInt, ChildrenInt, PropInt } from "./Interfaces";
1+
import { ComponentInt, ComponentsInt, ChildInt, ChildrenInt, PropInt } from './Interfaces';
2+
import cloneDeep from './cloneDeep';
23

3-
const componentRender = (component: ComponentInt, data: any) => {
4+
const componentRender = (component: ComponentInt, components: ComponentsInt) => {
45
const {
56
// stateful,
67
// id,
78
// position,
89
childrenArray,
910
title,
10-
props
11+
props,
1112
}: {
1213
childrenArray: ChildrenInt;
1314
title: string;
@@ -16,62 +17,66 @@ const componentRender = (component: ComponentInt, data: any) => {
1617

1718
function typeSwitcher(type: string) {
1819
switch (type) {
19-
case "string":
20-
return "string";
21-
case "number":
22-
return "number";
23-
case "object":
24-
return "object";
25-
case "array":
26-
return "any[]";
27-
case "bool":
28-
return "boolean";
29-
case "function":
30-
return "() => any";
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';
3132
// case 'symbol':
3233
// return 'string';
33-
case "node":
34-
return "string";
35-
case "element":
36-
return "string";
37-
case "tuple":
38-
return "[any]";
39-
case "enum":
40-
return "{}";
41-
case "any":
42-
return "any";
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';
4344
default:
44-
return "any";
45+
return 'any';
4546
}
4647
}
4748

4849
function propDrillTextGenerator(child: ChildInt) {
49-
if (child.childType === "COMP") {
50-
return data
50+
if (child.childType === 'COMP') {
51+
return components
5152
.find((c: any) => c.id === child.childComponentId)
5253
.props.map((prop: PropInt) => `${prop.key}={${prop.value}}`)
53-
.join(" ");
54+
.join(' ');
5455
}
55-
return "";
56+
if (child.childType === 'HTML') {
57+
const keys: string[] = Object.keys(child.HTMLInfo);
58+
return keys.map(key => `${key}={${child.HTMLInfo[key]}}`).join(' ');
59+
}
60+
return '';
5661
}
5762

5863
function componentNameGenerator(child: ChildInt) {
59-
if (child.childType === "HTML") {
64+
if (child.childType === 'HTML') {
6065
switch (child.componentName) {
61-
case "Image":
62-
return "img";
63-
case "Form":
64-
return "form";
65-
case "Button":
66-
return "button";
67-
case "Link":
66+
case 'Image':
67+
return 'img';
68+
case 'Form':
69+
return 'form';
70+
case 'Button':
71+
return 'button';
72+
case 'Link':
6873
return 'a href=""';
69-
case "List":
70-
return "ul";
71-
case "Paragraph":
72-
return "p";
74+
case 'List':
75+
return 'ul';
76+
case 'Paragraph':
77+
return 'p';
7378
default:
74-
return "div";
79+
return 'div';
7580
}
7681
} else {
7782
return child.componentName;
@@ -119,37 +124,30 @@ const componentRender = (component: ComponentInt, data: any) => {
119124
return `
120125
import React from 'react';
121126
${childrenArray
122-
.filter(child => child.childType !== "HTML")
123-
.map(
124-
child =>
125-
`import ${child.componentName} from './${child.componentName}.tsx'`
126-
)
127+
.filter(child => child.childType !== 'HTML')
128+
.map(child => `import ${child.componentName} from './${child.componentName}.tsx'`)
127129
.reduce((acc: Array<string>, child) => {
128130
if (!acc.includes(child)) {
129131
acc.push(child);
130132
return acc;
131133
}
132134
return acc;
133135
}, [])
134-
.join("\n")}
136+
.join('\n')}
135137
136138
type Props = {
137-
${props.map(prop => `${prop.key}: ${typeSwitcher(prop.type)}`).join("\n")}
139+
${props.map(prop => `${prop.key}: ${typeSwitcher(prop.type)}`).join('\n')}
138140
}
139141
140142
const ${title} = (props: Props) => {
141-
const {${props.map(el => el.key).join(",\n")}} = props
143+
const {${props.map(el => el.key).join(',\n')}} = props
142144
143145
return (
144146
<div>
145-
${childrenArray
146-
.map(
147-
child =>
148-
`<${componentNameGenerator(child)} ${propDrillTextGenerator(
149-
child
150-
)}/>`
151-
)
152-
.join("\n")}
147+
${cloneDeep(childrenArray)
148+
.sort((a, b) => a.childSort - b.childSort)
149+
.map(child => `<${componentNameGenerator(child)} ${propDrillTextGenerator(child)}/>`)
150+
.join('\n')}
153151
</div>
154152
);
155153
}

0 commit comments

Comments
 (0)