diff --git a/app/MindWork AI Studio/MarkdownClipboardService.cs b/app/MindWork AI Studio/MarkdownClipboardService.cs new file mode 100644 index 0000000..66cc961 --- /dev/null +++ b/app/MindWork AI Studio/MarkdownClipboardService.cs @@ -0,0 +1,28 @@ +using AIStudio.Tools; + +using Microsoft.JSInterop; + +using MudBlazor; + +// ReSharper disable ClassNeverInstantiated.Global + +namespace AIStudio; + +/// +/// Wire up the clipboard service to copy markdown to the clipboard. +/// We use our own Rust-based clipboard service for this. +/// +public sealed class MarkdownClipboardService(Rust rust, IJSRuntime jsRuntime, ISnackbar snackbar) : IMudMarkdownClipboardService +{ + private IJSRuntime JsRuntime { get; } = jsRuntime; + + private ISnackbar Snackbar { get; } = snackbar; + + private Rust Rust { get; } = rust; + + /// + /// Gets called when the user wants to copy the markdown to the clipboard. + /// + /// The Markdown text to copy. + public async ValueTask CopyToClipboardAsync(string text) => await this.Rust.CopyText2Clipboard(this.JsRuntime, this.Snackbar, text); +} \ No newline at end of file diff --git a/app/MindWork AI Studio/Program.cs b/app/MindWork AI Studio/Program.cs index 6a62fb0..e9464c5 100644 --- a/app/MindWork AI Studio/Program.cs +++ b/app/MindWork AI Studio/Program.cs @@ -1,3 +1,4 @@ +using AIStudio; using AIStudio.Components; using AIStudio.Settings; @@ -18,6 +19,8 @@ builder.Services.AddMudServices(config => }); builder.Services.AddMudMarkdownServices(); +builder.Services.AddSingleton(); +builder.Services.AddMudMarkdownClipboardService(); builder.Services.AddSingleton(); builder.Services.AddRazorComponents() .AddInteractiveServerComponents()