diff --git a/Blazorade.Mermaid/Components/MermaidDiagram.razor.cs b/Blazorade.Mermaid/Components/MermaidDiagram.razor.cs index 947e32e..e433a0e 100644 --- a/Blazorade.Mermaid/Components/MermaidDiagram.razor.cs +++ b/Blazorade.Mermaid/Components/MermaidDiagram.razor.cs @@ -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; @@ -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/ /// - partial class MermaidDiagram + partial class MermaidDiagram : IAsyncDisposable { /// /// The Mermaid definition to render as a diagram. @@ -61,14 +62,27 @@ destroy B [Parameter] public string? Id { get; set; } + /// + public async ValueTask DisposeAsync() + { + } + + /// + /// The callback method that will be called by Mermaid JS when a diagram element is clicked. + /// + [JSInvokable] + public async Task OnElementClickCallbackAsync(ElementClickCallbackArgs args) + { + + } + [Inject] private IJSRuntime JSRuntime { get; set; } = null!; /// protected async override Task OnAfterRenderAsync(bool firstRender) { - var jsModule = await this.GetBlazoradeMermaidModuleAsync(); - await jsModule.InvokeVoidAsync("run", this.Id, this.Definition); + await this.UpdateDiagramAsync(); } /// @@ -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(); + } + } } diff --git a/Blazorade.Mermaid/Model/ElementClickCallbackArgs.cs b/Blazorade.Mermaid/Model/ElementClickCallbackArgs.cs new file mode 100644 index 0000000..61ac84e --- /dev/null +++ b/Blazorade.Mermaid/Model/ElementClickCallbackArgs.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Blazorade.Mermaid.Model +{ + /// + /// Callback arguments for when a diagram element is clicked. + /// + public class ElementClickCallbackArgs + { + /// + /// The Mermaid ID of the element that was clicked. + /// + public string Id { get; set; } = string.Empty; + + } +}