Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blazor Web Component Blazor POC #15647

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 24 additions & 0 deletions OrchardCore.sln
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,14 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OrchardCore.Email.Smtp", "s
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OrchardCore.Rules.Core", "src\OrchardCore\OrchardCore.Rules.Core\OrchardCore.Rules.Core.csproj", "{4BAA08A2-878C-4B96-86BF-5B3DB2B6C2C7}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "OrchardCore.Components", "OrchardCore.Components", "{7525406F-AEA0-4397-8E6B-3837ABEC2A36}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OrchardCore.Admin.Components", "src\OrchardCore.Components\OrchardCore.Admin.Components\OrchardCore.Admin.Components.csproj", "{0734E6A3-5D42-4698-91F1-4068364E8FCC}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OrchardCore.Admin.WebAssembly.App", "src\OrchardCore.Components\OrchardCore.Admin.WebAssembly.App\OrchardCore.Admin.WebAssembly.App.csproj", "{361B5892-DE24-4249-827E-3D144CC68643}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OrchardCore.Common.Components", "src\OrchardCore.Components\OrchardCore.Common.Components\OrchardCore.Common.Components.csproj", "{2C2CD2A9-BFD8-4A9C-A30F-3CA973E734B7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -1377,6 +1385,18 @@ Global
{4BAA08A2-878C-4B96-86BF-5B3DB2B6C2C7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4BAA08A2-878C-4B96-86BF-5B3DB2B6C2C7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4BAA08A2-878C-4B96-86BF-5B3DB2B6C2C7}.Release|Any CPU.Build.0 = Release|Any CPU
{0734E6A3-5D42-4698-91F1-4068364E8FCC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0734E6A3-5D42-4698-91F1-4068364E8FCC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0734E6A3-5D42-4698-91F1-4068364E8FCC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0734E6A3-5D42-4698-91F1-4068364E8FCC}.Release|Any CPU.Build.0 = Release|Any CPU
{361B5892-DE24-4249-827E-3D144CC68643}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{361B5892-DE24-4249-827E-3D144CC68643}.Debug|Any CPU.Build.0 = Debug|Any CPU
{361B5892-DE24-4249-827E-3D144CC68643}.Release|Any CPU.ActiveCfg = Release|Any CPU
{361B5892-DE24-4249-827E-3D144CC68643}.Release|Any CPU.Build.0 = Release|Any CPU
{2C2CD2A9-BFD8-4A9C-A30F-3CA973E734B7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2C2CD2A9-BFD8-4A9C-A30F-3CA973E734B7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2C2CD2A9-BFD8-4A9C-A30F-3CA973E734B7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2C2CD2A9-BFD8-4A9C-A30F-3CA973E734B7}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -1615,6 +1635,10 @@ Global
{C35AB37B-5A09-4896-BEEE-B126B7E7018A} = {A066395F-6F73-45DC-B5A6-B4E306110DCE}
{E8A1097D-A65A-4B17-A3A2-F50D79552732} = {A066395F-6F73-45DC-B5A6-B4E306110DCE}
{4BAA08A2-878C-4B96-86BF-5B3DB2B6C2C7} = {F23AC6C2-DE44-4699-999D-3C478EF3D691}
{7525406F-AEA0-4397-8E6B-3837ABEC2A36} = {275E087F-A4E2-4A7B-A924-ED68E3A52086}
{0734E6A3-5D42-4698-91F1-4068364E8FCC} = {7525406F-AEA0-4397-8E6B-3837ABEC2A36}
{361B5892-DE24-4249-827E-3D144CC68643} = {7525406F-AEA0-4397-8E6B-3837ABEC2A36}
{2C2CD2A9-BFD8-4A9C-A30F-3CA973E734B7} = {7525406F-AEA0-4397-8E6B-3837ABEC2A36}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {46A1D25A-78D1-4476-9CBF-25B75E296341}
Expand Down
5 changes: 5 additions & 0 deletions src/OrchardCore.Build/Dependencies.AspNetCore.props
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@
<PackageManagement Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="$(AspNetCorePackagesVersion)" />
<PackageManagement Include="Microsoft.AspNetCore.Mvc.Testing" Version="$(AspNetCorePackagesVersion)" />
<PackageManagement Include="Microsoft.AspNetCore.Owin" Version="$(AspNetCorePackagesVersion)" />
<PackageManagement Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="$(AspNetCorePackagesVersion)"/>
<PackageManagement Include="Microsoft.AspNetCore.Components.Web" Version="$(AspNetCorePackagesVersion)"/>
<PackageManagement Include="Microsoft.AspNetCore.Components.WebAssembly" Version="$(AspNetCorePackagesVersion)"/>
<PackageManagement Include="Microsoft.AspNetCore.Components.CustomElements" Version="$(AspNetCorePackagesVersion)"/>

</ItemGroup>

<!-- 'Microsoft.Extensions' packages that are not included in the ASP.NET Core shared framework -->
Expand Down
5 changes: 4 additions & 1 deletion src/OrchardCore.Cms.Web/OrchardCore.Cms.Web.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project ToolsVersion="15.0" Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">

<Import Project="..\OrchardCore.Build\Dependencies.props" />

Expand Down Expand Up @@ -30,10 +30,13 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" />
<PackageReference Include="Microsoft.AspNetCore.Components.CustomElements" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Condition="'$(RazorRuntimeCompilation)' == 'true'" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\OrchardCore.Components\OrchardCore.Admin.WebAssembly.App\OrchardCore.Admin.WebAssembly.App.csproj" />
<ProjectReference Include="..\OrchardCore\OrchardCore.Application.Cms.Targets\OrchardCore.Application.Cms.Targets.csproj" />
<ProjectReference Include="..\OrchardCore\OrchardCore.Logging.NLog\OrchardCore.Logging.NLog.csproj" />
</ItemGroup>
Expand Down
6 changes: 5 additions & 1 deletion src/OrchardCore.Cms.Web/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@

