SimpleBlazorMonaco 1.0.7
dotnet add package SimpleBlazorMonaco --version 1.0.7
NuGet\Install-Package SimpleBlazorMonaco -Version 1.0.7
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SimpleBlazorMonaco" Version="1.0.7" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SimpleBlazorMonaco --version 1.0.7
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: SimpleBlazorMonaco, 1.0.7"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install SimpleBlazorMonaco as a Cake Addin #addin nuget:?package=SimpleBlazorMonaco&version=1.0.7 // Install SimpleBlazorMonaco as a Cake Tool #tool nuget:?package=SimpleBlazorMonaco&version=1.0.7
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Installing
You can install from NuGet using the following command:
Install-Package SimpleBlazorMonaco
Or via the Visual Studio package manger.
Setup
You can add the following using statement to your main _Imports.razor
to make referencing the component a bit easier.
@using MonacoRazor
@using SimpleBlazorMonaco
Usage
Below is a list of all the options available on the Editor.
Properties
Language
- The language of the editor.Code
- The code to be displayed in the editor.OnCompletionsRequested
- A method that is called when the editor requests completions.Height
- The height of the editor.Width
- The width of the editor.Border
- The border of the editor.Margin
- The margin of the editor.MinHeight
- The minimum height of the editor.
Methods
GetCodeAsync()
- Gets the content of the editor.UpdateCodeAsync(code)
- Updates the content of the editor.
Basic Example
<details> <summary>Code</summary>
@page "/"
@using SimpleBlazorMonaco
<h1>Hello, world!</h1>
Welcome to your new app.
<CodeEditor @ref="@MonacoCodeEditor"
Language="csharp"
Code="@CurrentScript"
OnCompletionsRequested="GetCompletionsAsync"
Height="300px"
Width="90%"
Border="2px solid gray"
Margin="1em 0"
MinHeight="300px" />
<br />
<button @onclick="GetCode">Get Code</button>
<button @onclick="UpdateCode">Update Code</button>
@if (!string.IsNullOrEmpty(Message))
{
<div class="modal fade show" tabindex="-1" role="dialog"
style="display: block;" aria-modal="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Current Script</h5>
</div>
<div class="modal-body">
<CodeEditor
Language="csharp"
Height="90%"
Width="99%"
Border="0px"
Code="@Message" />
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary"
data-bs-dismiss="modal" @onclick="CloseMessagePopup">
Close
</button>
</div>
</div>
</div>
</div>
<div class="modal-backdrop fade show"></div>
}
@code {
CodeEditor MonacoCodeEditor;
string CurrentScript = "";
string SampleScript = @"namespace Sample
{
public class MyClass
{
}
}";
protected override void OnInitialized()
{
CurrentScript = SampleScript;
}
Task<Suggestion[]> GetCompletionsAsync(string currentValue, Position position)
{
return Task.FromResult(new[]
{
new Suggestion {Label = "From C#", InsertText = "From C#" },
new Suggestion {Label = "OK", InsertText = "OK" },
});
}
private async Task GetCode()
{
CurrentScript = await MonacoCodeEditor.GetCodeAsync();
Message = CurrentScript;
}
private async Task UpdateCode()
{
await MonacoCodeEditor.UpdateCodeAsync(SampleScript);
}
private string Message = "";
private void CloseMessagePopup()
{
Message = "";
}
}
</details>
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net9.0
- Microsoft.AspNetCore.Components.Web (>= 9.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.