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

plugin-dnd 配置了 draggingContainer 后,最新代码计算位置仍有偏差 #3978

Closed
cyrilluce opened this issue Oct 17, 2023 · 0 comments · Fixed by #3979
Closed

plugin-dnd 配置了 draggingContainer 后,最新代码计算位置仍有偏差 #3978

cyrilluce opened this issue Oct 17, 2023 · 0 comments · Fixed by #3979

Comments

@cyrilluce
Copy link
Contributor

Describe the bug

之前的issue: #3873 以及相关修改: #3953

draggingContainer 没有设置 position 时(即默认的position:static),这里错误的减掉了draggingContainer的偏移;
另外,当 draggingContainer 或其它上层容器有滚动条时,也没有正确计算进去

Your Example Website or App

Steps to Reproduce the Bug or Issue

Expected behavior

Screenshots or Videos

No response

Platform

  • OS: [e.g. macOS, Windows, Linux]
  • Browser: [e.g. Chrome, Safari, Firefox]
  • Version: [e.g. 2.11.1]

Additional context

看了下 ant-design-vue,使用的是 dom-align 库进行对齐计算的,它会处理各层容器的scroll、position等

附上使用dom-align修复方案作参考

export default class MyDndPlugin extends Dnd {
    protected updateGraphPosition(clientX: number, clientY: number) {
        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,
        };

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

        // TODO 原组件目前没有使用这个返回值(代码注释掉了)
        // 而 dom-align 又没有返回计算后的top/left值
        // 考虑干掉?
        return offset;
    }
}
cyrilluce pushed a commit to cyrilluce/X6 that referenced this issue Oct 17, 2023
NewByVector pushed a commit that referenced this issue Nov 3, 2023
* fix: use `dom-align` to position dnd container (#3978)

* fix: Remove unused `originOffset` in plugin-dnd

---------

Co-authored-by: cluezhang <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant