Playzor.Blazor.Editor
1.0.1
dotnet add package Playzor.Blazor.Editor --version 1.0.1
NuGet\Install-Package Playzor.Blazor.Editor -Version 1.0.1
<PackageReference Include="Playzor.Blazor.Editor" Version="1.0.1" />
<PackageVersion Include="Playzor.Blazor.Editor" Version="1.0.1" />
<PackageReference Include="Playzor.Blazor.Editor" />
paket add Playzor.Blazor.Editor --version 1.0.1
#r "nuget: Playzor.Blazor.Editor, 1.0.1"
#:package Playzor.Blazor.Editor@1.0.1
#addin nuget:?package=Playzor.Blazor.Editor&version=1.0.1
#tool nuget:?package=Playzor.Blazor.Editor&version=1.0.1
Playzor.Blazor.Editor
The Playzor playground as a Blazor component: monaco editors for any number of files, roslyn compiling in the browser, dockable panels for file tree, preview, errors and console, and a tool bar whose built in buttons can be picked and extended.
Looking for the small iframe embed of the hosted playground instead? That is Playzor.Blazor.
@using Playzor.Blazor.Editor.Components
<PlayzorEditor Height="100%" DefaultSnippet="@("<h3>Hi</h3>")" />
Setup
// Program.cs
builder.Services.AddScoped(_ => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
builder.Services.AddPlayzor(); // pass a MudEx configuration to let it add MudBlazor too
<link href="_content/Playzor.Blazor.Editor/css/playzor-editor.css" rel="stylesheet" />
<script src="_content/Playzor.Blazor.Editor/lib/monaco-editor/min/vs/loader.js"></script>
<script src="_content/Playzor.Blazor.Editor/js/playzor-editor.js"></script>
<script src="_content/MudBlazor.Extensions/js/mudExPopoutEvents.js"></script>
Panels can be dragged into their own browser window. Blazor delivers dom events through the document of the page it started in, so a panel over there would be dead without that last script: it records the listeners and replays them into the popout window.
Two more things are needed, and the editor tells you when one is missing:
- A package proxy. nuget.org answers without CORS headers, so a
.nupkgcannot be fetched from the browser. Add Playzor.Server andapp.MapPlayzorApi(), or point the editor at a public playground:AddPlayzor(o => o.BaseAddress = PlayzorApiOptions.PlayzorNet). - A preview page. The compiled component runs in a second WebAssembly instance. Reference
Playzor.UserComponents, follow its
readme, then point
CompiledPreviewUrlat that route.
Content
| Parameter | Default | Description |
|---|---|---|
Files |
– | Files to edit. A new collection replaces the whole session |
FilesChanged |
– | Raised after edits, with the editor content pulled in |
DefaultSnippet |
MudEx sample | Content of the main file for a fresh session |
DefaultPackages |
MudBlazor + MudEx | Packages a fresh session starts with |
PersistState |
true |
Keeps files, tabs and layout in local storage |
StateKey |
– | Storage prefix, so two editors do not share a session |
SnippetStore |
from DI | IPlayzorSnippetStore used by save and samples |
SnippetId / SnippetIdChanged |
– | Id of the loaded snippet, set after saving |
Tool bar and panels
| Parameter | Default | Description |
|---|---|---|
ToolButtons |
All |
Flags: Run, Save, Embed, Download, Upload, Samples, Packages, Panels, Layout, Theme, plus Standalone and None |
Panels |
All |
Flags: Files, Preview, Errors, Console, Packages |
PackagesInDialog |
false |
Nuget buttons open the dialog instead of the packages panel |
ShowStatusBar |
true |
Error counts, packages, preview reload |
ToolBarStartContent |
– | Before the first built in button |
ToolBarContent |
– | Between the built in buttons and the spacer |
HeaderContent |
– | Right hand side of the tool bar, after the menus |
StatusBarContent |
– | Right hand side of the status bar |
ChildContent |
– | Additional MudExDockItem panels, dockable like the built in ones |
Save, Embed, Samples and Theme need someone to answer: their button appears once the
matching event (OnSaveRequested, OnEmbedRequested, OnSampleSelected + Samples,
DarkModeChanged) is wired — or, for save and samples, once an IPlayzorSnippetStore is
registered. ToolButtons="PlayzorToolButtons.Standalone" gives you everything that works alone.
<PlayzorEditor ToolButtons="PlayzorToolButtons.Standalone | PlayzorToolButtons.Theme"
DarkMode="@_dark" DarkModeChanged="@(d => _dark = d)">
<ToolBarContent>
<MudIconButton Icon="@Icons.Material.Outlined.Share" OnClick="@ShareAsync" />
</ToolBarContent>
<HeaderContent>
<MudText Typo="Typo.h6" Class="ml-2">My playground</MudText>
</HeaderContent>
<ChildContent>
<MudExDockItem Id="docs" Title="Docs" Direction="DockDirection.Right">
<MyDocsPanel />
</MudExDockItem>
</ChildContent>
</PlayzorEditor>
Preview, theme and layout
| Parameter | Default | Description |
|---|---|---|
PreviewUrl |
/user-page |
Page shown before anything was compiled |
CompiledPreviewUrl |
/__main |
Route of the compiled component |
PopoutUrl |
package page | Host page for popped out panels |
AutoRun |
false |
Compiles once as soon as the editor is up |
DarkMode / DarkModeChanged |
true |
Monaco theme; the app owns its own theme |
Culture |
ui culture | Two letter culture of the editor ui (en, de) |
InitialLayoutJson |
built in | dockview layout to start with |
Height / ToolBarHeight / StatusBarHeight |
100% / 48px / 26px |
Sizes |
OnCompiled |
– | Raised after every compilation with the result |
Methods: TriggerCompileAsync(), GetFiles(), SetFilesAsync(files), OpenFileAsync(path),
ResetLayoutAsync(), ReloadPreview().
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Blazored.LocalStorage (>= 4.5.0)
- Microsoft.AspNetCore.Components.Web (>= 10.0.9)
- Microsoft.AspNetCore.WebUtilities (>= 10.0.9)
- MudBlazor.Extensions (>= 9.8.0)
- Playzor.Core (>= 1.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.
