Set up a Blazor host

Русский

Lierne runs in a .NET 11 Blazor application. The host registers Flare, registers one or more themes and palettes, and lists the plugins that make up the workspace. Lierne manages the selection among the registered themes and palettes through its Themes settings; it does not ship, install or register a theme itself.

Install

dotnet add package Lierne
dotnet add package Flare.Blazor
# add one or more Flare theme packages of your choice

The Lierne package references the Flare IDE components. Add Flare.Blazor and one or more Flare theme packages of your choice when the host does not already use them. Lierne ships no theme.

Try the sample

Run this command from the repository root with the .NET 11 SDK.

dotnet run --project samples/Lierne.SampleIde

Open the address printed in the terminal. Choose New note, type a few lines, and reload the page. The sample restores the note from browser storage. In Tools → Options, you can change the shortcut for New note or the default note title.

Connect your application

For a Blazor Web App, reference src/Lierne/Lierne.csproj from this checkout or install the Lierne package. Reference Flare.Blazor and the Flare theme packages your application offers; none of them is required by Lierne.

For an interactive server host, register the services before builder.Build(). Replace NotesPlugin with your own plugin when you move beyond the sample.

using Flare.Extensions;
using Flare.Theme.YourTheme;
using Lierne;
using Lierne.SampleIde;

var builder = WebApplication.CreateBuilder(args);
builder.Services.AddRazorComponents().AddInteractiveServerComponents();
builder.Services.AddLocalization();

builder.Services.AddFlare(options => options.DefaultTheme = new YourTheme());
builder.Services.AddFlareTheme(new YourTheme());

builder.Services.AddLierne(options => options
    .AddPlugin<LierneHostPlugin>()
    .AddPlugin<NotesPlugin>());
builder.Services.AddLierneComponents();
builder.Services.AddLierneBrowserStateStorage("my-ide");

var app = builder.Build();
app.MapStaticAssets();
app.UseAntiforgery();
app.MapRazorComponents<App>().AddInteractiveServerRenderMode();
app.Run();

Keep the Flare bootstrap script and stylesheets in the app's HTML shell. Set data-default-theme to the theme your application starts with. Lierne ships no stylesheet of its own.

<script src="_content/Flare.Components/js/flare-bootstrap.js" data-default-theme="your-theme-id"></script>
<link rel="stylesheet" href="_content/Flare.Components/css/flare-components.css" />
<link rel="stylesheet" href="_content/Flare.Components.IDE/css/flare-ide.css" />

Place the shell on an interactive page, inside the Flare providers.

@page "/"
@using Flare.Components
@using Lierne
@using Microsoft.AspNetCore.Components.Web
@rendermode @(new InteractiveServerRenderMode(prerender: false))

<FlareLocalizationProvider>
    <FlareThemeProvider>
        <LierneShell />
    </FlareThemeProvider>
</FlareLocalizationProvider>

LierneHostPlugin supplies the built-in options document, including the Themes page that switches between the themes and palettes your application registered. Browser storage is optional. See plugin composition for your first contribution and workspace configuration for storage and layout options.

Update a host that used Lattice

Point the host at src/Lierne/Lierne.csproj or the Lierne package, and update any direct references to Lierne.Core and Lierne.Abstractions. Change imports to using Lierne; and replace the Lattice prefix in API names with Lierne, as in AddLierne, ILiernePlugin and LierneShell. Remove the old Lattice stylesheet reference: Lierne no longer ships CSS, and the application's Flare theme styles the shell.

Keep your application key for browser storage or directory for file storage. Lierne reads existing workspaces and settings exports with their original identifiers.