Skip to content

Conversation

@tbouffard
Copy link
Member

@tbouffard tbouffard commented Apr 23, 2025

Introduce the "builtin-style-elements.ts" that export all builtin styles to simplify the root "index.ts" file.
This simplifies the maintenance and will reduce the impact of the future refactoring on EdgeStyle and Perimeter.

Simplify default builtins registration using a loop as this is already done to register Shapes.

Notes

Covers #759

Summary by CodeRabbit

  • Refactor

    • Streamlined and reorganized style-related exports for improved clarity and consistency.
    • Introduced a new module providing built-in style elements for edge styles, perimeters, and markers.
    • Updated export and import paths for style entities, replacing default exports with named exports.
    • Simplified registration of edge styles, perimeters, and markers using consolidated loops.
  • Chores

    • Updated internal documentation and licensing headers for new and reorganized modules.

Introduce the "builtin-style-elements.ts" that export all builtin styles to simplify the root "index.ts" file.
This simplifies the maintenance and will reduce the impact of the future refactoring on `EdgeStyle` and `Perimeter`.

Simplify default builtins registration using a loop as this is already done to register Shapes.
@tbouffard tbouffard added the refactor Code refactoring label Apr 23, 2025
@coderabbitai
Copy link

coderabbitai bot commented Apr 23, 2025

Walkthrough

This change reorganizes the export and import structure for edge marker styles, edge styles, and perimeters within the codebase. It introduces a new module, builtin-style-elements.ts, consolidating exports for style-related entities. The exports for MarkerShape, EdgeStyle, and Perimeter are now sourced from new or updated paths, and the previous direct exports and namespace exports for edge markers are removed. Additionally, registration functions for default styles, perimeters, and markers are refactored to use loops for more concise code. Import paths throughout related modules are updated to reflect the new structure, with no changes to underlying logic or public APIs.

Changes

File(s) Change Summary
packages/core/src/index.ts Refactored exports for edge marker styles, edge styles, and perimeters; removed direct exports and namespace exports; added export for all from builtin-style-elements.
packages/core/src/view/style/builtin-style-elements.ts New module that re-exports EdgeStyle, Perimeter, and all from marker/edge-markers as EdgeMarker; includes documentation and licensing header.
packages/core/src/view/style/edge/index.ts Changed import paths for edge style functions; made EdgeStyle a named export; removed default export.
packages/core/src/view/style/perimeter/index.ts Updated import paths for perimeter functions; made Perimeter a named export; removed default export.
packages/core/src/view/style/register.ts Changed imports to named imports from new paths; replaced repetitive registration calls with loops over arrays of name-function pairs for styles, perimeters, and markers.
packages/core/src/view/style/marker/EdgeMarkerRegistry.ts Updated import paths for types and dependencies to reflect new directory structure; no logic changes.
packages/core/src/view/style/marker/edge-markers.ts Updated import paths for types and constants to reflect new directory structure; no logic changes.
packages/core/src/view/Graph.ts
packages/core/src/view/handler/EdgeHandler.ts
Changed import of EdgeStyle from default import to named import from new module path; no logic changes.
packages/core/src/view/geometry/edge/ConnectorShape.ts Updated import path for MarkerShape to new location; no logic changes.

Sequence Diagram(s)

sequenceDiagram
    participant App
    participant Graph
    participant StyleRegistry
    participant MarkerShape

    App->>Graph: Create instance
    Graph->>StyleRegistry: Register default edge styles (via loop)
    Graph->>StyleRegistry: Register default perimeters (via loop)
    Graph->>MarkerShape: Register default edge markers (via loop)
Loading

Possibly related PRs

  • maxGraph/maxGraph#662: Removes utility functions for default style value retrieval, related due to restructuring of style-related modules and access patterns.
  • maxGraph/maxGraph#757: Introduces public registration/unregistration for default style elements and reorganizes exports for marker styles, directly overlapping with the current export and registration changes.
  • maxGraph/maxGraph#684: Refactors internal implementation of EdgeStyle and related modules; related at the module level due to changes in export structure, though not directly overlapping in code.

📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f5d34c4 and 4b3f74c.

