Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
erinnmclaughlin committed May 20, 2024
1 parent beb6d8d commit 2ebff16
Show file tree
Hide file tree
Showing 15 changed files with 48 additions and 175 deletions.
2 changes: 1 addition & 1 deletion HeadlessBlazor.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HeadlessBlazor.Dropdown", "
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Docs", "Docs", "{45E6AD2B-E550-4375-A452-63A8FE7787E4}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HeadlessBlazor.Core", "src\HeadlessBlazor.Core\HeadlessBlazor.Core.csproj", "{E3A1957A-9803-4B81-B1F0-EB66F8E7DE12}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HeadlessBlazor.Base", "src\HeadlessBlazor.Core\HeadlessBlazor.Base.csproj", "{E3A1957A-9803-4B81-B1F0-EB66F8E7DE12}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HeadlessBlazor.Docs.Client", "docs\HeadlessBlazor.Docs.Client\HeadlessBlazor.Docs.Client.csproj", "{802E5B41-3FE0-49D3-B6F6-B43F98DD294A}"
EndProject
Expand Down
38 changes: 0 additions & 38 deletions package-lock.json

This file was deleted.

18 changes: 0 additions & 18 deletions package.json

This file was deleted.

4 changes: 2 additions & 2 deletions src/HeadlessBlazor.Core/HBElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class HBElement : HBElementBase
[Parameter]
public RenderFragment? ChildContent { get; set; }

protected override void AddChildContent(RenderTreeBuilder builder, ref int sequence)
protected override void AddChildContent(ref int sequence, RenderTreeBuilder builder)
{
if (ChildContent != null)
builder.AddContent(sequence, ChildContent);
Expand All @@ -20,7 +20,7 @@ public class HBElement<T> : HBElementBase where T : HBElement<T>
[Parameter]
public RenderFragment<T>? ChildContent { get; set; }

protected override void AddChildContent(RenderTreeBuilder builder, ref int sequence)
protected override void AddChildContent(ref int sequence, RenderTreeBuilder builder)
{
if (ChildContent != null)
builder.AddContent(sequence, ChildContent, (T)this);
Expand Down
41 changes: 19 additions & 22 deletions src/HeadlessBlazor.Core/HBElementBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,56 +32,53 @@ protected sealed override void OnInitialized()
OnAfterInitialized();
}

protected void BuildRenderTree(RenderTreeBuilder builder, ref int sequenceNumber)
protected override void BuildRenderTree(RenderTreeBuilder builder)
{
var seq = 0;
BuildRenderTree(ref seq, builder);
}

protected void BuildRenderTree(ref int sequence, RenderTreeBuilder builder)
{
var createElement = !string.IsNullOrWhiteSpace(ElementName);

if (createElement)
{
builder.OpenElement(sequenceNumber++, ElementName);
builder.OpenElement(sequence++, ElementName);

foreach (var attr in UserAttributes)
{
if (attr.Value != null)
builder.AddAttribute(sequenceNumber, attr.Key, attr.Value);
builder.AddAttribute(sequence, attr.Key, attr.Value);
}

builder.AddAttribute(sequenceNumber, "data-hb-tag", GetType().Name);

AddEventHandlers(builder, ref sequenceNumber);
builder.AddEventStopPropagationAttribute(sequenceNumber, "onclick", OnClickStopPropagation);
builder.AddEventPreventDefaultAttribute(sequenceNumber, "onclick", OnClickPreventDefault);
AddEventHandlers(ref sequence, builder);
builder.AddEventStopPropagationAttribute(sequence, "onclick", OnClickStopPropagation);
builder.AddEventPreventDefaultAttribute(sequence, "onclick", OnClickPreventDefault);

AddElementReference(builder, ref sequenceNumber);
AddElementReference(ref sequence, builder);
}

AddBehaviors(builder, ref sequenceNumber);

AddChildContent(builder, ref sequenceNumber);
AddBehaviors(ref sequence, builder);
AddChildContent(ref sequence, builder);

if (createElement)
builder.CloseElement();
}

protected override void BuildRenderTree(RenderTreeBuilder builder)
{
var seq = 0;
BuildRenderTree(builder, ref seq);
}

protected virtual void AddChildContent(RenderTreeBuilder builder, ref int sequence)
protected virtual void AddChildContent(ref int sequence, RenderTreeBuilder builder)
{
}

protected virtual void AddBehaviors(RenderTreeBuilder builder, ref int sequenceNumber)
protected virtual void AddBehaviors(ref int sequence, RenderTreeBuilder builder)
{
}

protected virtual void AddElementReference(RenderTreeBuilder builder, ref int sequenceNumber)
protected virtual void AddElementReference(ref int sequence, RenderTreeBuilder builder)
{
}

protected virtual void AddEventHandlers(RenderTreeBuilder builder, ref int sequenceNumber)
protected virtual void AddEventHandlers(ref int sequence, RenderTreeBuilder builder)
{
}
}
3 changes: 0 additions & 3 deletions src/HeadlessBlazor.Core/Utilities/ClientRect.cs

This file was deleted.

34 changes: 0 additions & 34 deletions src/HeadlessBlazor.Core/Utilities/DOM.cs

This file was deleted.

3 changes: 0 additions & 3 deletions src/HeadlessBlazor.Core/Utilities/Dimensions.cs

This file was deleted.

37 changes: 0 additions & 37 deletions src/HeadlessBlazor.Core/wwwroot/utils.js

This file was deleted.

