Skip to content

Commit 02c0d55

Browse files
ChristianEdwardPadillatolgamizrakcispincycle01ShlomoPorges
committed
final merge
final Co-authored-by: Tolga Mizrakci <tolgamizrakci@gmail.com> Co-authored-by: Adam Singer <spincycle01@yahoo.com> Co-authored-by: Shlomo Porges <porges.s@gmail.com>
1 parent e85290b commit 02c0d55

File tree

7 files changed

+57
-70
lines changed

7 files changed

+57
-70
lines changed

src/utils/Interfaces.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export interface ChildInt {
2222
position: PositionInt;
2323
color: string | null; // maybe optional instead, look up null vs undefined
2424
htmlElement: string | null; // maybe should be optional instead
25-
HTMLInfo: { [index: string]: { info: any } }; // replace with HTMLinfo specifics
25+
HTMLInfo: { [index: string]: string }; // replace with HTMLinfo specifics
2626
}
2727

2828
export interface ChildrenInt extends Array<ChildInt> {}

src/utils/colors.util.ts

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,29 @@
11
const colors: Array<string> = [
2-
"#E27D60",
3-
"#E3AFBC",
4-
"#E8A87C",
5-
"#C38D9E",
6-
"#41B3A3",
7-
"#D12FA2",
8-
"#F64C72",
9-
"#DAAD86",
10-
"#8EE4AF",
11-
"#5CDB95",
12-
"#7395AE", // light grey
13-
"#b90061",
14-
"#AFD275",
15-
"#45A29E",
16-
"#D79922",
17-
"#C5CBE3", // lightish grey
18-
"#FFCB9A",
19-
"#E98074",
20-
"#8860D0",
21-
"#5AB9EA",
22-
"#5860E9",
23-
"#84CEEB",
24-
"#61892F"
2+
'#E27D60',
3+
'#E3AFBC',
4+
'#E8A87C',
5+
'#C38D9E',
6+
'#41B3A3',
7+
'#D12FA2',
8+
'#F64C72',
9+
'#DAAD86',
10+
'#8EE4AF',
11+
'#5CDB95',
12+
'#7395AE', // light grey
13+
'#b90061',
14+
'#AFD275',
15+
'#45A29E',
16+
'#D79922',
17+
'#C5CBE3', // lightish grey
18+
'#FFCB9A',
19+
'#E98074',
20+
'#8860D0',
21+
'#5AB9EA',
22+
'#5860E9',
23+
'#84CEEB',
24+
'#61892F',
2525
];
2626

27-
const getColor = (): string =>
28-
colors[Math.floor(Math.random() * colors.length)];
27+
const getColor = (): string => colors[Math.floor(Math.random() * colors.length)];
2928

3029
export default getColor;

src/utils/componentReducer.util.ts

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,7 @@ import getSelectable from './getSelectable.util.ts';
22
import getColor from './colors.util.ts';
33
import { getSize } from './htmlElements.util.ts';
44
import cloneDeep from './cloneDeep.ts';
5-
import {
6-
ComponentInt,
7-
ApplicationStateInt,
8-
ChildrenInt,
9-
ChildInt,
10-
ComponentsInt,
11-
PropInt,
12-
} from './Interfaces.ts';
5+
import { ComponentInt, ApplicationStateInt, ChildrenInt, ChildInt, ComponentsInt, PropInt } from './Interfaces.ts';
136

147
const initialComponentState: ComponentInt = {
158
id: 0,
@@ -228,7 +221,8 @@ export const deleteChild = (
228221
focusComponent: calledFromDeleteComponent ? state.focusComponent : parentComponentCopy, // when called from delete component we dont need want to touch the focus
229222
focusChild: calledFromDeleteComponent
230223
? cloneDeep(state.initialApplicationFocusChild)
231-
: parentComponentCopy.childrenArray[parentComponentCopy.childrenArray.length - 1],
224+
: parentComponentCopy.childrenArray[parentComponentCopy.childrenArray.length - 1] ||
225+
cloneDeep(state.initialApplicationFocusChild), // guard in case final child is deleted
232226
};
233227
};
234228

@@ -288,11 +282,9 @@ export const handleTransform = (
288282
};
289283

290284
const children = [
291-
...state.components
292-
.find(comp => comp.id === componentId)
293-
.childrenArray.filter(child => {
294-
if (child.childId !== childId) return child;
295-
}),
285+
...state.components.find(comp => comp.id === componentId).childrenArray.filter(child => {
286+
if (child.childId !== childId) return child;
287+
}),
296288
transformedChild,
297289
];
298290

src/utils/createFiles.util.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,15 @@ import componentRender from './componentRender.util.ts';
44

