refact: getRect logic
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
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
- Enhancements
- Refined canvas interactions with smoother hover, selection, and drag-and-drop behavior.
- Improved event responsiveness for more accurate element state updates.
- Enhanced component mounting processes for better overall app performance.
[!IMPORTANT]
Review skipped
Draft detected.
Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.
Walkthrough
This PR updates several canvas modules by refining how hover states and node selections are handled. In the CanvasContainer component, mouse event handling has been modified to use a newly imported hover state. A set of helper functions and reactive variables is added in the component-selection module to support Vue component detection and bounding rectangle computations. Additionally, container logic and event handling in drag-and-drop operations are updated to better integrate the new hover state functions. The Vue application initialization is also enhanced with a new mixin that attaches component instances to DOM elements.
Changes
| File(s) | Change Summary |
|---|---|
| packages/.../CanvasContainer.vue | Updated event handling in the setup function by replacing commented logic with use of currentHoverNode and calling updateHoverNode(ev) on mouseover; streamlined hover state management. |
| packages/.../component-selection.js | Added functions (getClosedVueElement, getElement, getTextRect, createRect, mergeRects, getFragmentRect, getElementRect) and reactive variables (currentHoverInstance, currentHoverRect, currentHoverNode) to manage Vue components and hover states; introduced updateHoverNode(e). |
| packages/.../container.js | Modified setSelectRect and selectNode to accept an instance parameter; updated dragMove to use updateLineState instead of direct hover state setting; exported getElement from component-selection. |
| packages/.../render/src/render.ts | Commented out the assignment of the onMouseover event in getBindProps while retaining onFocus and onClickCapture functions. |
| packages/.../render/src/runner.ts | Introduced the GetComponentByDomNode object with an install method that attaches Vue components to the DOM via a mixin; updated the Vue app creation to use this new mixin alongside TinyI18nHost. |
Sequence Diagram(s)
sequenceDiagram
participant User
participant CanvasContainer
participant CompSel
participant VueState
User->>CanvasContainer: Mouseover event
CanvasContainer->>CompSel: updateHoverNode(event)
CompSel->>VueState: Update currentHoverNode, currentHoverInstance, currentHoverRect
VueState-->>CanvasContainer: Return updated hover state
sequenceDiagram
participant AppCreator
participant VueApp
participant GetComponentByDomNode
participant TinyI18nHost
AppCreator->>VueApp: createApp(Main)
VueApp->>GetComponentByDomNode: Install mixin
GetComponentByDomNode->>VueApp: Attach __vueComponent on mount
VueApp->>TinyI18nHost: Use translation host
Possibly related PRs
- opentiny/tiny-engine#956: Modifications related to managing canvas interactions using
currentHoverNodeandupdateHoverNode. - opentiny/tiny-engine#576: Updates in the CanvasContainer component focusing on hover state management using similar reactive variables.
- opentiny/tiny-engine#1117: Involves hover state updates in the CanvasContainer, aligning with the current changes in node handling.
Suggested labels
enhancement, refactor-main
Suggested reviewers
- hexqi
- rhlin
Poem
I'm a rabbit coding through the night,
Hopscotching with functions shining bright.
With hover states and mixins in tow,
My paws update the code as I go.
Celebrate these changes, leaping free—
A joyful PR made just for me! 🐰🌟
🪧 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.Generate unit testing code for this file.Open a follow-up GitHub issue for this discussion.
- Files and specific lines of code (under the "Files changed" tab): Tag
@coderabbitaiin a new review comment at the desired location with your query. Examples:@coderabbitai generate unit testing code for this file.@coderabbitai modularize this function.
- PR comments: Tag
@coderabbitaiin 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 generate unit testing code.@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.
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 pauseto pause the reviews on a PR.@coderabbitai resumeto resume the paused reviews.@coderabbitai reviewto trigger an incremental review. This is useful when automatic reviews are disabled for the repository.@coderabbitai full reviewto do a full review from scratch and review all the files again.@coderabbitai summaryto regenerate the summary of the PR.@coderabbitai generate docstringsto generate docstrings for this PR.@coderabbitai resolveresolve all the CodeRabbit review comments.@coderabbitai configurationto show the current CodeRabbit configuration for the repository.@coderabbitai helpto get help.
Other keywords and placeholders
- Add
@coderabbitai ignoreanywhere in the PR description to prevent this PR from being reviewed. - Add
@coderabbitai summaryto generate the high-level summary at a specific location in the PR description. - Add
@coderabbitaianywhere in the PR title to generate the title automatically.
CodeRabbit Configuration File (.coderabbit.yaml)
- You can programmatically configure CodeRabbit by adding a
.coderabbit.yamlfile 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.