Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use dom-align to position dnd container (#3978) #3979

Merged
merged 2 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/x6-plugin-dnd/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,8 @@
"publishConfig": {
"access": "public",
"registry": "https://registry.npmjs.org"
},
"dependencies": {
"dom-align": "^1.12.4"
}
}
46 changes: 22 additions & 24 deletions packages/x6-plugin-dnd/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
EventArgs,
} from '@antv/x6'
import { content } from './style/raw'
import { alignPoint } from 'dom-align'

export class Dnd extends View implements Graph.Plugin {
public name = 'dnd'
Expand Down Expand Up @@ -169,35 +170,32 @@ export class Dnd extends View implements Graph.Plugin {
}

protected updateGraphPosition(clientX: number, clientY: number) {
const scrollTop =
document.body.scrollTop || document.documentElement.scrollTop
const scrollLeft =
document.body.scrollLeft || document.documentElement.scrollLeft
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 + scrollLeft,
top: clientY - delta.y - nodeBBox.height / 2 - padding + scrollTop,
}
left: clientX - delta.x - nodeBBox.width / 2 - padding,
top: clientY - delta.y - nodeBBox.height / 2 - padding,
};

if (this.draggingGraph) {
if (this.options.draggingContainer) {
const { top, left } = Dom.offset(this.options.draggingContainer)
Dom.css(this.container, {
left: `${offset.left - left}px`,
top: `${offset.top - top}px`,
})
} else {
Dom.css(this.container, {
left: `${offset.left}px`,
top: `${offset.top}px`,
})
}
alignPoint(
this.container,
{
clientX: offset.left,
clientY: offset.top,
},
{
points: ['tl'],
},
);
}

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

protected updateNodePosition(x: number, y: number) {
const local = this.targetGraph.clientToLocal(x, y)
Expand Down
34 changes: 14 additions & 20 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading