Skip to content

Commit

Permalink
Fix Bug w/ Custom Options
Browse files Browse the repository at this point in the history
  • Loading branch information
DotJoshJohnson committed Oct 19, 2021
1 parent a8a7b20 commit 305b237
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
6 changes: 5 additions & 1 deletion demo/MermaidJS.Blazor.Demo/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ public static async Task Main(string[] args)

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

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

await builder.Build().RunAsync();
}
Expand Down
2 changes: 1 addition & 1 deletion src/MermaidJS.Blazor/MermaidOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ public class MermaidOptions
/// <summary>
/// Name of a pre-defined MermaidJS theme.
/// </summary>
public string? Theme { get; set; }
public string Theme { get; set; } = "dark";
}
}
9 changes: 6 additions & 3 deletions src/MermaidJS.Blazor/wwwroot/MermaidDiagramInterop.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
function initializeGlobals(options) {
function initializeGlobals() {
console.log("initializeGlobals", window.mermaidDiagramBlazorOptions);
function loadMermaid() {
return new Promise((resolve) => {
if (!window.mermaid) {
Expand All @@ -8,7 +9,7 @@
script.async = false;
script.defer = false;
script.onload = () => {
window.mermaid.mermaidAPI.initialize(options);
window.mermaid.mermaidAPI.initialize(window.mermaidDiagramBlazorOptions);

resolve();
};
Expand Down Expand Up @@ -70,7 +71,9 @@ export function beginRender(componentId, definition) {
}

export function registerComponent(componentId, componentRef, options) {
initializeGlobals(options).then(() => {
window.mermaidDiagramBlazorOptions = window.mermaidDiagramBlazorOptions || options;

initializeGlobals().then(() => {
window.mermaidDiagramBlazorComponents.set(componentId, componentRef);
});
}
Expand Down

0 comments on commit 305b237

Please sign in to comment.