Skip to content

fix: canvas drag and drop issue#1449

Merged
hexqi merged 4 commits intoopentiny:developfrom
chilingling:fix/canvasDndIssue
Jun 5, 2025
Merged

fix: canvas drag and drop issue#1449
hexqi merged 4 commits intoopentiny:developfrom
chilingling:fix/canvasDndIssue

Conversation

@chilingling
Copy link
Copy Markdown
Member

@chilingling chilingling commented May 29, 2025

  1. 修复从物料列表拖拽取消后,点击选中画布的节点,会导致选中的节点被移动到画布最后的 bug
  2. 修复往表格列插槽拖动时,有可能拖动节点到插槽的顶层,导致节点被插入到 TinyGrid children,导致表格显示的 bug。

English | 简体中文

PR

PR Checklist

Please check if your PR fulfills the following requirements:

  • The commit message follows our Commit Message Guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)
  • Built its own designer, fully self-validated

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

Background and solution

【问题描述】
bug1:物料拖拽不完全点击画布组件导致组件被移动到画布最后面的 bug

  • 从物料列表中,拖拽物料,但是不在画布释放,拖动到画布外进行释放(相当于没有完成拖拽过程)
  • 选中画布的组件
    问题:被选中的画布的组件,被移动到了画布的最后面。
2025-05-29.20.51.51.mov

bug2:拖拽组件到表格插槽可能会误拖拽到表格 children 的 bug

  • 拖入 TinyGrid 表格,开启表格列插槽
  • 拖入 div
  • 再往上一步拖入的 div 旁边拖入 div
  • 检查页面 schema,发现 schema 被插入到了 TinyGrid 的 children 中。
default.mov

【问题分析】

bug1:在左侧物料列表开启拖拽之后,会触发canvas的拖拽完成监听,但是如果拖拽过程回到了物料列表,或者是通过 esc 键进行释放,但是 canvas 的 mouseup 拖拽完成监听没有取消,等到下一次点击的时候,会误以为是拖拽完成事件,但是此时的参照组件为空,所以被意外移动到了画布最后面。

bug2:在构建表格列插槽的 NodesMap 的时候,表格列插槽是一个数组,他们的 parent 被设置成了 TinyGrid,如果拖拽到了与插槽数组同级的节点,会被误插件到 TinyGrid 的 children 中。

【修复方案】
bug1: dragItem 增加 dragEnd 监听事件,如果dragEnd 事件得到的 dataTransfer.dropEffect 值是 none,说明没有完成拖拽,此时手动触发 dragEnd 清理函数。
bug2:构建一个虚拟的 Template 节点,使得他们同级插入的时候,都被插入到正确的数组中。

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Summary by CodeRabbit

Summary by CodeRabbit

  • Bug Fixes
    • Improved drag-and-drop behavior in TinyGrid columns to prevent nodes from being incorrectly inserted directly into TinyGrid.
    • Enhanced insertion logic to ensure nodes are only inserted when a valid reference is available, reducing errors during drag-and-drop operations.
    • Added handling to properly reset drag state when drag operations end without a successful drop.

1. 修复从物料列表拖拽取消后,点击选中画布的节点,会导致选中的节点被移动到画布最后的 bug
2. 修复往表格列插槽拖动时,有可能拖动节点到插槽的顶层,导致节点被插入到 TinyGrid children,导致表格显示的 bug。
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 29, 2025

Walkthrough

The updates introduce a virtual Template node as a wrapper for TinyGrid column slot children in the canvas API, ensuring proper parent-child relationships during drag-and-drop operations. The container API now exposes a new dragEnd method. The CanvasDragItem component listens for the dragend event to call this method when a drag operation ends without a drop.

Changes

File(s) Change Summary
packages/canvas/DesignCanvas/src/api/useCanvas.ts Modified slot handling to wrap TinyGrid column slot children in a virtual Template node for drag-and-drop.
packages/canvas/container/src/container.ts Added dragEnd method to the exported canvasApi object.
packages/common/component/CanvasDragItem.vue Added dragend event handler to call canvasApi.dragEnd() if drag ends without a drop.

Poem

🐰 In grids where tiny columns play,
A Template hops to lead the way.
Dragging ends, no drop in sight,
The canvas clears, sets all things right.
With every move and gentle sway,
Rabbits cheer the code’s ballet! 🎨✨

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions Bot added the bug Something isn't working label May 29, 2025
@chilingling chilingling marked this pull request as ready for review May 29, 2025 12:49
@chilingling chilingling marked this pull request as draft May 29, 2025 13:16
@chilingling chilingling marked this pull request as ready for review May 30, 2025 02:15
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
packages/common/component/CanvasDragItem.vue (1)

33-38: Effective implementation for drag cancellation cleanup.

The dragend handler correctly identifies cancelled drag operations by checking if dropEffect === 'none' and appropriately calls the canvas API's cleanup method. This should resolve the issue where cancelled drags caused unexpected node movements.

Consider adding type annotation for the event parameter:

-    const dragend = (e) => {
+    const dragend = (e: DragEvent) => {
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c39f134 and 924be07.

📒 Files selected for processing (2)
  • packages/canvas/container/src/container.ts (1 hunks)
  • packages/common/component/CanvasDragItem.vue (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/canvas/container/src/container.ts
🔇 Additional comments (2)
packages/common/component/CanvasDragItem.vue (2)

2-2: LGTM! Proper dragend event handling added.

The addition of the @dragend="dragend" event listener correctly captures the end of drag operations, which is essential for handling cancelled drags as described in the PR objectives.


50-50: Correct function export for template binding.

The dragend function is properly exported in the setup return object, making it available for the template's event binding.

@chilingling chilingling added the ready_for_review This PR requires more reviews label May 30, 2025
@chilingling chilingling added this to the v2.6.0 milestone Jun 4, 2025
@hexqi hexqi merged commit 4a6cf0e into opentiny:develop Jun 5, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working ready_for_review This PR requires more reviews

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants