Skip to content

feat: add registerDefaultStyleElements to register all builtin style elements - #1142

Merged
redfish4ktc merged 1 commit into
mainfrom
feat/register_default_style_elements
Aug 11, 2026
Merged

feat: add registerDefaultStyleElements to register all builtin style elements#1142
redfish4ktc merged 1 commit into
mainfrom
feat/register_default_style_elements

Conversation

@redfish4ktc

@redfish4ktc redfish4ktc commented Aug 11, 2026

Copy link
Copy Markdown
Member

Problem

Two documentation pages already referred to a registerDefaultStyleElements function as the place to check which style elements maxGraph registers by default:

  • packages/website/docs/usage/perimeters.md: "To check the list of registered perimeters, refer to the registerDefaultStyleElements function."
  • packages/website/docs/usage/edge-styles.md: "To check the list of registered EdgeStyles, refer to the registerDefaultStyleElements function."

No such function existed. The four existing helpers (registerDefaultEdgeMarkers, registerDefaultEdgeStyles, registerDefaultPerimeters and registerDefaultShapes) had to be called one by one, and the only place listing them all was the private Graph.registerDefaults() override, which is not reachable from user code.

Solution

Add registerDefaultStyleElements(), which calls the four helpers. BaseGraph consumers who do want every builtin now get a single entry point without subclassing, and Graph.registerDefaults() delegates to it instead of duplicating the list, so there is a single source of truth.

import { BaseGraph, registerDefaultStyleElements } from '@maxgraph/core';

registerDefaultStyleElements();

const graph = new BaseGraph({ container });

The two documentation pages quoted above now point at something that exists.

Why a dedicated module

The function lives in packages/core/src/view/register-style-elements.ts rather than in view/style/register.ts. Adding an import of view/shape/register-shapes.js to the latter would create a static edge from a module that applications import for a single edge style helper (registerOrthogonalEdgeStyle, for instance) towards all sixteen builtin shapes. Bundlers drop it thanks to the side-effect-free package declaration, but the granularity of that analysis varies between bundlers, so the edge is better avoided entirely.

Tree-shaking caveat

Registering everything defeats tree-shaking, which is the whole point of BaseGraph. This is stated in the JSDoc and in a warning in the Global Configuration page, so the function does not read as the recommended default. It is meant as a convenience for prototyping, and as the first step of a Graph to BaseGraph migration: load everything so the application behaves as before, then trim progressively.

Changes

  • packages/core/src/view/register-style-elements.ts: the new function
  • packages/core/src/index.ts: export it
  • packages/core/src/view/Graph.ts: registerDefaults() delegates to it
  • packages/core/__tests__/view/register-style-elements.test.ts: 5 tests covering the four registries and idempotence
  • packages/website/docs/usage/global-configuration.md: document it alongside the four granular functions, with the tree-shaking warning

No CHANGELOG.md entry: this is not a breaking change.

Related to #665.

Validation

  • npm run build -w packages/core
  • npm test -w packages/core: 540 tests, 61 suites
  • npm run check:circular-dependencies -w packages/core
  • npm run lint
  • npm run build -w packages/website

Summary by CodeRabbit

  • New Features

    • Added a public helper to register all default styling elements at once.
    • Default graph styling is now registered consistently through this helper.
  • Documentation

    • Documented the new registration helper and its impact on bundle size, including guidance for preserving tree-shaking.
  • Tests

    • Added coverage for default markers, styles, perimeters, shapes, and repeated registration behavior.

…elements

Two documentation pages already referred to a `registerDefaultStyleElements` function as the place to check which
style elements maxGraph registers by default, but no such function existed. The four existing helpers
(`registerDefaultEdgeMarkers`, `registerDefaultEdgeStyles`, `registerDefaultPerimeters`, `registerDefaultShapes`) had
to be called one by one, and the only place listing them all was the private `Graph.registerDefaults()` override.

The new function calls the four helpers, so `BaseGraph` consumers who do want every builtin get a single entry point
without subclassing, and `Graph.registerDefaults()` now delegates to it instead of duplicating the list.

It lives in its own module rather than in `view/style/register.ts` on purpose: adding an import of
`view/shape/register-shapes.js` there would create a static edge from a module that applications import for a single
edge style helper towards all sixteen builtin shapes. Bundlers drop it thanks to the side-effect-free package
declaration, but the granularity varies between bundlers, so the edge is better avoided entirely.

The JSDoc and the Global Configuration page both warn that registering everything defeats tree-shaking, to keep the
function from reading as the recommended default.
@redfish4ktc redfish4ktc added the enhancement New feature or request label Aug 11, 2026
@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 84677456-dfa4-4783-b389-de8bce34b491

📥 Commits

Reviewing files that changed from the base of the PR and between 76c4e44 and 41e1c60.

📒 Files selected for processing (5)
  • packages/core/__tests__/view/register-style-elements.test.ts
  • packages/core/src/index.ts
  • packages/core/src/view/Graph.ts
  • packages/core/src/view/register-style-elements.ts
  • packages/website/docs/usage/global-configuration.md

Walkthrough

The PR adds registerDefaultStyleElements, which registers all default style categories. Graph uses the helper during initialization. The helper is publicly exported, tested, and documented.

Changes

Default style registration

Layer / File(s) Summary
Registration helper and validation
packages/core/src/view/register-style-elements.ts, packages/core/__tests__/view/register-style-elements.test.ts
Adds registerDefaultStyleElements and tests registration, registry cleanup, and idempotent shape reuse.
Graph integration and public API
packages/core/src/view/Graph.ts, packages/core/src/index.ts, packages/website/docs/usage/global-configuration.md
Updates graph initialization to use the helper, exports it from the core barrel, and documents its bundle impact.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Graph
  participant registerDefaultStyleElements
  participant StyleRegistries
  Graph->>registerDefaultStyleElements: register default style elements
  registerDefaultStyleElements->>StyleRegistries: register edge markers, edge styles, perimeters, and shapes
  StyleRegistries-->>Graph: retain registered style elements
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the primary feature added by the pull request.
Description check ✅ Passed The description explains the problem, solution, implementation, tree-shaking impact, tests, documentation, and validation steps.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

Comment @coderabbitai help to get the list of available commands.

@sonarqubecloud

Copy link
Copy Markdown

@redfish4ktc
redfish4ktc merged commit b3c49e3 into main Aug 11, 2026
14 checks passed
@redfish4ktc
redfish4ktc deleted the feat/register_default_style_elements branch August 11, 2026 09:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant