2025-02-09 03:28:00 -06:00
|
|
|
@inherits FeedbackComponent<string>
|
2024-11-30 19:24:02 -06:00
|
|
|
@inject IMessageService MessageService
|
|
|
|
|
@inject ILogger<ScriptEditorDialog> Logger
|
|
|
|
|
|
|
|
|
|
<StandaloneCodeEditor @ref="Editor" Id="@("editor-" + Id.ToString())" ConstructionOptions="EditorConstructionOptions" OnDidInit="InitEditor" />
|
|
|
|
|
|
|
|
|
|
<style>
|
|
|
|
|
.monaco-editor-container {
|
|
|
|
|
height: 600px;
|
|
|
|
|
}
|
|
|
|
|
</style>
|
|
|
|
|
|
|
|
|
|
@code {
|
|
|
|
|
Guid Id = Guid.NewGuid();
|
|
|
|
|
string Contents = "";
|
|
|
|
|
StandaloneCodeEditor? Editor;
|
|
|
|
|
|
|
|
|
|
string FilePath { get { return $"wwwroot/css/{Options}"; } }
|
|
|
|
|
|
|
|
|
|
StandaloneEditorConstructionOptions EditorConstructionOptions(StandaloneCodeEditor editor)
|
|
|
|
|
{
|
|
|
|
|
return new StandaloneEditorConstructionOptions
|
|
|
|
|
{
|
|
|
|
|
AutomaticLayout = true,
|
|
|
|
|
Language = "css",
|
|
|
|
|
Value = Contents,
|
|
|
|
|
Theme = "vs-dark",
|
2026-05-10 19:32:27 -05:00
|
|
|
Minimap = new EditorMinimapOptions { Enabled = false },
|
|
|
|
|
BracketPairColorization = new BracketPairColorizationOptions { Enabled = true },
|
|
|
|
|
WordWrap = "on",
|
2024-11-30 19:24:02 -06:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnParametersSet()
|
|
|
|
|
{
|
|
|
|
|
if (File.Exists(FilePath))
|
|
|
|
|
Contents = File.ReadAllText(FilePath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async Task InitEditor()
|
|
|
|
|
{
|
|
|
|
|
if (Editor != null)
|
|
|
|
|
{
|
|
|
|
|
await Editor.AddCommand((int)BlazorMonaco.KeyMod.CtrlCmd | (int)BlazorMonaco.KeyCode.KeyS, (editor) =>
|
|
|
|
|
{
|
|
|
|
|
Save();
|
|
|
|
|
}, null);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override async Task OnFeedbackOkAsync(ModalClosingEventArgs args)
|
|
|
|
|
{
|
|
|
|
|
var success = await Save();
|
|
|
|
|
|
|
|
|
|
if (!success)
|
|
|
|
|
args.Reject();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async Task<bool> Save()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
File.WriteAllText(FilePath, await Editor.GetValue());
|
|
|
|
|
|
|
|
|
|
MessageService.Success("Stylesheet saved!");
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
MessageService.Error("Stylesheet could not be saved!");
|
|
|
|
|
Logger.LogError(ex, "Stylesheet could not be saved!");
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|