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: drag handle scrolling fixed #5619

Merged
merged 4 commits into from
Oct 8, 2024
Merged

fix: drag handle scrolling fixed #5619

merged 4 commits into from
Oct 8, 2024

Conversation

Palanikannan1437
Copy link
Collaborator

@Palanikannan1437 Palanikannan1437 commented Sep 16, 2024

Description

Added dynamic scrolling in Pages such that you could scroll easily while dragging and dropping nodes.

Summary by CodeRabbit

  • New Features
    • Enhanced drag-and-drop functionality with improved scrolling behavior when dragging elements.
    • Exported new utility functions for identifying scrollable elements and handling drag events more effectively.
  • Improvements
    • Adjusted scrolling thresholds in the side menu for a more responsive user experience.
    • Minor code adjustments for better clarity and performance.

Copy link
Contributor

coderabbitai bot commented Sep 16, 2024

Walkthrough

The pull request modifies the SideMenuExtension in the side-menu.tsx file by changing the upward scrollThreshold from 300 to 200. In the drag-handle.ts file, it exports the nodeDOMAtCoords function to enhance drag-and-drop functionality, allowing for the identification of various node types. Additionally, new utility functions for scroll detection are introduced, improving the drag experience. Minor adjustments include the removal of unused variables and added comments, while maintaining the overall structure and responsiveness.

Changes

File Path Change Summary
packages/editor/src/core/extensions/side-menu.tsx Adjusted scrollThreshold for upward scrolling from 300 to 200.
packages/editor/src/core/plugins/drag-handle.ts Exported nodeDOMAtCoords function; added isScrollable and getScrollParent functions; modified drag handling logic for improved scrolling behavior. Removed unused variable and added comments.

Possibly related PRs

Suggested labels

🐛bug, 🌐frontend

Suggested reviewers

  • SatishGandham
  • aaryan610

Poem

In the editor's cozy den,
The side menu scrolls again.
With drag and drop, it glides so free,
A smoother path for you and me.
Hops and jumps, a joyful spree,
Thanks to changes, let it be! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • 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 @coderabbitai in 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 @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 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 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 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.

@Palanikannan1437 Palanikannan1437 self-assigned this Oct 3, 2024
@Palanikannan1437 Palanikannan1437 marked this pull request as ready for review October 3, 2024 12:23
Copy link
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: 1

🧹 Outside diff range and nitpick comments (1)
packages/editor/src/core/extensions/side-menu.tsx (1)

45-45: LGTM. Consider adding a comment explaining the change.

The reduction of the scrollThreshold.up value from 300 to 200 aligns with the PR objective of fixing drag handle scrolling. This change should make the side menu more responsive to upward scrolls.

Could you provide more context on why 200 was chosen as the new threshold? Consider adding a brief comment explaining the rationale behind this specific value to improve maintainability.

For example:

scrollThreshold: { 
  up: 200, // Reduced from 300 to improve responsiveness to upward scrolls
  down: 100 
},
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 8533eba and ea8e17a.

📒 Files selected for processing (2)
  • packages/editor/src/core/extensions/side-menu.tsx (1 hunks)
  • packages/editor/src/core/plugins/drag-handle.ts (2 hunks)
🔇 Additional comments (3)
packages/editor/src/core/plugins/drag-handle.ts (3)

44-45: Addition of selectors for image components is appropriate

The inclusion of .image-component and .image-upload-component in the generalSelectors array enhances the functionality to correctly identify image nodes at specific coordinates.


236-245: isScrollable function correctly determines scrollable elements

The implementation of isScrollable effectively checks if an element is scrollable by examining the overflow and overflow-y CSS properties.


267-276: ⚠️ Potential issue

Use scrollable parent's dimensions instead of window.innerHeight

When calculating scroll thresholds for scrolling, using window.innerHeight may lead to incorrect behavior if the scrollableParent is not the window. To ensure accurate scrolling within nested scrollable containers, use the dimensions of scrollableParent.

Apply this diff to use scrollableParent.getBoundingClientRect():

