Skip to content

Conversation

@tbouffard
Copy link
Member

@tbouffard tbouffard commented May 3, 2025

BREAKING CHANGES: The constants.FONT enum has been removed and replaced by the constants.FONT_STYLE_FLAG value object.

Notes

Covers #378

Summary by CodeRabbit

  • New Features

    • None.
  • Refactor

    • Replaced the font style enum with a constant object for font style flags throughout the application, updating all font style references including UI text styling and editor actions.
    • Improved internal handling of font style flags with enhanced bitmask matching supporting nullish values.
  • Documentation

    • Updated changelog and code comments to reflect the new font style flag usage.
  • Tests

    • Updated test cases to use the new font style flag constants.
  • Chores

    • Increased the chunk size warning limit in the build configuration.

BREAKING CHANGES: The `constants.FONT` enum has been removed and replaced by the `constants.FONT_STYLE_FLAG` value object.
@tbouffard tbouffard added the refactor Code refactoring label May 3, 2025
@coderabbitai
Copy link

coderabbitai bot commented May 3, 2025

Walkthrough

The changes systematically replace the FONT TypeScript enum with a new constant object FONT_STYLE_MASK for representing font style flags (BOLD, ITALIC, UNDERLINE, STRIKETHROUGH) throughout the codebase. All references, imports, documentation comments, and test cases that previously used FONT are updated to use FONT_STYLE_MASK. This update affects core source files, utility functions, rendering logic, plugins, tests, documentation, and several example story files. Additionally, the changelog is updated to document this breaking change, the matchBinaryMask function is enhanced to accept nullish values, and a minor build configuration adjustment is made to the Vite config.

Changes

