Skip to content

Commit

Permalink
Initial structures for enabling click events to be routed from JS to …
Browse files Browse the repository at this point in the history
…Blazorade Mermaid.
  • Loading branch information
MikaBerglund committed Feb 28, 2024
1 parent 6a89d1a commit f397855
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 4 deletions.
36 changes: 32 additions & 4 deletions Blazorade.Mermaid/Components/MermaidDiagram.razor.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Components;
using Blazorade.Mermaid.Model;
using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
using System;
using System.Collections.Generic;
Expand All @@ -17,7 +18,7 @@ namespace Blazorade.Mermaid.Components
/// For more information on Mermaid and what kind of diagrams you can display with it, please
/// refer to https://mermaid.js.org/
/// </remarks>
partial class MermaidDiagram
partial class MermaidDiagram : IAsyncDisposable
{
/// <summary>
/// The Mermaid definition to render as a diagram.
Expand Down Expand Up @@ -61,14 +62,27 @@ destroy B
[Parameter]
public string? Id { get; set; }

/// <inheritdoc/>
public async ValueTask DisposeAsync()
{
}

/// <summary>
/// The callback method that will be called by Mermaid JS when a diagram element is clicked.
/// </summary>
[JSInvokable]
public async Task OnElementClickCallbackAsync(ElementClickCallbackArgs args)
{

}

[Inject]
private IJSRuntime JSRuntime { get; set; } = null!;

/// <inheritdoc/>
protected async override Task OnAfterRenderAsync(bool firstRender)
{
var jsModule = await this.GetBlazoradeMermaidModuleAsync();
await jsModule.InvokeVoidAsync("run", this.Id, this.Definition);
await this.UpdateDiagramAsync();
}

/// <inheritdoc/>
Expand Down Expand Up @@ -96,5 +110,19 @@ private void SetIdIfEmpty(string? id = null)
this.Attributes.Add("id", id);
}
}

private async ValueTask RegisterClickCallbacksAsync()
{

}

private async ValueTask UpdateDiagramAsync()
{
var jsModule = await this.GetBlazoradeMermaidModuleAsync();
await jsModule.InvokeVoidAsync("run", this.Id, this.Definition);

await this.RegisterClickCallbacksAsync();
}

}
}
20 changes: 20 additions & 0 deletions Blazorade.Mermaid/Model/ElementClickCallbackArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Blazorade.Mermaid.Model
{
/// <summary>
/// Callback arguments for when a diagram element is clicked.
/// </summary>
public class ElementClickCallbackArgs
{
/// <summary>
/// The Mermaid ID of the element that was clicked.
/// </summary>
public string Id { get; set; } = string.Empty;

}
}

0 comments on commit f397855

Please sign in to comment.