Skip to content

feat(dia.Graph): add syncCells method - #3087

Closed
MartinKanera wants to merge 12 commits into
clientIO:masterfrom
MartinKanera:feat/add-sync-cells
Closed

MartinKanera wants to merge 12 commits into
clientIO:masterfrom
MartinKanera:feat/add-sync-cells

Conversation

@MartinKanera

@MartinKanera MartinKanera commented Oct 28, 2025 •

Copy link
Copy Markdown
Contributor

Replaced by #3090

Description

This PR introduces a new syncCells method to the dia.Graph class that synchronizes graph cells with a provided array of cells (or cell JSONs). The method can add new cells, update existing ones, replace cells when their type changes, and optionally remove cells that are missing from the sync array.

Usage

You can either edit the JSON directly or generate it from another source of truth, then apply it to the graph model.
The method ensures that new cells are added, modified cells are updated, and missing cells are removed automatically.

const updatedJSON = await fetch('/diagram/1');
// Sync the current graph with the updated JSON
graph.syncCells(updatedJSON.cells, { remove: true });

You also now have a simple way to change an element’s type:

const [rectangle] = graph.getElements();
const circle = new Circle({ id: rectangle.id });
graph.syncCells([circle]);

Key changes

  • Implementation of syncCells method with support for adding, updating, and replacing cells
  • Modified dia.Paper to ensure connected links are updated when cells are replaced
  • Add tests for all synchronization scenarios

@kumilingus kumilingus closed this Oct 30, 2025
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.

2 participants