File(s) Change Summary
packages/core/src/util/Constants.ts Replaced exported FONT enum with FONT_STYLE_MASK constant object with same flag values as readonly properties.
packages/core/src/editor/Editor.ts,
packages/core/src/util/styleUtils.ts,
packages/core/src/view/geometry/node/TextShape.ts,
packages/core/src/view/plugins/CellEditorHandler.ts,
packages/core/src/view/canvas/SvgCanvas2D.ts
Updated imports and all references from FONT to FONT_STYLE_MASK for font style bitmask operations and checks.
packages/core/src/types.ts Updated documentation comment for fontStyle property to reference FONT_STYLE_FLAG instead of FONT.
packages/core/__tests__/internal/utils.test.ts,
packages/core/__tests__/util/styleUtils.test.ts,
packages/core/__tests__/view/mixins/CellMixin.test.ts
Updated all test imports and usages from FONT to FONT_STYLE_MASK; added tests for matchBinaryMask with nullish values. Test logic unchanged.
packages/html/stories/EdgeCurvedAndRounded.stories.ts,
packages/html/stories/HoverStyle.stories.js,
packages/html/stories/Merge.stories.ts,
packages/html/stories/SecondLabel.stories.js
Updated all assignments of fontStyle from constants.FONT to constants.FONT_STYLE_MASK.
CHANGELOG.md Added breaking change entry documenting replacement of FONT enum with FONT_STYLE_FLAG value object.
packages/ts-example-selected-features/vite.config.js Increased Vite chunk size warning limit from 377 to 378.
packages/core/src/internal/utils.ts Modified matchBinaryMask function signature to accept `number

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Editor
    participant Constants
    participant Renderer

    User->>Editor: Toggle font style (e.g., bold)
    Editor->>Constants: Access FONT_STYLE_MASK.BOLD
    Editor->>Renderer: Apply style using FONT_STYLE_MASK.BOLD
    Renderer->>Constants: Use FONT_STYLE_MASK to determine rendering
Loading
sequenceDiagram
    participant TestSuite
    participant Constants

    TestSuite->>Constants: Import FONT_STYLE_MASK
    TestSuite->>TestSuite: Use FONT_STYLE_MASK in assertions and style flag combinations
Loading
✨ Finishing Touches
  • 📝 Generate Docstrings

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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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.

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

🧹 Nitpick comments (2)
packages/ts-example-selected-features/vite.config.js (1)

30-30: Verify the chunk size warning limit bump
The chunkSizeWarningLimit was incremented from 377 to 378. Please confirm this change reflects the actual bundle size increase for the @maxgraph/core chunk after your refactor. If this is intentional, consider adding a brief comment to document why the threshold was adjusted.

packages/core/src/util/styleUtils.ts (1)

350-352: Update example usage in JSDoc snippet
The documentation example now demonstrates constants.FONT_STYLE_FLAG.BOLD. For clarity, consider showing the corresponding import in the snippet.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 6d99b3a and 98a03be.

📒 Files selected for processing (16)
  • CHANGELOG.md (1 hunks)
  • packages/core/__tests__/internal/utils.test.ts (1 hunks)
  • packages/core/__tests__/util/styleUtils.test.ts (3 hunks)
  • packages/core/__tests__/view/mixins/CellMixin.test.ts (2 hunks)
  • packages/core/src/editor/Editor.ts (2 hunks)
  • packages/core/src/types.ts (1 hunks)
  • packages/core/src/util/Constants.ts (1 hunks)
  • packages/core/src/util/styleUtils.ts (3 hunks)
  • packages/core/src/view/canvas/SvgCanvas2D.ts (5 hunks)
  • packages/core/src/view/geometry/node/TextShape.ts (3 hunks)
  • packages/core/src/view/plugins/CellEditorHandler.ts (2 hunks)
  • packages/html/stories/EdgeCurvedAndRounded.stories.ts (1 hunks)
  • packages/html/stories/HoverStyle.stories.js (1 hunks)
  • packages/html/stories/Merge.stories.ts (1 hunks)
  • packages/html/stories/SecondLabel.stories.js (1 hunks)
  • packages/ts-example-selected-features/vite.config.js (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (5)
packages/core/__tests__/internal/utils.test.ts (2)
packages/core/src/internal/utils.ts (1)
  • matchBinaryMask (68-70)
packages/core/src/util/Constants.ts (1)
  • FONT_STYLE_FLAG (402-411)
packages/core/__tests__/util/styleUtils.test.ts (3)
packages/core/src/util/Constants.ts (1)
  • FONT_STYLE_FLAG (402-411)
packages/core/src/util/styleUtils.ts (2)
  • setStyleFlag (391-412)
  • setCellStyleFlags (360-380)
packages/core/src/view/mixins/CellsMixin.ts (1)
  • setCellStyleFlags (349-361)
packages/core/__tests__/view/mixins/CellMixin.test.ts (1)
packages/core/src/util/Constants.ts (1)
  • FONT_STYLE_FLAG (402-411)
packages/core/src/view/plugins/CellEditorHandler.ts (2)
packages/html/stashed/grapheditor/www/js/Graph.js (2)
  • bold (9508-9510)
  • italic (9511-9513)
packages/core/src/util/Constants.ts (1)
  • FONT_STYLE_FLAG (402-411)
packages/core/src/editor/Editor.ts (1)
packages/core/src/util/Constants.ts (1)
  • FONT_STYLE_FLAG (402-411)
⏰ 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)
🔇 Additional comments (34)
packages/core/src/util/Constants.ts (1)

402-411: Good implementation of the FONT_STYLE_FLAG value object.

The conversion from an enum to a constant object with as const is a good approach. This provides better type safety while maintaining the same functionality and bit flag values (1, 2, 4, 8) for font styles.

packages/html/stories/SecondLabel.stories.js (1)

130-130: Correctly updated to use FONT_STYLE_FLAG instead of FONT.

The update from constants.FONT.ITALIC to constants.FONT_STYLE_FLAG.ITALIC preserves the original functionality while adapting to the new API.

packages/html/stories/HoverStyle.stories.js (1)

48-48: Correctly updated to use FONT_STYLE_FLAG instead of FONT.

The font style value has been properly updated to use the new FONT_STYLE_FLAG.BOLD constant, maintaining the same functionality in the hover style logic.

packages/html/stories/EdgeCurvedAndRounded.stories.ts (2)

94-94: Correctly updated to use FONT_STYLE_FLAG instead of FONT.

The vertex style's font style property has been properly updated to use the new constant object.


99-99: Correctly updated to use FONT_STYLE_FLAG instead of FONT.

The edge style's font style property has been properly updated to use the new constant object.

packages/html/stories/Merge.stories.ts (2)

74-74: Replaced deprecated FONT enum with FONT_STYLE_FLAG for vertex style
Consistently updated to use the new bitmask constant.


80-80: Replaced deprecated FONT enum with FONT_STYLE_FLAG for edge style
Consistently updated to use the new bitmask constant.

packages/core/__tests__/internal/utils.test.ts (5)

18-18: Replaced FONT import with FONT_STYLE_FLAG
Import updated to the new value object in the test.


23-25: Updated test to use FONT_STYLE_FLAG for STRIKETHROUGH
Assertion now matches the new bitmask constant.


28-28: Updated test to use FONT_STYLE_FLAG for BOLD
Assertion now matches the new bitmask constant.


31-31: Updated test to use FONT_STYLE_FLAG for UNDERLINE
Assertion now matches the new bitmask constant.


34-34: Updated test to use FONT_STYLE_FLAG for ITALIC
Assertion now matches the new bitmask constant.

packages/core/__tests__/view/mixins/CellMixin.test.ts (2)

20-20: Replaced FONT import with FONT_STYLE_FLAG
Import updated to the new value object in the mixin test.


53-53: Updated fontStyle flag for setCellStyleFlags
Using FONT_STYLE_FLAG.UNDERLINE to compute the combined fontStyle correctly.

CHANGELOG.md (1)

27-27: Document breaking change from FONT to FONT_STYLE_FLAG
CHANGELOG entry clearly describes the removal of the FONT enum and replacement by FONT_STYLE_FLAG.

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

337-338: Updated documentation to reference FONT_STYLE_FLAG
Comment now correctly links to the new constant object for font styles.

packages/core/src/editor/Editor.ts (2)

36-36: Update import to use FONT_STYLE_FLAG
Import now references the new FONT_STYLE_FLAG constant object instead of the removed FONT enum. Confirm there are no lingering FONT imports in this module.


1143-1156: Use new font style flags in toggle actions
The action handlers for 'bold', 'italic', and 'underline' have been updated to call toggleCellStyleFlags with FONT_STYLE_FLAG.BOLD, .ITALIC, and .UNDERLINE. This change preserves the existing behavior under the new flag constants.

packages/core/src/util/styleUtils.ts (1)

20-25: Replace FONT enum import with FONT_STYLE_FLAG
The import correctly brings in FONT_STYLE_FLAG from Constants.ts. Ensure that all references to font style flags in this file now use FONT_STYLE_FLAG.

packages/core/src/view/canvas/SvgCanvas2D.ts (4)

27-27: Update import to use FONT_STYLE_FLAG
The import statement has been updated from the removed FONT enum to the new FONT_STYLE_FLAG constant object.


475-483: Use FONT_STYLE_FLAG in alternate text rendering
In getAlternateText, the bitmask checks have been switched to use the new flags (FONT_STYLE_FLAG.BOLD, etc.), and map to the same SVG attributes as before.


1360-1368: Update font style flags in CSS generation
The getTextCss method now correctly toggles font-weight and font-style based on FONT_STYLE_FLAG. Behavior is unchanged.


1653-1661: Apply new font style flags in updateFont
In the updateFont method, bitmask checks now use FONT_STYLE_FLAG to set SVG attributes (font-weight, font-style, text-decoration). This aligns with the refactor.

packages/core/src/view/plugins/CellEditorHandler.ts (3)

28-28: Consistent enum replacement with object constant.

The import has been properly changed from FONT enum to the new FONT_STYLE_FLAG value object, aligning with the PR objective.


699-700: Properly replaced enum with value object for bold and italic flags.

The bitwise font style checks have been correctly updated to use FONT_STYLE_FLAG instead of the previous FONT enum.


703-707: Correctly updated underline and strikethrough font style flag checks.

The bitwise operations have been properly migrated to use FONT_STYLE_FLAG while maintaining the same functionality.

packages/core/src/view/geometry/node/TextShape.ts (3)

26-26: Import correctly updated to use FONT_STYLE_FLAG.

The import has been properly changed to use the new constant object, consistent with the PR objective.


597-606: Font style checks properly migrated in getTextCss method.

The bitwise checks in the CSS generation have been correctly updated to use FONT_STYLE_FLAG with the matchBinaryMask helper function, maintaining the same functionality.


802-815: Successfully updated font style checks in updateFont method.

The font style flag checks in the updateFont method have been properly migrated to use FONT_STYLE_FLAG constants.

packages/core/__tests__/util/styleUtils.test.ts (5)

24-24: Updated import to use new FONT_STYLE_FLAG constant.

The import has been correctly changed to use the new constant object instead of the enum.


48-54: Test case properly updated to use FONT_STYLE_FLAG.

The test case has been appropriately updated to use the new FONT_STYLE_FLAG constant object for creating styles and setting flags.


55-56: Expectation correctly updated to use FONT_STYLE_FLAG bitwise operations.

The test's expected result has been properly updated to use the new constants with the same bitwise logic.


63-68: Multiple flag combination tests correctly updated.

All test cases that combine multiple font style flags have been properly migrated to use FONT_STYLE_FLAG, maintaining the same test logic and expectations.


146-152: Successfully updated setCellStyleFlags test.

The test for setCellStyleFlags function has been properly updated to use the new FONT_STYLE_FLAG constant.

tbouffard added 3 commits May 4, 2025 08:54
introduce variables to remove duplicated calls
use matchBinaryMask for clarity and consistency with other places in the code
@sonarqubecloud
Copy link

sonarqubecloud bot commented May 4, 2025

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/internal/utils.ts (1)

68-69: Consider handling nullish values more explicitly

The function now accepts undefined and null values but uses a non-null assertion (!) which tells TypeScript to ignore the possibility of nullish values. While this works because of JavaScript's coercion (null/undefined become 0 in bitwise operations), it can be confusing and potentially risky.

Consider explicitly handling nullish values for better clarity and type safety:

- export const matchBinaryMask = (value: number | undefined | null, mask: number) => {
-   return (value! & mask) === mask;
- };
+ export const matchBinaryMask = (value: number | undefined | null, mask: number) => {
+   // Explicitly handle nullish values - they behave like 0 in bitwise operations
+   if (value === null || value === undefined) {
+     return mask === 0;
+   }
+   return (value & mask) === mask;
+ };

Or using nullish coalescing:

- export const matchBinaryMask = (value: number | undefined | null, mask: number) => {
-   return (value! & mask) === mask;
- };
+ export const matchBinaryMask = (value: number | undefined | null, mask: number) => {
+   return ((value ?? 0) & mask) === mask;
+ };
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 80f24e3 and 55f3f6a.

📒 Files selected for processing (14)
  • packages/core/__tests__/internal/utils.test.ts (1 hunks)
  • packages/core/__tests__/util/styleUtils.test.ts (3 hunks)
  • packages/core/__tests__/view/mixins/CellMixin.test.ts (2 hunks)
  • packages/core/src/editor/Editor.ts (2 hunks)
  • packages/core/src/internal/utils.ts (1 hunks)
  • packages/core/src/util/Constants.ts (1 hunks)
  • packages/core/src/util/styleUtils.ts (3 hunks)
  • packages/core/src/view/canvas/SvgCanvas2D.ts (5 hunks)
  • packages/core/src/view/geometry/node/TextShape.ts (3 hunks)
  • packages/core/src/view/plugins/CellEditorHandler.ts (4 hunks)
  • packages/html/stories/EdgeCurvedAndRounded.stories.ts (1 hunks)
  • packages/html/stories/HoverStyle.stories.js (1 hunks)
  • packages/html/stories/Merge.stories.ts (1 hunks)
  • packages/html/stories/SecondLabel.stories.js (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (13)
  • packages/html/stories/HoverStyle.stories.js
  • packages/html/stories/Merge.stories.ts
  • packages/core/tests/view/mixins/CellMixin.test.ts
  • packages/html/stories/SecondLabel.stories.js
  • packages/core/tests/internal/utils.test.ts
  • packages/core/src/view/canvas/SvgCanvas2D.ts
  • packages/core/src/util/styleUtils.ts
  • packages/html/stories/EdgeCurvedAndRounded.stories.ts
  • packages/core/src/editor/Editor.ts
  • packages/core/tests/util/styleUtils.test.ts
  • packages/core/src/util/Constants.ts
  • packages/core/src/view/plugins/CellEditorHandler.ts
  • packages/core/src/view/geometry/node/TextShape.ts
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: build
  • GitHub Check: build (windows-2022)
  • GitHub Check: build (ubuntu-22.04)
  • GitHub Check: build (macos-14)

@tbouffard tbouffard merged commit 6207f1e into main May 4, 2025
7 checks passed
@tbouffard tbouffard deleted the refactor/378-replace_FONT_enum_by_FONT_MASK_value branch May 4, 2025 09:31
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