Skip to content

Commit c44fa8c

Browse files
Merge pull request #96 from ChristianEdwardPadilla/development
html attrs added to exported code
2 parents df6151f + 73d6d1c commit c44fa8c

File tree

12 files changed

+469
-523
lines changed

12 files changed

+469
-523
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';
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} align="center">
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: 50 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,103 +1,91 @@
1-
import React, { Component, Fragment } from "react";
2-
import { connect } from "react-redux";
3-
import { withStyles } from "@material-ui/core/styles";
4-
import Grid from "@material-ui/core/Grid";
5-
import TextField from "@material-ui/core/TextField";
6-
import IconButton from "@material-ui/core/IconButton";
7-
import Typography from "@material-ui/core/Typography";
8-
import SaveIcon from "@material-ui/icons/Save";
9-
import Paper from "@material-ui/core/Paper";
10-
import Fab from "@material-ui/core/Fab";
11-
import { updateHtmlAttr } from "../actions/components.ts";
12-
import { HTMLelements, getSize } from "../utils/htmlElements.util.ts";
1+
import React, { Component, Fragment } from 'react';
2+
import { connect } from 'react-redux';
3+
import { withStyles } from '@material-ui/core/styles';
4+
import Grid from '@material-ui/core/Grid';
5+
import TextField from '@material-ui/core/TextField';
6+
import IconButton from '@material-ui/core/IconButton';
7+
import Typography from '@material-ui/core/Typography';
8+
import SaveIcon from '@material-ui/icons/Save';
9+
import Paper from '@material-ui/core/Paper';
10+
import Fab from '@material-ui/core/Fab';
11+
import { updateHtmlAttr } from '../actions/components.ts';
12+
import { HTMLelements, getSize } from '../utils/htmlElements.util.ts';
1313

1414
const styles = theme => ({
1515
root: {
16-
display: "flex",
17-
justifyContent: "center",
18-
flexWrap: "wrap"
16+
display: 'flex',
17+
justifyContent: 'center',
18+
flexWrap: 'wrap',
1919
},
2020
cssLabel: {
21-
color: "white",
22-
"&$cssFocused": {
23-
color: "green"
24-
}
21+
color: 'white',
22+
},
23+
cssFocused: {
24+
color: 'green',
2525
},
2626
input: {
27-
color: "#fff",
28-
opacity: "0.7",
29-
marginBottom: "10px"
30-
}
27+
color: '#fff',
28+
opacity: '0.7',
29+
marginBottom: '15px',
30+
},
3131
});
3232

3333
const mapDispatchToProps = dispatch => ({
34-
updateHtmlAttr: ({ attr, value }) => dispatch(updateHtmlAttr({ attr, value }))
34+
updateHtmlAttr: ({ attr, value }) => dispatch(updateHtmlAttr({ attr, value })),
3535
});
3636

3737
const mapStateToProps = store => ({
3838
focusComponent: store.workspace.focusComponent,
39-
focusChild: store.workspace.focusChild
39+
focusChild: store.workspace.focusChild,
4040
});
4141

