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

address two rich text editor bugs #210

Merged
merged 3 commits into from
Oct 12, 2024

Conversation

Southclaws
Copy link
Owner

@Southclaws Southclaws commented Oct 12, 2024

  • file upload input id non-unique so inserts into the wrong editor instance
  • menu positioning broken

…ges being uploaded to the wrong editor instance
Copy link

vercel bot commented Oct 12, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
storyden ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 12, 2024 3:44pm
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
storyden-homepage ⬜️ Ignored (Inspect) Visit Preview Oct 12, 2024 3:44pm

Copy link

coderabbitai bot commented Oct 12, 2024

Caution

Review failed

The head commit changed during the review from 6425b52 to 3429a4e.

📝 Walkthrough
📝 Walkthrough

Walkthrough

The pull request introduces updates to the ContentComposer component and its associated useContentComposer hook, adding a uniqueID property for generating unique identifiers for various elements. This change enhances the management of multiple component instances. Additionally, the FloatingMenuView class and FloatingMenu component are modified to improve the positioning logic of the floating menu based on the caret's position in the editor.

Changes

File Change Summary
web/src/components/content/ContentComposer/ContentComposer.tsx Added uniqueID property to useContentComposer hook for unique ID generation in various elements.
web/src/components/content/ContentComposer/useContentComposer.ts Introduced useId and useMemo hooks; created uniqueID for file upload input; ensured editor initializes correctly.
web/src/components/content/ContentComposer/plugins/MenuPlugin.tsx Enhanced FloatingMenuView positioning logic; simplified offsetY calculation and introduced offsetX.

Possibly related PRs

  • upgrade tiptap/prosemirror to v2.8.0 #197: The changes in this PR also involve the useContentComposer function, which is directly related to the modifications made in the main PR regarding the useContentComposer hook.

Poem

In the garden where we play,
Unique IDs lead the way.
Floating menus dance with glee,
As changes bloom, so joyfully!
Hops and skips, let’s celebrate,
With every click, we elevate! 🐇✨


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.

Copy link

@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 (3)
web/src/components/content/ContentComposer/useContentComposer.ts (3)

9-9: LGTM, but consider removing unused import.

The addition of useId is appropriate for the new uniqueID functionality. However, useMemo is imported but not used in the visible changes.

Consider removing the useMemo import if it's not needed, or comment on its intended use if it will be used in future changes.


71-71: LGTM: Good use of data-editor-id attribute.

The addition of the data-editor-id attribute with the uniqueID value is a good way to uniquely identify each editor instance. This will be helpful for targeting specific editor instances in JavaScript or CSS.

For consistency with React naming conventions, consider using camelCase for the data attribute name: data-editorId.


198-198: LGTM: Exposing uniqueID in the return object.

Adding uniqueID to the returned object is a good way to make this value available to consumers of the hook. This can be useful for components that need to reference the specific editor instance.

Consider adding a comment or updating the function's JSDoc to document this new return value, explaining its purpose and potential uses.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 679e71b and 2bf0eed.

📒 Files selected for processing (3)
  • web/src/components/content/ContentComposer/ContentComposer.tsx (3 hunks)
  • web/src/components/content/ContentComposer/plugins/MenuPlugin.tsx (1 hunks)
  • web/src/components/content/ContentComposer/useContentComposer.ts (3 hunks)
🧰 Additional context used
🔇 Additional comments (7)
web/src/components/content/ContentComposer/ContentComposer.tsx (5)

35-36: LGTM: Addition of uniqueID to destructured properties

The inclusion of uniqueID in the destructured properties from useContentComposer is a good addition. This will allow for unique identification of multiple ContentComposer instances, improving the component's flexibility and reusability.


40-40: LGTM: Unique ID for LStack component

The addition of uniqueID to the id attribute of the LStack component is a good practice. It ensures that each instance of the ContentComposer has a unique identifier for its container, which can be useful for styling, scripting, or accessibility purposes.


Line range hint 200-210: LGTM: Unique IDs for file input and label

The addition of uniqueID to both the htmlFor attribute of the label and the id attribute of the file input is a good practice. This ensures that:

  1. Each instance of the ContentComposer has a unique file input.
  2. The label is correctly associated with its corresponding input, maintaining accessibility.

These changes improve the component's ability to handle multiple instances without ID conflicts.


Line range hint 218-224: LGTM: Unique ID for EditorContent component

The addition of uniqueID to the id attribute of the EditorContent component is a good practice. It ensures that each instance of the ContentComposer has a unique identifier for its editor content, which can be beneficial for:

  1. Styling specific editor instances
  2. Scripting or event handling tied to specific editors
  3. Improved debugging and error reporting

This change aligns well with the overall approach of using unique identifiers throughout the component.


Line range hint 35-224: Overall changes look good, consider verifying uniqueID generation

The changes to incorporate uniqueID throughout the ContentComposer component are consistent and well-implemented. They improve the component's ability to handle multiple instances without ID conflicts, which is crucial for larger applications.

To ensure the robustness of this implementation:

  1. Verify that the uniqueID is properly generated and passed down from the parent component or generated within useContentComposer.
  2. Consider adding a prop type check or default value for uniqueID to handle cases where it might not be provided.

To verify the uniqueID generation and usage, you can run the following script:

This script will help ensure that uniqueID is properly handled throughout the related components.

web/src/components/content/ContentComposer/useContentComposer.ts (2)

64-66: LGTM: Good use of useId() for unique identification.

The addition of uniqueID using useId() is a good practice for generating stable, unique identifiers. The comment clearly explains its purpose for the menu's file upload input ID.


Line range hint 1-258: Overall assessment: Good improvements for multi-instance support.

The changes in this file enhance the useContentComposer hook by adding unique identification for each editor instance. This is a valuable improvement for scenarios where multiple editors might be used on the same page. The implementation is clean and follows React best practices.

Key points:

  1. Good use of useId() for generating stable, unique identifiers.
  2. Proper application of the unique ID to the editor's attributes.
  3. Exposing the uniqueID in the hook's return object for flexibility.

These changes will facilitate better management and targeting of individual editor instances, improving the overall functionality and maintainability of the component.

Comment on lines 117 to 118
const offsetY = caretY + 16;
const offsetX = containerLeft;
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider aligning the floating menu horizontally with the caret position

Currently, offsetX is set to containerLeft, which positions the floating menu at the left edge of the editor. This may result in the menu appearing far from the caret when it's located towards the right side of the editor, potentially leading to a less intuitive user experience.

To improve usability, consider aligning the menu horizontally with the caret's position by using caretX instead of containerLeft.

Apply the following changes:

 const { bottom: caretY } = posToDOMRect(view, from, to);
+const { left: caretX } = posToDOMRect(view, from, to);
 const offsetY = caretY + 16;
-const offsetX = containerLeft;
+const offsetX = caretX;

 // NOTE: Left is -1px for optical alignment due to the border radius.
 this.element.setAttribute(
   "style",
-  `top: ${offsetY}px; left: ${offsetX - 1}px;`,
+  `top: ${offsetY}px; left: ${offsetX - 1}px;`,
 );

Also applies to: 121-124

@Southclaws Southclaws force-pushed the fix-rich-text-editor-menu-image-bugs branch from 2bf0eed to 6425b52 Compare October 12, 2024 15:37
@Southclaws Southclaws changed the title fix menu location address two rich text editor bugs Oct 12, 2024
@Southclaws Southclaws merged commit 947513b into main Oct 12, 2024
4 checks passed
@Southclaws Southclaws deleted the fix-rich-text-editor-menu-image-bugs branch October 12, 2024 15:45
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 this pull request may close these issues.

1 participant