Skip to content

Commit 5a028c1

Browse files
authored
Merge pull request #37 from sean1292/ace
Added Code Edit Mode
2 parents 7099773 + 1233346 commit 5a028c1

File tree

10 files changed

+284
-139
lines changed

10 files changed

+284
-139
lines changed

src/actionTypes/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
export const ADD_CHILD: string = 'ADD_CHILD';
22
export const ADD_COMPONENT: string = 'ADD_COMPONENT';
33
export const ADD_PROP: string = 'ADD_PROP';
4-
export const CHANGE_COMPONENT_FOCUS_CHILD: string = 'CHANGE_COMPONENT_FOCUS_CHILD';
4+
export const CHANGE_COMPONENT_FOCUS_CHILD: string =
5+
'CHANGE_COMPONENT_FOCUS_CHILD';
56
export const CHANGE_FOCUS_CHILD: string = 'CHANGE_FOCUS_CHILD';
67
export const CHANGE_FOCUS_COMPONENT: string = 'CHANGE_FOCUS_COMPONENT';
78
export const CHANGE_IMAGE_PATH: string = 'CHANGE_IMAGE_PATH';
89
export const CHANGE_IMAGE_SOURCE: string = 'CHANGE_IMAGE_SOURCE';
910
export const CHANGE_TUTORIAL: string = 'CHANGE_TUTORIAL';
11+
export const CODE_EDIT: string = 'CODE_EDIT';
1012
export const CREATE_APPLICATION: string = 'CREATE_APPLICATION';
1113
export const CREATE_APPLICATION_ERROR: string = 'CREATE_APPLICATION_ERROR';
1214
export const CREATE_APPLICATION_SUCCESS: string = 'CREATE_APPLICATION_SUCCESS';

src/actions/actionCreators.ts

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
ComponentsInt,
44
PropInt,
55
ChildInt,
6-
Action,
6+
Action
77
} from '../interfaces/Interfaces';
88

