Skip to content

Commit

Permalink
fix: 馃悰 dnd with snapline
Browse files Browse the repository at this point in the history
  • Loading branch information
bubkoo committed Aug 12, 2020
1 parent 343ea4f commit 634b9fb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
26 changes: 14 additions & 12 deletions packages/x6/src/addon/dnd/index.ts
Expand Up @@ -74,9 +74,8 @@ export class Dnd extends View {
this.prepareDragging(node, e.clientX, e.clientY)

const local = this.updateNodePosition(e.clientX, e.clientY)
const snapline = this.snapline
if (snapline) {
snapline.captureCursorOffset({
if (this.isSnaplineEnabled()) {
this.snapline.captureCursorOffset({
e,
node,
cell: node,
Expand All @@ -90,18 +89,21 @@ export class Dnd extends View {
this.delegateDocumentEvents(Dnd.documentEvents, e.data)
}

protected isSnaplineEnabled() {
return this.snapline && !this.snapline.disabled
}

protected prepareDragging(node: Node, clientX: number, clientY: number) {
const delegateGraph = this.delegateGraph
const delegateModel = delegateGraph.model
const delegateNode = this.options.getDragNode(node).position(0, 0)

let padding = 5
const snapline = this.snapline
if (snapline) {
padding += snapline.options.tolerance || 0
if (this.isSnaplineEnabled()) {
padding += this.snapline.options.tolerance || 0
}

if (snapline || this.options.scaled) {
if (this.isSnaplineEnabled() || this.options.scaled) {
const scale = this.targetGraph.scale()
delegateGraph.scale(scale.sx, scale.sy)
padding *= Math.max(scale.sx, scale.sy)
Expand Down Expand Up @@ -193,10 +195,9 @@ export class Dnd extends View {

this.updateGraphPosition(clientX, clientY)
const local = this.updateNodePosition(clientX, clientY)
const snapline = this.snapline
const embeddingMode = this.targetGraph.options.embedding.enabled
const isValidArea =
(embeddingMode || snapline) &&
(embeddingMode || this.isSnaplineEnabled()) &&
this.isInsideValidArea({
x: clientX,
y: clientY,
Expand All @@ -212,16 +213,17 @@ export class Dnd extends View {
}
}

if (snapline) {
// update snapline
if (this.isSnaplineEnabled()) {
if (isValidArea) {
snapline.snapOnMoving({
this.snapline.snapOnMoving({
e,
view: draggingView!,
x: local.x,
y: local.y,
} as EventArgs['node:mousemove'])
} else {
snapline.hide()
this.snapline.hide()
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/x6/src/global/version.ts
Expand Up @@ -3,5 +3,5 @@
/**
* Auto generated version file, do not modify it!
*/
const version = '0.10.46'
const version = '0.10.47'
export { version }

0 comments on commit 634b9fb

Please sign in to comment.