Finished the Pandoc integration (#487)

This commit is contained in:
Thorsten Sommer authored and GitHub committed 2025-05-30 22:39:16 +02:00
1 parent 5b685193ef
commit 437da0fd9b
30 files changed
+1600 -349

No files matched your search

@@ -1,15 +1,22 @@
@if (!this.IsInline)
@if (!this.IsInline)
{
@if (this.ParentTabs is null)
{
<MudPaper Class="code-block no-elevation" Style="@this.BlockPadding()">
<pre><code>@this.ChildContent</code></pre>
<MudPaper Class="code-block no-elevation" Style="@this.BlockPadding">
<pre>
<code>
@this.ChildContent
</code>
</pre>
</MudPaper>
}
}
else
{
<span class="inline-code-block"><kbd>@this.ChildContent</kbd></span>
<span class="inline-code-block">
<kbd>
@this.ChildContent
</kbd>
</span>
}
@@ -33,8 +33,5 @@ public partial class CodeBlock : ComponentBase
}
}
private string BlockPadding()
{
return this.ParentTabs is null ? "padding: 16px !important;" : "padding: 8px !important";
}
private string BlockPadding => this.ParentTabs is null ? "padding: 16px !important;" : "padding: 8px !important";
}
@@ -1,5 +1,5 @@
<MudTabs @bind-ActivePanelIndex="selectedIndex" PanelClass="code-block" MinimumTabWidth="30px" Class="mt-2">
@foreach (var block in blocks)
<MudTabs ActivePanelIndex="this.SelectedIndex" ActivePanelIndexChanged="async idx => await this.TabChanged(idx)" PanelClass="code-block mt-1" MinimumTabWidth="30px" Class="mt-2">
@foreach (var block in this.blocks)
{
<MudTabPanel Text="@block.Title">
@block.Fragment
@@ -7,8 +7,13 @@ public partial class CodeTabs : ComponentBase
[Parameter]
public RenderFragment? ChildContent { get; set; }
[Parameter]
public int SelectedIndex { get; set; }
[Parameter]
public EventCallback<int> SelectedIndexChanged { get; set; }
private readonly List<CodeTabItem> blocks = new();
private int selectedIndex;
internal void RegisterBlock(string title, RenderFragment fragment)
{
@@ -27,4 +32,11 @@ public partial class CodeTabs : ComponentBase
public RenderFragment Fragment { get; init; } = null!;
}
private async Task TabChanged(int index)
{
this.SelectedIndex = index;
await this.SelectedIndexChanged.InvokeAsync(index);
await this.InvokeAsync(this.StateHasChanged);
}
}
@@ -1,4 +1,4 @@
<MudExpansionPanel Class="border-solid border rounded-lg" Expanded="@this.IsExpanded">
<MudExpansionPanel Class="border-solid border rounded-lg" Expanded="@this.IsExpanded" MaxHeight="@this.MaxHeight" ExpandedChanged="async s => await this.ExpandedChanged(s)">
<TitleContent>
<div class="d-flex align-center">
<MudIcon Icon="@this.HeaderIcon" Size="@this.IconSize" Color="@this.IconColor" class="mr-3"/>
@@ -16,6 +16,12 @@ public partial class ExpansionPanel : ComponentBase
[Parameter]
public string HeaderText { get; set; } = "n/a";
[Parameter]
public int? MaxHeight { get; set; }
[Parameter]
public Func<bool, Task> ExpandedChanged { get; set; } = _ => Task.CompletedTask;
[Parameter]
public RenderFragment? ChildContent { get; set; }
@@ -0,0 +1,10 @@
@inherits MSGComponentBase
<MudStack Row="false" Class="mb-3 pa-3 border-dashed border rounded-lg">
<MudJustifiedText Typo="Typo.body1">
@this.DetermineIntroText()
</MudJustifiedText>
<MudButton Color="@this.DetermineButtonColor()" Variant="Variant.Filled" OnClick="() => this.ShowPandocDialogAsync()">
@this.DetermineButtonText()
</MudButton>
</MudStack>
@@ -0,0 +1,97 @@
using AIStudio.Dialogs;
using AIStudio.Tools.Services;
using Microsoft.AspNetCore.Components;
using DialogOptions = AIStudio.Dialogs.DialogOptions;
namespace AIStudio.Components;
public partial class ManagePandocDependency : MSGComponentBase
{
[Parameter]
public string IntroText { get; set; } = string.Empty;
[Inject]
private IDialogService DialogService { get; init; } = null!;
[Inject]
private RustService RustService { get; init; } = null!;
private PandocInstallation pandocInstallation;
#region Overrides of MSGComponentBase
protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();
this.pandocInstallation = await Pandoc.CheckAvailabilityAsync(this.RustService, false);
}
#endregion
private Color DetermineButtonColor()
{
if (this.pandocInstallation == default)
return Color.Default;
switch (this.pandocInstallation)
{
case { CheckWasSuccessful: true, IsAvailable: true }:
return Color.Default;
case { CheckWasSuccessful: true, IsAvailable: false }:
return Color.Warning;
case { CheckWasSuccessful: false }:
return Color.Error;
}
}
private string DetermineButtonText()
{
if(this.pandocInstallation == default)
return T("Please wait while we check the availability of Pandoc.");
switch (this.pandocInstallation)
{
case { CheckWasSuccessful: true, IsAvailable: true }:
return T("Check your Pandoc installation");
case { CheckWasSuccessful: true, IsAvailable: false }:
return T("Update Pandoc");
case { CheckWasSuccessful: false }:
return T("Install Pandoc");
}
}
private string DetermineIntroText()
{
if (this.pandocInstallation == default)
return $"{this.IntroText} {T("Please wait while we check the availability of Pandoc.")}";
switch (this.pandocInstallation)
{
case { CheckWasSuccessful: true, IsAvailable: true }:
return $"{this.IntroText} {T("Your Pandoc installation meets the requirements.")}";
case { CheckWasSuccessful: true, IsAvailable: false }:
return $"{this.IntroText} {T("Your Pandoc installation is outdated. Please update it to the latest version to ensure compatibility with all features.")}";
case { CheckWasSuccessful: false }:
return $"{this.IntroText} {T("Pandoc is not installed or not available. Please install it to use the features that require Pandoc.")}";
}
}
private async Task ShowPandocDialogAsync()
{
var dialogReference = await this.DialogService.ShowAsync<PandocDialog>(T("Pandoc Installation"), DialogOptions.FULLSCREEN);
await dialogReference.Result;
// Refresh the availability of Pandoc after the dialog is closed:
this.pandocInstallation = await Pandoc.CheckAvailabilityAsync(this.RustService, false);
await this.InvokeAsync(this.StateHasChanged);
}
}