editor first run

This commit is contained in:
EugeneTes
2026-02-04 14:20:08 +01:00
parent 2748c6586e
commit eca5ced38a
33 changed files with 2322 additions and 5 deletions

View File

@@ -0,0 +1,3 @@
@inherits LayoutComponentBase
@Body

View File

@@ -0,0 +1,113 @@
@page "/"
@using BlazorMonaco
@using BlazorMonaco.Editor
@using BlazorMonaco.Languages
@using Inspectron.PrintServer.TemplateEditor.Services
@inject IJSRuntime JSRuntime
<div class="editor-container">
<div class="toolbar">
<button class="toolbar-btn" title="New">New</button>
<button class="toolbar-btn" title="Open">Open</button>
<button class="toolbar-btn" title="Save">Save</button>
<div class="toolbar-separator"></div>
<button class="toolbar-btn" title="Load JSON data file for expression completions" @onclick="LoadJsonAsync">Load JSON</button>
@if (!string.IsNullOrEmpty(_loadedJsonFile))
{
<span class="json-indicator" title="@_loadedJsonFile">@_loadedJsonFile</span>
}
</div>
<div class="split-pane">
<div class="pane pane-editor">
<div class="pane-header">Editor</div>
<StandaloneCodeEditor @ref="_editor" Id="my-editor-id"
ConstructionOptions="EditorConstructionOptions"
OnDidInit="OnEditorInitAsync"
OnDidChangeModelContent="OnContentChanged" />
</div>
<div class="pane pane-preview">
<div class="pane-header">Preview</div>
<div class="preview-content">
</div>
</div>
</div>
</div>
@code {
private StandaloneCodeEditor _editor = null!;
private string _editorContent = "";
private string? _loadedJsonFile;
private readonly TemplateCompletionProvider _completionProvider = new();
private StandaloneEditorConstructionOptions EditorConstructionOptions(StandaloneCodeEditor editor)
{
return new StandaloneEditorConstructionOptions
{
AutomaticLayout = true,
Language = "receipt-xml",
Theme = "receipt-dark"
};
}
private async Task OnEditorInitAsync()
{
// Register custom language and theme
await JSRuntime.InvokeVoidAsync("receiptLanguage.register");
await JSRuntime.InvokeVoidAsync("receiptLanguage.defineTheme");
// Apply the theme now that it's defined
await BlazorMonaco.Editor.Global.SetTheme(JSRuntime, "receipt-dark");
// Wire up content accessor for the completion provider
_completionProvider.SetEditorContentAccessor(() => _editorContent);
// Register completion provider
await BlazorMonaco.Languages.Global.RegisterCompletionItemProvider(
JSRuntime,
"receipt-xml",
_completionProvider.ProvideCompletionItems,
_completionProvider.ResolveCompletionItem);
}
private async Task OnContentChanged(ModelContentChangedEvent e)
{
_editorContent = await _editor.GetValue();
}
private async Task LoadJsonAsync()
{
try
{
var result = await FilePicker.Default.PickAsync(new PickOptions
{
PickerTitle = "Select a JSON data file",
FileTypes = new FilePickerFileType(new Dictionary<DevicePlatform, IEnumerable<string>>
{
{ DevicePlatform.WinUI, new[] { ".json" } },
{ DevicePlatform.macOS, new[] { "json" } },
{ DevicePlatform.iOS, new[] { "public.json" } },
{ DevicePlatform.Android, new[] { "application/json" } },
})
});
if (result is null)
return;
using var stream = await result.OpenReadAsync();
using var reader = new StreamReader(stream);
var json = await reader.ReadToEndAsync();
var paths = JsonPathExtractor.Extract(json);
_completionProvider.SetJsonPaths(paths);
_loadedJsonFile = result.FileName;
StateHasChanged();
}
catch (Exception)
{
// User cancelled or file read failed
}
}
}

View File

@@ -0,0 +1,5 @@
@page "/not-found"
@layout MainLayout
<h3>Not Found</h3>
<p>Sorry, the content you are looking for does not exist.</p>

View File

@@ -0,0 +1,6 @@
<Router AppAssembly="typeof(MauiProgram).Assembly" NotFoundPage="typeof(Pages.NotFound)">
<Found Context="routeData">
<RouteView RouteData="routeData" DefaultLayout="typeof(Layout.MainLayout)" />
<FocusOnNavigate RouteData="routeData" Selector="h1" />
</Found>
</Router>

View File

@@ -0,0 +1,10 @@
@using System.Net.Http
@using System.Net.Http.Json
@using Microsoft.AspNetCore.Components.Forms
@using Microsoft.AspNetCore.Components.Routing
@using Microsoft.AspNetCore.Components.Web
@using Microsoft.AspNetCore.Components.Web.Virtualization
@using Microsoft.JSInterop
@using Inspectron.PrintServer.TemplateEditor
@using Inspectron.PrintServer.TemplateEditor.Components
@using Inspectron.PrintServer.TemplateEditor.Components.Layout