Skip to content

Commit 5f3b025

Browse files
Tolga MizrakciTolga Mizrakci
authored andcommitted
Merge branch 'development' of https://github.com/team-reactype/ReacType into development
2 parents dda6a38 + 845aa4d commit 5f3b025

15 files changed

+531
-16985
lines changed

package-lock.json

Lines changed: 0 additions & 16635 deletions
This file was deleted.

src/actions/components.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,11 @@ export const openExpansionPanel = component => ({
213213
// type: DELETE_ALL_DATA,
214214
// });
215215

216-
export const deleteProp = ({ id, index }) => ({
217-
type: DELETE_PROP,
218-
payload: { id, index },
219-
});
216+
217+
218+
export const deleteProp = ( propId ) => (dispatch) => {
219+
; dispatch({ type: DELETE_PROP, payload: propId });
220+
};
220221

221222
export const addProp = prop => ({
222223
type: ADD_PROP,

src/components/BottomPanel.jsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@ const mapDispatchToProps = dispatch => ({
1212
});
1313

1414
const mapStateToProps = store => ({
15-
successOpen: store.workspace.successOpen,
16-
errorOpen: store.workspace.errorOpen,
17-
appDir: store.workspace.appDir,
15+
// successOpen: store.workspace.successOpen,
16+
// errorOpen: store.workspace.errorOpen,
17+
// appDir: store.workspace.appDir,
1818
});
1919

2020
class BottomPanel extends Component {
21-
state = {
22-
successOpen: false,
23-
errorOpen: false,
24-
};
21+
// state = {
22+
// successOpen: false,
23+
// errorOpen: false,
24+
// };
2525

2626
viewAppDir = () => {
2727
IPC.send('view_app_dir', this.props.appDir);

src/components/DataTable.jsx

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import React from 'react';
2+
// import PropTypes from 'prop-types';
3+
import { withStyles } from '@material-ui/core/styles';
4+
import Table from '@material-ui/core/Table';
5+
import TableBody from '@material-ui/core/TableBody';
6+
import TableCell from '@material-ui/core/TableCell';
7+
import TableHead from '@material-ui/core/TableHead';
8+
import TableRow from '@material-ui/core/TableRow';
9+
import Paper from '@material-ui/core/Paper';
10+
import Button from '@material-ui/core/Button';
11+
12+
13+
14+
const styles = theme => ({
15+
root: {
16+
width: '100%',
17+
marginTop: theme.spacing.unit * 3,
18+
overflowX: 'auto',
19+
},
20+
table: {
21+
minWidth: 700,
22+
},
23+
});
24+
25+
26+
/****************************
27+
* cannot have a row header or a key in the data called "key"
28+
* ,ust have unique id
29+
* ****************************** */
30+
31+
function dataTable(props) {
32+
const { classes , rowData, rowHeader , deletePropHandler } = props;
33+
34+
// console.log(classes)
35+
console.log(`rowHeader`)
36+
console.log(rowHeader)
37+
console.log(`rowData`)
38+
console.log(rowData)
39+
40+
const renderHeader = rowHeader.map( (col,idx) => {
41+
return <TableCell key={`head_+${idx}`}>{col}</TableCell>
42+
})
43+
44+
function renderRowCells (row) {
45+
if(!row) return;
46+
// for some reason we must put each value in a div.
47+
return (
48+
rowHeader.map( (header,idx) =>
49+
<TableCell key={'td_'+ idx}>
50+
<div>
51+
{ typeof row[header] == 'string' ? row[header] : row[header].toString() }
52+
</div>
53+
</TableCell>
54+
)
55+
)
56+
}
57+
58+
const renderRows =
59+
rowData.map((row) =>
60+
<TableRow key={`row-${row.id}`}>
61+
{renderRowCells(row)}
62+
<TableCell>
63+
<Button onClick={ ()=>deletePropHandler(row.id) } >
64+
Delete
65+
</Button>
66+
</TableCell>
67+
</TableRow>
68+
)
69+
70+
return (
71+
<Paper className={classes.root}>
72+
<Table className={classes.table}>
73+
<TableHead>
74+
<TableRow>
75+
{renderHeader}
76+
</TableRow>
77+
</TableHead>
78+
<TableBody>
79+
{renderRows}
80+
</TableBody>
81+
</Table>
82+
</Paper>
83+
);
84+
}
85+
86+
// dataTable.propTypes = {
87+
// classes: PropTypes.object.isRequired,
88+
// };
89+
90+
export default withStyles(styles)(dataTable);

src/components/GrandchildRectangle.jsx

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ class GrandchildRectangle extends Component {
77
return color;
88
}
99

10+
getPseudoChild() {
11+
return this.props.components.find(comp => comp.id === this.props.childComponentId);
12+
}
13+
1014
render() {
1115
const {
1216
x,
@@ -64,12 +68,20 @@ class GrandchildRectangle extends Component {
6468
childComponentId={grandchild.childComponentId}
6569
focusChild={focusChild}
6670
childId={childId}
67-
x={grandchild.position.x * (width / (window.innerWidth / 2))}
68-
y={grandchild.position.y * (height / window.innerHeight)}
69-
scaleX={1}
70-
scaleY={1}
71-
width={grandchild.position.width * (width / (window.innerWidth / 2))}
72-
height={grandchild.position.height * (height / window.innerHeight)}
71+
// x={grandchild.position.x * (width / window.innerWidth)}
72+
// y={grandchild.position.y * (height / window.innerHeight)}
73+
// width={grandchild.position.width * (width / window.innerWidth)}
74+
// height={grandchild.position.height * (height / window.innerHeight)}
75+
width={grandchild.position.width * (width / this.getPseudoChild().position.width)}
76+
height={grandchild.position.height * (height / this.getPseudoChild().position.height)}
77+
x={
78+
(grandchild.position.x - this.getPseudoChild().position.x)
79+
* (width / this.getPseudoChild().position.width)
80+
}
81+
y={
82+
(grandchild.position.y - this.getPseudoChild().position.y)
83+
* (height / this.getPseudoChild().position.height)
84+
}
7385
/>
7486
))}
7587
</Group>

src/components/KonvaStage.jsx

Lines changed: 36 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
1-
import React, { Component, createRef, Fragment } from "react";
1+
import React, { Component, createRef, Fragment } from 'react';
22
// import PropTypes from 'prop-types';
33
import {
4-
Stage,
5-
Layer,
6-
Line,
7-
Group,
8-
Label,
9-
Text,
10-
Rect,
11-
Transformer
12-
} from "react-konva";
13-
import Rectangle from "./Rectangle.jsx";
4+
Stage, Layer, Line, Group, Label, Text, Rect, Transformer,
5+
} from 'react-konva';
6+
import Rectangle from './Rectangle.jsx';
147

158
class KonvaStage extends Component {
169
constructor(props) {
@@ -20,7 +13,7 @@ class KonvaStage extends Component {
2013
stageHeight: 1000,
2114
blockSnapSize: 5,
2215
grid: [],
23-
gridStroke: 1
16+
gridStroke: 1,
2417
};
2518
}
2619

@@ -29,120 +22,112 @@ class KonvaStage extends Component {
2922
// here we should add listener for "container" resize
3023
// take a look here https://developers.google.com/web/updates/2016/10/resizeobserver
3124
// for simplicity I will just listen window resize
32-
window.addEventListener("resize", this.checkSize);
25+
window.addEventListener('resize', this.checkSize);
3326
this.createGrid();
3427
}
3528

3629
componentWillUnmount() {
37-
window.removeEventListener("resize", this.checkSize);
30+
window.removeEventListener('resize', this.checkSize);
3831
}
3932

4033
checkSize = () => {
4134
const width = this.container.offsetWidth;
4235
const height = this.container.offsetHeight;
4336
this.setState({
4437
stageWidth: width,
45-
stageHeight: height
38+
stageHeight: height,
4639
});
4740
};
4841

49-
handleStageMouseDown = e => {
42+
handleStageMouseDown = (e) => {
5043
// // clicked on stage - clear selection
5144
if (e.target === e.target.getStage()) {
5245
// add functionality for allowing no focusChild
53-
console.log("user clicked on canvas:");
46+
console.log('user clicked on canvas:');
5447
return;
5548
}
5649
// // clicked on transformer - do nothing
57-
const clickedOnTransformer =
58-
e.target.getParent().className === "Transformer";
50+
const clickedOnTransformer = e.target.getParent().className === 'Transformer';
5951
if (clickedOnTransformer) {
60-
console.log("user clicked on transformer");
61-
console.log("HELLOOOO", e.target.getParent().className);
52+
console.log('user clicked on transformer');
53+
console.log('HELLOOOO', e.target.getParent().className);
6254
return;
6355
}
6456

6557
// find clicked rect by its name
6658
const rectChildId = e.target.attrs.childId;
67-
console.log("user clicked on child rectangle with Id: ", rectChildId);
59+
console.log('user clicked on child rectangle with childId: ', rectChildId);
6860
this.props.changeFocusChild({ childId: rectChildId });
6961
this.props.changeComponentFocusChild({
7062
componentId: this.props.focusComponent.id,
71-
childId: rectChildId
63+
childId: rectChildId,
7264
});
7365
};
7466

7567
createGrid = () => {
76-
let output = [];
68+
const output = [];
7769
for (let i = 0; i < this.state.stageWidth / this.state.blockSnapSize; i++) {
7870
output.push(
7971
<Line
8072
points={[
8173
Math.round(i * this.state.blockSnapSize) + 0.5,
8274
0,
8375
Math.round(i * this.state.blockSnapSize) + 0.5,
84-
this.state.stageHeight
76+
this.state.stageHeight,
8577
]}
86-
stroke={"#ddd"}
78+
stroke={'#ddd'}
8779
strokeWidth={this.state.gridStroke}
88-
key={i + "vertical"}
89-
/>
80+
key={`${i}vertical`}
81+
/>,
9082
);
9183
}
92-
for (
93-
let j = 0;
94-
j < this.state.stageHeight / this.state.blockSnapSize;
95-
j++
96-
) {
84+
for (let j = 0; j < this.state.stageHeight / this.state.blockSnapSize; j++) {
9785
output.push(
9886
<Line
9987
points={[
10088
0,
10189
Math.round(j * this.state.blockSnapSize),
10290
this.state.stageWidth,
103-
Math.round(j * this.state.blockSnapSize)
91+
Math.round(j * this.state.blockSnapSize),
10492
]}
105-
stroke={"#ddd"}
93+
stroke={'#ddd'}
10694
strokeWidth={this.state.gridStroke}
107-
key={j + "horizontal"}
108-
/>
95+
key={`${j}horizontal`}
96+
/>,
10997
);
11098
}
111-
console.log("calling function to render grid");
99+
console.log('calling function to render grid');
112100
this.setState({
113-
grid: output
101+
grid: output,
114102
});
115103
};
116104

117105
render() {
118106
const {
119-
components,
120-
handleTransform,
121-
focusComponent,
122-
focusChild
107+
components, handleTransform, focusComponent, focusChild,
123108
} = this.props;
124109

125110
return (
126111
<div
127112
style={{
128-
width: "100%",
129-
height: "100%"
113+
width: '100%',
114+
height: '100%',
130115
}}
131-
ref={node => {
116+
ref={(node) => {
132117
this.container = node;
133118
}}
134119
>
135120
<Stage
136-
className={"canvasStage"}
137-
ref={node => {
121+
className={'canvasStage'}
122+
ref={(node) => {
138123
this.stage = node;
139124
}}
140125
onMouseDown={this.handleStageMouseDown}
141126
width={this.state.stageWidth}
142127
height={this.state.stageHeight}
143128
>
144129
<Layer
145-
ref={node => {
130+
ref={(node) => {
146131
this.layer = node;
147132
}}
148133
>
@@ -171,10 +156,8 @@ class KonvaStage extends Component {
171156
/>
172157
))
173158
.sort(
174-
(rectA, rectB) =>
175-
rectA.props.width * rectA.props.height <
176-
rectB.props.width * rectB.props.height
177-
)
159+
(rectA, rectB) => rectA.props.width * rectA.props.height < rectB.props.width * rectB.props.height,
160+
) // shouldnt this be subtraction instead of < ? see MDN
178161
// reasoning for the sort:
179162
// Konva determines zIndex (which rect is clicked on if rects overlap) based on rendering order
180163
// as long as the smallest components are rendered last they will always be accessible over the big boys

src/components/LeftColExpansionPanel.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ const LeftColExpansionPanel = (props) => {
4949
style={{ color }}
5050
/>
5151
<ListItemSecondaryAction>
52-
{isFocused() || !selectableChildren.includes(id) ? (
52+
{ id == 1 || isFocused() || !selectableChildren.includes(id) ? (
5353
<div />
5454
) : (
5555
<IconButton aria-label="Add">

0 commit comments

Comments
 (0)