Skip to content

Commit a09fcce

Browse files
Merge pull request #96 from ChristianEdwardPadilla/development
html attrs added to exported code
2 parents e3c309f + 5d05d00 commit a09fcce

File tree

12 files changed

+176
-186
lines changed

12 files changed

+176
-186
lines changed

src/components/CodePreview.tsx

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import React, { Component, Fragment } from "react";
2-
import { withStyles } from "@material-ui/core/styles";
3-
import { format } from "prettier";
4-
import componentRender from "../utils/componentRender.util.ts";
5-
import { ComponentInt, ComponentsInt } from "../utils/interfaces";
6-
import SortChildren from "./SortChildren.jsx";
1+
import React, { Component, Fragment } from 'react';
2+
import { withStyles } from '@material-ui/core/styles';
3+
import { format } from 'prettier';
4+
import componentRender from '../utils/componentRender.util.ts';
5+
import { ComponentInt, ComponentsInt } from '../utils/interfaces';
6+
import SortChildren from './SortChildren.jsx';
77

88
type Props = {
99
focusComponent: ComponentInt;
@@ -17,25 +17,25 @@ class CodePreview extends Component<Props> {
1717

1818
return (
1919
<Fragment>
20-
<SortChildren />
20+
{/* <SortChildren /> */}
2121
<div
2222
style={{
23-
width: "500px",
24-
height: "290px",
25-
direction: "rtl",
26-
paddingLeft: "20px",
27-
color: "#D3D3D3",
23+
width: '800px',
24+
height: '290px',
25+
direction: 'rtl',
26+
paddingLeft: '20px',
27+
color: '#D3D3D3',
2828
fontSize: 16,
29-
overflow: "auto"
29+
overflow: 'auto',
3030
}}
3131
>
32-
<pre style={{ direction: "ltr" }}>
32+
<pre style={{ direction: 'ltr' }}>
3333
{format(componentRender(focusComponent, components), {
3434
singleQuote: true,
35-
trailingComma: "es5",
35+
trailingComma: 'es5',
3636
bracketSpacing: true,
3737
jsxBracketSameLine: true,
38-
parser: "typescript"
38+
parser: 'typescript',
3939
})}
4040
</pre>
4141
</div>

src/components/HTMLComponentPanel.jsx

Lines changed: 19 additions & 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}>
@@ -71,6 +72,9 @@ class HTMLComponentPanel extends Component {
7172
margin: 0,
7273
padding: 0,
7374
}}
75+
onClick={() => {
76+
this.handleCreateHTMLChild('Image');
77+
}}
7478
/>
7579
</div>
7680
</Grid>
@@ -96,6 +100,9 @@ class HTMLComponentPanel extends Component {
96100
color: 'white',
97101
fontSize: '80%',
98102
}}
103+
onClick={() => {
104+
this.handleCreateHTMLChild('Form');
105+
}}
99106
/>
100107
</Grid>
101108
<Grid item xs={4}>
@@ -120,6 +127,9 @@ class HTMLComponentPanel extends Component {
120127
color: 'white',
121128
fontSize: '80%',
122129
}}
130+
onClick={() => {
131+
this.handleCreateHTMLChild('Button');
132+
}}
123133
/>
124134
</Grid>
125135
<Grid item xs={4}>
@@ -144,6 +154,9 @@ class HTMLComponentPanel extends Component {
144154
color: 'white',
145155
fontSize: '80%',
146156
}}
157+
onClick={() => {
158+
this.handleCreateHTMLChild('Link');
159+
}}
147160
/>
148161
</Grid>
149162
<Grid item xs={4}>
@@ -168,6 +181,9 @@ class HTMLComponentPanel extends Component {
168181
color: 'white',
169182
fontSize: '80%',
170183
}}
184+
onClick={() => {
185+
this.handleCreateHTMLChild('List');
186+
}}
171187
/>
172188
</Grid>
173189
<Grid
@@ -203,6 +219,9 @@ class HTMLComponentPanel extends Component {
203219
padding: '0px',
204220
margin: '0px',
205221
}}
222+
onClick={() => {
223+
this.handleCreateHTMLChild('Paragraph');
224+
}}
206225
/>
207226
</Grid>
208227
</Grid>

src/components/HtmlAttr.jsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ 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',
2828
opacity: '0.7',
29-
marginBottom: '10px',
29+
marginBottom: '15px',
3030
},
3131
});
3232