99
import {
@@ -15,6 +15,7 @@ import {
1515
CHANGE_FOCUS_COMPONENT,
1616
CHANGE_IMAGE_SOURCE,
1717
CHANGE_TUTORIAL,
18+
CODE_EDIT,
1819
CREATE_APPLICATION,
1920
CREATE_APPLICATION_ERROR,
2021
CREATE_APPLICATION_SUCCESS,
@@ -36,7 +37,7 @@ import {
3637
TOGGLE_STATE,
3738
UNDO,
3839
UPDATE_HTML_ATTR,
39-
UPDATE_CODE,
40+
UPDATE_CODE
4041
} from '../actionTypes/index';
4142
import { loadState } from '../localStorage';
4243
import createFiles from '../utils/createFiles.util';
@@ -62,17 +63,17 @@ export const addComponent = ({ title }: { title: string }) => (
6263

6364
export const addProp = (prop: PropInt) => ({
6465
type: ADD_PROP,
65-
payload: { ...prop },
66+
payload: { ...prop }
6667
});
6768

6869
export const changeTutorial = (tutorial: number) => ({
6970
type: CHANGE_TUTORIAL,
70-
payload: { tutorial },
71+
payload: { tutorial }
7172
});
7273

7374
export const changeImagePath = (imageSource: string) => ({
7475
type: CHANGE_IMAGE_SOURCE,
75-
payload: { imageSource },
76+
payload: { imageSource }
7677
});
7778

7879
export const deleteChild = ({}) => (dispatch: (arg: Action) => void) => {
@@ -195,7 +196,7 @@ export const deleteAllData = () => ({
195196
});
196197

197198
export const deleteImage = () => ({
198-
type: DELETE_IMAGE,
199+
type: DELETE_IMAGE
199200
});
200201

201202
export const deleteProp = (propId: number) => (
@@ -214,7 +215,7 @@ export const exportFiles = ({
214215
components,
215216
path,
216217
appName,
217-
exportAppBool,
218+
exportAppBool
218219
}: {
219220
components: ComponentsInt;
220221
path: string;
@@ -223,26 +224,26 @@ export const exportFiles = ({
223224
}) => (dispatch: (arg: Action) => void) => {
224225
// this dispatch sets the global state property 'loading' to true until the createFiles call resolves below
225226
dispatch({
226-
type: EXPORT_FILES,
227+
type: EXPORT_FILES
227228
});
228229
createFiles(components, path, appName, exportAppBool)
229230
.then((dir: any) =>
230231
dispatch({
231232
type: EXPORT_FILES_SUCCESS,
232-
payload: { status: true, dir: dir[0] },
233+
payload: { status: true, dir: dir[0] }
233234
})
234235
)
235236
.catch((err: string) =>
236237
dispatch({
237238
type: EXPORT_FILES_ERROR,
238-
payload: { status: true, err },
239+
payload: { status: true, err }
239240
})
240241
);
241242
};
242243

243244
export const handleClose = () => ({
244245
type: HANDLE_CLOSE,
245-
payload: false,
246+
payload: false
246247
});
247248

248249
export const handleTransform = (
@@ -252,7 +253,7 @@ export const handleTransform = (
252253
x,
253254
y,
254255
width,
255-
height,
256+
height
256257
}: { x: number; y: number; width: number; height: number }
257258
) => ({
258259
type: HANDLE_TRANSFORM,
@@ -262,8 +263,8 @@ export const handleTransform = (
262263
x,
263264
y,
264265
width,
265-
height,
266-
},
266+
height
267+
}
267268
});
268269

269270
export const loadInitData = () => (dispatch: (arg: Action) => void) => {
@@ -273,8 +274,8 @@ export const loadInitData = () => (dispatch: (arg: Action) => void) => {
273274
payload: {
274275
data: data
275276
? { ...data.workspace, history: [], historyIndex: 0, future: [] } //erase history upon opening app
276-
: {},
277-
},
277+
: {}
278+
}
278279
});
279280
});
280281
};
@@ -302,7 +303,11 @@ export const toggleEditMode = ({ id }: { id: number }) => (
302303
};
303304
//action creators for undo and redo
304305
export const undo = () => ({
305-
type: UNDO,
306+
type: UNDO
307+
});
308+
309+
export const toggleCodeEdit = () => ({
310+
type: CODE_EDIT
306311
});
307312

308313
export const updateCode = ({

src/components/bottom/BottomPanel.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,30 @@ import { connect } from 'react-redux';
33
import { handleClose, deleteProp, addProp } from '../../actions/actionCreators';
44
import BottomTabs from './BottomTabs';
55
import { PropsInt, PropInt } from '../../interfaces/Interfaces';
6+
import { toggleCodeEdit } from '../../actions/actionCreators';
67

78
const IPC = require('electron').ipcRenderer;
89

910
const mapDispatchToProps = (dispatch: any) => ({
1011
handleNotificationClose: () => dispatch(handleClose()),
1112
deleteProp: (id: number) => dispatch(deleteProp(id)),
12-
addProp: (prop: PropInt) => dispatch(addProp(prop))
13+
addProp: (prop: PropInt) => dispatch(addProp(prop)),
14+
toggleCodeEdit: () => dispatch(toggleCodeEdit())
1315
});
1416

1517
const mapStateToProps = (store: any) => ({
1618
focusChild: store.workspace.focusChild,
17-
components: store.workspace.components
19+
components: store.workspace.components,
20+
codeReadOnly: store.workspace.codeReadOnly
1821
});
1922

2023
interface BottomPanelPropsInt extends PropsInt {
2124
deleteProp(id: number): void;
2225
addProp(prop: PropInt): void;
2326
changeFocusComponent(arg: { title: string }): void;
2427
updateCode(arg: { componentId: number; code: string }): void;
28+
toggleCodeEdit(): void;
29+
codeReadOnly: boolean;
2530
}
2631

2732
class BottomPanel extends Component<BottomPanelPropsInt> {
@@ -33,7 +38,9 @@ class BottomPanel extends Component<BottomPanelPropsInt> {
3338
addProp,
3439
focusChild,
3540
changeFocusComponent,
36-
updateCode
41+
updateCode,
42+
toggleCodeEdit,
43+
codeReadOnly
3744
} = this.props;
3845

3946
return (
@@ -46,6 +53,8 @@ class BottomPanel extends Component<BottomPanelPropsInt> {
4653
focusChild={focusChild}
4754
changeFocusComponent={changeFocusComponent}
4855
updateCode={updateCode}
56+
toggleCodeEdit={toggleCodeEdit}
57+
codeReadOnly={codeReadOnly}
4958
/>
5059
</div>
5160
);

src/components/bottom/BottomTabs.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ interface BottomTabsPropsInt extends PropsInt {
1515
classes: any;
1616
changeFocusComponent(arg: { title: string }): void;
1717
updateCode(arg: { componentId: number; code: string }): void;
18+
toggleCodeEdit(): void;
19+
codeReadOnly: boolean;
1820
}
1921

2022
// interface TreeInt {
@@ -141,7 +143,9 @@ class BottomTabs extends Component<BottomTabsPropsInt, StateInt> {
141143
deleteProp,
142144
addProp,
143145
focusChild,
144-
updateCode
146+
updateCode,
147+
toggleCodeEdit,
148+
codeReadOnly
145149
} = this.props;
146150
const { value } = this.state;
147151

@@ -161,12 +165,12 @@ class BottomTabs extends Component<BottomTabsPropsInt, StateInt> {
161165
<Tab
162166
disableRipple
163167
classes={{ root: classes.tabRoot, selected: classes.tabSelected }}
164-
label='Application Tree'
168+
label="Application Tree"
165169
/>
166170
<Tab
167171
disableRipple
168172
classes={{ root: classes.tabRoot, selected: classes.tabSelected }}
169-
label='Code Preview'
173+
label="Code Preview"
170174
/>
171175
<Tab
172176
disableRipple
@@ -183,13 +187,13 @@ class BottomTabs extends Component<BottomTabsPropsInt, StateInt> {
183187
<Tab
184188
disableRipple
185189
classes={{ root: classes.tabRoot, selected: classes.tabSelected }}
186-
label='Add Child Props'
190+
label="Add Child Props"
187191
/>
188192
</Tabs>
189193

190194
{value === 0 && (
191195
<div
192-
id='treeWrapper'
196+
id="treeWrapper"
193197
style={{
194198
width: '100%',
195199
height: '100%'
@@ -229,6 +233,8 @@ class BottomTabs extends Component<BottomTabsPropsInt, StateInt> {
229233
updateCode={updateCode}
230234
components={components}
231235
changeFocusComponent={this.props.changeFocusComponent}
236+
toggleCodeEdit={toggleCodeEdit}
237+
codeReadOnly={codeReadOnly}
232238
/>
233239
)}
234240
{value === 2 && <Props />}

0 commit comments

Comments
 (0)