feat(m9/T31): Monaco JSON-schema hover/completion on value-entry surface
This commit is contained in:
@@ -28,6 +28,16 @@
|
||||
[Parameter] public bool ReadOnly { get; set; } = false;
|
||||
[Parameter] public bool ShowToolbar { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// Optional JSON Schema (the resolved schema text — any
|
||||
/// <c>{"$ref":"lib:Name"}</c> already inlined) applied to this editor's
|
||||
/// model when <see cref="Language"/> is <c>json</c>. Wires Monaco's
|
||||
/// built-in JSON language so the editor offers schema-driven hover,
|
||||
/// completion, and diagnostics on the entered JSON. Ignored for non-JSON
|
||||
/// languages. Updating it re-applies the schema to the live model.
|
||||
/// </summary>
|
||||
[Parameter] public string? JsonSchema { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Runtime globals surface the script is analyzed against. Defaults to
|
||||
/// template/shared-script globals; set to <c>InboundApi</c> on the API
|
||||
@@ -87,6 +97,7 @@
|
||||
private DotNetObjectReference<MonacoEditor>? _dotNetRef;
|
||||
private readonly string _id = Guid.NewGuid().ToString("N");
|
||||
private string _lastSentValue = "";
|
||||
private string? _lastSentSchema;
|
||||
private bool _initialized;
|
||||
private bool _wrap;
|
||||
private bool _minimap;
|
||||
@@ -108,10 +119,12 @@
|
||||
{
|
||||
value = Value ?? "",
|
||||
language = Language,
|
||||
readOnly = ReadOnly
|
||||
readOnly = ReadOnly,
|
||||
jsonSchema = JsonSchema
|
||||
},
|
||||
_dotNetRef);
|
||||
_initialized = true;
|
||||
_lastSentSchema = JsonSchema;
|
||||
}
|
||||
catch (InvalidOperationException)
|
||||
{
|
||||
@@ -128,10 +141,18 @@
|
||||
Logger.LogError(ex, "Monaco editor {EditorId} failed to initialize.", _id);
|
||||
}
|
||||
}
|
||||
else if (_initialized && (Value ?? "") != _lastSentValue)
|
||||
else if (_initialized)
|
||||
{
|
||||
_lastSentValue = Value ?? "";
|
||||
await SafeInvokeAsync("MonacoBlazor.setValue", "set editor value", _id, _lastSentValue);
|
||||
if ((Value ?? "") != _lastSentValue)
|
||||
{
|
||||
_lastSentValue = Value ?? "";
|
||||
await SafeInvokeAsync("MonacoBlazor.setValue", "set editor value", _id, _lastSentValue);
|
||||
}
|
||||
if (JsonSchema != _lastSentSchema)
|
||||
{
|
||||
_lastSentSchema = JsonSchema;
|
||||
await SafeInvokeAsync("MonacoBlazor.setJsonSchema", "set JSON schema", _id, JsonSchema);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user