@@ -66,12 +66,13 @@ 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: {
7373
root: classes.cssLabel,
7474
focused: classes.cssFocused,
75+
input: classes.input,
7576
},
7677
}}
7778
InputProps={{

src/components/KonvaStage.tsx

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ class KonvaStage extends Component {
1010
constructor(props) {
1111
super(props);
1212
this.state = {
13-
stageWidth: 1000,
14-
stageHeight: 1000,
13+
stageWidth: 1500,
14+
stageHeight: 1500,
1515
blockSnapSize: 10,
1616
grid: [],
1717
gridStroke: 1,
@@ -47,13 +47,13 @@ class KonvaStage extends Component {
4747
// here we should add listener for "container" resize
4848
// take a look here https://developers.google.com/web/updates/2016/10/resizeobserver
4949
// for simplicity I will just listen window resize
50-
window.addEventListener('resize', this.checkSize);
50+
// window.addEventListener('resize', this.checkSize);
5151
this.container.addEventListener('keydown', this.handleKeyDown);
5252
this.createGrid();
5353
}
5454

5555
componentWillUnmount() {
56-
window.removeEventListener('resize', this.checkSize);
56+
// window.removeEventListener('resize', this.checkSize);
5757
this.container.removeEventListener('keydown', this.handleKeyDown);
5858
}
5959

@@ -67,15 +67,17 @@ class KonvaStage extends Component {
6767
};
6868

6969
handleKeyDown = e => {
70-
if (e.keyCode === 46 || e.keyCode === 8) {
70+
// backspace and delete keys are keyCode 8 and 46, respectively
71+
// this function is only used for deleting children atm, could be used for other things
72+
if (e.keyCode === 8 || e.keyCode === 46) {
7173
this.props.deleteChild({});
7274
}
7375
};
7476

7577
handleStageMouseDown = e => {
76-
// // clicked on stage - clear selection
78+
// clicked on stage - clear selection
7779
if (e.target === e.target.getStage()) {
78-
// add functionality for allowing no focusChild
80+
// TODO add functionality for allowing no focusChild
7981
console.log('user clicked on canvas:');
8082
return;
8183
}
@@ -205,14 +207,20 @@ class KonvaStage extends Component {
205207
handleTransform={handleTransform}
206208
draggable={true}
207209
blockSnapSize={this.state.blockSnapSize}
208-
imageSource={child.htmlElement == 'Image' && child.HTMLInfo.Src ? child.HTMLInfo.Src : null}
210+
imageSource={child.htmlElement === 'Image' && child.HTMLInfo.Src ? child.HTMLInfo.Src : null}
209211
/>
210212
))
211-
.sort((rectA, rectB) => rectB.props.width * rectB.props.height - rectA.props.width * rectA.props.height)
213+
.sort((rectA, rectB) => {
214+
if (rectB.props.childId === -1) {
215+
return 1;
216+
}
217+
return rectB.props.width * rectB.props.height - rectA.props.width * rectA.props.height;
218+
})
212219
// reasoning for the sort:
213220
// Konva determines zIndex (which rect is clicked on if rects overlap) based on rendering order
214221
// as long as the smallest components are rendered last they will always be accessible over the big boys
215222
// to guarantee they are rendered last, sort the array in reverse order by size
223+
// only exception is the pseudochild, which should always be rendered first for UX, regardless of size
216224
// THIS COULD BE A BIG PERFORMANCE PROBLEM (PROBABLY WILL BE!)
217225
// TRY TO REFACTOR TO ONLY CHANGE ORDER OF RENDERING IF A BOX IS RESIZED
218226
}

src/components/LeftColExpansionPanel.jsx

Lines changed: 13 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import Grid from '@material-ui/core/Grid';
99
import AddIcon from '@material-ui/icons/Add';
1010
import DeleteIcon from '@material-ui/icons/Delete';
1111
import Button from '@material-ui/core/Button';
12+
import Tooltip from '@material-ui/core/Tooltip';
1213

1314
const LeftColExpansionPanel = props => {
1415
const {
@@ -46,9 +47,7 @@ const LeftColExpansionPanel = props => {
4647
<Grid item xs={9}>
4748
<div
4849
className={classes.root}
49-
style={
50-
!isFocused() ? {} : { boxShadow: "0 10px 10px rgba(0,0,0,0.22)" }
51-
}
50+
style={!isFocused() ? {} : { boxShadow: '0 10px 10px rgba(0,0,0,0.25)' }}
5251
>
5352
<Grid item xs={12} style={{ color: "red" }}>
5453
<List style={{ color: "red" }}>
@@ -78,33 +77,6 @@ const LeftColExpansionPanel = props => {
7877
<div />
7978
) : (
8079
<Fragment>
81-
<span>
82-
{directParents ? (
83-
<p
84-
style={{
85-
padding: '0px',
86-
marginTop: '0px',
87-
marginLeft: '15px',
88-
color: '#D3D3D3',
89-
fontSize: '12px',
90-
}}
91-
>
92-
Used in: {directParents}
93-
</p>
94-
) : (
95-
<p
96-
style={{
97-
padding: '0px',
98-
marginTop: '0px',
99-
marginLeft: '15px',
100-
color: '#D3D3D3',
101-
fontSize: '12px',
102-
}}
103-
>
104-
Not used
105-
</p>
106-
)}
107-
</span>
10880
<Button
10981
variant="text"
11082
size="small"
@@ -125,7 +97,7 @@ const LeftColExpansionPanel = props => {
12597
}}
12698
>
12799
<DeleteIcon style={{ color: '#D3D3D3' }} />
128-
Delete
100+
Delete Component
129101
</Button>
130102
{/* <IconButton
131103
style={{ display: "inline-block" }}
@@ -147,14 +119,16 @@ const LeftColExpansionPanel = props => {
147119
{id === 1 || isFocused() || !selectableChildren.includes(id) ? (
148120
<div />
149121
) : (
150-
<IconButton
151-
aria-label="Add"
152-
onClick={() => {
153-
addChild({ title, childType: "COMP" });
154-
}}
155-
>
156-
<AddIcon style={{ color, float: "right" }} />
157-
</IconButton>
122+
<Tooltip title="add as child" aria-label="add as child" placement="left">
123+
<IconButton
124+
aria-label="Add"
125+
onClick={() => {
126+
addChild({ title, childType: 'COMP' });
127+
}}
128+
>
129+
<AddIcon style={{ color, float: 'right' }} />
130+
</IconButton>
131+
</Tooltip>
158132
)}
159133
</Grid>
160134
</div>

src/components/MainContainerHeader.jsx

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ const styles = () => ({
4646
},
4747
});
4848

49-
const MainContainerHeader = (props) => {
49+
const MainContainerHeader = props => {
5050
const {
5151
classes,
5252
image,
@@ -63,12 +63,7 @@ const MainContainerHeader = (props) => {
6363
<div className="main-header-buttons">
6464
<Tooltip title="remove image">
6565
<div>
66-
<Button
67-
disabled={!image}
68-
color="default"
69-
className={classes.button}
70-
onClick={showImageDeleteModal}
71-
>
66+
<Button disabled={!image} color="default" className={classes.button} onClick={showImageDeleteModal}>
7267
<DeleteOutlineIcon className={classes.light} />
7368
</Button>
7469
</div>
@@ -79,25 +74,21 @@ const MainContainerHeader = (props) => {
7974
<ImageSearchIcon className={classes.light} />
8075
</Button>
8176
</div>
82-
</Tooltip>
83-
<Tooltip title={'export'}>
84-
<div>
85-
<Button
86-
color="primary"
87-
variant="text"
88-
// variant="outlined"
89-
className={classes.clearButton}
90-
disabled={totalComponents < 1}
91-
onClick={showGenerateAppModal}
92-
>
93-
<GetAppIcon
94-
className={classes.light}
95-
style={{ paddingLeft: '5px', paddingRight: '5px' }}
96-
/>
97-
Export Project
98-
</Button>
99-
</div>
100-
</Tooltip>
77+
</Tooltip>{' '}
78+
*/}
79+
<div>
80+
<Button
81+
color="primary"
82+
variant="text"
83+
// variant="outlined"
84+
className={classes.clearButton}
85+
disabled={totalComponents < 1}
86+
onClick={showGenerateAppModal}
87+
>
88+
<GetAppIcon className={classes.light} style={{ paddingLeft: '5px', paddingRight: '5px' }} />
89+
Export Project
90+
</Button>
91+
</div>
10192
</div>
10293
</div>
10394
);

src/components/Props.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const styles = theme => ({
2323
flexWrap: 'wrap',
2424
},
2525
chip: {
26-
margin: theme.spacing.unit,
26+
// margin: theme.spacing.unit,
2727
color: '#eee',
2828
backgroundColor: '#333333',
2929
},
@@ -176,10 +176,10 @@ class Props extends Component {
176176
<div className={'htmlattr'}>
177177
{' '}
178178
{Object.keys(focusComponent).length < 1 ? (
179-
<div style={{ marginTop: '20px', marginLeft: '20px' }}>Click a component to view its props.</div>
179+
<div style={{ marginTop: '20px', width: '90%' }}>Click a component to view its props.</div>
180180
) : (
181181
<Fragment>
182-
<div className="props-container">
182+
<div className="props-container" style={{ marginTop: '20px', width: '90%', height: '80%' }}>
183183
<Grid container spacing={8}>
184184
<Grid item xs={4}>
185185
<form className="props-input" onSubmit={this.handleAddProp}>

0 commit comments

Comments
 (0)