Skip to content

Conversation

@tbouffard
Copy link
Member

@tbouffard tbouffard commented Jan 21, 2025

Browsers supported by maxGraph support the asynchronous clipboard API.
In addition, the fallback function used the obsolete document.execCommand('copy') function.

Also improve the clipboard JSDoc and used the standard clipboard import in the editor (a mx prefix was left over from mxGraph).

Notes

No impact on the ts-example (with or without defaults) as the clipboard is not used in the 2 examples.

https://caniuse.com/async-clipboard

image

Summary by CodeRabbit

Release Notes

  • Refactor

    • Updated clipboard functionality with improved type annotations and documentation
    • Simplified text copying mechanism by removing fallback methods
    • Standardized clipboard method signatures to enhance type safety
  • Bug Fixes

    • Improved clipboard operation reliability and error handling

The changes focus on enhancing the clipboard and utility functions with more robust type checking and cleaner implementation.

Browsers supported by maxGraph support the asynchronous clipboard API.
In addition, the fallback function used the obsolete `document.execCommand('copy')` function.

Also improve the clipboard JSDoc and used the standard clipboard import in the editor (a mx prefix was left over from
mxGraph).
@tbouffard tbouffard added the refactor Code refactoring label Jan 21, 2025
@coderabbitai
Copy link

coderabbitai bot commented Jan 21, 2025

Walkthrough

The pull request introduces modifications to clipboard-related functionality across multiple files in the project. The changes primarily focus on updating the Clipboard class with improved type annotations, refining method signatures, and enhancing documentation. The implementation now uses a more streamlined approach to clipboard operations, removing fallback mechanisms for text copying and standardizing the clipboard interaction methods.

Changes

File Change Summary
packages/core/src/editor/Editor.ts Updated import from mxClipboard to Clipboard
packages/core/src/util/Clipboard.ts - Enhanced type annotations for methods
- Updated method signatures with explicit return types
- Improved documentation and code formatting
- Refined control flow in paste method
packages/core/src/util/Utils.ts Removed fallback clipboard copying mechanism and related function

Sequence Diagram

sequenceDiagram
    participant Editor
    participant Clipboard
    participant Graph

    Editor->>Clipboard: copy(graph)
    Clipboard-->>Graph: canExportCell check
    Clipboard->>Clipboard: setCells(copied cells)
    
    Editor->>Clipboard: paste(graph)
    Clipboard-->>Graph: canImportCell check
    Clipboard->>Graph: insert copied cells
Loading

The sequence diagram illustrates the high-level interaction between the Editor, Clipboard, and Graph components during copy and paste operations, highlighting the key steps in the clipboard functionality.

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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: 0

🧹 Nitpick comments (1)
packages/core/src/util/Clipboard.ts (1)

100-100: Type annotations improve code safety and clarity.

The addition of explicit return types to method signatures enhances type safety and makes the API contract clearer. Consider adding JSDoc @returns tags to complement the TypeScript return types for better documentation.

Example improvement for the setCells method:

 /**
  * Sets the cells in the clipboard. Fires a {@link InternalEvent.CHANGE} event.
+ * @returns void
  */
 static setCells(cells: Cell[]): void {

Also applies to: 107-107, 114-114, 126-126, 140-140, 152-152, 167-167

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d0f6bd5 and c5a4ebd.

📒 Files selected for processing (3)
  • packages/core/src/editor/Editor.ts (2 hunks)
  • packages/core/src/util/Clipboard.ts (5 hunks)
  • packages/core/src/util/Utils.ts (0 hunks)
💤 Files with no reviewable changes (1)
  • packages/core/src/util/Utils.ts
🔇 Additional comments (4)
packages/core/src/editor/Editor.ts (1)

985-997: LGTM! Clean refactor of clipboard usage.

The changes correctly update the clipboard method calls to use the modernized Clipboard class directly, aligning with the PR's objective of removing legacy clipboard handling.

packages/core/src/util/Clipboard.ts (3)

28-34: Documentation improvements look good.

The updated documentation provides clearer examples and references to Graph methods using the correct notation (e.g., Graph.canExportCell instead of graph.canExportCell).

Also applies to: 36-38


Line range hint 39-76: Example code is well-structured and documented.

The example code demonstrates proper usage of the Clipboard class with TypeScript types and includes helpful comments explaining the workflow.


Line range hint 1-1: Verify removal of old browser fallback code.

The PR objective mentions removing clipboard fallback for old browsers, but the changes shown focus on type annotations and documentation. Let's verify the actual removal of fallback code.

@tbouffard tbouffard merged commit 977fd0d into main Jan 23, 2025
6 checks passed
@tbouffard tbouffard deleted the refactor/remove_clipboard_fallback_old_browser branch January 23, 2025 05:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor Code refactoring

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant