2025-01-27 00:21:46 -06:00
|
|
|
using BlazorMonaco.Editor;
|
|
|
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
|
|
|
|
|
|
namespace LANCommander.UI.Components;
|
|
|
|
|
|
|
|
|
|
public class MonacoCodeEditor : StandaloneCodeEditor
|
|
|
|
|
{
|
|
|
|
|
[Parameter]
|
|
|
|
|
public string Value { get; set; }
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public EventCallback<string> ValueChanged { get; set; }
|
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public EventCallback OnSave { get; set; }
|
|
|
|
|
|
|
|
|
|
protected override void OnInitialized()
|
|
|
|
|
{
|
|
|
|
|
OnDidChangeModelContent = Microsoft.AspNetCore.Components.EventCallback.Factory.Create<ModelContentChangedEvent>(this, OnChanged);
|
|
|
|
|
OnDidInit = Microsoft.AspNetCore.Components.EventCallback.Factory.Create(this, OnInit);
|
|
|
|
|
|
|
|
|
|
base.OnInitialized();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task OnInit()
|
|
|
|
|
{
|
|
|
|
|
await AddCommand((int)BlazorMonaco.KeyMod.CtrlCmd | (int)BlazorMonaco.KeyCode.KeyS, async (editor) =>
|
|
|
|
|
{
|
|
|
|
|
if (OnSave.HasDelegate)
|
|
|
|
|
await OnSave.InvokeAsync();
|
|
|
|
|
}, null);
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-20 00:01:12 -05:00
|
|
|
private async Task OnChanged(ModelContentChangedEvent e)
|
2025-01-27 00:21:46 -06:00
|
|
|
{
|
|
|
|
|
Value = await GetValue();
|
|
|
|
|
|
|
|
|
|
if (ValueChanged.HasDelegate)
|
2026-03-20 00:01:12 -05:00
|
|
|
await ValueChanged.InvokeAsync(Value);
|
2025-01-27 00:21:46 -06:00
|
|
|
}
|
|
|
|
|
}
|