Skip to content

Commit 6d715ff

Browse files
authored
Merge pull request #34 from sean1292/ace
Code preview is now editable
2 parents 1e9ba05 + 0c97755 commit 6d715ff

File tree

15 files changed

+416
-234
lines changed

15 files changed

+416
-234
lines changed

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,12 @@
9494
"@material-ui/icons": "^4.0.1",
9595
"@material-ui/styles": "^4.9.6",
9696
"@types/prettier": "^1.19.0",
97+
"@types/prismjs": "^1.16.0",
9798
"@types/react": "^16.8.14",
9899
"@types/react-dom": "^16.8.4",
99100
"@types/react-redux": "^7.0.8",
100101
"@types/react-syntax-highlighter": "^11.0.4",
102+
"ace-builds": "^1.4.8",
101103
"autoprefixer": "^9.0.1",
102104
"babel-polyfill": "^6.26.0",
103105
"classnames": "^2.2.6",
@@ -113,13 +115,16 @@
113115
"lodash.throttle": "^4.1.1",
114116
"material-table": "^1.25.2",
115117
"prettier": "^1.19.1",
118+
"prismjs": "^1.19.0",
116119
"prop-types": "^15.6.2",
117120
"react": "^16.13.0",
121+
"react-ace": "^8.1.0",
118122
"react-d3-tree": "^1.12.3",
119123
"react-dom": "^16.4.1",
120124
"react-draggable": "^3.0.5",
121125
"react-konva": "^16.12.0-0",
122126
"react-redux": "^5.0.7",
127+
"react-simple-code-editor": "^0.11.0",
123128
"react-sortable-tree": "^2.2.0",
124129
"react-syntax-highlighter": "^10.2.1",
125130
"redux": "^4.0.0",

src/actionTypes/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ export const DELETE_CHILD: string = 'DELETE_CHILD';
55
export const UPDATE_COMPONENT: string = 'UPDATE_COMPONENT';
66
export const DELETE_COMPONENT: string = 'DELETE_COMPONENT';
77
export const CHANGE_FOCUS_COMPONENT: string = 'CHANGE_FOCUS_COMPONENT';
8-
export const CHANGE_COMPONENT_FOCUS_CHILD: string = 'CHANGE_COMPONENT_FOCUS_CHILD';
8+
export const CHANGE_COMPONENT_FOCUS_CHILD: string =
9+
'CHANGE_COMPONENT_FOCUS_CHILD';
910
export const CHANGE_FOCUS_CHILD: string = 'CHANGE_FOCUS_CHILD';
1011
export const UPDATE_CHILDREN: string = 'UPDATE_CHILDREN';
1112
export const REASSIGN_PARENT: string = 'REASSIGN_PARENT';
@@ -34,5 +35,6 @@ export const TOGGLE_CLASS: string = 'TOGGLE_CLASS';
3435
export const CHANGE_TUTORIAL: string = 'CHANGE_TUTORIAL';
3536
export const UNDO: string = 'UNDO';
3637
export const REDO: string = 'REDO';
38+
export const UPDATE_CODE: string = 'UPDATE_CODE';
3739
export const EDIT_MODE: string = 'EDIT_MODE';
38-
export const EDIT_COMPONENT: string = 'EDIT_COMPONENT';
40+
export const EDIT_COMPONENT: string = 'EDIT_COMPONENT';

src/actions/components.ts

Lines changed: 49 additions & 37 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 '../utils/Interfaces';
88

