Skip to content

Commit 8ba7c20

Browse files
authored
Merge pull request #11 from sean1292/staging
State Toggle works with code preview
2 parents 98c8ee2 + eb7b53d commit 8ba7c20

File tree

9 files changed

+130
-221
lines changed

9 files changed

+130
-221
lines changed

src/actions/components.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import {
2525
ADD_PROP,
2626
DELETE_ALL_DATA,
2727
UPDATE_HTML_ATTR,
28-
2928
UPDATE_CHILDREN_SORT,
3029
CHANGE_IMAGE_SOURCE,
3130
DELETE_IMAGE
@@ -35,7 +34,6 @@ import { loadState } from '../localStorage';
3534
import createFiles from '../utils/createFiles.util.ts';
3635
import createApplicationUtil from '../utils/createApplication.util.ts';
3736

38-
3937
export const changeImagePath = (imageSource: string) => ({
4038
type: CHANGE_IMAGE_SOURCE,
4139
payload: { imageSource },
@@ -128,7 +126,6 @@ export const deleteImage = () => ({
128126
type: DELETE_IMAGE
129127
})
130128

131-
132129
export const exportFiles = ({
133130
components,
134131
path,
@@ -168,12 +165,7 @@ export const handleClose = () => ({
168165
export const handleTransform = (
169166
componentId: number,
170167
childId: number,
171-
{
172-
x,
173-
y,
174-
width,
175-
height
176-
}: { x: number; y: number; width: number; height: number }
168+
{ x, y, width, height }: { x: number; y: number; width: number; height: number }
177169
) => ({
178170
type: HANDLE_TRANSFORM,
179171
payload: {
@@ -280,4 +272,4 @@ export const updateHtmlAttr = ({ attr, value }: { attr: string; value: string })
280272
// type: UPDATE_CHILDREN_SORT,
281273
// payload: { newSortValues },
282274
// });
283-
// };
275+
// };

src/components/CodePreview.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class CodePreview extends Component<Props> {
2626
}}
2727
>
2828
<SyntaxHighlighter style={hybrid}>
29-
{format(componentRender(focusComponent, components))}
29+
{componentRender(focusComponent, components)}
3030
</SyntaxHighlighter>
3131
</div>
3232
);

src/components/LeftColExpansionPanel.tsx

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { Fragment } from 'react';
1+
import React, { Fragment, useEffect } from 'react';
22
import { withStyles } from '@material-ui/core/styles';
33
import Typography from '@material-ui/core/Typography';
44
import List from '@material-ui/core/List';
@@ -30,25 +30,19 @@ const LeftColExpansionPanel = (props: any) => {
3030
} = props;
3131

3232
const { title, id, color } = component;
33+
useEffect(() => {
34+
console.log('title: ', title);
35+
});
3336

3437
function isFocused() {
3538
return focusComponent.id === id ? 'focused' : '';
3639
}
37-
3840
return (
39-
<Grid
40-
container
41-
spacing={16}
42-
direction='row'
43-
justify='flex-start'
44-
alignItems='center'
45-
>
41+
<Grid container spacing={16} direction="row" justify="flex-start" alignItems="center">
4642
<Grid item xs={9}>
4743
<div
4844
className={classes.root}
49-
style={
50-
!isFocused() ? {} : { boxShadow: '0 10px 10px rgba(0,0,0,0.25)' }
51-
}
45+
style={!isFocused() ? {} : { boxShadow: '0 10px 10px rgba(0,0,0,0.25)' }}
5246
>
5347
<Grid item xs={12} style={{ color: 'red' }}>
5448
<List style={{ color: 'red' }}>
@@ -64,12 +58,12 @@ const LeftColExpansionPanel = (props: any) => {
6458
className={classes.light}
6559
primary={
6660
<div>
67-
<Typography type='body2' style={{ color }}>
61+
<Typography type="body2" style={{ color }}>
6862
{title}
6963
</Typography>
7064
{/* TOGGLE FOR STATEFULNESS */}
7165
<InputLabel
72-
htmlFor='stateful'
66+
htmlFor="stateful"
7367
style={{
7468
color: '#fff',
7569
marginBottom: '10px',
@@ -81,17 +75,25 @@ const LeftColExpansionPanel = (props: any) => {
8175
>
8276
State?
8377
</InputLabel>
78+
{/*
79+
Have to change focus component after toggling state
80+
in order to properly change the code that appears in the code
81+
peview
82+
*/}
8483
<Switch
85-
onChange={e => toggleComponentState(props.id)}
86-
value='stateful'
87-
color='primary'
84+
onChange={e => {
85+
toggleComponentState(props.id);
86+
changeFocusComponent(title);
87+
}}
88+
value="stateful"
89+
color="primary"
8890
id={props.id.toString()}
8991
// id={props.index.toString()}
9092
/>
9193
<div>
9294
{/* TOGGLE FOR CLASS BASED */}
9395
<InputLabel
94-
htmlFor='classBased'
96+
htmlFor="classBased"
9597
style={{
9698
color: '#fff',
9799
marginBottom: '10px',
@@ -108,8 +110,8 @@ const LeftColExpansionPanel = (props: any) => {
108110
// onChange={e => ONCHANGE FUNCTION PENDING ON CLASS REDUCER
109111
// updateComponent(id, { classBased: e.target.checked })
110112
// }
111-
value='classBased'
112-
color='primary'
113+
value="classBased"
114+
color="primary"
113115
id={props.index.toString()}
114116
/>
115117
</div>
@@ -125,10 +127,10 @@ const LeftColExpansionPanel = (props: any) => {
125127
) : (
126128
<Fragment>
127129
<Button
128-
variant='text'
129-
size='small'
130-
color='default'
131-
aria-label='Delete'
130+
variant="text"
131+
size="small"
132+
color="default"
133+
aria-label="Delete"
132134
className={classes.margin}
133135
onClick={() =>
134136
deleteComponent({
@@ -156,13 +158,9 @@ const LeftColExpansionPanel = (props: any) => {
156158
{id === 1 || isFocused() || !selectableChildren.includes(id) ? (
157159
<div />
158160
) : (
159-
<Tooltip
160-
title='add as child'
161-
aria-label='add as child'
162-
placement='left'
163-
>
161+
<Tooltip title="add as child" aria-label="add as child" placement="left">
164162
<IconButton
165-
aria-label='Add'
163+
aria-label="Add"
166164
onClick={() => {
167165
addChild({ title, childType: 'COMP' });
168166
}}

src/components/Rectangle.tsx

Lines changed: 13 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ class Rectangle extends Component<PropsInt, StateInt> {
3636
};
3737

3838
getComponentColor(componentId: number) {
39-
const color = this.props.components.find(
40-
(comp: ComponentInt) => comp.id === componentId
41-
).color;
39+
const color = this.props.components.find((comp: ComponentInt) => comp.id === componentId).color;
4240
return color;
4341
}
4442

@@ -48,12 +46,7 @@ class Rectangle extends Component<PropsInt, StateInt> {
4846
);
4947
}
5048

51-
handleResize(
52-
componentId: number,
53-
childId: number,
54-
target: any,
55-
blockSnapSize: number
56-
) {
49+
handleResize(componentId: number, childId: number, target: any, blockSnapSize: number) {
5750
let focChild: ChildInt = this.props.components
5851
.find((comp: ComponentInt) => comp.id === this.props.componentId)
5952
.childrenArray.find((child: ChildInt) => child.childId === childId);
@@ -64,24 +57,15 @@ class Rectangle extends Component<PropsInt, StateInt> {
6457
);
6558
}
6659
const transformation = {
67-
width:
68-
Math.round((target.width() * target.scaleX()) / blockSnapSize) *
69-
blockSnapSize,
70-
height:
71-
Math.round((target.height() * target.scaleY()) / blockSnapSize) *
72-
blockSnapSize,
60+
width: Math.round((target.width() * target.scaleX()) / blockSnapSize) * blockSnapSize,
61+
height: Math.round((target.height() * target.scaleY()) / blockSnapSize) * blockSnapSize,
7362
x: target.x() + focChild.position.x,
7463
y: target.y() + focChild.position.y
7564
};
7665
this.props.handleTransform(componentId, childId, transformation);
7766
}
7867

79-
handleDrag(
80-
componentId: number,
81-
childId: number,
82-
target: any,
83-
blockSnapSize: any
84-
) {
68+
handleDrag(componentId: number, childId: number, target: any, blockSnapSize: any) {
8569
const transformation = {
8670
x: Math.round(target.x() / blockSnapSize) * blockSnapSize,
8771
y: Math.round(target.y() / blockSnapSize) * blockSnapSize
@@ -129,20 +113,18 @@ class Rectangle extends Component<PropsInt, StateInt> {
129113
scaleY={scaleY}
130114
width={width}
131115
height={height}
132-
onDragEnd={event =>
133-
this.handleDrag(componentId, childId, event.target, blockSnapSize)
134-
}
116+
onDragEnd={event => this.handleDrag(componentId, childId, event.target, blockSnapSize)}
135117
ref={node => {
136118
this.group = node;
137119
}}
138-
tabIndex='0' // required for keypress event to be heard by this.group
120+
tabIndex="0" // required for keypress event to be heard by this.group
139121
>
140122
<Rect
141123
// a Konva Rect is generated for each child of the focusComponent (including the pseudochild, representing the focusComponent itself)
142124
ref={node => {
143125
this.rect = node;
144126
}}
145-
tabIndex='0' // required for keypress event to be heard by this.group
127+
tabIndex="0" // required for keypress event to be heard by this.group
146128
name={`${childId}`}
147129
className={'childRect'}
148130
x={0}
@@ -154,11 +136,7 @@ class Rectangle extends Component<PropsInt, StateInt> {
154136
scaleY={1}
155137
width={width}
156138
height={height}
157-
stroke={
158-
childType === 'COMP'
159-
? this.getComponentColor(childComponentId)
160-
: '#000000'
161-
}
139+
stroke={childType === 'COMP' ? this.getComponentColor(childComponentId) : '#000000'}
162140
onTransformEnd={event =>
163141
this.handleResize(componentId, childId, event.target, blockSnapSize)
164142
}
@@ -167,11 +145,9 @@ class Rectangle extends Component<PropsInt, StateInt> {
167145
draggable={false}
168146
fill={null}
169147
shadowBlur={childId === -1 ? 6 : null}
170-
171148
fillPatternImage={this.state.image ? this.state.image : null}
172149
fillPatternScaleX={this.state.image ? width / this.state.image.width : 1}
173150
fillPatternScaleY={this.state.image ? height / this.state.image.height : 1}
174-
175151
_useStrictMode
176152
/>
177153
<Label>
@@ -180,11 +156,7 @@ class Rectangle extends Component<PropsInt, StateInt> {
180156
fontVariant={'small-caps'}
181157
// pseudochild's label should look different than normal children:
182158
text={childId === -1 ? title.slice(0, title.length - 2) : title}
183-
fill={
184-
childId === -1
185-
? this.getComponentColor(childComponentId)
186-
: '#000000'
187-
}
159+
fill={childId === -1 ? this.getComponentColor(childComponentId) : '#000000'}
188160
fontSize={childId === -1 ? 15 : 10}
189161
x={4}
190162
y={childId === -1 ? -20 : -12}
@@ -203,20 +175,14 @@ class Rectangle extends Component<PropsInt, StateInt> {
203175
componentId={componentId}
204176
directParentName={childComponentName}
205177
childType={grandchild.childType}
206-
imageSource={
207-
grandchild.htmlElement === 'Image' && grandchild.HTMLInfo.Src
208-
}
178+
imageSource={grandchild.htmlElement === 'Image' && grandchild.HTMLInfo.Src}
209179
childComponentName={grandchild.componentName}
210180
childComponentId={grandchild.childComponentId}
211181
focusChild={focusChild}
212182
childId={childId} // scary addition, grandchildren rects default to childId of "direct" children
213-
width={
214-
grandchild.position.width *
215-
(width / this.getPseudoChild().position.width)
216-
}
183+
width={grandchild.position.width * (width / this.getPseudoChild().position.width)}
217184
height={
218-
grandchild.position.height *
219-
(height / this.getPseudoChild().position.height)
185+
grandchild.position.height * (height / this.getPseudoChild().position.height)
220186
}
221187
x={
222188
(grandchild.position.x - this.getPseudoChild().position.x) *

0 commit comments

Comments
 (0)