-
-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from MadinventorZero/bugbusting
Fixed several bugs. Details in PR.
- Loading branch information
Showing
6 changed files
with
67 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// 100% Caret | ||
// This function will evaluate the target destination when moving an element on the canvas | ||
// If the target destination is actually a nested component within its own children array | ||
// the new target parent is not a valid parent to change position | ||
const validateNewParent = (state: object, currentChildId: number, toTargetParentId: number) => { | ||
const focusIndex = state.canvasFocus.componentId - 1; | ||
const childrenArray = state.components[focusIndex].children; | ||
// Checks to see if a Parent is trying to nest inside one of its children | ||
const selfNestingCheck = (array, nestedChild = false, nestedParent = false) => { | ||
for (const element of array) { | ||
if (element.childId === toTargetParentId && nestedChild === true) return nestedParent = true; | ||
else if (element.childId === currentChildId && element.children.length > 0 && nestedChild === false) nestedParent = selfNestingCheck(element.children, nestedChild = true, nestedParent); | ||
else if (element.children.length > 0 && nestedChild === false) nestedParent = selfNestingCheck(element.children, nestedChild, nestedParent); | ||
} | ||
return nestedParent; | ||
} | ||
const parentNestingIntoChild = selfNestingCheck(childrenArray); | ||
console.log("Is a Parent trying to nest inside one of it's children? True fails, False passes,", parentNestingIntoChild); | ||
if (parentNestingIntoChild === true) return false; | ||
return true; | ||
}; | ||
|
||
export default validateNewParent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters