Skip to content

Commit

Permalink
fix: Remove unused originOffset in plugin-dnd
Browse files Browse the repository at this point in the history
  • Loading branch information
cluezhang committed Oct 25, 2023
1 parent e23d877 commit 984ee57
Showing 1 changed file with 19 additions and 26 deletions.
45 changes: 19 additions & 26 deletions packages/x6-plugin-dnd/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import {
Graph,
EventArgs,
} from '@antv/x6'
import { content } from './style/raw'
import { alignPoint } from 'dom-align'
import { content } from './style/raw'

export class Dnd extends View implements Graph.Plugin {
public name = 'dnd'
Expand All @@ -27,7 +27,6 @@ export class Dnd extends View implements Graph.Plugin {
protected delta: Point | null
protected padding: number | null
protected snapOffset: Point.PointLike | null
protected originOffset: null | { left: number; top: number }

public options: Dnd.Options
public draggingGraph: Graph
Expand Down Expand Up @@ -166,36 +165,31 @@ export class Dnd extends View implements Graph.Plugin {
this.draggingView = delegateView
this.draggingBBox = draggingNode.getBBox()
this.padding = padding
this.originOffset = this.updateGraphPosition(clientX, clientY)
this.updateGraphPosition(clientX, clientY)
}

protected updateGraphPosition(clientX: number, clientY: number) {
const delta = this.delta!;
const nodeBBox = this.geometryBBox;
const padding = this.padding || 5;
const delta = this.delta!
const nodeBBox = this.geometryBBox
const padding = this.padding || 5
const offset = {
left: clientX - delta.x - nodeBBox.width / 2 - padding,
top: clientY - delta.y - nodeBBox.height / 2 - padding,
};
left: clientX - delta.x - nodeBBox.width / 2 - padding,
top: clientY - delta.y - nodeBBox.height / 2 - padding,
}

if (this.draggingGraph) {
alignPoint(
this.container,
{
clientX: offset.left,
clientY: offset.top,
},
{
points: ['tl'],
},
);
alignPoint(
this.container,
{
clientX: offset.left,
clientY: offset.top,
},
{
points: ['tl'],
},
)
}

// TODO 原组件目前没有使用这个返回值(代码注释掉了)
// 而 dom-align 又没有返回计算后的top/left值
// 考虑干掉?
return offset;
}
}

protected updateNodePosition(x: number, y: number) {
const local = this.targetGraph.clientToLocal(x, y)
Expand Down Expand Up @@ -331,7 +325,6 @@ export class Dnd extends View implements Graph.Plugin {
this.delta = null
this.padding = null
this.snapOffset = null
this.originOffset = null
this.undelegateDocumentEvents()
}
}
Expand Down

0 comments on commit 984ee57

Please sign in to comment.