55
const createFiles = (components: any, path: string, appName: string, exportAppBool: boolean) => {
66
let dir = path;
7-
if (!dir.match(/components|\*$/)) {
8-
if (fs.existsSync(`${dir}/src`)) {
9-
dir = `${dir}/src`;
7+
if (exportAppBool === false) {
8+
if (!dir.match(/components|\*$/)) {
9+
if (fs.existsSync(`${dir}/src`)) {
10+
dir = `${dir}/src`;
11+
}
12+
dir = `${dir}/components`;
13+
if (!fs.existsSync(dir)) {
14+
fs.mkdirSync(dir);
15+
}
1016
}
1117
} else if (exportAppBool) {
1218
if (!dir.match(/${appName}|\*$/)) {

src/utils/getSelectable.util.ts

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
import { ComponentInt, ComponentsInt, ChildInt } from "./interfaces.ts";
1+
import { ComponentInt, ComponentsInt, ChildInt } from './interfaces.ts';
22

33
interface getSelectableInt {
44
[key: string]: Array<number>;
55
}
66

7-
function getSelectable(
8-
newFocusComponent: ComponentInt,
9-
components: ComponentsInt
10-
) {
7+
function getSelectable(newFocusComponent: ComponentInt, components: ComponentsInt) {
118
const focusComponentId = newFocusComponent.id;
129
const componentsToCheck = components
1310
.map((comp: ComponentInt) => comp.id)
@@ -19,12 +16,12 @@ function findAncestors(
1916
components: ComponentsInt,
2017
currentCompArr: ComponentsInt,
2118
componentsToCheck: ComponentsInt,
22-
ancestors: Array<number> = []
19+
ancestors: Array<number> = [],
2320
): getSelectableInt {
2421
if (!currentCompArr.length) {
2522
return {
26-
ancestors: ancestors,
27-
selectableChildren: componentsToCheck
23+
ancestors,
24+
selectableChildren: componentsToCheck,
2825
};
2926
}
3027

@@ -33,20 +30,16 @@ function findAncestors(
3330
for (let i = 0; i < components.length; i++) {
3431
if (componentsToCheck.includes(components[i].id)) {
3532
const myChildren = components[i].childrenArray.map(
36-
(child: ChildInt) => child.childComponentId
33+
(child: ChildInt) => child.childComponentId,
3734
);
3835

39-
const found = currentCompArr.filter((comp: ComponentInt) =>
40-
myChildren.includes(comp)
41-
);
36+
const found = currentCompArr.filter((comp: ComponentInt) => myChildren.includes(comp));
4237

4338
if (found.length) {
4439
ancestors.push(components[i].id);
4540
newAncestors.push(components[i].id);
4641

47-
const indexToDelete = componentsToCheck.findIndex(
48-
(c: Number) => c === components[i].id
49-
);
42+
const indexToDelete = componentsToCheck.findIndex((c: Number) => c === components[i].id);
5043

5144
componentsToCheck.splice(indexToDelete, 1);
5245
}

src/utils/htmlElements.util.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,48 +18,46 @@ const HTMLelements: htmlElementsInt = {
1818
Image: {
1919
width: 100,
2020
height: 100,
21-
attributes: ['className', 'id', 'src']
21+
attributes: ['className', 'id', 'src'],
2222
},
2323
Button: {
2424
width: 75,
2525
height: 28,
26-
attributes: ['className', 'id', 'text']
26+
attributes: ['className', 'id', 'text'],
2727
},
2828
Form: {
2929
width: 150,
3030
height: 150,
31-
attributes: ['className', 'id', 'text']
31+
attributes: ['className', 'id', 'text'],
3232
},
3333
Paragraph: {
3434
width: 250,
3535
height: 75,
36-
attributes: ['className', 'id', 'text']
36+
attributes: ['className', 'id', 'text'],
3737
},
3838
List: {
3939
width: 75,
4040
height: 75,
41-
attributes: ['className', 'id', 'text']
41+
attributes: ['className', 'id', 'text'],
4242
},
4343
Link: {
4444
width: 50,
4545
height: 50,
46-
attributes: ['className', 'id', 'text']
47-
}
46+
attributes: ['className', 'id', 'text'],
47+
},
4848
};
4949

5050
function getSize(htmlElement: string): htmlElemPositionInt {
5151
const localHTMLelements = HTMLelements;
5252

5353
if (!(htmlElement in localHTMLelements)) {
54-
window.alert(
55-
`htmlElement error: "${htmlElement} is not found in our database"`
56-
);
54+
window.alert(`htmlElement error: "${htmlElement} is not found in our database"`);
5755
return;
5856
}
5957

6058
return {
6159
width: HTMLelements[htmlElement].width || 300,
62-
height: HTMLelements[htmlElement].height || 300
60+
height: HTMLelements[htmlElement].height || 300,
6361
};
6462
}
6563

webpack.config.development.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ module.exports = {
2222
path: BUILD_DIR,
2323
filename: 'js/bundle.js',
2424
},
25-
resolve: { extensions: ['.ts', '.tsx', '.js', '.jsx'] },
2625
module: {
2726
rules: [
2827
{ test: /\.tsx?$/, exclude: /node-modules/, loader: 'babel-loader' },

0 commit comments

Comments
 (0)