var app = builder.Build();

if (!app.Environment.IsDevelopment())
if (app.Environment.IsDevelopment())
{
app.UseWebAssemblyDebugging();
}
else
{
app.UseExceptionHandler("/Error");
}
Expand Down
4 changes: 3 additions & 1 deletion src/OrchardCore.Cms.Web/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@
"Kestrel": {
"commandName": "Project",
"launchBrowser": true,
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
"launchUrl": "https://localhost:5001",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
"ASPNETCORE_ENVIRONMENT": "Development",
"ORCHARD_APP_DATA": "C:\\k8s\\oc_github"
},
"applicationUrl": "https://localhost:5001;http://localhost:5000"
}
Expand Down
10 changes: 10 additions & 0 deletions src/OrchardCore.Components/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<Import Project="..\..\Directory.Build.props" />
<Import Project="..\OrchardCore.Build\OrchardCore.Commons.props" />

<PropertyGroup>
<TargetFrameworks>$(CommonTargetFrameworks)</TargetFrameworks>
</PropertyGroup>

</Project>
5 changes: 5 additions & 0 deletions src/OrchardCore.Components/Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<Import Project="..\OrchardCore.Build\OrchardCore.Commons.targets" />

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@using Microsoft.AspNetCore.Components.Routing
<Router AppAssembly="GetType().Assembly">
<Found Context="routeData">
<RouteView RouteData="routeData" />
<FocusOnNavigate RouteData="routeData" Selector="h1" />
</Found>
</Router>
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<TargetFrameworks>$(CommonTargetFrameworks)</TargetFrameworks>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>


<ItemGroup>
<SupportedPlatform Include="browser" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.Web" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\OrchardCore.Common.Components\OrchardCore.Common.Components.csproj" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@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 static Microsoft.AspNetCore.Components.Web.RenderMode
@using Microsoft.AspNetCore.Components.Web.Virtualization
@using Microsoft.JSInterop
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<h3>Initializer</h3>

@code {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">

<PropertyGroup>
<TargetFrameworks>$(CommonTargetFrameworks)</TargetFrameworks>

<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<NoDefaultLaunchSettingsFile>true</NoDefaultLaunchSettingsFile>
<StaticWebAssetProjectMode>Default</StaticWebAssetProjectMode>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" />
<PackageReference Include="Microsoft.AspNetCore.Components.CustomElements" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\OrchardCore.Admin.Components\OrchardCore.Admin.Components.csproj" />
<ProjectReference Include="..\OrchardCore.Common.Components\OrchardCore.Common.Components.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using OrchardCore.Admin.WebAssembly.App;
using OrchardCore.Common.Components;

var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.RegisterCustomElement<OptionEditor>("option-editor");
builder.RootComponents.RegisterCustomElement<Initializer>("init");


await builder.Build().RunAsync();
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@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 static Microsoft.AspNetCore.Components.Web.RenderMode
@using Microsoft.AspNetCore.Components.Web.Virtualization
@using Microsoft.JSInterop
@using OrchardCore.Admin.WebAssembly.App
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;

namespace OrchardCore.Common.Components;

public class CollocatedJSComponent : ComponentBase, IAsyncDisposable
{
[Inject]
private IJSRuntime? JS { get; set; }

[Parameter]
public bool RaiseDomEvents { get; set; }

protected IJSObjectReference? JSModule { get; private set; }

protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
var ns = GetType().Namespace;
var cmp = GetType().Name;
if (JS is not null)
{
JSModule = await JS.InvokeAsync<IJSObjectReference>("import",
$"./_content/{ns}/{cmp}.razor.js");
Copy link
Contributor Author

@Skrypt Skrypt Apr 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here the ES6 module are imported based on their name. This should be renamed to .mjs to make a distinction or support it at least.

}
}
}

async ValueTask IAsyncDisposable.DisposeAsync()
{
if (JSModule is not null)
{
await JSModule.DisposeAsync();
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<div class="modal fade @IsOpenClass text-start" role="dialog" style="display:@IsOpenDisplayStyle" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">@Title</h5>
<button type="button" class="btn-close" aria-label="Close" @onclick="Close"></button>
</div>
<div class="modal-body">
@Body
</div>
<div class="modal-footer">
@Actions
</div>
</div>
</div>
</div>

@if (ShowBackdrop && IsOpen)
{
<div class="modal-backdrop fade show"></div>
}

@code {

[Parameter]
public string? Title { get; set; }
[Parameter]
public bool ShowBackdrop { get; set; }
[Parameter]
public RenderFragment? Body { get; set; }
[Parameter]
public RenderFragment? Actions { get; set; }


public bool IsOpen { get; set; }

string IsOpenClass { get; set; } = string.Empty;

string IsOpenDisplayStyle { get; set; } = "none";

public async Task Open()
{
IsOpenDisplayStyle = "block";
IsOpen = true;
await Task.Delay(100);//Delay allows bootstrap to perform nice fade animation
IsOpenClass = "show";
StateHasChanged();

}

public async Task Close()
{
IsOpenClass = "";
IsOpen = false;
await Task.Delay(250);//Delay allows bootstrap to perform nice fade animation
IsOpenDisplayStyle = "none";
StateHasChanged();
}
}