Skip to content

Commit da53d41

Browse files
Merge pull request #4 from MadinventorZero/codepreview
Added Input/Label elements, Fixed Broken Img
2 parents 0d74350 + 76a7a9f commit da53d41

File tree

8 files changed

+75
-30
lines changed

8 files changed

+75
-30
lines changed

app/src/components/left/HTMLItem.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,14 @@ const HTMLItem : React.FC<{
119119
})
120120
);
121121
};
122-
122+
// Caret updated the id's to reflect the new element types input and label
123123
return ( // HTML Elements
124124
<Grid item xs={5} key={`html-g${name}`}>
125-
{ id <= 11 &&
125+
{ id <= 13 &&
126126
<div ref={drag} className={isThemeLight ? `${classes.HTMLPanelItem} ${classes.lightThemeFontColor}` : `${classes.HTMLPanelItem} ${classes.darkThemeFontColor}`} id="HTMLItem">
127127
<h3>{name}</h3>
128128
</div>}
129-
{id > 11 &&
129+
{id > 13 &&
130130
<span id="customHTMLElement">
131131
<div ref={drag} className={isThemeLight ? `${classes.HTMLPanelItem} ${classes.lightThemeFontColor}` : `${classes.HTMLPanelItem} ${classes.darkThemeFontColor}`} id="HTMLItem">
132132
<h3>{name}</h3>

app/src/components/main/DemoRender.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@ const DemoRender = (props): JSX.Element => {
2828
const innerText = element.attributes.compText;
2929
const classRender = element.attributes.cssClasses;
3030
let renderedChildren;
31-
if (element.children.length > 0) {
31+
if (elementType !== 'input' && elementType !== 'img' && element.children.length > 0) {
3232
renderedChildren = componentBuilder(element.children);
3333
}
34-
componentsToRender.push(<Box component={elementType} className={classRender} style={elementStyle} key={key} id={childId}>{innerText}{renderedChildren}</Box>);
34+
if (elementType === 'input' || elementType === 'img') componentsToRender.push(<Box component={elementType} className={classRender} style={elementStyle} key={key} id={childId}>{innerText}</Box>);
35+
else componentsToRender.push(<Box component={elementType} className={classRender} style={elementStyle} key={key} id={childId}>{innerText}{renderedChildren}</Box>);
3536
key += 1;
3637
}
3738
}

app/src/containers/RightContainer.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ const RightContainer = ({ isThemeLight }): JSX.Element => {
147147
focusTarget.child.style = focusChild.style;
148148
break;
149149
}
150-
currentChild.children.forEach(child => searchArray.push(child));
150+
// Caret Update
151+
if (currentChild.name !== 'input' && currentChild.name !== 'img') currentChild.children.forEach(child => searchArray.push(child));
151152
}
152153

153154
// if type is Component, use child's typeId to search through state components and find matching component's name

app/src/context/HTMLTypes.tsx

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,28 @@ const HTMLTypes: HTMLType[] = [
113113
id: 5,
114114
tag: 'span',
115115
name: 'Span',
116-
style: { fontSize: '1.5em' },
116+
style: { fontSize: '1em' },
117117
placeHolderShort: 'Span',
118118
placeHolderLong: '',
119119
icon: HeaderIcon
120+
},
121+
{
122+
id: 12,
123+
tag: 'input',
124+
name: 'Input',
125+
style: { fontSize: '1em' },
126+
placeHolderShort: 'Input',
127+
placeHolderLong: '',
128+
icon: HeaderIcon
129+
},
130+
{
131+
id: 13,
132+
tag: 'label',
133+
name: 'Label',
134+
style: { fontSize: '1em' },
135+
placeHolderShort: <label>Label</label>,
136+
placeHolderLong: '',
137+
icon: HeaderIcon
120138
}
121139
];
122140

app/src/helperFunctions/generateCode.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,19 @@ const generateUnformattedCode = (
9898
return `<${child.tag}${formatStyles(
9999
child.style
100100
)}>${writeNestedElements(child.children)}</${child.tag}>`;
101-
} else if (child.tag === 'p') {
101+
}
102+
// Caret Start
103+
else if (child.tag === 'input') {
104+
return `<${child.tag}${formatStyles(child.style)}>Input</${
105+
child.tag
106+
}>`;
107+
} else if (child.tag === 'label') {
108+
return `<${child.tag}${formatStyles(child.style)}>Label</${
109+
child.tag
110+
}>`;
111+
}
112+
// Caret End
113+
else if (child.tag === 'p') {
102114
return `<${child.tag}${formatStyles(
103115
child.style
104116
)}>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</${

app/src/helperFunctions/manageSeparators.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ manageSeparators.handleSeparators = (arr: object[], str: string) => {
3737
manageSeparators.nextTopSeparatorId += 1;
3838
}
3939
// check is length is > 0 or it is a nested element
40-
if (arr[index].children.length) {
40+
// Caret Update
41+
if ((arr[index].name !== 'input' && arr[index].name !== 'img') && arr[index].children.length) {
4142
// recursive call if children array
4243
(str === 'delete' || str === 'change position') ? manageSeparators.handleSeparators(arr[index].children, str) : manageSeparators.handleSeparators(arr[index].children);
4344
}

app/src/interfaces/Interfaces.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
nsimport { DragObjectWithType } from 'react-dnd';
1+
import { DragObjectWithType } from 'react-dnd';
22

33
export interface State {
44
name: string;

app/src/reducers/componentReducer.ts

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,17 @@ const reducer = (state: State, action: Action) => {
3333
// shift off the first value and assign to an element
3434
const currentNode = nodeArr.shift();
3535
// try to find id of childNode in children
36-
for (let i = 0; i <= currentNode.children.length - 1; i++) {
37-
// if match is found return object with both the parent and the index value of the child
38-
if (currentNode.children[i].childId === childId) {
39-
return { directParent: currentNode, childIndexValue: i };
36+
// Caret Update
37+
if (currentNode.name !== 'input' && currentNode.name !== 'img') {
38+
for (let i = 0; i <= currentNode.children.length - 1; i++) {
39+
// if match is found return object with both the parent and the index value of the child
40+
if (currentNode.children[i].childId === childId) {
41+
return { directParent: currentNode, childIndexValue: i };
42+
}
4043
}
44+
// if child node isn't found add each of the current node's children to the search array
45+
currentNode.children.forEach((node: ChildElement) => nodeArr.push(node));
4146
}
42-
// if child node isn't found add each of the current node's children to the search array
43-
currentNode.children.forEach((node: ChildElement) => nodeArr.push(node));
4447
}
4548
// if no search is found return -1
4649
return { directParent: null, childIndexValue: null };
@@ -84,7 +87,8 @@ const reducer = (state: State, action: Action) => {
8487
const currentNode = nodeArr.shift();
8588
if (currentNode.childId === childId) return currentNode;
8689
// if child node isn't found add each of the current node's children to the search array
87-
currentNode.children.forEach(node => nodeArr.push(node));
90+
// Caret Update
91+
if (currentNode.name !== 'input' && currentNode.name !== 'img') currentNode.children.forEach(node => nodeArr.push(node));
8892
}
8993
// if no match is found return false
9094
return;
@@ -309,6 +313,9 @@ const reducer = (state: State, action: Action) => {
309313

310314
// if the childId is null, this signifies that we are adding a child to the top-level component rather than another child element
311315
// we also add a separator before any new child
316+
// Caret Update if the newChild Element is an input or img type, delete the children key/value pair
317+
if (newChild.name === 'input' && newChild.name === 'img') delete newChild.children;
318+
312319
let directParent;
313320
if (childId === null) {
314321
parentComponent.children.push(topSeparator);
@@ -365,20 +372,25 @@ const reducer = (state: State, action: Action) => {
365372
component,
366373
currentChildId
367374
);
368-
369-
const child = { ...directParent.children[childIndexValue] };
370-
371-
directParent.children.splice(childIndexValue, 1);
372-
373-
// if the childId is null, this signifies that we are adding a child to the top level component rather than another child element
374-
if (newParentChildId === null) {
375-
component.children.push(child);
376-
}
377-
// if there is a childId (childId here references the direct parent of the new child) find that child and a new child to its children array
378-
else {
379-
const directParent = findChild(component, newParentChildId);
380-
directParent.children.push(child);
375+
// Caret start
376+
// BREAKING HERE during manipulation of positions. Sometimes get a null value when manipulating positions
377+
// Only run if the directParent exists
378+
if (directParent) {
379+
const child = { ...directParent.children[childIndexValue] };
380+
381+
directParent.children.splice(childIndexValue, 1);
382+
383+
// if the childId is null, this signifies that we are adding a child to the top level component rather than another child element
384+
if (newParentChildId === null) {
385+
component.children.push(child);
386+
}
387+
// if there is a childId (childId here references the direct parent of the new child) find that child and a new child to its children array
388+
else {
389+
const directParent = findChild(component, newParentChildId);
390+
directParent.children.push(child);
391+
}
381392
}
393+
// Caret End
382394

383395
let nextTopSeparatorId = state.nextTopSeparatorId;
384396

0 commit comments

Comments
 (0)