Skip to content

Conversation

@tbouffard
Copy link
Member

@tbouffard tbouffard commented Jul 10, 2025

GraphViewCodec and StylesheetCodec:

  • fix style property retrieval: correctly loop over the properties of the style of CellState
  • add tests

Other fixes:

  • Graph codec: only exclude existing fields
  • exclude and idrefs: enforce type in array
  • ObjectCodec: use right numeric attributes names for Geometry and Point

Improvements:

  • ModelCodec: improve method signature of encodeObject
  • use explicit names for object and array codecs
  • decode/import: generate a warning log when no codec found for a node
  • types in codecs: use specific types instead of any to better detect type errors
  • declare more precise types in method signature of EditorToolbar and accept null parameters in some methods
  • improve JSDoc
  • add tests for GraphDataModel codec for extra node in addition to root

BREAKING CHANGES: the return types of some methods of EditorToolbar are now more precise.

  • addPrototype(): HTMLImageElement instead of HTMLImageElement | HTMLButtonElement
  • addCombo(): HTMLSelectElement instead of HTMLElement

Summary by CodeRabbit

  • New Features

    • Added comprehensive tests for graph and stylesheet serialization, improving reliability and coverage for XML import/export scenarios.
    • Introduced utility functions to streamline serialization test setup and assertions.
  • Bug Fixes

    • Enhanced handling of complex cell values and extra XML nodes during serialization, ensuring correct import/export of nested objects and unknown XML elements.
  • Refactor

    • Improved type safety and nullability throughout serialization and editor toolbar components.
    • Updated method signatures and documentation for clarity and consistency.
    • Centralized codec creation logic for maintainability.
    • Enhanced attribute handling and iteration styles in serialization codecs.
    • Refined GraphView clear method with recursive option for better control.
  • Documentation

    • Updated and clarified JSDoc comments and changelog entries for improved developer guidance.

GraphViewCodec and StylesheetCodec:
  - fix style property retrieval: correctly loop over the properties of the style of CellState
  - add tests

Other fixes:
  - Graph codec: only exclude existing fields
  - exclude and idrefs: enforce type in array
  - ObjectCodec: use right numeric attributes names for Geometry and Point

Improvements:
  - ModelCodec: improve method signature of encodeObject
  - use explicit names for object and array codecs
  - decode/import: generate a warning log when no codec found for a node
  - types in codecs: use specific types instead of any to better detect type errors
  - declare more precise types in method signature of EditorToolbar and accept null parameters in some methods
  - improve JSDoc
  - add tests for GraphDataModel codec for extra node in addition to root

BREAKING CHANGES: the return types of some methods of EditorToolbar are now more precise.
  - addPrototype(): HTMLImageElement, no longer HTMLImageElement | HTMLButtonElement
  - addCombo(): HTMLSelectElement instead of HTMLElement
@tbouffard tbouffard added the bug Something isn't working label Jul 10, 2025
@coderabbitai
Copy link

coderabbitai bot commented Jul 10, 2025

Walkthrough

This update refines type safety and documentation across serialization, editor, and view modules. It introduces new and refactored tests for serialization codecs, enhances method signatures, clarifies JSDoc comments, and improves internal type handling. A new test utility module is added, and several methods now use more precise parameter and return types.

Changes

File(s) Change Summary
CHANGELOG.md Updated to document refined return types for EditorToolbar methods.
packages/core/tests/serialization/codecs/GraphViewCodec.test.ts Added test for GraphViewCodec export functionality.
packages/core/tests/serialization/codecs/StylesheetCodec.test.ts Added tests for StylesheetCodec import/export behavior.
packages/core/tests/serialization/codecs/all-graph-classes.test.ts Refactored to use shared import/export helpers and expanded stylesheet XML template.
packages/core/tests/serialization/codecs/shared.ts New utility module with importToObject and exportObject functions for codec tests.
packages/core/tests/serialization/serialization.xml.test.ts Expanded tests for XML serialization/deserialization, handling complex values and extra nodes.
packages/core/tests/serialization/utils.ts Broadened accepted value types in ModelChecker methods to include objects.
packages/core/src/editor/EditorToolbar.ts Refined method signatures, improved nullability handling, and updated documentation references.
packages/core/src/serialization/Codec.ts Improved type annotations, error logging, and stricter runtime checks in Codec class.
packages/core/src/serialization/CodecRegistry.ts Renamed parameters in addAlias for clarity and updated documentation.
packages/core/src/serialization/ObjectCodec.ts Added numeric attribute arrays, improved type safety, and updated method signatures.
packages/core/src/serialization/codecs/BaseGraphCodec.ts Removed obsolete fields from transient fields comment.
packages/core/src/serialization/codecs/CellCodec.ts Added type assertions for property key arrays in constructor.
packages/core/src/serialization/codecs/ChildChangeCodec.ts Updated isReference signature and delegated fallback logic to superclass.
packages/core/src/serialization/codecs/GraphCodec.ts Added type annotation to excludedFields, removed obsolete fields, and suppressed type check for private field.
packages/core/src/serialization/codecs/GraphViewCodec.ts Added type annotations, helper for numeric attributes, and improved style iteration.
packages/core/src/serialization/codecs/ModelCodec.ts Refined parameter types and replaced dynamic method call with superclass call.
packages/core/src/serialization/codecs/RootChangeCodec.ts Added type assertion for property names array in constructor.
packages/core/src/serialization/codecs/StylesheetCodec.ts Improved type safety and iteration style in encode method.
packages/core/src/serialization/codecs/TerminalChangeCodec.ts Added type assertions for property key arrays in constructor.
packages/core/src/serialization/codecs/editor/EditorCodec.ts Updated to use Editor type annotations and renamed unused parameters.
packages/core/src/serialization/codecs/editor/EditorKeyHandlerCodec.ts Specified parameter types in encode method.
packages/core/src/serialization/codecs/editor/EditorPopupMenuCodec.ts Updated JSDoc and parameter type for decode method.
packages/core/src/serialization/codecs/editor/EditorToolbarCodec.ts Improved type safety, nullability, and introduced a type alias for select options.
packages/core/src/serialization/register-shared.ts Introduced createObjectCodec helper and updated codec registration.
packages/core/src/util/EventUtils.ts Removed commented-out code and updated JSDoc references.
packages/core/src/view/GraphView.ts Added recurse parameter to clear method and updated documentation.
packages/core/src/view/cell/CellState.ts Updated JSDoc to use correct link tag for Point type.

Sequence Diagram(s)

sequenceDiagram
    participant TestSuite as Test Suite
    participant Codec as Codec
    participant XML as XML Document
    participant Object as Target Object

    TestSuite->>Codec: importToObject(Object, xmlString)
    Codec->>XML: parseXml(xmlString)
    Codec->>Object: decode(XML.root, Object)
    Object-->>TestSuite: Object populated

    TestSuite->>Codec: exportObject(Object)
    Codec->>XML: encode(Object)
    Codec->>TestSuite: getPrettyXml(XML.node)