99
import {
@@ -36,6 +36,7 @@ import {
3636
CHANGE_TUTORIAL,
3737
UNDO,
3838
REDO,
39+
UPDATE_CODE,
3940
EDIT_MODE,
4041
EDIT_COMPONENT
4142
} from '../actionTypes/index';
@@ -46,12 +47,12 @@ import createApplicationUtil from '../utils/createApplication.util';
4647

4748
export const changeTutorial = (tutorial: number) => ({
4849
type: CHANGE_TUTORIAL,
49-
payload: { tutorial },
50+
payload: { tutorial }
5051
});
5152

5253
export const changeImagePath = (imageSource: string) => ({
5354
type: CHANGE_IMAGE_SOURCE,
54-
payload: { imageSource },
55+
payload: { imageSource }
5556
});
5657

5758
export const loadInitData = () => (dispatch: (arg: Action) => void) => {
@@ -61,8 +62,8 @@ export const loadInitData = () => (dispatch: (arg: Action) => void) => {
6162
payload: {
6263
data: data
6364
? { ...data.workspace, history: [], historyIndex: 0, future: [] } //erase history upon opening app
64-
: {},
65-
},
65+
: {}
66+
}
6667
});
6768
});
6869
};
@@ -76,7 +77,7 @@ export const addComponent = ({ title }: { title: string }) => (
7677
export const addChild = ({
7778
title,
7879
childType,
79-
HTMLInfo,
80+
HTMLInfo
8081
}: {
8182
title: string;
8283
childType: string;
@@ -92,7 +93,7 @@ export const deleteChild = ({}) => (dispatch: (arg: Action) => void) => {
9293

9394
export const deleteComponent = ({
9495
componentId,
95-
stateComponents,
96+
stateComponents
9697
}: {
9798
componentId: number;
9899
stateComponents: ComponentsInt;
@@ -107,8 +108,8 @@ export const deleteComponent = ({
107108
payload: {
108109
parentId: parent.id,
109110
childId: child.childId,
110-
calledFromDeleteComponent: true,
111-
},
111+
calledFromDeleteComponent: true
112+
}
112113
});
113114
});
114115
});
@@ -134,26 +135,38 @@ export const changeFocusChild = ({ childId }: { childId: number }) => (
134135

135136
export const changeComponentFocusChild = ({
136137
componentId,
137-
childId,
138+
childId
138139
}: {
139140
componentId: number;
140141
childId: number;
141142
}) => (dispatch: (arg: Action) => void) => {
142143
dispatch({
143144
type: CHANGE_COMPONENT_FOCUS_CHILD,
144-
payload: { componentId, childId },
145+
payload: { componentId, childId }
145146
});
146147
};
147148

148149
export const deleteImage = () => ({
149-
type: DELETE_IMAGE,
150+
type: DELETE_IMAGE
150151
});
151152

153+
export const updateCode = ({
154+
componentId,
155+
code
156+
}: {
157+
componentId: number;
158+
code: string;
159+
}) => (dispatch: (arg: Action) => void) => {
160+
dispatch({
161+
type: UPDATE_CODE,
162+
payload: { componentId, code }
163+
});
164+
};
152165
export const exportFiles = ({
153166
components,
154167
path,
155168
appName,
156-
exportAppBool,
169+
exportAppBool
157170
}: {
158171
components: ComponentsInt;
159172
path: string;
@@ -162,26 +175,26 @@ export const exportFiles = ({
162175
}) => (dispatch: (arg: Action) => void) => {
163176
// this dispatch sets the global state property 'loading' to true until the createFiles call resolves below
164177
dispatch({
165-
type: EXPORT_FILES,
178+
type: EXPORT_FILES
166179
});
167180
createFiles(components, path, appName, exportAppBool)
168181
.then((dir: any) =>
169182
dispatch({
170183
type: EXPORT_FILES_SUCCESS,
171-
payload: { status: true, dir: dir[0] },
184+
payload: { status: true, dir: dir[0] }
172185
})
173186
)
174187
.catch((err: string) =>
175188
dispatch({
176189
type: EXPORT_FILES_ERROR,
177-
payload: { status: true, err },
190+
payload: { status: true, err }
178191
})
179192
);
180193
};
181194

182195
export const handleClose = () => ({
183196
type: HANDLE_CLOSE,
184-
payload: false,
197+
payload: false
185198
});
186199

187200
export const handleTransform = (
@@ -191,7 +204,7 @@ export const handleTransform = (
191204
x,
192205
y,
193206
width,
194-
height,
207+
height
195208
}: { x: number; y: number; width: number; height: number }
196209
) => ({
197210
type: HANDLE_TRANSFORM,
@@ -201,16 +214,16 @@ export const handleTransform = (
201214
x,
202215
y,
203216
width,
204-
height,
205-
},
217+
height
218+
}
206219
});
207220

208221
export const createApplication = ({
209222
path,
210223
components = [],
211224
genOption,
212225
appName = 'reactype_app',
213-
exportAppBool,
226+
exportAppBool
214227
}: {
215228
path: string;
216229
components: ComponentsInt;
@@ -225,48 +238,48 @@ export const createApplication = ({
225238
appName,
226239
path,
227240
components,
228-
exportAppBool,
241+
exportAppBool
229242
})
230243
);
231244
} else if (genOption) {
232245
exportAppBool = true;
233246
dispatch({
234-
type: CREATE_APPLICATION,
247+
type: CREATE_APPLICATION
235248
});
236249
createApplicationUtil({
237250
path,
238251
appName,
239-
genOption,
252+
genOption
240253
})
241254
.then(() => {
242255
dispatch({
243-
type: CREATE_APPLICATION_SUCCESS,
256+
type: CREATE_APPLICATION_SUCCESS
244257
});
245258
dispatch(
246259
exportFiles({
247260
appName,
248261
path,
249262
components,
250-
exportAppBool,
263+
exportAppBool
251264
})
252265
);
253266
})
254267
.catch((err: string) =>
255268
dispatch({
256269
type: CREATE_APPLICATION_ERROR,
257-
payload: { status: true, err },
270+
payload: { status: true, err }
258271
})
259272
);
260273
}
261274
};
262275

263276
export const openExpansionPanel = (component: ComponentInt) => ({
264277
type: OPEN_EXPANSION_PANEL,
265-
payload: { component },
278+
payload: { component }
266279
});
267280

268281
export const deleteAllData = () => ({
269-
type: DELETE_ALL_DATA,
282+
type: DELETE_ALL_DATA
270283
});
271284

272285
export const deleteProp = (propId: number) => (
@@ -289,16 +302,16 @@ export const toggleComponentClass = ({ id }: { id: number }) => (
289302

290303
export const addProp = (prop: PropInt) => ({
291304
type: ADD_PROP,
292-
payload: { ...prop },
305+
payload: { ...prop }
293306
});
294307

295308
//action creators for undo and redo
296309
export const undo = () => ({
297-
type: UNDO,
310+
type: UNDO
298311
});
299312

300313
export const redo = () => ({
301-
type: REDO,
314+
type: REDO
302315
});
303316

304317
export const toggleEditMode = ({ id }: { id: number }) => (
@@ -307,23 +320,22 @@ export const toggleEditMode = ({ id }: { id: number }) => (
307320
dispatch({ type: EDIT_MODE, payload: { id } });
308321
};
309322

310-
export const editComponent = ({ id, title }: { id: number, title: string }) => (
323+
export const editComponent = ({ id, title }: { id: number; title: string }) => (
311324
dispatch: (arg: Action) => void
312325
) => {
313-
dispatch({ type: EDIT_COMPONENT , payload: { id, title } });
326+
dispatch({ type: EDIT_COMPONENT, payload: { id, title } });
314327
};
315-
316328

317329
export const updateHtmlAttr = ({
318330
attr,
319-
value,
331+
value
320332
}: {
321333
attr: string;
322334
value: string;
323335
}) => (dispatch: (arg: Action) => void) => {
324336
dispatch({
325337
type: UPDATE_HTML_ATTR,
326-
payload: { attr, value },
338+
payload: { attr, value }
327339
});
328340
};
329341

src/components/BottomPanel.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,19 @@ const IPC = require('electron').ipcRenderer;
99
const mapDispatchToProps = (dispatch: any) => ({
1010
handleNotificationClose: () => dispatch(handleClose()),
1111
deleteProp: (id: number) => dispatch(deleteProp(id)),
12-
addProp: (prop: PropInt) => dispatch(addProp(prop)),
12+
addProp: (prop: PropInt) => dispatch(addProp(prop))
1313
});
1414

1515
const mapStateToProps = (store: any) => ({
1616
focusChild: store.workspace.focusChild,
17-
components: store.workspace.components,
17+
components: store.workspace.components
1818
});
1919

2020
interface BottomPanelPropsInt extends PropsInt {
2121
deleteProp(id: number): void;
2222
addProp(prop: PropInt): void;
2323
changeFocusComponent(arg: { title: string }): void;
24+
updateCode(arg: { componentId: number; code: string }): void;
2425
}
2526

2627
class BottomPanel extends Component<BottomPanelPropsInt> {
@@ -32,6 +33,7 @@ class BottomPanel extends Component<BottomPanelPropsInt> {
3233
addProp,
3334
focusChild,
3435
changeFocusComponent,
36+
updateCode
3537
} = this.props;
3638

3739
return (
@@ -43,6 +45,7 @@ class BottomPanel extends Component<BottomPanelPropsInt> {
4345
addProp={addProp}
4446
focusChild={focusChild}
4547
changeFocusComponent={changeFocusComponent}
48+
updateCode={updateCode}
4649
/>
4750
</div>
4851
);

0 commit comments

Comments
 (0)