4242
class HtmlAttr extends Component {
43-
state = HTMLelements[this.props.focusChild.htmlElement].attributes.reduce(
44-
(acc, attr) => {
45-
acc[attr] = "";
46-
return acc;
47-
},
48-
{}
49-
);
43+
state = HTMLelements[this.props.focusChild.htmlElement].attributes.reduce((acc, attr) => {
44+
acc[attr] = '';
45+
return acc;
46+
}, {});
5047

51-
handleSave = attr => {
48+
handleSave = (attr) => {
5249
console.log(attr, this.state[attr]);
5350
this.props.updateHtmlAttr({ attr, value: this.state[attr] });
5451
this.setState({
55-
[attr]: ""
52+
[attr]: '',
5653
});
5754
};
5855

59-
handleChange = event => {
56+
handleChange = (event) => {
6057
this.setState({
61-
[event.target.id]: event.target.value.trim()
58+
[event.target.id]: event.target.value.trim(),
6259
});
6360
};
6461

6562
render() {
6663
const {
67-
focusComponent,
68-
classes,
69-
deleteProp,
70-
addProp,
71-
focusChild,
72-
updateHtmlAttr
64+
focusComponent, classes, deleteProp, addProp, focusChild, updateHtmlAttr,
7365
} = this.props;
7466

7567
const focusChildType = focusChild.htmlElement;
7668

7769
const HtmlForm = HTMLelements[focusChildType].attributes.map((attr, i) => (
78-
<Grid
79-
container
80-
spacing={0}
81-
key={i}
82-
style={{ marginTop: "10px", marginRight: "20px" }}
83-
>
84-
<Grid item xs={1.5}>
70+
<Grid container spacing={0} key={i} style={{ marginTop: '10px', marginRight: '20px' }}>
71+
<Grid item xs={2}>
8572
<TextField
8673
InputLabelProps={{
8774
classes: {
8875
root: classes.cssLabel,
89-
focused: classes.cssFocused
90-
}
76+
focused: classes.cssFocused,
77+
input: classes.input,
78+
},
9179
}}
9280
InputProps={{
9381
classes: {
9482
root: classes.cssOutlinedInput,
9583
focused: classes.cssFocused,
9684
notchedOutline: classes.notchedOutline,
97-
input: classes.input
98-
}
85+
input: classes.input,
86+
},
9987
}}
100-
style={{ background: "#424242", height: "70%" }}
88+
style={{ background: '#424242', height: '70%' }}
10189
label={attr}
10290
variant="outlined"
10391
id={attr}
@@ -112,9 +100,9 @@ class HtmlAttr extends Component {
112100
color="default"
113101
aria-label="Save"
114102
style={{
115-
marginLeft: "10px",
116-
marginTop: "5px",
117-
marginBottom: "10px"
103+
marginLeft: '10px',
104+
marginTop: '5px',
105+
marginBottom: '10px',
118106
}}
119107
onClick={() => this.handleSave(attr)}
120108
>
@@ -123,22 +111,20 @@ class HtmlAttr extends Component {
123111
</Fab>
124112
</Grid>
125113
<Grid item xs={4}>
126-
<Paper className={classes.root} style={{ height: "70%" }}>
127-
<p style={{ color: "black" }}>
128-
{focusChild.HTMLInfo[attr]
129-
? focusChild.HTMLInfo[attr]
130-
: " no attribute assigned"}
114+
<Paper className={classes.root} style={{ height: '70%' }}>
115+
<p style={{ color: 'black' }}>
116+
{focusChild.HTMLInfo[attr] ? focusChild.HTMLInfo[attr] : ' no attribute assigned'}
131117
</p>
132118
</Paper>
133119
</Grid>
134120
</Grid>
135121
));
136122

137-
return <div className={"htmlattr"}>{HtmlForm}</div>;
123+
return <div className={'htmlattr'}>{HtmlForm}</div>;
138124
}
139125
}
140126

141127
export default connect(
142128
mapStateToProps,
143-
mapDispatchToProps
129+
mapDispatchToProps,
144130
)(withStyles(styles)(HtmlAttr));

src/components/KonvaStage.jsx

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ class KonvaStage extends Component {
1212
constructor(props) {
1313
super(props);
1414
this.state = {
15-
stageWidth: 1000,
16-
stageHeight: 1000,
15+
stageWidth: 1500,
16+
stageHeight: 1500,
1717
blockSnapSize: 10,
1818
grid: [],
1919
gridStroke: 1,
@@ -49,13 +49,13 @@ class KonvaStage extends Component {
4949
// here we should add listener for "container" resize
5050
// take a look here https://developers.google.com/web/updates/2016/10/resizeobserver
5151
// for simplicity I will just listen window resize
52-
window.addEventListener('resize', this.checkSize);
52+
// window.addEventListener('resize', this.checkSize);
5353
this.container.addEventListener('keydown', this.handleKeyDown);
5454
this.createGrid();
5555
}
5656

5757
componentWillUnmount() {
58-
window.removeEventListener('resize', this.checkSize);
58+
// window.removeEventListener('resize', this.checkSize);
5959
this.container.removeEventListener('keydown', this.handleKeyDown);
6060
}
6161

@@ -70,16 +70,16 @@ class KonvaStage extends Component {
7070

7171
handleKeyDown = (e) => {
7272
// backspace and delete keys are keyCode 8 and 46, respectively
73+
// this function is only used for deleting children atm, could be used for other things
7374
if (e.keyCode === 8 || e.keyCode === 46) {
74-
console.log(e);
7575
this.props.deleteChild({});
7676
}
7777
};
7878

7979
handleStageMouseDown = (e) => {
80-
// // clicked on stage - clear selection
80+
// clicked on stage - clear selection
8181
if (e.target === e.target.getStage()) {
82-
// add functionality for allowing no focusChild
82+
// TODO add functionality for allowing no focusChild
8383
console.log('user clicked on canvas:');
8484
return;
8585
}
@@ -217,17 +217,23 @@ class KonvaStage extends Component {
217217
draggable={true}
218218
blockSnapSize={this.state.blockSnapSize}
219219
imageSource={
220-
child.htmlElement == 'Image' && child.HTMLInfo.Src ? child.HTMLInfo.Src : null
220+
child.htmlElement === 'Image' && child.HTMLInfo.Src ? child.HTMLInfo.Src : null
221221
}
222222
/>
223223
))
224-
.sort(
225-
(rectA, rectB) => rectB.props.width * rectB.props.height - rectA.props.width * rectA.props.height,
226-
)
224+
.sort((rectA, rectB) => {
225+
if (rectB.props.childId === -1) {
226+
return 1;
227+
}
228+
return (
229+
rectB.props.width * rectB.props.height - rectA.props.width * rectA.props.height
230+
);
231+
})
227232
// reasoning for the sort:
228233
// Konva determines zIndex (which rect is clicked on if rects overlap) based on rendering order
229234
// as long as the smallest components are rendered last they will always be accessible over the big boys
230235
// to guarantee they are rendered last, sort the array in reverse order by size
236+
// only exception is the pseudochild, which should always be rendered first for UX, regardless of size
231237
// THIS COULD BE A BIG PERFORMANCE PROBLEM (PROBABLY WILL BE!)
232238
// TRY TO REFACTOR TO ONLY CHANGE ORDER OF RENDERING IF A BOX IS RESIZED
233239
}

0 commit comments

Comments
 (0)