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

Dnd插件一定要clone吗 #4169

Closed
America-first-melon opened this issue Jan 19, 2024 · 5 comments
Closed

Dnd插件一定要clone吗 #4169

America-first-melon opened this issue Jan 19, 2024 · 5 comments
Labels
type: discussion 讨论 Usage questions, guidance, and other discussions

Comments

@America-first-melon
Copy link

America-first-melon commented Jan 19, 2024

Describe the bug

dnd 一定要 clone 吗?

场景: 拖动前与拖动后的attr样式不一致,getDropNode 后需要修改 attrs

// 示例没有问题。
const dnd = new Addon.Dnd({
  getDropNode(node) {
    const { width, height } = node.size()
    // 返回一个新的节点作为实际放置到画布上的节点
    return node.clone().size(width * 3, height * 3)
  },
})
// 这样写没有作用,必须clone后replaceAttrs才有作用
const dnd = new Addon.Dnd({
  getDropNode(node) {
    node.replaceAttrs({})
    return node
  },
})

Your Example Website or App

null

Steps to Reproduce the Bug or Issue

null

Expected behavior

null

Screenshots or Videos

null

Platform

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

Additional context

null

@NewByVector
Copy link
Contributor

是的,需要 clone 一份的。

@NewByVector NewByVector added the type: discussion 讨论 Usage questions, guidance, and other discussions label Jan 24, 2024
@America-first-melon
Copy link
Author

dndStart 之前的 createNode 就是在生成新的 Node 了,getDropNode 的时候又使用 cloneNode, 忽然感觉前面的createNode没有了Node作用,只是作为一个拖动的形状(但是却又生成了图形Node)。

不知道这样理解是否偏差了。

我这里拖动的图形数据非常大,携带的data,如果json格式有时候几百K,所以drop的时候不是太想再clone一遍,目前已经通过其他方式处理了。

@NewByVector
Copy link
Contributor

getDragNode: 返回拖拽过程中的节点,可以是任意节点,默认是 clone 原始节点。
getDropNode: 返回放置到画布的节点,可以是任意节点,默认是 clone 拖拽节点。

@America-first-melon
Copy link
Author

getDragNode: 返回拖拽过程中的节点,可以是任意节点,默认是 clone 原始节点。 getDropNode: 返回放置到画布的节点,可以是任意节点,默认是 clone 拖拽节点。

close了,api clone 只是默认行为,也支持自定义控制,已经处理了。
感谢。

@x6-bot
Copy link
Contributor

x6-bot bot commented Jan 24, 2025

This thread has been automatically locked because it has not had recent activity.

Please open a new issue for related bugs and link to relevant comments in this thread.

@x6-bot x6-bot bot locked as resolved and limited conversation to collaborators Jan 24, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: discussion 讨论 Usage questions, guidance, and other discussions
Projects
None yet
Development

No branches or pull requests

2 participants