Skip to content

Conversation

lxfu1
Copy link
Member

@lxfu1 lxfu1 commented Sep 25, 2025

Description

Motivation and Context

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Enhancement (changes that improvement of current feature or performance)
  • Refactoring (changes that neither fixes a bug nor adds a feature)
  • Test Case (changes that add missing tests or correct existing tests)
  • Code style optimization (changes that do not affect the meaning of the code)
  • Docs (changes that only update documentation)
  • Chore (changes that don't modify src or test files)

Self Check before Merge

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Copy link
Contributor

Summary of Changes

Hello @lxfu1, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses an issue where certain registry tools were not properly available by refactoring their definition mechanism. Instead of using a functional .define() approach, components like Anchor, Arrowhead, Button, and CellEditor now extend their respective base classes and define their default configurations via static defaults properties. This change aims to improve the robustness and correct registration of these essential UI components within the system.

Highlights

  • Refactored Tool Definitions: The way Anchor, Arrowhead, Button, and CellEditor tools are defined has been refactored from using a .define() method to extending a base class and defining static defaults properties.
  • Enhanced Tool Availability: This refactoring likely addresses an issue where these registry tools were not correctly available or registered, ensuring their proper integration and functionality.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the way registry tools are defined, moving from a static define method to a more idiomatic class-based approach with static defaults. This is a great improvement for code clarity and maintainability.

My review focuses on ensuring consistency and preventing potential issues with the new implementation. I've noticed that in some files, the spread syntax (...) is used to extend default options, which performs a shallow copy. This can lead to unintended sharing of nested objects and arrays between base and subclasses. I've suggested using ObjectExt.merge for a deep merge, similar to the approach taken in editor.ts, to make the implementation more robust and consistent across all tool definitions.

Comment on lines +355 to +369
export class SourceAnchor extends Anchor {
public static defaults: Options = {
...Anchor.getDefaults(),
name: 'source-anchor',
type: 'source',
}
}

export const TargetAnchor = Anchor.define<Options>({
name: 'target-anchor',
type: 'target',
})
export class TargetAnchor extends Anchor {
public static defaults: Options = {
...Anchor.getDefaults(),
name: 'target-anchor',
type: 'target',
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Using the spread syntax ... for Anchor.getDefaults() performs a shallow copy. The Anchor.defaults object contains nested objects like markup, customAnchorAttrs, and defaultAnchorAttrs. This means that SourceAnchor.defaults and TargetAnchor.defaults will share references to these nested objects with Anchor.defaults.

This could lead to unintended side effects if a subclass modifies one of these nested objects, as it would also modify the base class's defaults.

To ensure that each tool has its own copy of the default options, it's safer to perform a deep merge. You're already doing this in src/registry/tool/editor.ts using ObjectExt.merge. I suggest applying the same pattern here for consistency and safety.

You'll need to import ObjectExt from ../../common.

export class SourceAnchor extends Anchor {
  public static defaults: Options = ObjectExt.merge({}, Anchor.getDefaults(), {
    name: 'source-anchor',
    type: 'source',
  })
}

export class TargetAnchor extends Anchor {
  public static defaults: Options = ObjectExt.merge({}, Anchor.getDefaults(), {
    name: 'target-anchor',
    type: 'target',
  })
}

Comment on lines +137 to +167
export class SourceArrowhead extends Arrowhead {
public static defaults: Options = {
...Arrowhead.getDefaults(),
name: 'source-arrowhead',
type: 'source',
ratio: 0,
attrs: {
d: 'M 10 -8 -10 0 10 8 Z',
fill: '#333',
stroke: '#fff',
'stroke-width': 2,
cursor: 'move',
},
}
}

export class TargetArrowhead extends Arrowhead {
public static defaults: Options = {
...Arrowhead.getDefaults(),
name: 'target-arrowhead',
type: 'target',
ratio: 1,
attrs: {
d: 'M -10 -8 10 0 -10 8 Z',
fill: '#333',
stroke: '#fff',
'stroke-width': 2,
cursor: 'move',
},
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Using the spread syntax ... for Arrowhead.getDefaults() performs a shallow copy. While Arrowhead.defaults itself doesn't have many nested objects, this pattern can be risky if they are added later. The attrs object is defined here, but if Arrowhead.defaults had its own attrs, they would be shallow-merged.

For consistency with the changes in editor.ts and to prevent potential bugs from shared object references, I recommend using ObjectExt.merge to perform a deep merge. This ensures that SourceArrowhead and TargetArrowhead get their own copies of the default options.

You'll need to import ObjectExt from ../../common.

export class SourceArrowhead extends Arrowhead {
  public static defaults: Options = ObjectExt.merge({}, Arrowhead.getDefaults(), {
    name: 'source-arrowhead',
    type: 'source',
    ratio: 0,
    attrs: {
      d: 'M 10 -8 -10 0 10 8 Z',
      fill: '#333',
      stroke: '#fff',
      'stroke-width': 2,
      cursor: 'move',
    },
  })
}

export class TargetArrowhead extends Arrowhead {
  public static defaults: Options = ObjectExt.merge({}, Arrowhead.getDefaults(), {
    name: 'target-arrowhead',
    type: 'target',
    ratio: 1,
    attrs: {
      d: 'M -10 -8 10 0 -10 8 Z',
      fill: '#333',
      stroke: '#fff',
      'stroke-width': 2,
      cursor: 'move',
    },
  })
}

Comment on lines +151 to +185
export class Remove extends Button {
public static defaults: Options = {
...Button.getDefaults(),
name: 'button-remove',
markup: [
{
tagName: 'circle',
selector: 'button',
attrs: {
r: 7,
fill: '#FF1D00',
cursor: 'pointer',
},
},
},
{
tagName: 'path',
selector: 'icon',
attrs: {
d: 'M -3 -3 3 3 M -3 3 3 -3',
fill: 'none',
stroke: '#FFFFFF',
'stroke-width': 2,
'pointer-events': 'none',
{
tagName: 'path',
selector: 'icon',
attrs: {
d: 'M -3 -3 3 3 M -3 3 3 -3',
fill: 'none',
stroke: '#FFFFFF',
'stroke-width': 2,
'pointer-events': 'none',
},
},
],
distance: 60,
offset: 0,
useCellGeometry: true,
onClick({ view, btn }) {
btn.parent.remove()
view.cell.remove({ ui: true, toolId: btn.cid })
},
],
distance: 60,
offset: 0,
useCellGeometry: true,
onClick({ view, btn }) {
btn.parent.remove()
view.cell.remove({ ui: true, toolId: btn.cid })
},
})
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Using the spread syntax ... for Button.getDefaults() performs a shallow copy. The Remove.defaults includes a markup array of objects. If Button.defaults also contained a markup array, the spread syntax would lead to a shallow merge, which could cause unexpected mutations if the array or its objects are modified in subclasses.

To ensure each tool has its own deep copy of the default options and for consistency with the pattern used in editor.ts, it's safer to use ObjectExt.merge.

You'll need to import ObjectExt from ../../common.

export class Remove extends Button {
  public static defaults: Options = ObjectExt.merge({}, Button.getDefaults(), {
    name: 'button-remove',
    markup: [
      {
        tagName: 'circle',
        selector: 'button',
        attrs: {
          r: 7,
          fill: '#FF1D00',
          cursor: 'pointer',
        },
      },
      {
        tagName: 'path',
        selector: 'icon',
        attrs: {
          d: 'M -3 -3 3 3 M -3 3 3 -3',
          fill: 'none',
          stroke: '#FFFFFF',
          'stroke-width': 2,
          'pointer-events': 'none',
        },
      },
    ],
    distance: 60,
    offset: 0,
    useCellGeometry: true,
    onClick({ view, btn }) {
      btn.parent.remove()
      view.cell.remove({ ui: true, toolId: btn.cid })
    },
  })
}

@codecov-commenter
Copy link

Codecov Report

❌ Patch coverage is 98.16514% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.06%. Comparing base (b1c0698) to head (eccfd90).

Files with missing lines Patch % Lines
src/registry/tool/button.ts 93.75% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #4799      +/-   ##
==========================================
+ Coverage   82.04%   82.06%   +0.01%     
==========================================
  Files         327      327              
  Lines       37628    37655      +27     
  Branches     7592     7597       +5     
==========================================
+ Hits        30873    30900      +27     
  Misses       6731     6731              
  Partials       24       24              
Flag Coverage Δ
x6 82.06% <98.16%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/registry/tool/anchor.ts 28.43% <100.00%> (+1.43%) ⬆️
src/registry/tool/arrowhead.ts 43.06% <100.00%> (+2.60%) ⬆️
src/registry/tool/editor.ts 18.94% <100.00%> (+3.56%) ⬆️
src/registry/tool/button.ts 38.12% <93.75%> (+1.36%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@lxfu1 lxfu1 merged commit 79abd8a into master Sep 29, 2025
2 checks passed
@lxfu1 lxfu1 deleted the fix/registry-tools branch September 29, 2025 02:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants