Skip to content

Commit

Permalink
1.0.0-preview9-01
Browse files Browse the repository at this point in the history
  • Loading branch information
chanan committed Sep 5, 2019
1 parent 328aa33 commit de61603
Show file tree
Hide file tree
Showing 68 changed files with 499 additions and 246 deletions.
Binary file modified docs/_framework/_bin/BlazorPrettyCode.dll
Binary file not shown.
Binary file modified docs/_framework/_bin/BlazorStyled.dll
Binary file not shown.
Binary file modified docs/_framework/_bin/BlazorStyled.pdb
Binary file not shown.
Binary file modified docs/_framework/_bin/BlazorTypography.dll
Binary file not shown.
Binary file modified docs/_framework/_bin/ClientSideSample.dll
Binary file not shown.
Binary file modified docs/_framework/_bin/ClientSideSample.pdb
Binary file not shown.
Binary file modified docs/_framework/_bin/Microsoft.AspNetCore.Authorization.dll
Binary file not shown.
Binary file modified docs/_framework/_bin/Microsoft.AspNetCore.Blazor.HttpClient.dll
Binary file not shown.
Binary file modified docs/_framework/_bin/Microsoft.AspNetCore.Blazor.dll
Binary file not shown.
Binary file not shown.
Binary file modified docs/_framework/_bin/Microsoft.AspNetCore.Components.Web.dll
Binary file not shown.
Binary file modified docs/_framework/_bin/Microsoft.AspNetCore.Components.dll
Binary file not shown.
Binary file modified docs/_framework/_bin/Microsoft.AspNetCore.Metadata.dll
Binary file not shown.
Binary file modified docs/_framework/_bin/Microsoft.Bcl.AsyncInterfaces.dll
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified docs/_framework/_bin/Microsoft.Extensions.Options.dll
Binary file not shown.
Binary file modified docs/_framework/_bin/Microsoft.Extensions.Primitives.dll
Binary file not shown.
Binary file modified docs/_framework/_bin/Microsoft.JSInterop.dll
Binary file not shown.
Binary file modified docs/_framework/_bin/Mono.Security.dll
Binary file not shown.
Binary file modified docs/_framework/_bin/Mono.WebAssembly.Interop.dll
Binary file not shown.
Binary file modified docs/_framework/_bin/SampleCore.dll
Binary file not shown.
Binary file modified docs/_framework/_bin/SampleCore.pdb
Binary file not shown.
Binary file modified docs/_framework/_bin/System.Core.dll
Binary file not shown.
Binary file modified docs/_framework/_bin/System.Net.Http.dll
Binary file not shown.
Binary file modified docs/_framework/_bin/System.Runtime.CompilerServices.Unsafe.dll
Binary file not shown.
Binary file modified docs/_framework/_bin/System.Text.Encodings.Web.dll
Binary file not shown.
Binary file modified docs/_framework/_bin/System.Text.Json.dll
Binary file not shown.
Binary file modified docs/_framework/_bin/System.dll
Binary file not shown.
Binary file modified docs/_framework/_bin/mscorlib.dll
Binary file not shown.
2 changes: 1 addition & 1 deletion docs/_framework/blazor.boot.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"main":"ClientSideSample.dll","entryPoint":"Sample.Program::Main","assemblyReferences":["BlazorPrettyCode.dll","BlazorStyled.dll","BlazorTypography.dll","CSHTMLTokenizer.dll","Microsoft.AspNetCore.Authorization.dll","Microsoft.AspNetCore.Blazor.dll","Microsoft.AspNetCore.Blazor.HttpClient.dll","Microsoft.AspNetCore.Components.dll","Microsoft.AspNetCore.Components.Web.dll","Microsoft.AspNetCore.Metadata.dll","Microsoft.Bcl.AsyncInterfaces.dll","Microsoft.Extensions.DependencyInjection.Abstractions.dll","Microsoft.Extensions.DependencyInjection.dll","Microsoft.Extensions.Logging.Abstractions.dll","Microsoft.Extensions.Options.dll","Microsoft.Extensions.Primitives.dll","Microsoft.JSInterop.dll","Mono.Security.dll","Mono.WebAssembly.Interop.dll","mscorlib.dll","Polished.net.dll","SampleCore.dll","Stateless.dll","System.Buffers.dll","System.ComponentModel.Annotations.dll","System.Core.dll","System.dll","System.Memory.dll","System.Net.Http.dll","System.Numerics.Vectors.dll","System.Runtime.CompilerServices.Unsafe.dll","System.Text.Encodings.Web.dll","System.Text.Json.dll","System.Threading.Tasks.Extensions.dll","BlazorStyled.pdb","ClientSideSample.pdb","SampleCore.pdb"],"cssReferences":[],"jsReferences":[],"linkerEnabled":true}
{"main":"ClientSideSample.dll","entryPoint":"Sample.Program::Main","assemblyReferences":["BlazorPrettyCode.dll","BlazorStyled.dll","BlazorTypography.dll","CSHTMLTokenizer.dll","Microsoft.AspNetCore.Authorization.dll","Microsoft.AspNetCore.Blazor.dll","Microsoft.AspNetCore.Blazor.HttpClient.dll","Microsoft.AspNetCore.Components.dll","Microsoft.AspNetCore.Components.Forms.dll","Microsoft.AspNetCore.Components.Web.dll","Microsoft.AspNetCore.Metadata.dll","Microsoft.Bcl.AsyncInterfaces.dll","Microsoft.Extensions.DependencyInjection.Abstractions.dll","Microsoft.Extensions.DependencyInjection.dll","Microsoft.Extensions.Logging.Abstractions.dll","Microsoft.Extensions.Options.dll","Microsoft.Extensions.Primitives.dll","Microsoft.JSInterop.dll","Mono.Security.dll","Mono.WebAssembly.Interop.dll","mscorlib.dll","Polished.net.dll","SampleCore.dll","Stateless.dll","System.Buffers.dll","System.ComponentModel.Annotations.dll","System.Core.dll","System.dll","System.Memory.dll","System.Net.Http.dll","System.Numerics.Vectors.dll","System.Runtime.CompilerServices.Unsafe.dll","System.Text.Encodings.Web.dll","System.Text.Json.dll","System.Threading.Tasks.Extensions.dll","BlazorStyled.pdb","ClientSideSample.pdb","SampleCore.pdb"],"cssReferences":[],"jsReferences":[],"linkerEnabled":true}
6 changes: 3 additions & 3 deletions docs/_framework/blazor.server.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/_framework/blazor.webassembly.js

Large diffs are not rendered by default.

325 changes: 159 additions & 166 deletions docs/_framework/wasm/mono.js

Large diffs are not rendered by default.

Binary file modified docs/_framework/wasm/mono.wasm
Binary file not shown.
4 changes: 2 additions & 2 deletions src/BlazorStyled.Tests/Hashcodes.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using BlazorStyled.Internal;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace BlazorStyled.Tests
{
Expand All @@ -12,7 +12,7 @@ public void Decleration()
RuleSet ruleSet = new RuleSet();
ruleSet.AddDeclaration(new Stylesheets.Declaration { Property = "color", Value = "red" });
Hash hash = new Hash();
var hashcode = hash.GetHashCode(ruleSet);
string hashcode = hash.GetHashCode(ruleSet);
Assert.AreEqual("dqma-qdh", hashcode);
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/BlazorStyled/BlazorStyled.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<LangVersion>8.0</LangVersion>
<AddRazorSupportForMvc>true</AddRazorSupportForMvc>
<PackageId>BlazorStyled</PackageId>
<Version>1.0.0-preview8-05</Version>
<Version>1.0.0-preview9-01</Version>
<Authors>Chanan Braunstein</Authors>
<Title>BlazorStyled</Title>
<Description>CSS in Blazor Components</Description>
Expand All @@ -16,8 +16,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Blazor" Version="3.0.0-preview8.19405.7" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="3.0.0-preview8.19405.7" />
<PackageReference Include="Microsoft.AspNetCore.Blazor" Version="3.0.0-preview9.19424.4" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="3.0.0-preview9.19424.4" />
</ItemGroup>

</Project>
23 changes: 23 additions & 0 deletions src/BlazorStyled/Internal/ComponentRenderedText.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System.Collections.Generic;

namespace BlazorStyled.Internal
{
internal readonly struct ComponentRenderedText
{
internal ComponentRenderedText(int componentId, IEnumerable<string> tokens)
{
ComponentId = componentId;
Tokens = tokens;
}

/// <summary>
/// Gets the id associated with the component.
/// </summary>
public int ComponentId { get; }

/// <summary>
/// Gets the sequence of tokens that when concatenated represent the html for the rendered component.
/// </summary>
public IEnumerable<string> Tokens { get; }
}
}
234 changes: 234 additions & 0 deletions src/BlazorStyled/Internal/HtmlRenderer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,234 @@
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.RenderTree;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.ExceptionServices;
using System.Threading.Tasks;

namespace BlazorStyled.Internal
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "BL0006:Do not use RenderTree types", Justification = "Preview version")]
internal class HtmlRenderer : Renderer
{
private static readonly HashSet<string> SelfClosingElements = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
{
"area", "base", "br", "col", "embed", "hr", "img", "input", "link", "meta", "param", "source", "track", "wbr"
};

private readonly Func<string, string> _htmlEncoder;

/// <summary>
/// Initializes a new instance of <see cref="HtmlRenderer"/>.
/// </summary>
/// <param name="serviceProvider">The <see cref="IServiceProvider"/> to use to instantiate components.</param>
/// <param name="loggerFactory">The <see cref="ILoggerFactory"/>.</param>
/// <param name="htmlEncoder">A <see cref="Func{T, TResult}"/> that will HTML encode the given string.</param>
public HtmlRenderer(IServiceProvider serviceProvider, ILoggerFactory loggerFactory, Func<string, string> htmlEncoder)
: base(serviceProvider, loggerFactory)
{
_htmlEncoder = htmlEncoder;
}

public override Dispatcher Dispatcher { get; } = Dispatcher.CreateDefault();

/// <inheritdoc />
protected override Task UpdateDisplayAsync(in RenderBatch renderBatch)
{
return Task.CompletedTask;
}

/// <summary>
/// Renders a component into a sequence of <see cref="string"/> fragments that represent the textual representation
/// of the HTML produced by the component.
/// </summary>
/// <param name="componentType">The type of the <see cref="IComponent"/>.</param>
/// <param name="initialParameters">A <see cref="ParameterView"/> with the initial parameters to render the component.</param>
/// <returns>A <see cref="Task"/> that on completion returns a sequence of <see cref="string"/> fragments that represent the HTML text of the component.</returns>
public async Task<ComponentRenderedText> RenderComponentAsync(Type componentType, ParameterView initialParameters)
{
(int componentId, ArrayRange<RenderTreeFrame> frames) = await CreateInitialRenderAsync(componentType, initialParameters);

List<string> result = new List<string>();
int newPosition = RenderFrames(result, frames, 0, frames.Count);
Debug.Assert(newPosition == frames.Count);
return new ComponentRenderedText(componentId, result);
}

/// <summary>
/// Renders a component into a sequence of <see cref="string"/> fragments that represent the textual representation
/// of the HTML produced by the component.
/// </summary>
/// <typeparam name="TComponent">The type of the <see cref="IComponent"/>.</typeparam>
/// <param name="initialParameters">A <see cref="ParameterView"/> with the initial parameters to render the component.</param>
/// <returns>A <see cref="Task"/> that on completion returns a sequence of <see cref="string"/> fragments that represent the HTML text of the component.</returns>
public Task<ComponentRenderedText> RenderComponentAsync<TComponent>(ParameterView initialParameters) where TComponent : IComponent
{
return RenderComponentAsync(typeof(TComponent), initialParameters);
}

/// <inheritdoc />
protected override void HandleException(Exception exception)
{
ExceptionDispatchInfo.Capture(exception).Throw();
}

private int RenderFrames(List<string> result, ArrayRange<RenderTreeFrame> frames, int position, int maxElements)
{
int nextPosition = position;
int endPosition = position + maxElements;
while (position < endPosition)
{
nextPosition = RenderCore(result, frames, position, maxElements);
if (position == nextPosition)
{
throw new InvalidOperationException("We didn't consume any input.");
}
position = nextPosition;
}

return nextPosition;
}

private int RenderCore(
List<string> result,
ArrayRange<RenderTreeFrame> frames,
int position,
int length)
{
ref RenderTreeFrame frame = ref frames.Array[position];
switch (frame.FrameType)
{
case RenderTreeFrameType.Element:
return RenderElement(result, frames, position);
case RenderTreeFrameType.Attribute:
return RenderAttributes(result, frames, position, 1);
case RenderTreeFrameType.Text:
result.Add(_htmlEncoder(frame.TextContent));
return ++position;
case RenderTreeFrameType.Markup:
result.Add(frame.MarkupContent);
return ++position;
case RenderTreeFrameType.Component:
return RenderChildComponent(result, frames, position);
case RenderTreeFrameType.Region:
return RenderFrames(result, frames, position + 1, frame.RegionSubtreeLength - 1);
case RenderTreeFrameType.ElementReferenceCapture:
case RenderTreeFrameType.ComponentReferenceCapture:
return ++position;
default:
throw new InvalidOperationException($"Invalid element frame type '{frame.FrameType}'.");
}
}

private int RenderChildComponent(
List<string> result,
ArrayRange<RenderTreeFrame> frames,
int position)
{
ref RenderTreeFrame frame = ref frames.Array[position];
ArrayRange<RenderTreeFrame> childFrames = GetCurrentRenderTreeFrames(frame.ComponentId);
RenderFrames(result, childFrames, 0, childFrames.Count);
return position + frame.ComponentSubtreeLength;
}

private int RenderElement(
List<string> result,
ArrayRange<RenderTreeFrame> frames,
int position)
{
ref RenderTreeFrame frame = ref frames.Array[position];
result.Add("<");
result.Add(frame.ElementName);
int afterAttributes = RenderAttributes(result, frames, position + 1, frame.ElementSubtreeLength - 1);
int remainingElements = frame.ElementSubtreeLength + position - afterAttributes;
if (remainingElements > 0)
{
result.Add(">");
int afterElement = RenderChildren(result, frames, afterAttributes, remainingElements);
result.Add("</");
result.Add(frame.ElementName);
result.Add(">");
Debug.Assert(afterElement == position + frame.ElementSubtreeLength);
return afterElement;
}
else
{
if (SelfClosingElements.Contains(frame.ElementName))
{
result.Add(" />");
}
else
{
result.Add(">");
result.Add("</");
result.Add(frame.ElementName);
result.Add(">");
}
Debug.Assert(afterAttributes == position + frame.ElementSubtreeLength);
return afterAttributes;
}
}

private int RenderChildren(List<string> result, ArrayRange<RenderTreeFrame> frames, int position, int maxElements)
{
if (maxElements == 0)
{
return position;
}

return RenderFrames(result, frames, position, maxElements);
}

private int RenderAttributes(
List<string> result,
ArrayRange<RenderTreeFrame> frames, int position, int maxElements)
{
if (maxElements == 0)
{
return position;
}

for (int i = 0; i < maxElements; i++)
{
int candidateIndex = position + i;
ref RenderTreeFrame frame = ref frames.Array[candidateIndex];
if (frame.FrameType != RenderTreeFrameType.Attribute)
{
return candidateIndex;
}

switch (frame.AttributeValue)
{
case bool flag when flag:
result.Add(" ");
result.Add(frame.AttributeName);
break;
case string value:
result.Add(" ");
result.Add(frame.AttributeName);
result.Add("=");
result.Add("\"");
result.Add(_htmlEncoder(value));
result.Add("\"");
break;
default:
break;
}
}

return position + maxElements;
}

private async Task<(int, ArrayRange<RenderTreeFrame>)> CreateInitialRenderAsync(Type componentType, ParameterView initialParameters)
{
IComponent component = InstantiateComponent(componentType);
int componentId = AssignRootComponentId(component);

await RenderRootComponentAsync(componentId, initialParameters);

return (componentId, GetCurrentRenderTreeFrames(componentId));
}
}
}
4 changes: 2 additions & 2 deletions src/BlazorStyled/Styled.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using BlazorStyled.Stylesheets;
using BlazorStyled.Internal;
using BlazorStyled.Stylesheets;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Rendering;
using Microsoft.AspNetCore.Components.RenderTree;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging.Abstractions;
using System;
Expand Down
4 changes: 2 additions & 2 deletions src/HostedSample/HostedSample.Server.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Blazor.Server" Version="3.0.0-preview8.19405.7" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.0.0-preview8.19405.7" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.Server" Version="3.0.0-preview9.19424.4" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.0.0-preview9.19424.4" />
</ItemGroup>

