Skip to content

Commit b3085de

Browse files
committed
working on separators
1 parent 916173e commit b3085de

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

app/src/helperFunctions/manageSeparators.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ const separator = {
1414
const manageSeparators: ManageSeparators = {
1515
nextTopSeparatorId: 1000,
1616
// this function checks for two separators in a row or missing separators and adds/removes as needed
17-
handleSeparators: (arr, str) => {
17+
handleSeparators: (arr: ChildElement[], str?) => {
1818
if (
1919
(str === 'delete' || str === 'change position') &&
2020
arr.length === 1 &&
21-
arr.slice(0,1).name === 'separator'
21+
arr[0].name === 'separator'
2222
) {
2323
arr.splice(0, 1);
2424
}
@@ -44,7 +44,12 @@ const manageSeparators: ManageSeparators = {
4444
name: 'separator',
4545
childId: manageSeparators.nextTopSeparatorId,
4646
style: separator.style,
47-
children: []
47+
attributes: {}, // Added
48+
events: {}, // Added
49+
stateProps: [], // Added
50+
passedInProps: [], // Added
51+
children: [],
52+
4853
};
4954
// add a topSeparator before the element that does not have one
5055
arr.splice(index, 0, topSeparator);
@@ -55,7 +60,7 @@ const manageSeparators: ManageSeparators = {
5560
if (
5661
arr[index].name !== 'input' &&
5762
arr[index].name !== 'img' &&
58-
arr[index].children.length
63+
arr[index].children?.length
5964
) {
6065
// recursive call if children array
6166
str === 'delete' || str === 'change position'
@@ -67,22 +72,22 @@ const manageSeparators: ManageSeparators = {
6772
},
6873

6974
// this function replaces separators onto which an element is dropped with the element itself
70-
mergeSeparator: (arr: object[], index: number) => {
75+
mergeSeparator: (arr: ChildElement[], index: number) => {
7176
return arr.map((child) => {
7277
// Added additional nested types for lists
7378
if (
7479
(child.name === 'div' ||
75-
child.name === 'form' ||
76-
child.name === 'ol' ||
77-
child.name === 'ul') &&
78-
child.children.length
80+
child.name === 'form' ||
81+
child.name === 'ol' ||
82+
child.name === 'ul') &&
83+
child?.children?.length
7984
) {
8085
const divContents = manageSeparators.mergeSeparator(
8186
child.children,
8287
index
83-
);
88+
)
8489
return { ...child, children: divContents };
85-
} else if (child.name === 'separator' && child.children.length) {
90+
} else if (child.name === 'separator' && child?.children?.length) {
8691
return child.children[index];
8792
} else return child;
8893
});

0 commit comments

Comments
 (0)