Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to dotnet 7 and latest MermaidJS #18

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- name: Setup .NET Core SDK
uses: actions/[email protected]
with:
dotnet-version: "5.0"
dotnet-version: "7.0"

- run: dotnet tool install -g Microsoft.Web.LibraryManager.Cli
- run: |
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -351,3 +351,6 @@ MigrationBackup/

# Client-Side Libraries
**/wwwroot/lib/

# vscode
.vscode/
10 changes: 6 additions & 4 deletions demo/MermaidJS.Blazor.Demo/MermaidJS.Blazor.Demo.csproj
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<Nullable>disable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="5.0.7" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="5.0.7" PrivateAssets="all" />
<PackageReference Include="System.Net.Http.Json" Version="5.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="7.0.10" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="7.0.10" PrivateAssets="all" />
<PackageReference Include="System.Net.Http.Json" Version="7.0.1" />
</ItemGroup>

<ItemGroup>
Expand Down
38 changes: 11 additions & 27 deletions demo/MermaidJS.Blazor.Demo/Program.cs
Original file line number Diff line number Diff line change
@@ -1,32 +1,16 @@
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

using MermaidJS.Blazor;
using MermaidJS.Blazor.Demo;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;

namespace MermaidJS.Blazor.Demo
{
public class Program
{
public static async Task Main(string[] args)
{
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("#app");
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("#app");

builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });

builder.Services.AddMermaidJS(options =>
{
options.MaxTextSize = 100000;
options.SecurityLevel = MermaidSecurityLevels.Loose;
});
builder.Services.AddMermaidJS(options =>
{
options.MaxTextSize = 100000;
options.SecurityLevel = MermaidSecurityLevels.Loose;
});

await builder.Build().RunAsync();
}
}
}
await builder.Build().RunAsync();
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using System;

using MermaidJS.Blazor;
using MermaidJS.Blazor;
using MermaidJS.Blazor.Internal;

namespace Microsoft.Extensions.DependencyInjection
{
/// <summary>
/// MermaidJS service collection extensions
/// </summary>
public static class IServiceCollectionExtensions
{
/// <summary>
Expand Down
7 changes: 1 addition & 6 deletions src/MermaidJS.Blazor/Internal/MermaidDiagramInterop.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
using System;
using System.Threading.Tasks;

using Microsoft.Extensions.Options;
using Microsoft.Extensions.Options;
using Microsoft.JSInterop;

namespace MermaidJS.Blazor.Internal
{
internal class MermaidDiagramInterop
{
private readonly IJSRuntime _jsRuntime;
private readonly IOptionsSnapshot<MermaidOptions> _mermaidOptions;
private readonly Lazy<Task<IJSObjectReference>> _jsModule;

public MermaidDiagramInterop(IJSRuntime jsRuntime, IOptionsSnapshot<MermaidOptions> mermaidOptions)
{
_jsRuntime = jsRuntime;
_mermaidOptions = mermaidOptions;
_jsModule = new(() => jsRuntime.InvokeAsync<IJSObjectReference>("import", "./_content/MermaidJS.Blazor/MermaidDiagramInterop.js").AsTask());
}
Expand Down
7 changes: 4 additions & 3 deletions src/MermaidJS.Blazor/MermaidJS.Blazor.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<Authors>JoshJohnson, TrueCommercePSG</Authors>
<Company>TrueCommerce, Inc</Company>
<Product>MermaidJS.Blazor</Product>
Expand All @@ -17,7 +18,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="5.0.7" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="7.0.10" />
</ItemGroup>

</Project>
7 changes: 2 additions & 5 deletions src/MermaidJS.Blazor/MermaidOptions.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System.Collections.Generic;
using System.Linq;

namespace MermaidJS.Blazor
namespace MermaidJS.Blazor
{
/// <summary>
/// Options used when initializing MermaidJS.
Expand Down Expand Up @@ -39,7 +36,7 @@ public class MermaidOptions
public string SecurityLevel { get; set; } = "strict";

/// <summary>
/// Dictates whether mermaind starts on Page load.
/// Dictates whether mermaid starts on Page load.
/// </summary>
public bool StartOnLoad { get; set; } = true;

Expand Down
2 changes: 1 addition & 1 deletion src/MermaidJS.Blazor/libman.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"defaultProvider": "cdnjs",
"libraries": [
{
"library": "mermaid@8.13.2",
"library": "mermaid@10.3.0",
"destination": "wwwroot/lib/mermaid"
}
]
Expand Down
13 changes: 7 additions & 6 deletions src/MermaidJS.Blazor/wwwroot/MermaidDiagramInterop.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
script.async = false;
script.defer = false;
script.onload = () => {
window.mermaid.mermaidAPI.initialize(window.mermaidDiagramBlazorOptions);
window.mermaid.initialize(window.mermaidDiagramBlazorOptions);

resolve();
};
Expand Down Expand Up @@ -52,14 +52,15 @@ export function beginRender(componentId, definition) {
return;
}

if (!definition) {
return;
}

try {
window.mermaid.mermaidAPI.render(`${componentId}-svg`, definition, (svg, bind) => {
mermaid.render(`${componentId}-svg`, definition).then(({ svg, bindFunctions }) => {
const host = document.getElementById(componentId);

host.innerHTML = svg;

bind(host);

bindFunctions?.(host);
componentRef.invokeMethodAsync("OnRenderCompleted");
});
}
Expand Down