📒 Files selected for processing (3)
  • packages/core/src/view/style/register.ts (4 hunks)
  • packages/ts-example-without-defaults/vite.config.js (1 hunks)
  • packages/ts-example/vite.config.js (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • packages/ts-example-without-defaults/vite.config.js
  • packages/ts-example/vite.config.js
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/core/src/view/style/register.ts
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: build
  • GitHub Check: build (windows-2022)
  • GitHub Check: build (macos-14)
  • GitHub Check: build (ubuntu-22.04)

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.
    • 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.
  • @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.

@tbouffard tbouffard marked this pull request as ready for review April 23, 2025 05:51
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 (3)
packages/core/src/view/style/edge/index.ts (1)

84-84: Appropriately changed to named export.

Converting the EdgeStyle class from an implicit non-exported class to an explicitly named export aligns with the PR objective of reorganizing and simplifying style elements.

However, consider refactoring this class in the future:

JavaScript best practices for static utility classes
🧰 Tools
🪛 Biome (1.9.4)

[error] 84-155: Avoid classes that contain only static members.

Prefer using simple functions instead of classes with only static members.

(lint/complexity/noStaticOnlyClass)

packages/core/src/view/style/builtin-style-elements.ts (1)

2-2: Update the copyright year.

The copyright year is set to 2025, which appears to be incorrect. It should reflect the actual year the file was created.

-Copyright 2025-present The maxGraph project Contributors
+Copyright 2024-present The maxGraph project Contributors
packages/core/src/view/style/register.ts (1)

69-78: Variable naming inconsistency

The variable name in the loop should match what it represents for better clarity.

-    for (const [name, edgeStyle] of perimetersToRegister) {
-      StyleRegistry.putValue(name, edgeStyle);
+    for (const [name, perimeter] of perimetersToRegister) {
+      StyleRegistry.putValue(name, perimeter);
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between aad57fa and f5d34c4.

📒 Files selected for processing (10)
  • packages/core/src/index.ts (1 hunks)
  • packages/core/src/view/Graph.ts (1 hunks)
  • packages/core/src/view/geometry/edge/ConnectorShape.ts (1 hunks)
  • packages/core/src/view/handler/EdgeHandler.ts (1 hunks)
  • packages/core/src/view/style/builtin-style-elements.ts (1 hunks)
  • packages/core/src/view/style/edge/index.ts (2 hunks)
  • packages/core/src/view/style/marker/EdgeMarkerRegistry.ts (1 hunks)
  • packages/core/src/view/style/marker/edge-markers.ts (1 hunks)
  • packages/core/src/view/style/perimeter/index.ts (1 hunks)
  • packages/core/src/view/style/register.ts (4 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
packages/core/src/view/style/edge/index.ts

[error] 84-155: Avoid classes that contain only static members.

Prefer using simple functions instead of classes with only static members.

(lint/complexity/noStaticOnlyClass)

🔇 Additional comments (14)
packages/core/src/view/style/marker/EdgeMarkerRegistry.ts (1)

19-22: Import paths updated correctly.

The import paths have been updated to reflect the reorganization of style-related modules in the codebase. This ensures proper references after the structural changes.

packages/core/src/view/style/edge/index.ts (1)

19-26: Import paths simplified properly.

The import paths have been simplified by removing the /edge/ subdirectory prefix, which is appropriate since the imports are now relative to the current directory.

packages/core/src/view/geometry/edge/ConnectorShape.ts (1)

21-21: Import path correctly updated.

The import path for MarkerShape has been properly updated to reflect the reorganized directory structure, maintaining the connection between ConnectorShape and the MarkerShape functionality.

packages/core/src/view/Graph.ts (1)

43-43: Import statement properly updated.

The import for EdgeStyle has been correctly changed from a default import to a named import, reflecting the changes made in the edge/index.ts file and aligning with the broader refactoring of style-related modules.

packages/core/src/view/handler/EdgeHandler.ts (2)

48-48: Import path updated for EdgeStyle.

The import has been changed from a default import to a named import from the new path structure, aligning with the broader style elements reorganization.


601-604: Code functionality preserved with the new import structure.

The usage of EdgeStyle.EntityRelation reference continues to work properly with the updated import, ensuring backward compatibility while benefiting from the reorganized structure.

packages/core/src/view/style/marker/edge-markers.ts (1)

19-23: Import paths updated to reflect new directory structure.

Import paths have been adjusted to use the correct relative paths after the restructuring of style-related modules.

packages/core/src/view/style/perimeter/index.ts (2)

19-23: Import paths simplified for perimeter functions.

The imports now reference the sibling files directly without the redundant ./perimeter/ subdirectory prefix, making the imports cleaner and more maintainable.


30-30: Changed Perimeter from default export to named export.

Converted Perimeter to a named export, which aligns with the broader refactoring goal of standardizing how style elements are exported and then consolidated through builtin-style-elements.ts.

packages/core/src/view/style/builtin-style-elements.ts (1)

1-29: Well-structured new module for consolidating style elements.

This new file successfully serves as a central point for exporting all built-in style elements:

  1. Exports EdgeStyle from './edge'
  2. Exports Perimeter from './perimeter'
  3. Exports all exports from './marker/edge-markers' as the EdgeMarker namespace

The JSDoc comments provide clear documentation about these being built-in edge markers that can be registered in MarkerShape, making the code more discoverable and easier to use.

packages/core/src/index.ts (1)

160-163: LGTM - Clean reorganization of style elements

The new export statement referring to the consolidated 'builtin-style-elements' module and the updated import path for MarkerShape align well with the PR objectives of simplifying the root index.ts file and making it easier to maintain.

packages/core/src/view/style/register.ts (3)

18-27: LGTM - Well-structured import organization

The imports have been updated to reflect the new module structure, with a clearer separation of concerns. Using named imports instead of default imports is also a good practice for better clarity and consistency.


40-52: LGTM - Improved registration pattern

Using an array of tuples and a loop for registration is a great improvement that makes the code more maintainable and consistent with how Shapes are registered, as mentioned in the PR objectives.


111-124: LGTM - Consistent registration pattern

The marker registration follows the same pattern as the other registrations, making the codebase more consistent and maintainable.

@sonarqubecloud
Copy link

@tbouffard tbouffard merged commit 94a1609 into main Apr 23, 2025
7 checks passed
@tbouffard tbouffard deleted the refactor/reorg_builtin_style_elements branch April 23, 2025 06:09
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