267           if (e.clientY < scrollThreshold.up) {
268             const overflow = scrollThreshold.up - e.clientY;
269             const ratio = Math.min(overflow / scrollThreshold.up, 1);
270             const scrollAmount = -maxScrollSpeed * ratio;
271             scrollableParent.scrollBy({ top: scrollAmount });
272           } else if (scrollableParent.getBoundingClientRect().bottom - e.clientY < scrollThreshold.down) {
273             const overflow = e.clientY - (scrollableParent.getBoundingClientRect().bottom - scrollThreshold.down);
274             const ratio = Math.min(overflow / scrollThreshold.down, 1);
275             const scrollAmount = maxScrollSpeed * ratio;
276             scrollableParent.scrollBy({ top: scrollAmount });

To ensure this change works correctly, please verify the scroll behavior within nested scrollable elements.

packages/editor/src/core/plugins/drag-handle.ts Outdated Show resolved Hide resolved
Copy link
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

🧹 Outside diff range and nitpick comments (2)
packages/editor/src/core/plugins/drag-handle.ts (2)

236-245: Well-implemented isScrollable function

The isScrollable function is a good addition:

  1. It correctly checks both overflow and overflow-y properties.
  2. The type check at the beginning ensures type safety.

For a minor optimization, consider using Array.prototype.some() instead of checking each property individually:

return ["overflow", "overflow-y"].some(prop => 
  ["auto", "scroll"].includes(style.getPropertyValue(prop))
);

This change would make the function slightly more concise and efficient.


258-275: Improved drag event handling with dynamic scrolling

The changes to the drag event listener significantly enhance the drag-and-drop functionality:

  1. The use of getScrollParent ensures scrolling works correctly in nested scrollable containers.
  2. The implementation handles both upward and downward scrolling smoothly.
  3. The scrolling speed is dynamically adjusted based on the cursor's proximity to the viewport edge, providing a natural feel.

To improve code readability, consider extracting the scrolling logic into a separate function:

const handleScroll = (clientY: number, scrollableParent: Element) => {
  const { innerHeight } = window;
  const { up, down } = options.scrollThreshold;

  if (clientY < up) {
    const ratio = Math.min((up - clientY) / up, 1);
    scrollableParent.scrollBy({ top: -maxScrollSpeed * ratio });
  } else if (innerHeight - clientY < down) {
    const ratio = Math.min((clientY - (innerHeight - down)) / down, 1);
    scrollableParent.scrollBy({ top: maxScrollSpeed * ratio });
  }
};

// In the drag event listener:
handleScroll(e.clientY, scrollableParent);

This refactoring would make the main drag event listener more concise and easier to understand.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between ea8e17a and 10ce567.

📒 Files selected for processing (2)
  • packages/editor/src/core/extensions/side-menu.tsx (1 hunks)
  • packages/editor/src/core/plugins/drag-handle.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/editor/src/core/extensions/side-menu.tsx
🔇 Additional comments (4)
packages/editor/src/core/plugins/drag-handle.ts (4)

33-45: Improved nodeDOMAtCoords function with extended functionality

The changes to the nodeDOMAtCoords function are well-implemented:

  1. Exporting the function enhances its reusability across the codebase.
  2. The addition of .image-component and .image-upload-component selectors extends the function's capability to identify image-related components, which is likely beneficial for drag-and-drop operations involving images.

These improvements contribute to a more versatile and robust drag-and-drop system.


247-256: Well-implemented getScrollParent function

The getScrollParent function is a valuable addition:

  1. It efficiently traverses the DOM tree to find the nearest scrollable parent.
  2. The function correctly uses the isScrollable helper function.
  3. The fallback to document.scrollingElement or document.documentElement ensures a valid scrollable element is always returned.

This function will be crucial for implementing smooth scrolling behavior during drag operations.


251-251: Removal of console.log statement

The removal of the console.log statement is appropriate:

  1. It eliminates unnecessary logging in production code.
  2. This change addresses the previous review comment suggesting its removal.

Good job on maintaining clean code by removing debugging statements.


Line range hint 1-365: Overall assessment: Significant improvements to drag-and-drop functionality

This pull request introduces valuable enhancements to the drag-and-drop functionality:

  1. The nodeDOMAtCoords function has been expanded to handle image components.
  2. New utility functions isScrollable and getScrollParent have been added, improving the code's ability to handle scrollable containers.
  3. The drag event handling now includes dynamic scrolling, greatly improving the user experience when dragging elements near viewport edges.
  4. Debugging code has been removed, keeping the production code clean.

These changes collectively contribute to a more robust, user-friendly drag-and-drop system. The code is well-structured and thoughtfully implemented. Minor suggestions for optimization and readability have been provided in the individual comments.

Great work on this feature enhancement!

@pushya22 pushya22 merged commit 5fb7e98 into preview Oct 8, 2024
13 of 15 checks passed
@pushya22 pushya22 deleted the fix/drag-drop-scrolling branch October 8, 2024 11:14
@sriramveeraghanta sriramveeraghanta added this to the v0.24.0 milestone Oct 8, 2024
sriramveeraghanta pushed a commit that referenced this pull request Oct 10, 2024
* fix: drag handle scrolling fixed

* fix: closest scrollable parent found and scrolled

* fix: removed overflow auto from framerenderer

* fix: make dragging dynamic and smoother
@sriramveeraghanta sriramveeraghanta modified the milestones: v0.24.0, v0.23.1 Oct 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants