-
Notifications
You must be signed in to change notification settings - Fork 199
refactor!: remove the SHAPE enum #795
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
Conversation
Prefer the usage of the `ShapeValue` type. This slightly decreases the size of applications. In maxGraph examples, the decrease is about 0.5 kB. BREAKING CHANGES: the `SHAPE` enum has been removed. Use values of the `ShapeValue` type instead.
WalkthroughThis change removes the Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant Graph
participant CellRenderer
participant ShapeClass
User->>Graph: Create or update cell with style.shape = "rectangle" (string literal)
Graph->>CellRenderer: Request shape rendering for "rectangle"
CellRenderer->>ShapeClass: Instantiate RectangleShape
ShapeClass-->>CellRenderer: Rendered shape
CellRenderer-->>Graph: Rendered cell
Graph-->>User: Displayed cell
Note over Graph,CellRenderer: Shape names are now string literals (e.g., "rectangle"), not SHAPE enum values.
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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 comments (1)
packages/core/src/view/style/Stylesheet.ts (1)
135-136: 🛠️ Refactor suggestionUpdate code example in documentation
The code example in documentation still references
SHAPE.RECTANGLEwhich no longer exists after this refactor./** * style.shape = SHAPE.RECTANGLE; * style.perimeter = PERIMETER.RECTANGLE; + */ + +/** + * style.shape = 'rectangle'; + * style.perimeter = 'rectanglePerimeter'; * style.rounded = true; * graph.getStylesheet().putCellStyle('rounded', style);
🧹 Nitpick comments (2)
CHANGELOG.md (1)
12-14: Document removal of SHAPE enum in changelog
The new breaking change entry correctly informs users about the removal of theSHAPEenum and directs them to use theShapeValuetype. Consider adding a link to the type definition inpackages/core/src/types.tsfor easier migration.packages/html/stories/SwimLanes.stories.ts (1)
123-123: Consider using undefined assignment instead of deleteThe static analysis tool has flagged the use of the
deleteoperator which can impact performance.- delete style.rounded; + style.rounded = undefined;🧰 Tools
🪛 Biome (1.9.4)
[error] 123-123: Avoid the delete operator which can impact performance.
Unsafe fix: Use an undefined assignment instead.
(lint/performance/noDelete)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (28)
CHANGELOG.md(1 hunks)packages/core/src/types.ts(1 hunks)packages/core/src/util/Constants.ts(0 hunks)packages/core/src/view/cell/register-shapes.ts(1 hunks)packages/core/src/view/geometry/edge/ArrowConnectorShape.ts(1 hunks)packages/core/src/view/geometry/edge/ArrowShape.ts(1 hunks)packages/core/src/view/geometry/edge/ConnectorShape.ts(1 hunks)packages/core/src/view/geometry/edge/LineShape.ts(1 hunks)packages/core/src/view/geometry/edge/PolylineShape.ts(1 hunks)packages/core/src/view/geometry/node/ActorShape.ts(1 hunks)packages/core/src/view/geometry/node/CloudShape.ts(1 hunks)packages/core/src/view/geometry/node/CylinderShape.ts(1 hunks)packages/core/src/view/geometry/node/DoubleEllipseShape.ts(1 hunks)packages/core/src/view/geometry/node/EllipseShape.ts(1 hunks)packages/core/src/view/geometry/node/HexagonShape.ts(1 hunks)packages/core/src/view/geometry/node/ImageShape.ts(1 hunks)packages/core/src/view/geometry/node/LabelShape.ts(1 hunks)packages/core/src/view/geometry/node/RectangleShape.ts(1 hunks)packages/core/src/view/geometry/node/RhombusShape.ts(1 hunks)packages/core/src/view/geometry/node/SwimlaneShape.ts(1 hunks)packages/core/src/view/geometry/node/TextShape.ts(1 hunks)packages/core/src/view/geometry/node/TriangleShape.ts(1 hunks)packages/core/src/view/mixins/CellsMixin.ts(1 hunks)packages/core/src/view/mixins/SwimlaneMixin.ts(2 hunks)packages/core/src/view/style/Stylesheet.ts(3 hunks)packages/html/stories/ColorStylePlaceHolders.stories.ts(2 hunks)packages/html/stories/Folding.stories.ts(1 hunks)packages/html/stories/SwimLanes.stories.ts(3 hunks)
💤 Files with no reviewable changes (1)
- packages/core/src/util/Constants.ts
🧰 Additional context used
🪛 Biome (1.9.4)
packages/html/stories/SwimLanes.stories.ts
[error] 123-123: Avoid the delete operator which can impact performance.
Unsafe fix: Use an undefined assignment instead.
(lint/performance/noDelete)
🔇 Additional comments (35)
packages/html/stories/Folding.stories.ts (1)
74-74: Replace enum reference with string literal
The import ofconstantswas removed andstyle.shapenow uses the literal'rectangle', which aligns with the removal of theSHAPEenum. EnsureShapeValueincludes this value across all story files for consistency.packages/core/src/view/geometry/node/TriangleShape.ts (1)
27-28: Update documentation with string identifier
The JSDoc now clearly indicates thatTriangleShapeis registered under the key'triangle', replacing the former enum reference. This matches the updated shape registration approach.packages/core/src/view/mixins/CellsMixin.ts (1)
960-960: Replace shape enum check with literal
The conditional now comparesstyle.shape === 'label'instead ofSHAPE.LABEL, reflecting the removed enum. Verify that downstream code handling shape types aligns with this change.packages/core/src/view/geometry/node/TextShape.ts (1)
27-27: Clarify TextShape registration behavior
The added note explicitly states thatTextShapeis not registered by default, matching the registration details for other shapes. This enhances documentation clarity.packages/html/stories/ColorStylePlaceHolders.stories.ts (2)
17-17: Correctly removed constants importThe import statement has been properly modified to remove the unused
constantsimport from '@maxgraph/core', keeping only theGraphimport which is still used in the code.
47-47: Successfully migrated from SHAPE enum to string literalThe shape property now correctly uses the string literal
'swimlane'directly instead of the removedconstants.SHAPE.SWIMLANEenum value, aligning with the refactor objective.packages/core/src/view/style/Stylesheet.ts (3)
19-19: Properly simplified importsThe import statement has been correctly updated to remove the unused
SHAPEimport, maintaining only the necessaryALIGNandNONEconstants.
68-68: Successfully migrated from SHAPE enum to string literalThe default vertex style now correctly uses the string literal
'rectangle'directly instead of the removedSHAPE.RECTANGLEenum value.
84-84: Successfully migrated from SHAPE enum to string literalThe default edge style now correctly uses the string literal
'connector'directly instead of the removedSHAPE.CONNECTORenum value.packages/core/src/view/geometry/edge/PolylineShape.ts (1)
30-30: Updated documentation correctlyThe class documentation has been appropriately updated to clarify that this shape is not registered in the
CellRendererby using explicit description instead of referencing the removedSHAPEenum.packages/core/src/view/geometry/edge/ArrowConnectorShape.ts (1)
33-33: Updated documentation correctlyThe class documentation has been properly updated to specify that the shape is registered under the string literal
'arrowConnector'instead of using the removedSHAPE.ARROW_CONNECTORenum reference.packages/core/src/view/mixins/SwimlaneMixin.ts (2)
20-20: Properly simplified importsThe import statement has been correctly updated to remove the unused
SHAPEimport, keeping only the necessary constants.
194-194: Successfully migrated from SHAPE enum to string literalThe
isSwimlanemethod now correctly checks against the string literal'swimlane'directly instead of the removedSHAPE.SWIMLANEenum value.packages/core/src/view/geometry/node/CloudShape.ts (1)
25-26: Documentation comment correctly updated to use string literal 'cloud'.The JSDoc now accurately reflects that this shape is registered under the
'cloud'key inCellRenderer, replacing the removed enum. Formatting and punctuation are consistent with other shape classes.packages/core/src/view/geometry/node/LabelShape.ts (1)
27-28: Documentation comment correctly updated to use string literal 'label'.The comment now specifies registration under
'label'inCellRenderer, aligning with the removal of theSHAPEenum. The style and punctuation match the other vertex shape docs.packages/core/src/view/geometry/node/HexagonShape.ts (1)
27-28: Documentation comment correctly updated to use string literal 'hexagon'.The JSDoc accurately indicates registration under
'hexagon'inCellRenderer, reflecting the enum removal. The change is consistent with the overall refactor.packages/core/src/view/geometry/edge/ConnectorShape.ts (1)
33-33: Documentation comment correctly updated to use string literal 'connector'.This doc now states registration under
'connector'inCellRenderer, matching the rest of the enum-removal changes.packages/core/src/view/geometry/edge/LineShape.ts (1)
29-29: Documentation comment correctly updated to use string literal 'line'.The JSDoc now specifies registration under
'line'inCellRenderer, in line with the removal ofSHAPE.LINE. The style is consistent with other edge shape docs.packages/core/src/view/geometry/node/ActorShape.ts (1)
27-28: Docs Update: Reflect string-based registration
The JSDoc now correctly replaces the removedSHAPEenum with the literal'actor'for registration inCellRenderer, aligning with the updated mechanism.packages/core/src/view/geometry/node/RhombusShape.ts (1)
27-28: Docs Update: Use literal'rhombus'for registration
The documentation comment now accurately states that the shape is registered under the string key'rhombus'instead of the old enum constant, ensuring consistency.packages/core/src/view/geometry/node/EllipseShape.ts (1)
25-26: Docs Update: Use literal'ellipse'for registration
The JSDoc has been updated to reference the string literal'ellipse'rather than the removed enum, matching the new registration approach.packages/core/src/view/geometry/edge/ArrowShape.ts (1)
27-31: Docs Update: Clarify edge shape registration and usage
The JSDoc now clearly separates the note that this shape is for edges and specifies registration under the literal'arrow', replacing the removed enum constant. This improves readability and consistency across the codebase.packages/core/src/view/geometry/node/ImageShape.ts (1)
28-29: Docs Update: Reflect string-based registration for image shape
The documentation now correctly states that the image shape is registered under the key'image'inCellRenderer, in line with the removal of theSHAPEenum.packages/core/src/view/geometry/node/CylinderShape.ts (1)
26-27: Documentation accurately updated to reflect enum removalThe documentation now correctly references the string literal
'cylinder'instead of the removedSHAPEenum, which aligns with the refactoring objectives.packages/core/src/view/geometry/node/DoubleEllipseShape.ts (1)
25-26: Documentation properly updated to use string literalThe documentation now correctly references the string literal
'doubleEllipse'instead of the removedSHAPE.DOUBLE_ELLIPSEenum, aligning with the refactoring goal.packages/core/src/view/cell/register-shapes.ts (1)
48-63: Shape registration successfully converted to string literalsThe shape registration array has been correctly updated to use string literals directly instead of the removed
SHAPEenum constants. This change maintains the same functionality while reducing the codebase size as mentioned in the PR objectives.packages/core/src/view/geometry/node/SwimlaneShape.ts (1)
32-33: Documentation updated correctly for string literal usageThe documentation now properly references the string literal
'swimlane'instead of the removedSHAPE.SWIMLANEenum, consistent with the refactoring approach used throughout the codebase.packages/core/src/view/geometry/node/RectangleShape.ts (1)
27-28: JSDoc updated to reflect shape registration by string keyThe JSDoc comment has been properly updated to reflect the new registration mechanism that uses the string key
'rectangle'instead of the removedSHAPE.RECTANGLEenum value. This change aligns with the PR objective of removing theSHAPEenum.packages/html/stories/SwimLanes.stories.ts (5)
99-99: String literal 'swimlane' replaces SHAPE enumThe code has been updated to use the string literal
'swimlane'directly instead of the removedSHAPE.SWIMLANEenum value. This change aligns with the PR objective of removing theSHAPEenum.
111-111: String literal 'rectangle' replaces SHAPE enumThe code has been updated to use the string literal
'rectangle'directly instead of the removedSHAPE.RECTANGLEenum value. This change aligns with the PR objective of removing theSHAPEenum.
121-121: String literal 'ellipse' replaces SHAPE enumThe code has been updated to use the string literal
'ellipse'directly instead of the removedSHAPE.ELLIPSEenum value. This change aligns with the PR objective of removing theSHAPEenum.
127-127: String literal 'rhombus' replaces SHAPE enumThe code has been updated to use the string literal
'rhombus'directly instead of the removedSHAPE.RHOMBUSenum value. This change aligns with the PR objective of removing theSHAPEenum.
135-135: String literal 'doubleEllipse' replaces SHAPE enumThe code has been updated to use the string literal
'doubleEllipse'directly instead of the removedSHAPE.DOUBLE_ELLIPSEenum value. This change aligns with the PR objective of removing theSHAPEenum.packages/core/src/types.ts (2)
957-962: Documentation improved for ShapeValue typeThe JSDoc comment for the
ShapeValuetype has been updated to clearly explain that these are names used to register shapes, which can be used as values for theCellStateStyle.shapeproperty. This documentation improvement helps users understand the purpose of theShapeValuetype after the removal of theSHAPEenum.
966-997: Well-documented ShapeValue union typeThe
ShapeValuetype has been expanded and properly documented with JSDoc comments for each shape name, indicating which shape class it corresponds to. This comprehensive documentation is valuable for users who previously relied on theSHAPEenum for discoverability of available shapes.This change effectively makes
ShapeValuethe new authoritative source for shape names in the codebase, replacing the removedSHAPEenum.
|



Prefer the usage of the
ShapeValuetype.This slightly decreases the size of applications. In maxGraph examples, the decrease is about 0.5 kB.
BREAKING CHANGES: the
SHAPEenum has been removed. Use values of theShapeValuetype instead.Notes
Covers #378
Summary by CodeRabbit
Breaking Changes
SHAPEenum; shape types should now be referenced using string literals as defined in the expanded and documentedShapeValuetype.Documentation
Refactor
SHAPEenum with string literals for shape names in all relevant areas.