Loading

Suggested labels

refactor, enhancement, documentation

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

npm error Exit handler never called!
npm error This is an error with npm itself. Please report this error at:
npm error https://github.com/npm/cli/issues
npm error A complete log of this run can be found in: /.npm/_logs/2025-07-11T08_47_56_594Z-debug-0.log


📜 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 c17b124 and b41afad.

📒 Files selected for processing (3)
  • packages/core/src/serialization/ObjectCodec.ts (8 hunks)
  • packages/core/src/serialization/codecs/CellCodec.ts (2 hunks)
  • packages/core/src/util/EventUtils.ts (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • packages/core/src/util/EventUtils.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/core/src/serialization/ObjectCodec.ts
  • packages/core/src/serialization/codecs/CellCodec.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: build (windows-2022)
  • GitHub Check: build (ubuntu-24.04)
  • GitHub Check: build (macos-14)
  • GitHub Check: build
✨ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

* Lookup table for resolving IDs to elements.
*/
elements: any = null; // TODO why not { [key: string]: Element } | null
elements: Record<string, Element> = {};
Copy link
Member Author

Choose a reason for hiding this comment

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

thought: not a breaking change, this is an internal property

@tbouffard tbouffard marked this pull request as ready for review July 10, 2025 19:09
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

♻️ Duplicate comments (1)
CHANGELOG.md (1)

19-21: LGTM! Changelog accurately documents EditorToolbar API changes.

The breaking changes are clearly documented, showing the more precise return types for addPrototype() and addCombo() methods. This addresses the previous review feedback and helps users understand the API refinements.

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

134-138: One lingering JSDoc reference still points to mxGraph.isMouseDown.

The comment for isMiddleMouseButton (lines 136-138) wasn’t updated and now diverges from the earlier fix.

- * {@link mxGraph.isMouseDown} property.
+ * {@link Graph.isMouseDown} property.
packages/core/src/serialization/ObjectCodec.ts (1)

29-36: LGTM: Well-defined numeric attribute constants.

The constant arrays provide clear, maintainable definitions of numeric attributes for Geometry and Point objects. This approach is more reliable than string-based checks and easier to maintain.

Note: Line 35 appears to have an incorrect type annotation - pointNumericAttributes should be Array<keyof Point> instead of Array<keyof Geometry>.

Fix the type annotation:

-const pointNumericAttributes: Array<keyof Geometry> = ['_x', '_y'];
+const pointNumericAttributes: Array<keyof Point> = ['_x', '_y'];
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ed5982f and c17b124.

📒 Files selected for processing (28)
  • CHANGELOG.md (1 hunks)
  • packages/core/__tests__/serialization/codecs/GraphViewCodec.test.ts (1 hunks)
  • packages/core/__tests__/serialization/codecs/StylesheetCodec.test.ts (1 hunks)
  • packages/core/__tests__/serialization/codecs/all-graph-classes.test.ts (4 hunks)
  • packages/core/__tests__/serialization/codecs/shared.ts (1 hunks)
  • packages/core/__tests__/serialization/serialization.xml.test.ts (3 hunks)
  • packages/core/__tests__/serialization/utils.ts (4 hunks)
  • packages/core/src/editor/EditorToolbar.ts (8 hunks)
  • packages/core/src/serialization/Codec.ts (7 hunks)
  • packages/core/src/serialization/CodecRegistry.ts (1 hunks)
  • packages/core/src/serialization/ObjectCodec.ts (7 hunks)
  • packages/core/src/serialization/codecs/BaseGraphCodec.ts (0 hunks)
  • packages/core/src/serialization/codecs/CellCodec.ts (1 hunks)
  • packages/core/src/serialization/codecs/ChildChangeCodec.ts (1 hunks)
  • packages/core/src/serialization/codecs/GraphCodec.ts (1 hunks)
  • packages/core/src/serialization/codecs/GraphViewCodec.ts (6 hunks)
  • packages/core/src/serialization/codecs/ModelCodec.ts (2 hunks)
  • packages/core/src/serialization/codecs/RootChangeCodec.ts (1 hunks)
  • packages/core/src/serialization/codecs/StylesheetCodec.ts (1 hunks)
  • packages/core/src/serialization/codecs/TerminalChangeCodec.ts (1 hunks)
  • packages/core/src/serialization/codecs/editor/EditorCodec.ts (4 hunks)
  • packages/core/src/serialization/codecs/editor/EditorKeyHandlerCodec.ts (1 hunks)
  • packages/core/src/serialization/codecs/editor/EditorPopupMenuCodec.ts (1 hunks)
  • packages/core/src/serialization/codecs/editor/EditorToolbarCodec.ts (10 hunks)
  • packages/core/src/serialization/register-shared.ts (1 hunks)
  • packages/core/src/util/EventUtils.ts (1 hunks)
  • packages/core/src/view/GraphView.ts (1 hunks)
  • packages/core/src/view/cell/CellState.ts (1 hunks)
💤 Files with no reviewable changes (1)
  • packages/core/src/serialization/codecs/BaseGraphCodec.ts
🧰 Additional context used
🧠 Learnings (18)
📓 Common learnings
Learnt from: tbouffard
PR: maxGraph/maxGraph#776
File: packages/core/src/view/AbstractGraph.ts:492-495
Timestamp: 2025-04-24T12:34:56.726Z
Learning: PR #776 focuses on refactoring to introduce AbstractGraph as a base class and moving code from Graph to AbstractGraph. Type improvements and other refinements should be addressed in future PRs to keep this one focused on the core architectural change.
Learnt from: tbouffard
PR: maxGraph/maxGraph#857
File: packages/core/src/view/plugins/SelectionHandler.ts:1081-1092
Timestamp: 2025-06-26T13:27:19.012Z
Learning: User tbouffard prefers to keep PRs focused on their main objective and defer implementation improvements or logic fixes to future dedicated PRs. For maxGraph, refactoring PRs like Dictionary→Map migration should not include unrelated logic improvements even when valid issues are identified in the migrated code.
Learnt from: tbouffard
PR: maxGraph/maxGraph#740
File: packages/core/src/util/requestUtils.ts:79-106
Timestamp: 2025-03-31T08:32:17.055Z
Learning: PR #740 is focused on reorganizing code into namespaces (guiUtils and requestUtils) without changing any implementations. Implementation improvements should be suggested for future PRs.
Learnt from: tbouffard
PR: maxGraph/maxGraph#593
File: .github/workflows/create-github-release.yml:42-42
Timestamp: 2025-01-28T16:22:25.804Z
Learning: In the GitHub release notes template for maxGraph, TODO comments are intentionally included to mark sections that must be reviewed by maintainers before publishing the release. These TODOs should not be removed or converted to validation steps as they are part of the release review process.
Learnt from: tbouffard
PR: maxGraph/maxGraph#715
File: packages/html/stories/ZoomAndFit.stories.ts:0-0
Timestamp: 2025-03-14T06:01:22.326Z
Learning: For future improvements to the Graph component in maxGraph, tbouffard is interested in refactoring the `fit` method to use an object parameter pattern instead of multiple positional parameters, as the current approach makes the API harder to use when many parameters need to be specified with default values.
Learnt from: tbouffard
PR: maxGraph/maxGraph#791
File: packages/core/src/view/style/edge/Segment.ts:26-35
Timestamp: 2025-04-29T13:29:45.122Z
Learning: In the maxGraph project, JSDoc `{@link}` references to symbols don't need to be imported in the current file to work correctly. TypeDoc can resolve symbols across the entire project namespace, not just within the current file, which is common in modern documentation systems and IDEs.
Learnt from: tbouffard
PR: maxGraph/maxGraph#849
File: packages/html/stories/DragSource.stories.js:98-101
Timestamp: 2025-06-13T07:48:10.300Z
Learning: User tbouffard prefers answers in English; avoid switching to other languages in future replies.
packages/core/src/view/cell/CellState.ts (1)
Learnt from: tbouffard
PR: maxGraph/maxGraph#791
File: packages/core/src/view/style/edge/Segment.ts:26-35
Timestamp: 2025-04-29T13:29:45.122Z
Learning: In the maxGraph project, JSDoc `{@link}` references to symbols don't need to be imported in the current file to work correctly. TypeDoc can resolve symbols across the entire project namespace, not just within the current file, which is common in modern documentation systems and IDEs.
packages/core/src/util/EventUtils.ts (2)
Learnt from: tbouffard
PR: maxGraph/maxGraph#791
File: packages/core/src/view/style/edge/Segment.ts:26-35
Timestamp: 2025-04-29T13:29:45.122Z
Learning: In the maxGraph project, JSDoc `{@link}` references to symbols don't need to be imported in the current file to work correctly. TypeDoc can resolve symbols across the entire project namespace, not just within the current file, which is common in modern documentation systems and IDEs.
Learnt from: tbouffard
PR: maxGraph/maxGraph#770
File: packages/core/src/view/cell/CellTracker.ts:99-101
Timestamp: 2025-04-18T07:02:31.931Z
Learning: In TypeScript, when implementing an interface, methods can have fewer parameters than declared in the interface due to TypeScript's structural typing system. Both omitting unused parameters entirely and prefixing them with underscore (e.g., _sender) are valid patterns in the maxGraph codebase.
packages/core/src/serialization/codecs/CellCodec.ts (2)
Learnt from: tbouffard
PR: maxGraph/maxGraph#618
File: packages/website/docs/tutorials/graph.md:56-59
Timestamp: 2025-01-06T09:09:47.410Z
Learning: In the maxGraph library, the classes "Cell" and "GraphDataModel" are valid, while "GraphCell" and "GraphModel" do not exist.
Learnt from: tbouffard
PR: maxGraph/maxGraph#776
File: packages/core/src/view/Graph.ts:85-92
Timestamp: 2025-04-24T12:34:10.366Z
Learning: The Graph class intentionally doesn't use collaborators (cellRenderer, selectionModel, view) from options in initializeCollaborators, as it's designed to replicate the previous implementation using only its factory methods for backward compatibility.
packages/core/__tests__/serialization/codecs/shared.ts (2)
Learnt from: tbouffard
PR: maxGraph/maxGraph#582
File: packages/core/__tests__/view/handler/config.test.ts:0-0
Timestamp: 2024-11-24T17:28:08.023Z
Learning: In `packages/core/__tests__/view/handler/config.test.ts`, when writing Jest tests in TypeScript for configuration reset functions, small duplication is acceptable if it maintains test clarity and readability. Avoid refactoring tests in ways that could make them harder to understand, especially when future use cases might require specific checks.
Learnt from: tbouffard
PR: maxGraph/maxGraph#791
File: packages/core/src/view/style/edge/Segment.ts:26-35
Timestamp: 2025-04-29T13:29:45.122Z
Learning: In the maxGraph project, JSDoc `{@link}` references to symbols don't need to be imported in the current file to work correctly. TypeDoc can resolve symbols across the entire project namespace, not just within the current file, which is common in modern documentation systems and IDEs.
CHANGELOG.md (5)
Learnt from: tbouffard
PR: maxGraph/maxGraph#791
File: packages/core/src/view/style/edge/Segment.ts:26-35
Timestamp: 2025-04-29T13:29:45.122Z
Learning: In the maxGraph project, JSDoc `{@link}` references to symbols don't need to be imported in the current file to work correctly. TypeDoc can resolve symbols across the entire project namespace, not just within the current file, which is common in modern documentation systems and IDEs.
Learnt from: tbouffard
PR: maxGraph/maxGraph#770
File: packages/core/src/view/cell/CellTracker.ts:99-101
Timestamp: 2025-04-18T07:02:31.931Z
Learning: In TypeScript, when implementing an interface, methods can have fewer parameters than declared in the interface due to TypeScript's structural typing system. Both omitting unused parameters entirely and prefixing them with underscore (e.g., _sender) are valid patterns in the maxGraph codebase.
Learnt from: tbouffard
PR: maxGraph/maxGraph#726
File: packages/core/src/editor/EditorPopupMenu.ts:197-197
Timestamp: 2025-03-25T14:13:25.331Z
Learning: The team has decided to keep using `eval()` in EditorPopupMenu.ts as the implementation is loaded from XML configuration. Finding alternatives to `eval()` for improved security is planned for future work.
Learnt from: tbouffard
PR: maxGraph/maxGraph#857
File: packages/core/src/view/plugins/SelectionHandler.ts:1081-1092
Timestamp: 2025-06-26T13:27:19.012Z
Learning: User tbouffard prefers to keep PRs focused on their main objective and defer implementation improvements or logic fixes to future dedicated PRs. For maxGraph, refactoring PRs like Dictionary→Map migration should not include unrelated logic improvements even when valid issues are identified in the migrated code.
Learnt from: tbouffard
PR: maxGraph/maxGraph#679
File: packages/html/stories/Drop.stories.js:71-94
Timestamp: 2025-02-17T06:01:50.745Z
Learning: maxGraph does not support Internet Explorer, making IE-specific browser compatibility checks unnecessary.
packages/core/src/serialization/codecs/editor/EditorPopupMenuCodec.ts (1)
Learnt from: tbouffard
PR: maxGraph/maxGraph#726
File: packages/core/src/editor/EditorPopupMenu.ts:197-197
Timestamp: 2025-03-25T14:13:25.331Z
Learning: The team has decided to keep using `eval()` in EditorPopupMenu.ts as the implementation is loaded from XML configuration. Finding alternatives to `eval()` for improved security is planned for future work.
packages/core/src/serialization/codecs/GraphCodec.ts (8)
Learnt from: tbouffard
PR: maxGraph/maxGraph#776
File: packages/core/src/view/AbstractGraph.ts:492-495
Timestamp: 2025-04-24T12:34:56.726Z
Learning: PR #776 focuses on refactoring to introduce AbstractGraph as a base class and moving code from Graph to AbstractGraph. Type improvements and other refinements should be addressed in future PRs to keep this one focused on the core architectural change.
Learnt from: tbouffard
PR: maxGraph/maxGraph#770
File: packages/core/src/view/cell/CellTracker.ts:99-101
Timestamp: 2025-04-18T07:02:31.931Z
Learning: In TypeScript, when implementing an interface, methods can have fewer parameters than declared in the interface due to TypeScript's structural typing system. Both omitting unused parameters entirely and prefixing them with underscore (e.g., _sender) are valid patterns in the maxGraph codebase.
Learnt from: tbouffard
PR: maxGraph/maxGraph#791
File: packages/core/src/view/style/edge/Segment.ts:26-35
Timestamp: 2025-04-29T13:29:45.122Z
Learning: In the maxGraph project, JSDoc `{@link}` references to symbols don't need to be imported in the current file to work correctly. TypeDoc can resolve symbols across the entire project namespace, not just within the current file, which is common in modern documentation systems and IDEs.
Learnt from: tbouffard
PR: maxGraph/maxGraph#774
File: packages/ts-example-selected-features/package.json:11-13
Timestamp: 2025-04-22T16:34:40.309Z
Learning: In the maxGraph project, TypeScript is defined as a dependency in the root package.json and not in individual package.json files for example packages. The build scripts in example packages can use `tsc` because it's available through this hoisted dependency in the monorepo structure.
Learnt from: tbouffard
PR: maxGraph/maxGraph#774
File: packages/ts-example-selected-features/package.json:11-13
Timestamp: 2025-04-22T16:34:40.309Z
Learning: In the maxGraph project, TypeScript is defined as a dependency in the root package.json (~5.8.2) and not in individual package.json files for example packages. The build scripts in example packages can use `tsc` commands because the TypeScript dependency is hoisted in the monorepo structure.
Learnt from: tbouffard
PR: maxGraph/maxGraph#593
File: .github/workflows/create-github-release.yml:42-42
Timestamp: 2025-01-28T16:22:25.804Z
Learning: In the GitHub release notes template for maxGraph, TODO comments are intentionally included to mark sections that must be reviewed by maintainers before publishing the release. These TODOs should not be removed or converted to validation steps as they are part of the release review process.
Learnt from: tbouffard
PR: maxGraph/maxGraph#776
File: packages/core/src/view/Graph.ts:85-92
Timestamp: 2025-04-24T12:34:10.366Z
Learning: The Graph class intentionally doesn't use collaborators (cellRenderer, selectionModel, view) from options in initializeCollaborators, as it's designed to replicate the previous implementation using only its factory methods for backward compatibility.
Learnt from: tbouffard
PR: maxGraph/maxGraph#785
File: packages/core/src/view/style/register.ts:19-19
Timestamp: 2025-04-28T08:24:39.831Z
Learning: In the maxGraph project, the Perimeter namespace is defined in the 'builtin-style-elements.ts' file using the statement 'export * as Perimeter from './perimeter';'. To access the Perimeter namespace in other files, they must import from './builtin-style-elements' instead of directly from './perimeter', as part of the tree-shaking optimization.
packages/core/__tests__/serialization/codecs/GraphViewCodec.test.ts (6)
Learnt from: tbouffard
PR: maxGraph/maxGraph#582
File: packages/core/__tests__/view/handler/config.test.ts:0-0
Timestamp: 2024-11-24T17:28:08.023Z
Learning: In `packages/core/__tests__/view/handler/config.test.ts`, when writing Jest tests in TypeScript for configuration reset functions, small duplication is acceptable if it maintains test clarity and readability. Avoid refactoring tests in ways that could make them harder to understand, especially when future use cases might require specific checks.
Learnt from: tbouffard
PR: maxGraph/maxGraph#791
File: packages/core/src/view/style/edge/Segment.ts:26-35
Timestamp: 2025-04-29T13:29:45.122Z
Learning: In the maxGraph project, JSDoc `{@link}` references to symbols don't need to be imported in the current file to work correctly. TypeDoc can resolve symbols across the entire project namespace, not just within the current file, which is common in modern documentation systems and IDEs.
Learnt from: tbouffard
PR: maxGraph/maxGraph#826
File: packages/js-example-nodejs/src/index.cjs:64-69
Timestamp: 2025-05-13T12:54:55.231Z
Learning: For example code in the maxGraph repository, maintainers prefer to keep scripts simple without error handling to focus on demonstrating core functionality, especially in demonstration scripts like those in packages/js-example-nodejs.
Learnt from: tbouffard
PR: maxGraph/maxGraph#785
File: packages/core/src/view/style/register.ts:19-19
Timestamp: 2025-04-28T08:24:39.831Z
Learning: In the maxGraph project, the Perimeter namespace is defined in the './builtin-style-elements' file as a namespace export ('export * as Perimeter'), making this the correct import location for accessing the Perimeter namespace.
Learnt from: tbouffard
PR: maxGraph/maxGraph#785
File: packages/core/src/view/style/register.ts:19-19
Timestamp: 2025-04-28T08:24:39.831Z
Learning: In the maxGraph project, the Perimeter namespace is defined in the 'builtin-style-elements.ts' file using the statement 'export * as Perimeter from './perimeter';'. To access the Perimeter namespace in other files, they must import from './builtin-style-elements' instead of directly from './perimeter', as part of the tree-shaking optimization.
Learnt from: tbouffard
PR: maxGraph/maxGraph#791
File: packages/ts-example/vite.config.js:30-30
Timestamp: 2025-04-29T13:25:31.494Z
Learning: In the maxGraph project, each example package (ts-example, ts-example-selected-features, ts-example-without-defaults) implements different use cases with varying features, resulting in different application sizes. Therefore, each package has its own specific chunkSizeWarningLimit value in its vite.config.js file, calibrated to its expected bundle size.
packages/core/__tests__/serialization/codecs/StylesheetCodec.test.ts (4)
Learnt from: tbouffard
PR: maxGraph/maxGraph#582
File: packages/core/__tests__/view/handler/config.test.ts:0-0
Timestamp: 2024-11-24T17:28:08.023Z
Learning: In `packages/core/__tests__/view/handler/config.test.ts`, when writing Jest tests in TypeScript for configuration reset functions, small duplication is acceptable if it maintains test clarity and readability. Avoid refactoring tests in ways that could make them harder to understand, especially when future use cases might require specific checks.
Learnt from: tbouffard
PR: maxGraph/maxGraph#785
File: packages/core/src/view/style/register.ts:19-19
Timestamp: 2025-04-28T08:24:39.831Z
Learning: In the maxGraph project, the Perimeter namespace is defined in the './builtin-style-elements' file as a namespace export ('export * as Perimeter'), making this the correct import location for accessing the Perimeter namespace.
Learnt from: tbouffard
PR: maxGraph/maxGraph#785
File: packages/core/src/view/style/register.ts:19-19
Timestamp: 2025-04-28T08:24:39.831Z
Learning: In the maxGraph project, the Perimeter namespace is defined in the 'builtin-style-elements.ts' file using the statement 'export * as Perimeter from './perimeter';'. To access the Perimeter namespace in other files, they must import from './builtin-style-elements' instead of directly from './perimeter', as part of the tree-shaking optimization.
Learnt from: tbouffard
PR: maxGraph/maxGraph#791
File: packages/core/src/view/style/edge/Segment.ts:26-35
Timestamp: 2025-04-29T13:29:45.122Z
Learning: In the maxGraph project, JSDoc `{@link}` references to symbols don't need to be imported in the current file to work correctly. TypeDoc can resolve symbols across the entire project namespace, not just within the current file, which is common in modern documentation systems and IDEs.
packages/core/src/serialization/codecs/editor/EditorToolbarCodec.ts (1)
Learnt from: tbouffard
PR: maxGraph/maxGraph#726
File: packages/core/src/editor/EditorPopupMenu.ts:197-197
Timestamp: 2025-03-25T14:13:25.331Z
Learning: The team has decided to keep using `eval()` in EditorPopupMenu.ts as the implementation is loaded from XML configuration. Finding alternatives to `eval()` for improved security is planned for future work.
packages/core/src/view/GraphView.ts (1)
Learnt from: tbouffard
PR: maxGraph/maxGraph#776
File: packages/core/src/view/Graph.ts:85-92
Timestamp: 2025-04-24T12:34:10.366Z
Learning: The Graph class intentionally doesn't use collaborators (cellRenderer, selectionModel, view) from options in initializeCollaborators, as it's designed to replicate the previous implementation using only its factory methods for backward compatibility.
packages/core/__tests__/serialization/codecs/all-graph-classes.test.ts (10)
Learnt from: tbouffard
PR: maxGraph/maxGraph#582
File: packages/core/__tests__/view/handler/config.test.ts:0-0
Timestamp: 2024-11-24T17:28:08.023Z
Learning: In `packages/core/__tests__/view/handler/config.test.ts`, when writing Jest tests in TypeScript for configuration reset functions, small duplication is acceptable if it maintains test clarity and readability. Avoid refactoring tests in ways that could make them harder to understand, especially when future use cases might require specific checks.
Learnt from: tbouffard
PR: maxGraph/maxGraph#785
File: packages/core/src/view/style/register.ts:19-19
Timestamp: 2025-04-28T08:24:39.831Z
Learning: In the maxGraph project, the Perimeter namespace is defined in the 'builtin-style-elements.ts' file using the statement 'export * as Perimeter from './perimeter';'. To access the Perimeter namespace in other files, they must import from './builtin-style-elements' instead of directly from './perimeter', as part of the tree-shaking optimization.
Learnt from: tbouffard
PR: maxGraph/maxGraph#776
File: packages/core/src/view/AbstractGraph.ts:492-495
Timestamp: 2025-04-24T12:34:56.726Z
Learning: PR #776 focuses on refactoring to introduce AbstractGraph as a base class and moving code from Graph to AbstractGraph. Type improvements and other refinements should be addressed in future PRs to keep this one focused on the core architectural change.
Learnt from: tbouffard
PR: maxGraph/maxGraph#791
File: packages/core/src/view/style/edge/Segment.ts:26-35
Timestamp: 2025-04-29T13:29:45.122Z
Learning: In the maxGraph project, JSDoc `{@link}` references to symbols don't need to be imported in the current file to work correctly. TypeDoc can resolve symbols across the entire project namespace, not just within the current file, which is common in modern documentation systems and IDEs.
Learnt from: tbouffard
PR: maxGraph/maxGraph#774
File: packages/ts-example-selected-features/package.json:11-13
Timestamp: 2025-04-22T16:34:40.309Z
Learning: In the maxGraph project, TypeScript is defined as a dependency in the root package.json and not in individual package.json files for example packages. The build scripts in example packages can use `tsc` because it's available through this hoisted dependency in the monorepo structure.
Learnt from: tbouffard
PR: maxGraph/maxGraph#826
File: packages/js-example-nodejs/src/index.cjs:64-69
Timestamp: 2025-05-13T12:54:55.231Z
Learning: For example code in the maxGraph repository, maintainers prefer to keep scripts simple without error handling to focus on demonstrating core functionality, especially in demonstration scripts like those in packages/js-example-nodejs.
Learnt from: tbouffard
PR: maxGraph/maxGraph#598
File: packages/website/docs/manual/getting-started.md:70-70
Timestamp: 2024-12-15T18:19:56.236Z
Learning: In code examples within the documentation, such as in `packages/website/docs/manual/getting-started.md`, we assume that the `graph-container` element exists and is an `HTMLElement`, and we avoid adding error handling for its initialization to keep the code simple.
Learnt from: tbouffard
PR: maxGraph/maxGraph#785
File: packages/core/src/view/style/register.ts:19-19
Timestamp: 2025-04-28T08:24:39.831Z
Learning: In the maxGraph project, the Perimeter namespace is defined in the './builtin-style-elements' file as a namespace export ('export * as Perimeter'), making this the correct import location for accessing the Perimeter namespace.
Learnt from: tbouffard
PR: maxGraph/maxGraph#618
File: packages/website/docs/tutorials/graph.md:56-59
Timestamp: 2025-01-06T09:09:47.410Z
Learning: In the maxGraph library, the classes "Cell" and "GraphDataModel" are valid, while "GraphCell" and "GraphModel" do not exist.
Learnt from: tbouffard
PR: maxGraph/maxGraph#776
File: packages/core/src/view/Graph.ts:85-92
Timestamp: 2025-04-24T12:34:10.366Z
Learning: The Graph class intentionally doesn't use collaborators (cellRenderer, selectionModel, view) from options in initializeCollaborators, as it's designed to replicate the previous implementation using only its factory methods for backward compatibility.
packages/core/src/serialization/codecs/GraphViewCodec.ts (2)
Learnt from: tbouffard
PR: maxGraph/maxGraph#776
File: packages/core/src/view/AbstractGraph.ts:492-495
Timestamp: 2025-04-24T12:34:56.726Z
Learning: PR #776 focuses on refactoring to introduce AbstractGraph as a base class and moving code from Graph to AbstractGraph. Type improvements and other refinements should be addressed in future PRs to keep this one focused on the core architectural change.
Learnt from: tbouffard
PR: maxGraph/maxGraph#776
File: packages/core/src/view/Graph.ts:85-92
Timestamp: 2025-04-24T12:34:10.366Z
Learning: The Graph class intentionally doesn't use collaborators (cellRenderer, selectionModel, view) from options in initializeCollaborators, as it's designed to replicate the previous implementation using only its factory methods for backward compatibility.
packages/core/src/serialization/codecs/editor/EditorCodec.ts (1)
Learnt from: tbouffard
PR: maxGraph/maxGraph#726
File: packages/core/src/editor/EditorPopupMenu.ts:197-197
Timestamp: 2025-03-25T14:13:25.331Z
Learning: The team has decided to keep using `eval()` in EditorPopupMenu.ts as the implementation is loaded from XML configuration. Finding alternatives to `eval()` for improved security is planned for future work.
packages/core/__tests__/serialization/serialization.xml.test.ts (3)
Learnt from: tbouffard
PR: maxGraph/maxGraph#582
File: packages/core/__tests__/view/handler/config.test.ts:0-0
Timestamp: 2024-11-24T17:28:08.023Z
Learning: In `packages/core/__tests__/view/handler/config.test.ts`, when writing Jest tests in TypeScript for configuration reset functions, small duplication is acceptable if it maintains test clarity and readability. Avoid refactoring tests in ways that could make them harder to understand, especially when future use cases might require specific checks.
Learnt from: tbouffard
PR: maxGraph/maxGraph#618
File: packages/website/docs/tutorials/graph.md:56-59
Timestamp: 2025-01-06T09:09:47.410Z
Learning: In the maxGraph library, the classes "Cell" and "GraphDataModel" are valid, while "GraphCell" and "GraphModel" do not exist.
Learnt from: tbouffard
PR: maxGraph/maxGraph#776
File: packages/core/src/view/Graph.ts:85-92
Timestamp: 2025-04-24T12:34:10.366Z
Learning: The Graph class intentionally doesn't use collaborators (cellRenderer, selectionModel, view) from options in initializeCollaborators, as it's designed to replicate the previous implementation using only its factory methods for backward compatibility.
packages/core/__tests__/serialization/utils.ts (2)
Learnt from: tbouffard
PR: maxGraph/maxGraph#835
File: packages/html/stories/Orthogonal.stories.ts:114-117
Timestamp: 2025-05-26T12:34:54.318Z
Learning: The `null!` assertion pattern exists across multiple stories in the TypeScript migration and should be addressed systematically rather than in individual PRs.
Learnt from: tbouffard
PR: maxGraph/maxGraph#618
File: packages/website/docs/tutorials/graph.md:56-59
Timestamp: 2025-01-06T09:09:47.410Z
Learning: In the maxGraph library, the classes "Cell" and "GraphDataModel" are valid, while "GraphCell" and "GraphModel" do not exist.
packages/core/src/editor/EditorToolbar.ts (1)
Learnt from: tbouffard
PR: maxGraph/maxGraph#726
File: packages/core/src/editor/EditorPopupMenu.ts:197-197
Timestamp: 2025-03-25T14:13:25.331Z
Learning: The team has decided to keep using `eval()` in EditorPopupMenu.ts as the implementation is loaded from XML configuration. Finding alternatives to `eval()` for improved security is planned for future work.
🧬 Code Graph Analysis (14)
packages/core/src/serialization/codecs/TerminalChangeCodec.ts (1)
packages/core/src/view/undoable_changes/TerminalChange.ts (1)
  • TerminalChange (27-53)
packages/core/src/serialization/codecs/CellCodec.ts (1)
packages/core/src/view/cell/Cell.ts (1)
  • Cell (66-888)
packages/core/src/serialization/codecs/ModelCodec.ts (1)
packages/core/src/view/cell/Cell.ts (1)
  • Cell (66-888)
packages/core/__tests__/serialization/codecs/shared.ts (1)
packages/core/src/util/xmlUtils.ts (1)
  • getPrettyXml (132-220)
packages/core/src/serialization/codecs/editor/EditorKeyHandlerCodec.ts (1)
packages/core/src/editor/EditorKeyHandler.ts (1)
  • EditorKeyHandler (48-105)
packages/core/src/serialization/codecs/editor/EditorPopupMenuCodec.ts (1)
packages/core/src/editor/EditorPopupMenu.ts (1)
  • EditorPopupMenu (41-329)
packages/core/src/serialization/codecs/RootChangeCodec.ts (1)
packages/core/src/view/undoable_changes/RootChange.ts (1)
  • RootChange (27-45)
packages/core/src/serialization/codecs/GraphCodec.ts (1)
packages/core/src/index.ts (1)
  • AbstractGraph (20-20)
packages/core/__tests__/serialization/codecs/GraphViewCodec.test.ts (4)
packages/core/src/view/Graph.ts (1)
  • createGraphView (59-61)
packages/core/src/view/GraphView.ts (1)
  • GraphView (99-2393)
packages/core/src/serialization/register-other-codecs.ts (2)
  • unregisterAllCodecs (141-149)
  • registerCoreCodecs (78-97)
packages/core/__tests__/serialization/codecs/shared.ts (1)
  • exportObject (25-28)
packages/core/src/serialization/ObjectCodec.ts (2)
packages/core/src/util/domUtils.ts (1)
  • write (144-153)
packages/core/src/gui/MaxLog.ts (1)
  • write (321-345)
packages/core/src/serialization/codecs/editor/EditorToolbarCodec.ts (2)
packages/core/src/editor/EditorToolbar.ts (1)
  • EditorToolbar (59-478)
packages/core/src/editor/Editor.ts (1)
  • Editor (391-2597)
packages/core/src/serialization/codecs/StylesheetCodec.ts (1)
packages/core/src/view/style/Stylesheet.ts (1)
  • Stylesheet (49-200)
packages/core/__tests__/serialization/codecs/all-graph-classes.test.ts (1)
packages/core/__tests__/serialization/codecs/shared.ts (2)
  • exportObject (25-28)
  • importToObject (20-23)
packages/core/src/serialization/codecs/GraphViewCodec.ts (2)
packages/core/src/view/GraphView.ts (1)
  • GraphView (99-2393)
packages/core/src/view/cell/Cell.ts (1)
  • Cell (66-888)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: build (ubuntu-24.04)
  • GitHub Check: build (windows-2022)
🔇 Additional comments (65)
packages/core/src/util/EventUtils.ts (1)

116-122: 👍 Reference update to Graph.isMouseDown looks correct.

Thanks for aligning the JSDoc with the renamed symbol.

packages/core/src/view/cell/CellState.ts (1)

92-92: LGTM! JSDoc link formatting improved.

The change from <Point> to {@link Point} follows proper JSDoc linking conventions and will improve documentation generation.

packages/core/src/serialization/codecs/TerminalChangeCodec.ts (1)

43-44: LGTM! Type assertions improve type safety.

The explicit casting to Array<keyof TerminalChange> provides stronger type checking and ensures the arrays contain valid property names from the TerminalChange class. This aligns with the broader type safety improvements across codec classes in this PR.

packages/core/src/serialization/codecs/CellCodec.ts (1)

59-60: LGTM! Type assertions enhance type safety.

The explicit casting to Array<keyof Cell> ensures compile-time verification that the arrays contain valid Cell property names. This is consistent with similar improvements across other codec classes in this PR and strengthens type checking without affecting runtime behavior.

packages/core/src/serialization/codecs/editor/EditorPopupMenuCodec.ts (1)

45-47: LGTM! Documentation and type safety improvements.

Two positive changes:

  1. JSDoc improvement from <EditorPopupMenu> to {@link EditorPopupMenu} follows proper linking conventions
  2. Parameter type refinement from any to EditorPopupMenu provides better type safety

These changes align with the broader type safety enhancements across editor codec classes in this PR.

packages/core/src/serialization/codecs/editor/EditorKeyHandlerCodec.ts (1)

38-40: LGTM! Good type safety improvement.

The method signature now uses specific types (Codec and EditorKeyHandler) instead of generic types, which aligns with the PR's goal of improving type safety across codec classes.

packages/core/src/serialization/codecs/RootChangeCodec.ts (1)

38-40: LGTM! Explicit type assertion improves type safety.

The explicit cast to Array<keyof RootChange> ensures compile-time verification that the property names match the RootChange interface keys, preventing typos and improving type safety.

packages/core/src/serialization/codecs/ModelCodec.ts (2)

39-39: LGTM! Type annotation improvement.

The method signature now uses the specific Codec type instead of generic any, improving type safety and clarity.


52-52: LGTM! Clearer method dispatch.

Using super.decodeChild(dec, child, obj) instead of apply is more direct and clearer, explicitly indicating that the parent class implementation is being called.

packages/core/src/serialization/CodecRegistry.ts (1)

78-81: LGTM! Improved naming consistency.

The parameter names now follow camelCase conventions (className and codecName), which improves code consistency and readability.

packages/core/src/serialization/register-shared.ts (2)

37-38: LGTM! Good refactoring to use helper function.

Using the createObjectCodec helper function centralizes codec creation logic and provides consistent naming conventions.


44-48: LGTM! Useful helper function.

The createObjectCodec helper function provides a clean abstraction for creating and naming ObjectCodec instances, reducing code duplication and ensuring consistent codec registration.

packages/core/src/serialization/codecs/ChildChangeCodec.ts (3)

45-46: Excellent type safety improvement.

The explicit type assertions ensure that the arrays contain only valid keys of ChildChange, improving compile-time type checking and preventing potential runtime errors.


54-54: Good alignment with superclass signature.

The nullable attr parameter aligns with the ObjectCodec.isReference method signature, ensuring consistent type handling across the inheritance hierarchy.


58-58: Improved delegation pattern.

The change from direct array lookup to delegating to super.isReference is more maintainable and follows proper inheritance patterns. This ensures consistent reference determination logic across the codec hierarchy.

packages/core/src/serialization/codecs/GraphCodec.ts (2)

21-21: Necessary import for type annotation.

The AbstractGraph import is required to support the type annotation on the excludedFields array.


23-31: Enhanced type safety with appropriate handling of private property.

The explicit typing of excludedFields as Array<keyof AbstractGraph> improves compile-time type checking. The @ts-ignore directive appropriately handles the private plugins property that still needs to be excluded from serialization.

packages/core/__tests__/serialization/codecs/StylesheetCodec.test.ts (3)

22-30: Excellent test isolation setup.

The setup and teardown hooks properly manage codec registration to prevent side effects between tests, following best practices for test isolation.


32-51: Comprehensive import test coverage.

The test validates both XML parsing and the correct mapping of style properties, ensuring the import functionality works as expected.


53-89: Thorough export verification.

The test verifies the complete XML output including both default styles (defaultVertex, defaultEdge) and custom styles, providing comprehensive coverage of the export functionality.

packages/core/__tests__/serialization/codecs/shared.ts (2)

20-23: Clean and focused utility function.

The importToObject function provides a clean abstraction for XML-to-object deserialization, properly utilizing the existing parseXml and Codec infrastructure.


25-28: Well-designed export utility.

The exportObject function encapsulates the encode-and-format pattern used across tests, promoting consistency and code reuse throughout the test suite.

packages/core/__tests__/serialization/codecs/GraphViewCodec.test.ts (3)

27-30: Simple and effective helper function.

The createGraphView helper provides a clean way to create a GraphView instance for testing purposes.


43-43: Helpful explanatory comment.

The comment clearly explains why only export functionality is tested, providing valuable context for future maintainers.


44-103: Comprehensive export test with complex graph structure.

The test creates a sophisticated graph with vertices, edges, child elements, and various style properties, then validates the complete XML serialization including positioning, styling, and hierarchical relationships. This provides excellent coverage of the GraphViewCodec export functionality.

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

465-470: LGTM! Enhanced JSDoc documentation.

The JSDoc comment has been properly enhanced to document the new recurse parameter, clearly explaining its purpose and default behavior. This improves code documentation and developer experience.

packages/core/__tests__/serialization/codecs/all-graph-classes.test.ts (3)

28-28: LGTM! Improved code reusability.

Good refactoring to use shared utility functions exportObject and importToObject instead of local helpers. This promotes consistency across serialization codec tests and reduces code duplication.


60-78: Enhanced test coverage with detailed stylesheet.

Excellent enhancement to the XML template by expanding the previously empty <Stylesheet as="stylesheet" /> tag into a fully populated element with default vertex and edge style definitions. This provides better test coverage and aligns with the detailed stylesheet structure tested in other codec test suites.


104-104: Test calls correctly updated for shared utilities.

The test assertions have been properly updated to use the new shared functions while maintaining the original test logic and expectations.

Also applies to: 113-113

packages/core/src/serialization/codecs/editor/EditorToolbarCodec.ts (3)

29-29: Good type safety improvement with custom type alias.

The HTMLOptionElementWithCellStyle type alias properly handles the custom cellStyle attribute on select options, replacing the previous @ts-ignore comments. This enhances type safety while maintaining functionality.


133-135: Enhanced type safety with explicit typing.

Good improvements to type safety by explicitly typing the into parameter as EditorToolbar and using non-null assertion on editor. The non-null assertion is safe here since the code path only executes when into != null is verified.


144-147: Consistent use of non-null assertions improves type safety.

The non-null assertions on properties like toolbar!, icon!, pressedIcon! are correctly applied based on the control flow context. These assertions align with the coordinated updates in EditorToolbar.ts where method signatures have been refined to return more specific element types and accept nullable parameters.

Also applies to: 164-164, 184-184, 201-203, 214-221, 231-231, 235-235, 245-246, 255-262

packages/core/src/serialization/codecs/StylesheetCodec.ts (3)

52-52: LGTM: Improved type safety.

The parameter type change from any to Stylesheet provides better type safety and aligns with the method's purpose.


55-61: LGTM: Correct Map iteration pattern.

The changes properly use Map methods instead of object-like access:

  • Using obj.styles.keys() for iteration over Map keys
  • Using obj.styles.get(styleName) for proper Map value access
  • Checking styleName truthiness instead of i != null

This aligns with the Stylesheet.styles: Map<string, CellStateStyle> type definition.


62-69: LGTM: Safer object property iteration.

The changes improve property iteration:

  • Using Object.keys(style ?? {}) provides safer iteration over object properties
  • The TypeScript ignore comment is appropriately documented
  • Variable naming is more descriptive (stylePropertyName vs j)

This ensures the code handles potential null/undefined style objects gracefully.

packages/core/src/serialization/codecs/editor/EditorCodec.ts (2)

51-51: LGTM: Explicit typing for transient fields.

The explicit type annotation Array<keyof Editor> ensures compile-time verification that the transient field names are valid Editor properties.


106-106: LGTM: Improved type safety with specific Editor types.

Replacing any with specific Editor types provides:

  • Better type checking at compile time
  • Improved IDE support and autocomplete
  • Clear indication of parameter intent

The underscore prefix for unused parameters follows TypeScript conventions.

Also applies to: 128-128, 146-146

packages/core/src/serialization/ObjectCodec.ts (4)

350-351: LGTM: Improved null handling and modern array method.

The changes provide:

  • Proper null handling with explicit null check
  • Use of includes() instead of indexOf() for better readability
  • Clear boolean return logic

This makes the method more robust and easier to understand.


606-607: LGTM: Enhanced numeric attribute detection.

Using instanceof checks with the predefined constant arrays provides:

  • More reliable type checking than string comparisons
  • Better maintainability through centralized attribute definitions
  • Clearer logic flow

This approach is more robust than previous implementations.


692-692: LGTM: Appropriate non-null assertion.

The non-null assertion is justified here since the comment indicates that subsequent calls work correctly even when id is null.


873-873: LGTM: Safe method invocation.

Using optional chaining (?.) prevents runtime errors if the object doesn't have a push method, making the code more defensive.

packages/core/__tests__/serialization/utils.ts (1)

25-25: LGTM: Expanded value type support.

The new NullableStringOrObject type alias appropriately broadens the supported cell value types to include objects, which aligns with real-world usage where cells can have complex object values beyond just strings.

This enhancement enables better test coverage for serialization scenarios involving complex cell values.

Also applies to: 52-52, 65-65, 78-78

packages/core/src/serialization/codecs/GraphViewCodec.ts (4)

24-26: LGTM: Useful helper function for consistency.

The setNodeAttribute helper function ensures consistent string conversion of numeric values across all attribute setting operations. This eliminates code duplication and reduces the risk of inconsistent formatting.


20-22: LGTM: Enhanced type safety.

The improvements provide:

  • Type-only imports for better tree-shaking and clearer intent
  • Explicit Codec parameter typing
  • Clear Element | null return type specification

These changes enhance IDE support and catch potential type errors at compile time.

Also applies to: 48-48, 64-65


111-113: LGTM: Modern iteration pattern.

Using Object.keys() instead of for...in provides:

  • More predictable iteration behavior
  • Better type safety with explicit property names
  • Clearer intent with descriptive variable naming

The TypeScript ignore comment is appropriately documented for the indexed access pattern.


92-92: LGTM: Consistent attribute handling.

The changes provide several improvements:

  • Cached label assignment reduces redundant method calls
  • String value 'true' for HTML attribute ensures proper XML serialization
  • Consistent use of setNodeAttribute for all numeric values ensures uniform string conversion

This creates more maintainable and reliable XML output.

Also applies to: 95-95, 103-110, 125-125, 143-159

packages/core/src/serialization/Codec.ts (5)

162-162: LGTM: Improved type safety with proper initialization.

The change from nullable any to typed Record<string, Element> = {} improves type safety and provides proper initialization. This aligns well with the corresponding logic update in updateElements().


240-240: LGTM: Consistent emptiness check with new property type.

The logic correctly adapts to the new property initialization, checking for empty object instead of null. This is consistent with the type change on line 162.


358-358: LGTM: Enhanced method signature improves type safety.

The refined signature with object | null return type and optional typed into parameter is a significant improvement over the previous any types.


368-371: LGTM: Valuable debugging enhancement.

Adding warning logs when no codec is found greatly improves debugging capabilities. The fallback to return a cloned XML element with the as attribute removed is also a sensible approach.


414-419: LGTM: Robust runtime type checking.

The enhanced method signature and runtime verification that isCellCodec is a function before invocation prevents potential runtime errors. This is a solid defensive programming practice.

packages/core/__tests__/serialization/serialization.xml.test.ts (6)

29-29: LGTM: Required import for XML verification.

The getXml import is necessary for the new test that verifies XML element preservation in fallback scenarios.


32-32: LGTM: Enhanced helper function supports object values.

Extending the newVertex signature to accept string | object enables testing of complex cell values, which is covered in the new test cases.


167-196: LGTM: Comprehensive test for extra XML nodes.

This test effectively verifies that extra XML nodes outside the root structure are properly attached as properties on the model instance during import, which is an important edge case for robust XML handling.


198-251: LGTM: Thorough test for complex object cell values.

The test comprehensively verifies import of cells with nested object values containing arrays and objects, ensuring proper deserialization of complex data structures.


253-283: LGTM: Excellent test for fallback behavior.

This test validates the important fallback scenario where XML nodes without matching codecs are preserved as XML elements, demonstrating the robustness improvements mentioned in the PR objectives.


439-488: LGTM: Complete round-trip testing for object values.

This export test complements the import tests, ensuring that complex object values can be properly serialized to XML with the correct structure, providing comprehensive coverage.

packages/core/src/editor/EditorToolbar.ts (8)

53-55: LGTM: Corrected JSDoc reference.

Updated documentation to reference the correct EditorToolbarCodec instead of DefaultToolbarCodec.


146-151: LGTM: Enhanced flexibility with nullable parameters.

Making title, icon, and pressed parameters nullable improves the API's flexibility while maintaining type safety.


173-173: LGTM: Precise return type as per breaking changes.

The return type change from generic to HTMLSelectElement aligns with the documented breaking changes in the PR objectives, providing more precise typing.


212-215: LGTM: Improved method signature and typing.

The optional value parameter and precise HTMLOptionElement return type enhance type safety, with appropriate use of non-null assertion on the toolbar property.


263-263: LGTM: Consistent nullable parameter handling.

Making the icon parameter nullable is consistent with other method improvements and enhances API flexibility.


273-273: LGTM: Breaking change aligns with PR objectives.

The return type change from generic to HTMLImageElement matches the documented breaking change that addPrototype() now returns HTMLImageElement instead of HTMLImageElement | HTMLButtonElement.


295-295: LGTM: Appropriate use of optional chaining.

Using optional chaining (this.toolbar?.resetMode()) is safer than the previous casting approach.


299-299: LGTM: Consistent non-null assertion usage.

The non-null assertion (this.toolbar!.addMode) is appropriate here since the toolbar existence is guaranteed by the method's context.

@sonarqubecloud
Copy link

@tbouffard tbouffard merged commit b503bc3 into main Jul 11, 2025
7 checks passed
@tbouffard tbouffard deleted the fix/codec_improve_robustness branch July 11, 2025 10:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant