GeezerVison is showing github.com — feat: add registerDefaultStyleElements to register all builtin style elements by redfish4ktc · Pull Request #1142 · maxGraph/maxGraph
Conversation
redfish4ktc
commented
Aug 11, 2026
•
edited by coderabbitai
Bot
Loading
Uh oh!
There was an error while loading. Please reload this page.
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.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
…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.
coderabbitai
Bot
commented
Aug 11, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
|

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.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|