diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c0b64dff1..cabeaa6d1 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -16,11 +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/.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/CHANGELOG.md b/CHANGELOG.md index e15b4bac1..77932a03a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,26 @@ 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. + +### 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). + +### Removed + +- 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 ### Added diff --git a/Directory.Packages.props b/Directory.Packages.props index 25e2ea0d2..2bf656111 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -1,37 +1,47 @@ - - - - - - - - - - - - - + + + + + + + + + + + + + + + - - - - - - + + + + + + - - - - - - + + + + + + + + + + + + + + + + + + + + - - - - - - \ 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/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 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.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/Blazor.Diagrams.csproj b/src/Blazor.Diagrams/Blazor.Diagrams.csproj index 56b718b7a..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 @@ -47,7 +47,7 @@ - + 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 { 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/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/src/Blazor.Diagrams/wwwroot/default.styles.min.css.gz b/src/Blazor.Diagrams/wwwroot/default.styles.min.css.gz deleted file mode 100644 index 905f20cd3..000000000 Binary files a/src/Blazor.Diagrams/wwwroot/default.styles.min.css.gz and /dev/null differ 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 a4db96478..000000000 Binary files a/src/Blazor.Diagrams/wwwroot/script.min.js.gz and /dev/null differ 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 16ae04074..000000000 Binary files a/src/Blazor.Diagrams/wwwroot/style.min.css.gz and /dev/null differ diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 6cef34442..36ecd7dc4 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -1,8 +1,8 @@  - - 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/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 @@ + + 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); + } + } +} 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"); + } +} diff --git a/tests/Directory.Build.props b/tests/Directory.Build.props index 6cef34442..36ecd7dc4 100644 --- a/tests/Directory.Build.props +++ b/tests/Directory.Build.props @@ -1,8 +1,8 @@  - - 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