21 changed files with 265 additions and 56 deletions
@ -1,8 +1,12 @@ |
|||
using Volo.Abp.AspNetCore.Mvc.UI.Bundling; |
|||
using System.Collections.Generic; |
|||
using Volo.Abp.AspNetCore.Mvc.UI.Bundling; |
|||
|
|||
namespace Lsw.Abp.AspnetCore.Components.Server.AntDesignTheme.Bundling; |
|||
|
|||
public class BlazorAntDesignThemeScriptContributor: BundleContributor |
|||
{ |
|||
|
|||
public override void ConfigureBundle(BundleConfigurationContext context) |
|||
{ |
|||
context.Files.AddIfNotContains("/_content/AntDesign/js/ant-design-blazor.js"); |
|||
} |
|||
} |
|||
|
|||
@ -0,0 +1,17 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
|
|||
namespace Lsw.Abp.AspnetCore.Components.Web.AntDesignTheme; |
|||
|
|||
public class AbpDynamicLayoutComponentOptions |
|||
{ |
|||
/// <summary>
|
|||
/// Used to define components that renders in the layout
|
|||
/// </summary>
|
|||
public Dictionary<Type, IDictionary<string,object>?> Components { get; set; } |
|||
|
|||
public AbpDynamicLayoutComponentOptions() |
|||
{ |
|||
Components = new Dictionary<Type, IDictionary<string, object>?>(); |
|||
} |
|||
} |
|||
@ -1,56 +1,60 @@ |
|||
@using Volo.Abp |
|||
@implements IDisposable |
|||
@inject IComponentBundleManager BundleManager |
|||
@inject PersistentComponentState PersistentComponentState |
|||
|
|||
@inject PersistentComponentState ApplicationState |
|||
@if (ScriptFiles != null) |
|||
{ |
|||
foreach (var file in ScriptFiles) |
|||
{ |
|||
<script src="@file"></script> |
|||
var src = file; |
|||
if (!AppBasePath.IsNullOrWhiteSpace()) |
|||
{ |
|||
src = AppBasePath.EnsureEndsWith('/') + file.RemovePreFix("/"); |
|||
} |
|||
<script src="@src"></script> |
|||
} |
|||
} |
|||
|
|||
@code { |
|||
|
|||
private const string PrerenderedKey = "abp_script_prerendered"; |
|||
|
|||
[Parameter] |
|||
public List<string>? WebAssemblyScriptFiles { get; set; } |
|||
|
|||
[Parameter] |
|||
public string? BundleName { get; set; } |
|||
|
|||
[Parameter] |
|||
public string? AppBasePath { get; set; } |
|||
|
|||
private List<string>? ScriptFiles { get; set; } |
|||
|
|||
private PersistingComponentStateSubscription persistingSubscription; |
|||
private PersistingComponentStateSubscription _persistingSubscription; |
|||
|
|||
protected override async Task OnInitializedAsync() |
|||
{ |
|||
if (BundleName == null) |
|||
_persistingSubscription = ApplicationState.RegisterOnPersisting(Callback); |
|||
if (!ApplicationState.TryTakeFromJson<string>(PrerenderedKey, out _)) |
|||
{ |
|||
throw new AbpException("The BundleName parameter of the AbpScripts component can not be null!"); |
|||
} |
|||
|
|||
persistingSubscription = PersistentComponentState.RegisterOnPersisting(PersistScriptFiles); |
|||
|
|||
if (PersistentComponentState.TryTakeFromJson<List<string>>(nameof(ScriptFiles), out var restoredStyleFiles)) |
|||
{ |
|||
ScriptFiles = restoredStyleFiles; |
|||
if (!BundleName.IsNullOrWhiteSpace()) |
|||
{ |
|||
ScriptFiles = (await BundleManager.GetScriptBundleFilesAsync(BundleName!)).ToList(); |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
ScriptFiles = (await BundleManager.GetScriptBundleFilesAsync(BundleName!)).ToList(); |
|||
} |
|||
|
|||
if (WebAssemblyScriptFiles != null) |
|||
{ |
|||
ScriptFiles?.AddRange(WebAssemblyScriptFiles); |
|||
if (OperatingSystem.IsBrowser() && WebAssemblyScriptFiles != null) |
|||
{ |
|||
ScriptFiles = WebAssemblyScriptFiles; |
|||
} |
|||
} |
|||
} |
|||
|
|||
private Task PersistScriptFiles() |
|||
private Task Callback() |
|||
{ |
|||
PersistentComponentState.PersistAsJson(nameof(ScriptFiles), ScriptFiles); |
|||
ApplicationState.PersistAsJson(PrerenderedKey, PrerenderedKey); |
|||
return Task.CompletedTask; |
|||
} |
|||
|
|||
public void Dispose() => persistingSubscription.Dispose(); |
|||
public void Dispose() => _persistingSubscription.Dispose(); |
|||
} |
|||
@ -1,56 +1,74 @@ |
|||
@using Volo.Abp |
|||
@implements IDisposable |
|||
@inject IComponentBundleManager BundleManager |
|||
@inject PersistentComponentState PersistentComponentState |
|||
|
|||
@inject PersistentComponentState ApplicationState |
|||
@if (StyleFiles != null) |
|||
{ |
|||
foreach (var file in StyleFiles) |
|||
{ |
|||
<link rel="stylesheet" href="@file" /> |
|||
var href = file; |
|||
if (!AppBasePath.IsNullOrWhiteSpace()) |
|||
{ |
|||
href = AppBasePath.EnsureEndsWith('/') + file.RemovePreFix("/"); |
|||
} |
|||
<link rel="stylesheet" href="@href" /> |
|||
} |
|||
} |
|||
|
|||
@code { |
|||
|
|||
private const string PrerenderedKey = "abp_style_prerendered"; |
|||
|
|||
[Parameter] |
|||
public List<string>? WebAssemblyStyleFiles { get; set; } |
|||
|
|||
[Parameter] |
|||
public string? BundleName { get; set; } |
|||
|
|||
[Parameter] |
|||
public string? AppBasePath { get; set; } |
|||
|
|||
private List<string>? StyleFiles { get; set; } |
|||
|
|||
private PersistingComponentStateSubscription persistingSubscription; |
|||
private PersistingComponentStateSubscription _persistingSubscription; |
|||
|
|||
protected override async Task OnInitializedAsync() |
|||
{ |
|||
if (BundleName == null) |
|||
_persistingSubscription = ApplicationState.RegisterOnPersisting(Callback); |
|||
if (!ApplicationState.TryTakeFromJson<List<string>>(PrerenderedKey, out var scriptFiles)) |
|||
{ |
|||
throw new AbpException("The BundleName parameter of the AbpStyles component can not be null!"); |
|||
} |
|||
|
|||
persistingSubscription = PersistentComponentState.RegisterOnPersisting(PersistStyleFiles); |
|||
|
|||
if (PersistentComponentState.TryTakeFromJson<List<string>>(nameof(StyleFiles), out var restoredStyleFiles)) |
|||
{ |
|||
StyleFiles = restoredStyleFiles; |
|||
if (!BundleName.IsNullOrWhiteSpace()) |
|||
{ |
|||
StyleFiles = (await BundleManager.GetStyleBundleFilesAsync(BundleName!)).ToList(); |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
StyleFiles = (await BundleManager.GetStyleBundleFilesAsync(BundleName!)).ToList(); |
|||
StyleFiles = scriptFiles; |
|||
if (OperatingSystem.IsBrowser() && StyleFiles != null && WebAssemblyStyleFiles != null) |
|||
{ |
|||
StyleFiles.AddIfNotContains(WebAssemblyStyleFiles); |
|||
} |
|||
} |
|||
} |
|||
|
|||
if (OperatingSystem.IsBrowser() && WebAssemblyStyleFiles != null) |
|||
private bool _hasRemoveServerStyle = false; |
|||
|
|||
protected override async Task OnAfterRenderAsync(bool firstRender) |
|||
{ |
|||
if (!_hasRemoveServerStyle && OperatingSystem.IsBrowser() && WebAssemblyStyleFiles != null) |
|||
{ |
|||
StyleFiles?.AddRange(WebAssemblyStyleFiles); |
|||
_hasRemoveServerStyle = true; |
|||
await Task.Delay(3000); |
|||
StyleFiles = WebAssemblyStyleFiles; |
|||
StateHasChanged(); |
|||
} |
|||
} |
|||
|
|||
private Task PersistStyleFiles() |
|||
private Task Callback() |
|||
{ |
|||
PersistentComponentState.PersistAsJson(nameof(StyleFiles), StyleFiles); |
|||
ApplicationState.PersistAsJson(PrerenderedKey, StyleFiles); |
|||
return Task.CompletedTask; |
|||
} |
|||
|
|||
public void Dispose() => persistingSubscription.Dispose(); |
|||
} |
|||
public void Dispose() => _persistingSubscription.Dispose(); |
|||
} |
|||
|
|||
@ -0,0 +1,54 @@ |
|||
using Volo.Abp.AspNetCore.Mvc.UI.Bundling; |
|||
using Volo.Abp.Modularity; |
|||
|
|||
namespace Lsw.Abp.AspnetCore.Components.WebAssembly.AntDesignTheme.Bundling; |
|||
|
|||
[DependsOn( |
|||
typeof(AbpAspNetCoreMvcUiBundlingAbstractionsModule) |
|||
)] |
|||
public class AbpAspNetCoreComponentsWebAssemblyAntDesignThemeBundlingModule : AbpModule |
|||
{ |
|||
public override void ConfigureServices(ServiceConfigurationContext context) |
|||
{ |
|||
Configure<AbpBundlingOptions>(options => |
|||
{ |
|||
options.GlobalAssets.Enabled = true; |
|||
options.GlobalAssets.GlobalStyleBundleName = BlazorWebAssemblyAntDesignThemeBundles.Styles.Global; |
|||
options.GlobalAssets.GlobalScriptBundleName = BlazorWebAssemblyAntDesignThemeBundles.Scripts.Global; |
|||
|
|||
options |
|||
.StyleBundles |
|||
.Add(BlazorWebAssemblyStandardBundles.Styles.Global, bundle => |
|||
{ |
|||
bundle.AddContributors(typeof(BlazorWebAssemblyStyleContributor)); |
|||
}); |
|||
|
|||
options |
|||
.ScriptBundles |
|||
.Add(BlazorWebAssemblyStandardBundles.Scripts.Global, bundle => |
|||
{ |
|||
bundle.AddContributors(typeof(BlazorWebAssemblyScriptContributor)); |
|||
}); |
|||
|
|||
options |
|||
.StyleBundles |
|||
.Add(BlazorWebAssemblyAntDesignThemeBundles.Styles.Global, bundle => |
|||
{ |
|||
bundle |
|||
.AddBaseBundles(BlazorWebAssemblyStandardBundles.Styles.Global) |
|||
.AddContributors(typeof(BlazorWebAssemblyAntDesignThemeStyleContributor)); |
|||
}); |
|||
|
|||
options |
|||
.ScriptBundles |
|||
.Add(BlazorWebAssemblyAntDesignThemeBundles.Scripts.Global, bundle => |
|||
{ |
|||
bundle |
|||
.AddBaseBundles(BlazorWebAssemblyStandardBundles.Scripts.Global) |
|||
.AddContributors(typeof(BlazorWebAssemblyAntDesignThemeScriptContributor)); |
|||
}); |
|||
|
|||
options.MinificationIgnoredFiles.Add("_content/Microsoft.AspNetCore.Components.WebAssembly.Authentication/AuthenticationService.js"); |
|||
}); |
|||
} |
|||
} |
|||
@ -0,0 +1,14 @@ |
|||
namespace Lsw.Abp.AspnetCore.Components.WebAssembly.AntDesignTheme.Bundling; |
|||
|
|||
public class BlazorWebAssemblyAntDesignThemeBundles |
|||
{ |
|||
public static class Styles |
|||
{ |
|||
public static string Global = "BlazorWebAssembly.AntDesignTheme.Global"; |
|||
} |
|||
|
|||
public static class Scripts |
|||
{ |
|||
public static string Global = "BlazorWebAssembly.AntDesignTheme.Global"; |
|||
} |
|||
} |
|||
@ -0,0 +1,12 @@ |
|||
using System.Collections.Generic; |
|||
using Volo.Abp.AspNetCore.Mvc.UI.Bundling; |
|||
|
|||
namespace Lsw.Abp.AspnetCore.Components.WebAssembly.AntDesignTheme.Bundling; |
|||
|
|||
public class BlazorWebAssemblyAntDesignThemeScriptContributor: BundleContributor |
|||
{ |
|||
public override void ConfigureBundle(BundleConfigurationContext context) |
|||
{ |
|||
context.Files.AddIfNotContains("_content/AntDesign/js/ant-design-blazor.js"); |
|||
} |
|||
} |
|||
@ -0,0 +1,13 @@ |
|||
using System.Collections.Generic; |
|||
using Volo.Abp.AspNetCore.Mvc.UI.Bundling; |
|||
|
|||
namespace Lsw.Abp.AspnetCore.Components.WebAssembly.AntDesignTheme.Bundling; |
|||
|
|||
public class BlazorWebAssemblyAntDesignThemeStyleContributor: BundleContributor |
|||
{ |
|||
public override void ConfigureBundle(BundleConfigurationContext context) |
|||
{ |
|||
context.Files.AddIfNotContains("_content/AntDesign/css/ant-design-blazor.css"); |
|||
context.Files.AddIfNotContains("_content/Lsw.Abp.AspnetCore.Components.Web.AntDesignTheme/libs/abp/css/theme.css"); |
|||
} |
|||
} |
|||
@ -0,0 +1,15 @@ |
|||
using System.Collections.Generic; |
|||
using Volo.Abp.AspNetCore.Mvc.UI.Bundling; |
|||
|
|||
namespace Lsw.Abp.AspnetCore.Components.WebAssembly.AntDesignTheme.Bundling; |
|||
|
|||
public class BlazorWebAssemblyScriptContributor : BundleContributor |
|||
{ |
|||
public override void ConfigureBundle(BundleConfigurationContext context) |
|||
{ |
|||
context.Files.AddIfNotContains("_content/Microsoft.AspNetCore.Components.WebAssembly.Authentication/AuthenticationService.js"); |
|||
context.Files.AddIfNotContains("_content/Volo.Abp.AspNetCore.Components.Web/libs/abp/js/abp.js"); |
|||
context.Files.AddIfNotContains("_content/Volo.Abp.AspNetCore.Components.Web/libs/abp/js/lang-utils.js"); |
|||
context.Files.AddIfNotContains("_content/Volo.Abp.AspNetCore.Components.Web/libs/abp/js/authentication-state-listener.js"); |
|||
} |
|||
} |
|||
@ -0,0 +1,14 @@ |
|||
namespace Lsw.Abp.AspnetCore.Components.WebAssembly.AntDesignTheme.Bundling; |
|||
|
|||
public class BlazorWebAssemblyStandardBundles |
|||
{ |
|||
public static class Styles |
|||
{ |
|||
public static string Global = "BlazorWebAssembly.Global"; |
|||
} |
|||
|
|||
public static class Scripts |
|||
{ |
|||
public static string Global = "BlazorWebAssembly.Global"; |
|||
} |
|||
} |
|||
@ -0,0 +1,11 @@ |
|||
using System.Collections.Generic; |
|||
using Volo.Abp.AspNetCore.Mvc.UI.Bundling; |
|||
|
|||
namespace Lsw.Abp.AspnetCore.Components.WebAssembly.AntDesignTheme.Bundling; |
|||
|
|||
public class BlazorWebAssemblyStyleContributor : BundleContributor |
|||
{ |
|||
public override void ConfigureBundle(BundleConfigurationContext context) |
|||
{ |
|||
} |
|||
} |
|||
@ -0,0 +1,3 @@ |
|||
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd"> |
|||
<ConfigureAwait /> |
|||
</Weavers> |
|||
@ -0,0 +1,17 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk.Razor"> |
|||
|
|||
<Import Project="..\..\..\common.props" /> |
|||
<Import Project="..\..\..\configureawait.props" /> |
|||
|
|||
<PropertyGroup> |
|||
<TargetFramework>net9.0</TargetFramework> |
|||
<GenerateEmbeddedFilesManifest>true</GenerateEmbeddedFilesManifest> |
|||
<IsPackable>true</IsPackable> |
|||
<OutputType>Library</OutputType> |
|||
</PropertyGroup> |
|||
|
|||
<ItemGroup> |
|||
<PackageReference Include="Volo.Abp.AspNetCore.Mvc.UI.Bundling.Abstractions"/> |
|||
</ItemGroup> |
|||
|
|||
</Project> |
|||
Loading…
Reference in new issue