Skip to content

Commit

Permalink
chore(core): improve dnd
Browse files Browse the repository at this point in the history
  • Loading branch information
janryWang committed Oct 6, 2021
1 parent c419737 commit f59b65e
Showing 1 changed file with 48 additions and 10 deletions.
58 changes: 48 additions & 10 deletions packages/core/src/models/Dragon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { observable, define, action } from '@formily/reactive'
import {
calcDistanceOfPointToRect,
calcDistancePointToEdge,
isFn,
isNearAfter,
isPointInRect,
IPoint,
Expand Down Expand Up @@ -100,17 +99,39 @@ export class Dragon {
closestRect,
this.forceBlock ? false : isInline
)
const getValidParent = (node: TreeNode) => {
if (node.parent?.allowSibling(this.dragNodes)) return node.parent
return getValidParent(node.parent)
}
if (isPointInRect(point, closestRect, this.sensitive)) {
if (!closestNode.allowAppend(this.dragNodes)) {
if (!closestNode.allowSibling(this.dragNodes)) {
const parentClosestNode = getValidParent(this.closestNode)
if (parentClosestNode) {
this.closestNode = parentClosestNode
}
if (isInline) {
return isAfter
? ClosestPosition.ForbidAfter
: ClosestPosition.ForbidBefore
if (parentClosestNode) {
if (isAfter) {
return ClosestPosition.After
}
return ClosestPosition.Before
}
if (isAfter) {
return ClosestPosition.ForbidAfter
}
return ClosestPosition.ForbidBefore
} else {
return isAfter
? ClosestPosition.ForbidUnder
: ClosestPosition.ForbidUpper
if (parentClosestNode) {
if (isAfter) {
return ClosestPosition.Under
}
return ClosestPosition.Upper
}
if (isAfter) {
return ClosestPosition.ForbidUnder
}
return ClosestPosition.ForbidUpper
}
} else {
if (isInline) {
Expand All @@ -121,21 +142,38 @@ export class Dragon {
}
}
if (closestNode.contains(...this.dragNodes)) {
return isAfter
? ClosestPosition.InnerAfter
: ClosestPosition.InnerBefore
if (isAfter) {
return ClosestPosition.InnerAfter
}
return ClosestPosition.InnerBefore
} else {
return ClosestPosition.Inner
}
} else if (closestNode === closestNode.root) {
return isAfter ? ClosestPosition.InnerAfter : ClosestPosition.InnerBefore
} else {
if (!closestNode.allowSibling(this.dragNodes)) {
const parentClosestNode = getValidParent(this.closestNode)
if (parentClosestNode) {
this.closestNode = parentClosestNode
}
if (isInline) {
if (parentClosestNode) {
if (isAfter) {
return ClosestPosition.After
}
return ClosestPosition.Before
}
return isAfter
? ClosestPosition.ForbidAfter
: ClosestPosition.ForbidBefore
} else {
if (parentClosestNode) {
if (isAfter) {
return ClosestPosition.Under
}
return ClosestPosition.Upper
}
return isAfter
? ClosestPosition.ForbidUnder
: ClosestPosition.ForbidUpper
Expand Down

0 comments on commit f59b65e

Please sign in to comment.