-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Add lifecycle hooks for page and islands components
- Loading branch information
Showing
54 changed files
with
663 additions
and
4,286 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
using System; | ||
using System; | ||
|
||
namespace BlazeKit.Abstraction; | ||
/// <summary> | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
using Microsoft.AspNetCore.Components; | ||
using Microsoft.AspNetCore.Components.Web; | ||
using Microsoft.AspNetCore.Components.Web.HtmlRendering; | ||
using Microsoft.Extensions.Logging; | ||
using System.Diagnostics.CodeAnalysis; | ||
|
||
namespace BlazeKit.Static | ||
{ | ||
/// <summary> | ||
/// Provides a mechanism for rendering components non-interactively as HTML markup. | ||
/// </summary> | ||
public sealed class BKHtmlRenderer : IDisposable, IAsyncDisposable | ||
{ | ||
private readonly BKStaticHtmlRenderer _passiveHtmlRenderer; | ||
|
||
/// <summary> | ||
/// Constructs an instance of <see cref="HtmlRenderer"/>. | ||
/// </summary> | ||
/// <param name="services">The services to use when rendering components.</param> | ||
/// <param name="loggerFactory">The logger factory to use.</param> | ||
public BKHtmlRenderer(IServiceProvider services, ILoggerFactory loggerFactory) | ||
{ | ||
_passiveHtmlRenderer = new BKStaticHtmlRenderer(services, loggerFactory); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public void Dispose() | ||
=> _passiveHtmlRenderer.Dispose(); | ||
|
||
/// <inheritdoc /> | ||
public ValueTask DisposeAsync() | ||
=> _passiveHtmlRenderer.DisposeAsync(); | ||
|
||
/// <summary> | ||
/// Gets the <see cref="Components.Dispatcher" /> associated with this instance. Any calls to | ||
/// <see cref="RenderComponentAsync{TComponent}()"/> or <see cref="BeginRenderingComponent{TComponent}()"/> | ||
/// must be performed using this <see cref="Components.Dispatcher" />. | ||
/// </summary> | ||
public Dispatcher Dispatcher => _passiveHtmlRenderer.Dispatcher; | ||
|
||
/// <summary> | ||
/// Adds an instance of the specified component and instructs it to render. The resulting content represents the | ||
/// initial synchronous rendering output, which may later change. To wait for the component hierarchy to complete | ||
/// any asynchronous operations such as loading, await <see cref="HtmlRootComponent.QuiescenceTask"/> before | ||
/// reading content from the <see cref="HtmlRootComponent"/>. | ||
/// </summary> | ||
/// <typeparam name="TComponent">The component type.</typeparam> | ||
/// <returns>An <see cref="HtmlRootComponent"/> instance representing the render output.</returns> | ||
public HtmlRootComponent BeginRenderingComponent<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] TComponent>() where TComponent : IComponent | ||
=> _passiveHtmlRenderer.BeginRenderingComponent(typeof(TComponent), ParameterView.Empty); | ||
|
||
/// <summary> | ||
/// Adds an instance of the specified component and instructs it to render. The resulting content represents the | ||
/// initial synchronous rendering output, which may later change. To wait for the component hierarchy to complete | ||
/// any asynchronous operations such as loading, await <see cref="HtmlRootComponent.QuiescenceTask"/> before | ||
/// reading content from the <see cref="HtmlRootComponent"/>. | ||
/// </summary> | ||
/// <typeparam name="TComponent">The component type.</typeparam> | ||
/// <param name="parameters">Parameters for the component.</param> | ||
/// <returns>An <see cref="HtmlRootComponent"/> instance representing the render output.</returns> | ||
public HtmlRootComponent BeginRenderingComponent<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] TComponent>( | ||
ParameterView parameters) where TComponent : IComponent | ||
=> _passiveHtmlRenderer.BeginRenderingComponent(typeof(TComponent), parameters); | ||
|
||
/// <summary> | ||
/// Adds an instance of the specified component and instructs it to render. The resulting content represents the | ||
/// initial synchronous rendering output, which may later change. To wait for the component hierarchy to complete | ||
/// any asynchronous operations such as loading, await <see cref="HtmlRootComponent.QuiescenceTask"/> before | ||
/// reading content from the <see cref="HtmlRootComponent"/>. | ||
/// </summary> | ||
/// <param name="componentType">The component type. This must implement <see cref="IComponent"/>.</param> | ||
/// <returns>An <see cref="HtmlRootComponent"/> instance representing the render output.</returns> | ||
public HtmlRootComponent BeginRenderingComponent( | ||
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type componentType) | ||
=> _passiveHtmlRenderer.BeginRenderingComponent(componentType, ParameterView.Empty); | ||
|
||
/// <summary> | ||
/// Adds an instance of the specified component and instructs it to render. The resulting content represents the | ||
/// initial synchronous rendering output, which may later change. To wait for the component hierarchy to complete | ||
/// any asynchronous operations such as loading, await <see cref="HtmlRootComponent.QuiescenceTask"/> before | ||
/// reading content from the <see cref="HtmlRootComponent"/>. | ||
/// </summary> | ||
/// <param name="componentType">The component type. This must implement <see cref="IComponent"/>.</param> | ||
/// <param name="parameters">Parameters for the component.</param> | ||
/// <returns>An <see cref="HtmlRootComponent"/> instance representing the render output.</returns> | ||
public HtmlRootComponent BeginRenderingComponent( | ||
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type componentType, | ||
ParameterView parameters) | ||
=> _passiveHtmlRenderer.BeginRenderingComponent(componentType, parameters); | ||
|
||
/// <summary> | ||
/// Adds an instance of the specified component and instructs it to render, waiting | ||
/// for the component hierarchy to complete asynchronous tasks such as loading. | ||
/// </summary> | ||
/// <typeparam name="TComponent">The component type.</typeparam> | ||
/// <returns>A task that completes with <see cref="HtmlRootComponent"/> once the component hierarchy has completed any asynchronous tasks such as loading.</returns> | ||
public Task<HtmlRootComponent> RenderComponentAsync<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] TComponent>() where TComponent : IComponent | ||
=> RenderComponentAsync<TComponent>(ParameterView.Empty); | ||
|
||
/// <summary> | ||
/// Adds an instance of the specified component and instructs it to render, waiting | ||
/// for the component hierarchy to complete asynchronous tasks such as loading. | ||
/// </summary> | ||
/// <param name="componentType">The component type. This must implement <see cref="IComponent"/>.</param> | ||
/// <returns>A task that completes with <see cref="HtmlRootComponent"/> once the component hierarchy has completed any asynchronous tasks such as loading.</returns> | ||
public Task<HtmlRootComponent> RenderComponentAsync( | ||
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type componentType) | ||
=> RenderComponentAsync(componentType, ParameterView.Empty); | ||
|
||
/// <summary> | ||
/// Adds an instance of the specified component and instructs it to render, waiting | ||
/// for the component hierarchy to complete asynchronous tasks such as loading. | ||
/// </summary> | ||
/// <typeparam name="TComponent">The component type.</typeparam> | ||
/// <param name="parameters">Parameters for the component.</param> | ||
/// <returns>A task that completes with <see cref="HtmlRootComponent"/> once the component hierarchy has completed any asynchronous tasks such as loading.</returns> | ||
public Task<HtmlRootComponent> RenderComponentAsync<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] TComponent>( | ||
ParameterView parameters) where TComponent : IComponent | ||
=> RenderComponentAsync(typeof(TComponent), parameters); | ||
|
||
/// <summary> | ||
/// Adds an instance of the specified component and instructs it to render, waiting | ||
/// for the component hierarchy to complete asynchronous tasks such as loading. | ||
/// </summary> | ||
/// <param name="componentType">The component type. This must implement <see cref="IComponent"/>.</param> | ||
/// <param name="parameters">Parameters for the component.</param> | ||
/// <returns>A task that completes with <see cref="HtmlRootComponent"/> once the component hierarchy has completed any asynchronous tasks such as loading.</returns> | ||
public async Task<HtmlRootComponent> RenderComponentAsync( | ||
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type componentType, | ||
ParameterView parameters) | ||
{ | ||
var content = BeginRenderingComponent(componentType, parameters); | ||
await content.QuiescenceTask; | ||
return content; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using Microsoft.AspNetCore.Components.RenderTree; | ||
using Microsoft.AspNetCore.Components.Web.HtmlRendering; | ||
using Microsoft.AspNetCore.Components; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Logging; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Linq; | ||
using System.Runtime.ExceptionServices; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Components.Web; | ||
using Microsoft.AspNetCore.Components.HtmlRendering.Infrastructure; | ||
|
||
namespace BlazeKit.Static; | ||
|
||
/// <summary> | ||
/// A <see cref="Renderer"/> subclass that is intended for static HTML rendering. Application | ||
/// developers should not normally use this class directly. Instead, use | ||
/// <see cref="HtmlRenderer"/> for a more convenient API. | ||
/// </summary> | ||
#pragma warning disable BL0006 // Do not use RenderTree types | ||
public partial class BKStaticHtmlRenderer : StaticHtmlRenderer | ||
{ | ||
public BKStaticHtmlRenderer(IServiceProvider serviceProvider, ILoggerFactory loggerFactory) : base(serviceProvider,loggerFactory) | ||
{ | ||
|
||
} | ||
protected override IComponent ResolveComponentForRenderMode([DynamicallyAccessedMembers((DynamicallyAccessedMemberTypes)(-1))] Type componentType, int? parentComponentId, IComponentActivator componentActivator, IComponentRenderMode renderMode) | ||
=> renderMode switch | ||
{ | ||
InteractiveWebAssemblyRenderMode => componentActivator.CreateInstance(componentType), | ||
_ => throw new NotSupportedException($"Cannot create a component of type '{componentType}' because its render mode '{renderMode}' is not supported by BlazeKit rendering."), | ||
}; | ||
} | ||
#pragma warning restore BL0006 // Do not use RenderTree types |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.