-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
80 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { TreeController } from "../controllers/tree-controller"; | ||
|
||
export function safeToDrop(tree: TreeController<any>) { | ||
const targetParentNode = tree.dropTargetParentNode; | ||
const targetIndex = tree.dropTargetIndex; | ||
const dragNodes = tree.dragNodes; | ||
|
||
/* Basic Defaul Check */ | ||
if (targetParentNode === null && targetIndex === null) return false; | ||
|
||
for (const draggingNode of tree.dragNodes) { | ||
if ( | ||
draggingNode.isInternal && | ||
targetParentNode?.isDescendantOf(draggingNode) | ||
) { | ||
return false; | ||
} | ||
} | ||
|
||
/* User Provided Check */ | ||
const disableCheck = tree.props.disableDrop; | ||
if (typeof disableCheck == "function") { | ||
return !disableCheck({ dragNodes, targetParentNode, targetIndex }); | ||
} else if (typeof disableCheck == "string" && targetParentNode) { | ||
return !targetParentNode.data[disableCheck]; | ||
} else if (typeof disableCheck === "boolean") { | ||
return !disableCheck; | ||
} else { | ||
return true; | ||
} | ||
} |
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