<ItemGroup>
Expand Down
8 changes: 4 additions & 4 deletions src/Sample/ClientSideSample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Blazor" Version="3.0.0-preview8.19405.7" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.Build" Version="3.0.0-preview8.19405.7" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.HttpClient" Version="3.0.0-preview8.19405.7" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.DevServer" Version="3.0.0-preview8.19405.7" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Blazor" Version="3.0.0-preview9.19424.4" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.Build" Version="3.0.0-preview9.19424.4" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.HttpClient" Version="3.0.0-preview9.19424.4" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.DevServer" Version="3.0.0-preview9.19424.4" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions src/Sample/_Imports.razor
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
@using System.Collections.Generic;
@using Microsoft.AspNetCore.Components.Forms
@using Microsoft.AspNetCore.Components.Routing
@using Microsoft.AspNetCore.Components.Web
@using Microsoft.JSInterop
@using Sample
11 changes: 8 additions & 3 deletions src/SampleCore/App.razor
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
<Router AppAssembly="typeof(App).Assembly">
<NotFoundContent>
<p>Sorry, there's nothing at this address.</p>
</NotFoundContent>
<Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
</Found>
<NotFound>
<LayoutView Layout="@typeof(MainLayout)">
<p>Sorry, there's nothing at this address.</p>
</LayoutView>
</NotFound>
</Router>
2 changes: 1 addition & 1 deletion src/SampleCore/Pages/ButtonExample.razor
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<PrettyCode CodeFile="_content/SampleCore/components2.html" />

@code {
private void onclick(UIMouseEventArgs e)
private void onclick(MouseEventArgs e)
{
Console.WriteLine("Onclick");
}
Expand Down
1 change: 0 additions & 1 deletion src/SampleCore/Pages/_Imports.razor

This file was deleted.

8 changes: 4 additions & 4 deletions src/SampleCore/SampleCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BlazorPrettyCode" Version="1.0.0-preview8-08" />
<PackageReference Include="BlazorTypography" Version="1.0.0-preview8-04" />
<PackageReference Include="Microsoft.AspNetCore.Components" Version="3.0.0-preview8.19405.7" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="3.0.0-preview8.19405.7" />
<PackageReference Include="BlazorPrettyCode" Version="1.0.0-preview9-01" />
<PackageReference Include="BlazorTypography" Version="1.0.0-preview9-01" />
<PackageReference Include="Microsoft.AspNetCore.Components" Version="3.0.0-preview9.19424.4" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="3.0.0-preview9.19424.4" />
<PackageReference Include="Polished" Version="1.0.0-preview-02" />
</ItemGroup>

Expand Down
Loading

0 comments on commit de61603

Please sign in to comment.