From 6dd0b3811f120deac6f416fa24e495fd4ac4be84 Mon Sep 17 00:00:00 2001 From: Leonam Santos Date: Wed, 20 Mar 2024 13:45:59 +1100 Subject: [PATCH 01/13] Change DiagramCanvas to await unsubscription to Resizes subscription --- .../Components/DiagramCanvas.razor.cs | 6 ++-- .../Components/DiagramCanvasTests.cs | 28 +++++++++++++++++++ 2 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 tests/Blazor.Diagrams.Tests/Components/DiagramCanvasTests.cs diff --git a/src/Blazor.Diagrams/Components/DiagramCanvas.razor.cs b/src/Blazor.Diagrams/Components/DiagramCanvas.razor.cs index 8c723e043..b9f637941 100644 --- a/src/Blazor.Diagrams/Components/DiagramCanvas.razor.cs +++ b/src/Blazor.Diagrams/Components/DiagramCanvas.razor.cs @@ -8,7 +8,7 @@ namespace Blazor.Diagrams.Components; -public partial class DiagramCanvas : IDisposable +public partial class DiagramCanvas : IAsyncDisposable { private DotNetObjectReference? _reference; private bool _shouldRender; @@ -27,7 +27,7 @@ public partial class DiagramCanvas : IDisposable [Inject] public IJSRuntime JSRuntime { get; set; } = null!; - public void Dispose() + public async ValueTask DisposeAsync() { BlazorDiagram.Changed -= OnDiagramChanged; @@ -35,7 +35,7 @@ public void Dispose() return; if (elementReference.Id != null) - _ = JSRuntime.UnobserveResizes(elementReference); + await JSRuntime.UnobserveResizes(elementReference); _reference.Dispose(); } diff --git a/tests/Blazor.Diagrams.Tests/Components/DiagramCanvasTests.cs b/tests/Blazor.Diagrams.Tests/Components/DiagramCanvasTests.cs new file mode 100644 index 000000000..f3852758b --- /dev/null +++ b/tests/Blazor.Diagrams.Tests/Components/DiagramCanvasTests.cs @@ -0,0 +1,28 @@ +using Blazor.Diagrams.Components; +using Blazor.Diagrams.Core.Geometry; +using Bunit; +using Xunit; + +namespace Blazor.Diagrams.Tests.Components +{ + public class DiagramCanvasTests + { + [Fact] + public void Behavior_WhenDisposing_ShouldUnsubscribeToResizes() + { + // Arrange + JSRuntimeInvocationHandler call; + using (var ctx = new TestContext()) + { + ctx.JSInterop.Setup("ZBlazorDiagrams.getBoundingClientRect", _ => true); + call = ctx.JSInterop.SetupVoid("ZBlazorDiagrams.unobserve", _ => true).SetVoidResult(); + + // Act + var cut = ctx.RenderComponent(p => p.Add(n => n.BlazorDiagram, new BlazorDiagram())); + } + + // Assert + call.VerifyInvoke("ZBlazorDiagrams.unobserve", calledTimes: 1); + } + } +} From f3f4213f2f8330430433239c3f2c024ee2ac06b1 Mon Sep 17 00:00:00 2001 From: Mastros Date: Thu, 14 Nov 2024 21:32:54 +0200 Subject: [PATCH 02/13] migrate .net 9 --- .github/workflows/main.yml | 2 +- Directory.Packages.props | 10 +++++++++- docs/Directory.Build.props | 2 +- samples/Directory.Build.props | 2 +- .../wwwroot/default.styles.min.css.gz | Bin 683 -> 0 bytes src/Blazor.Diagrams/wwwroot/script.min.js.gz | Bin 521 -> 0 bytes src/Blazor.Diagrams/wwwroot/style.min.css.gz | Bin 416 -> 0 bytes src/Directory.Build.props | 2 +- tests/Directory.Build.props | 4 ++-- 9 files changed, 15 insertions(+), 7 deletions(-) delete mode 100644 src/Blazor.Diagrams/wwwroot/default.styles.min.css.gz delete mode 100644 src/Blazor.Diagrams/wwwroot/script.min.js.gz delete mode 100644 src/Blazor.Diagrams/wwwroot/style.min.css.gz diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a63cbcc88..bd30808af 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,6 +1,6 @@ name: DeployDemoToGitHubPages env: - PUBLISH_DIR: site/Site/bin/Release/net8.0/publish/wwwroot + PUBLISH_DIR: site/Site/bin/Release/net9.0/publish/wwwroot on: push: diff --git a/Directory.Packages.props b/Directory.Packages.props index 25e2ea0d2..20262efb0 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -2,7 +2,7 @@ - + @@ -34,4 +34,12 @@ + + + + + + + + \ No newline at end of file diff --git a/docs/Directory.Build.props b/docs/Directory.Build.props index c643f68a5..2a19dffc0 100644 --- a/docs/Directory.Build.props +++ b/docs/Directory.Build.props @@ -1,6 +1,6 @@  - net8.0 + net9.0 enable enable true diff --git a/samples/Directory.Build.props b/samples/Directory.Build.props index c643f68a5..2a19dffc0 100644 --- a/samples/Directory.Build.props +++ b/samples/Directory.Build.props @@ -1,6 +1,6 @@  - net8.0 + net9.0 enable enable true diff --git a/src/Blazor.Diagrams/wwwroot/default.styles.min.css.gz b/src/Blazor.Diagrams/wwwroot/default.styles.min.css.gz deleted file mode 100644 index 905f20cd3084e4807fd8feb323b3f30ca017d835..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 683 zcmV;c0#yAUiwFP!000003bj^iZlf>|zDlHOrACSoAx)baY42k2K)f+FvQ3gU>dE%U z9%-+zwt)a85AtJWCBfrw=9?Ge{QdnWppcP@8zdx!(}7X5#mg`(kMR~*zBPE`o)f7k zD5MBwmA2$aA=GD~RTc(4V+ZI5=9qv}ddFSv0pE{AYqvYG#-eSOF)7?IEU2mz;dy zUW}cr&?w_@?91GKkPyOIE^rFMfQnmGf?O=uxFvP1sNIW3x8GGu~E#^u?_>t(3O7QZk>YbJa;=ag~9aq2R6DgIe4`1Y4pJXJV%(h26nV z<50pdyy;DlNMmF%ji|=j3c4R0#vC%^Q#gUaVIN^}_-{;;B2ljHj}Uo&KDQ5jiI zqp-k}{Y=i4#ZFID1MU;t_xpkTwCILlQf8)m?_F=4b_92G^ML2I+pWVr>kUYdJdgW0F5LN-bG{VH5rY)L3(BCn^=g)x(5@fT(LVJK&pWM%AI z4LItk+}qsQ!B6R{TQ`h!Q~QFocJAhvb!Wa00|h0{qn8kxV!V1EF1|6CQyBGt@<2B5ur1w3hbZk-wAj|wu=|;Ywm5| Rf!sO%`Ul{II$Grk008_RO;G>< diff --git a/src/Blazor.Diagrams/wwwroot/script.min.js.gz b/src/Blazor.Diagrams/wwwroot/script.min.js.gz deleted file mode 100644 index a4db964787449a2e8b2e14e006712d8890102ecb..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 521 zcmV+k0`~nMiwFP!000003XM|1Zrd;n{T0`TKms&jhn*a#K)da>qChVLRs@4$$+1wI z8YDVF>iWxe*eC55M%ixS!?NyViZuD&Kf!tYdkJ~XoNR1`S4zPcyu3Jx{>S*HZ+ae_!Fo)LQA*X; z?dqv%3i)cqmcR-G%3v$$VDF#ooyFRln|Oqh<@fMlqkFcw0M3Vji!iC5vM22@OP_^i zzRH02jm6BVn-KI-R>8M~iaL-wsS$(Qc1X*Sl>?IofCSxI8R-{{Umeyg|GsT<&gXo$ zjno7?_JPx?qMTiPbelD-R`9lh6Z(byj{5v0sbI7e;gY2^oJASDoJ$P2SfZ<*kP93H z$dZ;Czqp8!7J=G9WVvyA7j*k>az0PXU!DQAC(jEI;}mhWrMP&415p(nEUC^!N1mrj zVrpnQ+U!giH|N}m25yF7eIO(JL4Lb!^s^72Cf-rS*Mc_Y^PWf~ffmU1JeI*XO)lO% z{p8p3^w)I2i~IZc+5d;N%W=uZb(HPdFyqUvrFnAe%~AAa?HZFr6j$#BofQUaDWtAH LWOWfaF9ZMp(kKVZ diff --git a/src/Blazor.Diagrams/wwwroot/style.min.css.gz b/src/Blazor.Diagrams/wwwroot/style.min.css.gz deleted file mode 100644 index 16ae0407444924c24781cba2eef209c2bd2f986e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 416 zcmV;R0bl+fiwFP!000003eA*3Zi6roMX!QXbr&PrB^;u?g25A*#(0oDIB8K%)#5Bl#7S=2ef1oR>nwY7VVqw&EAUiUMf{wu}h~PLJ?>b?z*DkEd_lm>` zU0GyBrTUOwNQ%GAYMDpGfVKT@@7%*GUs|00G4N^ljtnF?PfTMF*Z>w9o?&}>OR3>j zybCCtQ diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 6cef34442..103d27d17 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -1,6 +1,6 @@  - net8.0;net7.0;net6.0; + net9.0;net8.0;net7.0;net6.0; enable enable true diff --git a/tests/Directory.Build.props b/tests/Directory.Build.props index 6cef34442..03c9fec15 100644 --- a/tests/Directory.Build.props +++ b/tests/Directory.Build.props @@ -1,7 +1,7 @@  - net8.0;net7.0;net6.0; - enable + net9.0;net8.0;net7.0;net6.0; + enable enable true From d9221a041b14b9970d76b1e5405fa0a16288957f Mon Sep 17 00:00:00 2001 From: Haytam Zanid Date: Tue, 3 Dec 2024 10:27:15 +0100 Subject: [PATCH 03/13] Disable webcompiler gzip --- src/Blazor.Diagrams/Blazor.Diagrams.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Blazor.Diagrams/Blazor.Diagrams.csproj b/src/Blazor.Diagrams/Blazor.Diagrams.csproj index 56b718b7a..c99c4bffb 100644 --- a/src/Blazor.Diagrams/Blazor.Diagrams.csproj +++ b/src/Blazor.Diagrams/Blazor.Diagrams.csproj @@ -47,7 +47,7 @@ - + From c6e25301063cef6d93bf5b9768811ebfc2548d51 Mon Sep 17 00:00:00 2001 From: Haytam Zanid Date: Tue, 3 Dec 2024 10:27:25 +0100 Subject: [PATCH 04/13] Formatting --- Directory.Packages.props | 62 ++++++++++++++++++------------------- src/Directory.Build.props | 12 +++---- tests/Directory.Build.props | 12 +++---- 3 files changed, 43 insertions(+), 43 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index 20262efb0..8889dff74 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -1,39 +1,39 @@ - - - - - - - - - - - - - + + + + + + + + + + + + + - - - - - - + + + + + + - - - - - - + + + + + + - - - - - - + + + + + + diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 103d27d17..36ecd7dc4 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -1,8 +1,8 @@  - - net9.0;net8.0;net7.0;net6.0; - enable - enable - true - + + net9.0;net8.0;net7.0;net6.0; + enable + enable + true + \ No newline at end of file diff --git a/tests/Directory.Build.props b/tests/Directory.Build.props index 03c9fec15..36ecd7dc4 100644 --- a/tests/Directory.Build.props +++ b/tests/Directory.Build.props @@ -1,8 +1,8 @@  - - net9.0;net8.0;net7.0;net6.0; - enable - enable - true - + + net9.0;net8.0;net7.0;net6.0; + enable + enable + true + \ No newline at end of file From c93c07cef9befa300701e5a651ae0b1896136ad4 Mon Sep 17 00:00:00 2001 From: Haytam Zanid Date: Tue, 3 Dec 2024 10:27:40 +0100 Subject: [PATCH 05/13] Migrate Site to net9 too --- site/Site/Site.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/site/Site/Site.csproj b/site/Site/Site.csproj index b7b4fd577..cdaa77752 100644 --- a/site/Site/Site.csproj +++ b/site/Site/Site.csproj @@ -1,7 +1,7 @@ - net8.0 + net9.0 enable enable true From 6917417d263324cfc88767db573629c046c4aafd Mon Sep 17 00:00:00 2001 From: Haytam Zanid Date: Tue, 3 Dec 2024 10:53:44 +0100 Subject: [PATCH 06/13] Add registerDefaultBehaviors parameter to diagram ctors --- src/Blazor.Diagrams.Core/Diagram.cs | 8 ++++---- src/Blazor.Diagrams/BlazorDiagram.cs | 6 ++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/Blazor.Diagrams.Core/Diagram.cs b/src/Blazor.Diagrams.Core/Diagram.cs index a2fffeacb..713fbc758 100644 --- a/src/Blazor.Diagrams.Core/Diagram.cs +++ b/src/Blazor.Diagrams.Core/Diagram.cs @@ -4,9 +4,6 @@ using Blazor.Diagrams.Core.Layers; using Blazor.Diagrams.Core.Models.Base; using Blazor.Diagrams.Core.Events; -using System; -using System.Collections.Generic; -using System.Linq; using System.Runtime.CompilerServices; using Blazor.Diagrams.Core.Options; using Blazor.Diagrams.Core.Controls; @@ -38,7 +35,7 @@ public abstract class Diagram public event Action? ContainerChanged; public event Action? Changed; - protected Diagram() + protected Diagram(bool registerDefaultBehaviors = true) { _behaviors = new Dictionary(); _orderedSelectables = new List(); @@ -56,6 +53,9 @@ protected Diagram() Links.Removed += OnSelectableRemoved; Groups.Removed += OnSelectableRemoved; + if (!registerDefaultBehaviors) + return; + RegisterBehavior(new SelectionBehavior(this)); RegisterBehavior(new DragMovablesBehavior(this)); RegisterBehavior(new DragNewLinkBehavior(this)); diff --git a/src/Blazor.Diagrams/BlazorDiagram.cs b/src/Blazor.Diagrams/BlazorDiagram.cs index ab61d98a8..ad4041694 100644 --- a/src/Blazor.Diagrams/BlazorDiagram.cs +++ b/src/Blazor.Diagrams/BlazorDiagram.cs @@ -1,6 +1,4 @@ -using System; -using System.Collections.Generic; -using Blazor.Diagrams.Components.Controls; +using Blazor.Diagrams.Components.Controls; using Blazor.Diagrams.Core; using Blazor.Diagrams.Core.Controls.Default; using Blazor.Diagrams.Core.Models.Base; @@ -12,7 +10,7 @@ public class BlazorDiagram : Diagram { private readonly Dictionary _componentsMapping; - public BlazorDiagram(BlazorDiagramOptions? options = null) + public BlazorDiagram(BlazorDiagramOptions? options = null, bool registerDefaultBehaviors = true) : base(registerDefaultBehaviors) { _componentsMapping = new Dictionary { From 19ba04a9cc891e32c01848cbc676b0488830b25a Mon Sep 17 00:00:00 2001 From: Haytam Zanid Date: Tue, 3 Dec 2024 11:26:48 +0100 Subject: [PATCH 07/13] Update build.yml --- .github/workflows/build.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c0b64dff1..0648bf253 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -19,6 +19,9 @@ jobs: - uses: actions/checkout@v2 with: fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis + - uses: actions/setup-dotnet@v4 + with: + dotnet-version: '9' - name: Cache SonarCloud packages uses: actions/cache@v1 with: From c91e5d65eb6787959dbce59ff3903f454a92a834 Mon Sep 17 00:00:00 2001 From: Haytam Zanid Date: Tue, 3 Dec 2024 12:04:46 +0100 Subject: [PATCH 08/13] Upgrade bunit --- .github/workflows/build.yml | 4 ++-- Directory.Packages.props | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0648bf253..cabeaa6d1 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -16,14 +16,14 @@ jobs: uses: actions/setup-java@v1 with: java-version: 17 - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 with: fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis - uses: actions/setup-dotnet@v4 with: dotnet-version: '9' - name: Cache SonarCloud packages - uses: actions/cache@v1 + uses: actions/cache@v4 with: path: ~\sonar\cache key: ${{ runner.os }}-sonar diff --git a/Directory.Packages.props b/Directory.Packages.props index 8889dff74..afedd9770 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -5,7 +5,7 @@ - + From 7b9fcf0602218e9fdf0b262913465f8d13a7f63f Mon Sep 17 00:00:00 2001 From: Haytam Zanid Date: Tue, 3 Dec 2024 12:15:30 +0100 Subject: [PATCH 09/13] Upgrade vulnerable packages --- Directory.Packages.props | 6 ++++-- .../Blazor.Diagrams.Core.Tests.csproj | 6 ++++-- tests/Blazor.Diagrams.Tests/Blazor.Diagrams.Tests.csproj | 2 ++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index afedd9770..2bf656111 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -2,16 +2,18 @@ + + - - + + diff --git a/tests/Blazor.Diagrams.Core.Tests/Blazor.Diagrams.Core.Tests.csproj b/tests/Blazor.Diagrams.Core.Tests/Blazor.Diagrams.Core.Tests.csproj index f732b74b6..139ab2e19 100644 --- a/tests/Blazor.Diagrams.Core.Tests/Blazor.Diagrams.Core.Tests.csproj +++ b/tests/Blazor.Diagrams.Core.Tests/Blazor.Diagrams.Core.Tests.csproj @@ -7,13 +7,15 @@ + + - + runtime; build; native; contentfiles; analyzers; buildtransitive all - + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/tests/Blazor.Diagrams.Tests/Blazor.Diagrams.Tests.csproj b/tests/Blazor.Diagrams.Tests/Blazor.Diagrams.Tests.csproj index afd45bbd6..205fccd3f 100644 --- a/tests/Blazor.Diagrams.Tests/Blazor.Diagrams.Tests.csproj +++ b/tests/Blazor.Diagrams.Tests/Blazor.Diagrams.Tests.csproj @@ -9,6 +9,8 @@ + + From dd698322acea53056c550ae61252ea1015540f7f Mon Sep 17 00:00:00 2001 From: Haytam Zanid Date: Tue, 3 Dec 2024 12:19:52 +0100 Subject: [PATCH 10/13] Update Versions and CHANGELOG --- CHANGELOG.md | 13 ++++++++++++- .../Blazor.Diagrams.Algorithms.csproj | 6 +++--- .../Blazor.Diagrams.Core.csproj | 6 +++--- src/Blazor.Diagrams/Blazor.Diagrams.csproj | 6 +++--- 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e15b4bac1..2e368ee50 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,18 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## Diagram (3.0.0) - 2024-02-24 +## Diagrams (3.0.3) - 2024-12-03 + +### Added + +- Support for .NET 9 (thanks to @[PanayiotisTheodosiou](https://github.com/PanayiotisTheodosiou)) +- `registerDefaultBehaviors` argument to `BlazorDiagram` constructor, it's `true` by default and can be disabled if you want to control what behaviors are added and their order. + +### Removed + +- gzip versions of assets, it was causing an issue with .NET 9 + +## Diagram (3.0.2) - 2024-02-24 ### Added diff --git a/src/Blazor.Diagrams.Algorithms/Blazor.Diagrams.Algorithms.csproj b/src/Blazor.Diagrams.Algorithms/Blazor.Diagrams.Algorithms.csproj index d5847d04c..e7d64bccc 100644 --- a/src/Blazor.Diagrams.Algorithms/Blazor.Diagrams.Algorithms.csproj +++ b/src/Blazor.Diagrams.Algorithms/Blazor.Diagrams.Algorithms.csproj @@ -5,10 +5,10 @@ MIT zHaytam Algorithms for Z.Blazor.Diagrams - 3.0.2 - 3.0.2 + 3.0.3 + 3.0.3 https://github.com/zHaytam/Blazor.Diagrams - 3.0.2 + 3.0.3 Z.Blazor.Diagrams.Algorithms blazor diagrams diagramming svg drag algorithms layouts Z.Blazor.Diagrams.Algorithms diff --git a/src/Blazor.Diagrams.Core/Blazor.Diagrams.Core.csproj b/src/Blazor.Diagrams.Core/Blazor.Diagrams.Core.csproj index 8cb3269d2..6819f95e4 100644 --- a/src/Blazor.Diagrams.Core/Blazor.Diagrams.Core.csproj +++ b/src/Blazor.Diagrams.Core/Blazor.Diagrams.Core.csproj @@ -5,10 +5,10 @@ MIT zHaytam A fully customizable and extensible all-purpose diagrams library for Blazor - 3.0.2 - 3.0.2 + 3.0.3 + 3.0.3 https://github.com/Blazor-Diagrams/Blazor.Diagrams - 3.0.2 + 3.0.3 Z.Blazor.Diagrams.Core blazor diagrams diagramming svg drag Z.Blazor.Diagrams.Core diff --git a/src/Blazor.Diagrams/Blazor.Diagrams.csproj b/src/Blazor.Diagrams/Blazor.Diagrams.csproj index c99c4bffb..26ac305ac 100644 --- a/src/Blazor.Diagrams/Blazor.Diagrams.csproj +++ b/src/Blazor.Diagrams/Blazor.Diagrams.csproj @@ -4,11 +4,11 @@ enable zHaytam MIT - 3.0.2 - 3.0.2 + 3.0.3 + 3.0.3 https://github.com/Blazor-Diagrams/Blazor.Diagrams A fully customizable and extensible all-purpose diagrams library for Blazor - 3.0.2 + 3.0.3 true blazor diagrams diagramming svg drag Z.Blazor.Diagrams From efd4f320d87683722344d6413fbb297f34c46b32 Mon Sep 17 00:00:00 2001 From: Haytam Zanid Date: Tue, 3 Dec 2024 12:42:17 +0100 Subject: [PATCH 11/13] Avoid observing resizes when a node is invisible from the beginning --- .../Components/Renderers/NodeRenderer.cs | 7 ++-- .../Components/NodeRendererTests.cs | 36 +++++++++++++++++++ 2 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 tests/Blazor.Diagrams.Tests/Components/NodeRendererTests.cs diff --git a/src/Blazor.Diagrams/Components/Renderers/NodeRenderer.cs b/src/Blazor.Diagrams/Components/Renderers/NodeRenderer.cs index 2dbe58d02..aa4453205 100644 --- a/src/Blazor.Diagrams/Components/Renderers/NodeRenderer.cs +++ b/src/Blazor.Diagrams/Components/Renderers/NodeRenderer.cs @@ -1,6 +1,4 @@ -using System; -using System.Text; -using System.Threading.Tasks; +using System.Text; using Blazor.Diagrams.Core.Extensions; using Blazor.Diagrams.Core.Geometry; using Blazor.Diagrams.Core.Models; @@ -129,6 +127,9 @@ protected override void BuildRenderTree(RenderTreeBuilder builder) protected override async Task OnAfterRenderAsync(bool firstRender) { + if (firstRender && !Node.Visible) + return; + if (firstRender || _becameVisible) { _becameVisible = false; diff --git a/tests/Blazor.Diagrams.Tests/Components/NodeRendererTests.cs b/tests/Blazor.Diagrams.Tests/Components/NodeRendererTests.cs new file mode 100644 index 000000000..8ceb357e2 --- /dev/null +++ b/tests/Blazor.Diagrams.Tests/Components/NodeRendererTests.cs @@ -0,0 +1,36 @@ +using Blazor.Diagrams.Components.Renderers; +using Blazor.Diagrams.Core.Geometry; +using Blazor.Diagrams.Core.Models; +using Bunit; +using Xunit; + +namespace Blazor.Diagrams.Tests.Components; + +public class NodeRendererTests +{ + + [Fact] + public void NodeRenderer_WhenNodeVisibleIsFalseAndIsFirstRender_ShouldNotObserveResizes() + { + // Arrange + JSRuntimeInvocationHandler call; + using (var ctx = new TestContext()) + { + ctx.JSInterop.Setup("ZBlazorDiagrams.getBoundingClientRect", _ => true); + call = ctx.JSInterop.SetupVoid("ZBlazorDiagrams.observe", _ => true).SetVoidResult(); + + // Act + var cut = ctx.RenderComponent(p => + { + p.Add(n => n.BlazorDiagram, new BlazorDiagram()); + p.Add(n => n.Node, new NodeModel() + { + Visible = false + }); + }); + } + + // Assert + call.VerifyNotInvoke("ZBlazorDiagrams.observe"); + } +} From 51c1badc3471e1c899c93c13c6886442fc08d079 Mon Sep 17 00:00:00 2001 From: Haytam Zanid Date: Tue, 3 Dec 2024 12:42:22 +0100 Subject: [PATCH 12/13] Update CHANGELOG.md --- CHANGELOG.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2e368ee50..df6a1b541 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,9 +12,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Support for .NET 9 (thanks to @[PanayiotisTheodosiou](https://github.com/PanayiotisTheodosiou)) - `registerDefaultBehaviors` argument to `BlazorDiagram` constructor, it's `true` by default and can be disabled if you want to control what behaviors are added and their order. +### Fixed + +- Exception thrown when `node.Visible` was `false` from the creation and the library was trying to observe its resizes when the element won't exist (fixes #476). + ### Removed -- gzip versions of assets, it was causing an issue with .NET 9 +- gzip versions of assets, it was causing an issue with .NET 9 (fixes #471, thanks a lot @[robertmclaws](https://github.com/robertmclaws)) ## Diagram (3.0.2) - 2024-02-24 From 5942c8a59509b95e9608264941ca9088a9056a13 Mon Sep 17 00:00:00 2001 From: Haytam Zanid Date: Tue, 3 Dec 2024 12:48:44 +0100 Subject: [PATCH 13/13] Update CHANGELOG.md --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index df6a1b541..77932a03a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Support for .NET 9 (thanks to @[PanayiotisTheodosiou](https://github.com/PanayiotisTheodosiou)) - `registerDefaultBehaviors` argument to `BlazorDiagram` constructor, it's `true` by default and can be disabled if you want to control what behaviors are added and their order. +### Changed + +- Make `DiagramCanvas` await un-subscription to resizes subscription (thanks to @[toluwtglobal](https://github.com/toluwtglobal)) + ### Fixed - Exception thrown when `node.Visible` was `false` from the creation and the library was trying to observe its resizes when the element won't exist (fixes #476).