10 changes: 5 additions & 5 deletions src/HeadlessBlazor.Dropdown/HBDropdown.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ protected override void BuildRenderTree(RenderTreeBuilder builder)
builder.AddAttribute(seq++, "Value", this);
builder.AddAttribute(seq++, "ChildContent", (RenderFragment)((b) =>
{
BuildRenderTree(b, ref seq);
BuildRenderTree(ref seq, b);

if (IsOpen && CloseOnOutsideClick)
{
Expand All @@ -63,21 +63,21 @@ protected override void BuildRenderTree(RenderTreeBuilder builder)
builder.CloseComponent();
}

protected override void AddEventHandlers(RenderTreeBuilder builder, ref int sequenceNumber)
protected override void AddEventHandlers(ref int sequence, RenderTreeBuilder builder)
{
if (CloseOnEscape)
{
builder.AddAttribute(sequenceNumber++, "onkeydown", EventCallback.Factory.Create<KeyboardEventArgs>(this, async (args) =>
builder.AddAttribute(sequence++, "onkeydown", EventCallback.Factory.Create<KeyboardEventArgs>(this, async (args) =>
{
if (args.Key == "Escape")
await CloseAsync();
}));
}
}

protected override void AddElementReference(RenderTreeBuilder builder, ref int sequenceNumber)
protected override void AddElementReference(ref int sequence, RenderTreeBuilder builder)
{
builder.AddElementReferenceCapture(sequenceNumber++, async capturedRef =>
builder.AddElementReferenceCapture(sequence++, async capturedRef =>
{
ElementReference = capturedRef;
await InvokeAsync(StateHasChanged);
Expand Down
16 changes: 8 additions & 8 deletions src/HeadlessBlazor.Dropdown/HBDropdownMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,22 @@ public class HBDropdownMenu : HBElement
[Parameter]
public HBFloatSide? Side { get; set; }

protected override void AddBehaviors(RenderTreeBuilder builder, ref int sequenceNumber)
protected override void AddBehaviors(ref int sequence, RenderTreeBuilder builder)
{
if (AutoPosition)
{
builder.OpenComponent<HBFloatBehavior>(sequenceNumber++);
builder.AddAttribute(sequenceNumber++, nameof(HBFloatBehavior.Alignment), Alignment);
builder.AddAttribute(sequenceNumber++, nameof(HBFloatBehavior.Anchor), Dropdown.ElementReference);
builder.AddAttribute(sequenceNumber++, nameof(HBFloatBehavior.Content), ElementReference);
builder.AddAttribute(sequenceNumber++, nameof(HBFloatBehavior.Side), Side);
builder.OpenComponent<HBFloatBehavior>(sequence++);
builder.AddAttribute(sequence, nameof(HBFloatBehavior.Alignment), Alignment);
builder.AddAttribute(sequence, nameof(HBFloatBehavior.Anchor), Dropdown.ElementReference);
builder.AddAttribute(sequence, nameof(HBFloatBehavior.Content), ElementReference);
builder.AddAttribute(sequence, nameof(HBFloatBehavior.Side), Side);
builder.CloseComponent();
}
}

protected override void AddElementReference(RenderTreeBuilder builder, ref int sequenceNumber)
protected override void AddElementReference(ref int sequence, RenderTreeBuilder builder)
{
builder.AddElementReferenceCapture(sequenceNumber, async (elementRef) =>
builder.AddElementReferenceCapture(sequence, async (elementRef) =>
{
ElementReference = elementRef;
await InvokeAsync(StateHasChanged);
Expand Down
2 changes: 1 addition & 1 deletion src/HeadlessBlazor.Dropdown/HeadlessBlazor.Dropdown.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\HeadlessBlazor.Core\HeadlessBlazor.Core.csproj" />
<ProjectReference Include="..\HeadlessBlazor.Core\HeadlessBlazor.Base.csproj" />
<ProjectReference Include="..\HeadlessBlazor.FloatingElement\HeadlessBlazor.FloatingElement.csproj" />
<ProjectReference Include="..\HeadlessBlazor.OutsideClick\HeadlessBlazor.OutsideClick.csproj" />
</ItemGroup>
Expand Down
2 changes: 2 additions & 0 deletions src/HeadlessBlazor/HeadlessBlazor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@

<ItemGroup>
<ProjectReference Include="..\HeadlessBlazor.Dropdown\HeadlessBlazor.Dropdown.csproj" />
<ProjectReference Include="..\HeadlessBlazor.FloatingElement\HeadlessBlazor.FloatingElement.csproj" />
<ProjectReference Include="..\HeadlessBlazor.OutsideClick\HeadlessBlazor.OutsideClick.csproj" />
</ItemGroup>

</Project>
13 changes: 10 additions & 3 deletions src/HeadlessBlazor/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
using HeadlessBlazor.Utilities;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection;

namespace HeadlessBlazor;

/// <summary>
/// Extension methods for configuring HeadlessBlazor services.
/// </summary>
public static class ServiceCollectionExtensions
{
/// <summary>
/// Adds the required HeadlessBlazor services.
/// </summary>
/// <param name="services">The <see cref="IServiceCollection"/> to add the services to.</param>
/// <returns>A reference to this instance after the operation has completed.</returns>
public static IServiceCollection AddHeadlessBlazor(this IServiceCollection services)
{
services.AddTransient<DOM>();
// made ya look. there will be stuff here eventually
return services;
}
}

0 comments on commit 2ebff16

Please sign in to comment.