Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 43060cb

Browse files
authoredSep 15, 2019
Merge pull request #6 from SQL-MisterMagoo/version-1
Version 1
2 parents a6de699 + 852e23a commit 43060cb

21 files changed

+130
-101
lines changed
 

‎Directory.Build.props

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project>
22
<PropertyGroup>
3-
<BlazorVersion>0.9.0-preview3-19154-02</BlazorVersion>
4-
<AspNetCoreVersion>3.0.0-preview3-19153-02</AspNetCoreVersion>
5-
<ReleaseVersion>0.1.0-beta-4</ReleaseVersion>
3+
<BlazorVersion>3.0.0-preview9.19424.4</BlazorVersion>
4+
<AspNetCoreVersion>3.0.0-preview9.19424.4</AspNetCoreVersion>
5+
<ReleaseVersion>1.0.0</ReleaseVersion>
66
</PropertyGroup>
77
</Project>

‎README.md

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33

44
This is a component library that provides Blazor-style static file embedding for Razor Components/Blazor.
55

6-
Chanegelog:
6+
Changelog:
7+
8+
#### Version 1.0.0
9+
- Update to Preview9
710

811
#### Version 0.1.0-beta-4
912
- Add BlazorFileProvider : Static File Provider that serves embedded files from Blazor Libraries
@@ -38,17 +41,34 @@ https://www.nuget.org/packages/BlazorEmbedLibrary/
3841

3942
#### Using the EmbeddedComponent to extract CSS/JS files
4043

41-
Add a *Using* and an *addTagHelper* to the __ViewImports file
44+
I recommend placing this in your MainLayout (or equivalent), but you can do it on individual pages if that suits your project.
4245

43-
```
46+
Add a *Using* statement to the page to make it easier to reference the component
47+
48+
*MainLayout.razor*
49+
``` C#
4450
@using BlazorEmbedLibrary
45-
@addTagHelper *, BlazorEmbedLibrary
4651
```
4752

48-
Then add the component to whichever page you want e.g. MainLayout, Index.cshtml - wherever makes sense for your project/needs.
53+
...add the component :
4954

55+
``` HTML
56+
<EmbeddedContent BaseType="@(typeof(Component1))" />
5057
```
51-
<EmbeddedContent BaseType="@(typeof(Component1))" />
58+
``` C#
59+
@code
60+
{
61+
bool hasConnected = false;
62+
protected override void OnAfterRender(bool firstRender)
63+
{
64+
base.OnAfterRender(firstRender);
65+
if (firstRender)
66+
{
67+
StateHasChanged();
68+
hasConnected = true;
69+
}
70+
}
71+
}
5272
```
5373

5474
Note, by default the EmbeddedContent component has Debug turned off - if you enable it by setting Debug=true, it outputs the list of embedded resources.
@@ -62,7 +82,7 @@ From version 0.1.0-beta-3 onwards, you can now handle multiple component librari
6282
```
6383
<EmbeddedContent Assemblies="@Assemblies" />
6484
65-
@functions
85+
@code
6686
{
6787
List<System.Reflection.Assembly> Assemblies = new List<System.Reflection.Assembly>()
6888
{
@@ -82,7 +102,7 @@ This example will load content from Blazored.Toast and Component1, but will bloc
82102
```
83103
<EmbeddedContent Assemblies="@Assemblies" BlockCssFiles="@BlockCss" />
84104
85-
@functions
105+
@code
86106
{
87107
List<string> BlockCss = new List<string>()
88108
{
Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
<Project Sdk="Microsoft.NET.Sdk.Web">
1+
<Project Sdk="Microsoft.NET.Sdk.Razor">
22

33
<PropertyGroup>
44
<TargetFramework>netstandard2.0</TargetFramework>
5-
<OutputType>Library</OutputType>
65
<IsPackable>true</IsPackable>
76
<BlazorLinkOnBuild>false</BlazorLinkOnBuild>
87
<LangVersion>latest</LangVersion>
8+
<RazorLangVersion>3.0</RazorLangVersion>
9+
<AddRazorSupportForMvc>true</AddRazorSupportForMvc>
10+
<EnableDefaultContentItems>false</EnableDefaultContentItems>
911
</PropertyGroup>
1012

1113
<ItemGroup>
@@ -16,10 +18,15 @@
1618
</ItemGroup>
1719

1820
<ItemGroup>
19-
<PackageReference Include="Microsoft.AspNetCore.Blazor" Version="$(BlazorVersion)" />
20-
<PackageReference Include="Microsoft.AspNetCore.Blazor.Build" Version="$(BlazorVersion)" PrivateAssets="all" />
21+
<None Remove="Component1.razor" />
22+
</ItemGroup>
2123

22-
<DotNetCliToolReference Include="Microsoft.AspNetCore.Blazor.Cli" Version="$(BlazorVersion)" />
24+
<ItemGroup>
25+
<Content Include="Component1.razor" />
26+
</ItemGroup>
27+
28+
<ItemGroup>
29+
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="3.0.0-preview9.19424.4" />
2330
</ItemGroup>
2431

2532
</Project>

‎samples/BlazorComponentSample/Component1.cshtml renamed to ‎samples/BlazorComponentSample/Component1.razor

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1-
@using Microsoft.AspNetCore.Components
2-
@inherits ComponentBase
1+
@using Microsoft.AspNetCore.Components.Web
32
@using Microsoft.JSInterop
3+
@inherits ComponentBase
44
@inject IJSRuntime jSRuntime
5+
56
<div class="my-component">
67
This Blazor component is defined in the <strong>BlazorComponentSample</strong> package.
78
</div>
89

9-
<button onclick="@OnClick">Click Me!</button>
10+
<button @onclick="()=>OnClick()">Click Me!</button>
11+
1012

11-
@functions
13+
@code
1214
{
13-
Task OnClick(UIMouseEventArgs args)
15+
ValueTask<string> OnClick()
1416
{
1517
return ExampleJsInterop.Prompt(jSRuntime,"you clicked me");
1618
}

‎samples/BlazorComponentSample/ExampleJsInterop.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace BlazorComponentSample
66
{
77
public class ExampleJsInterop
88
{
9-
public static Task<string> Prompt(IJSRuntime jSRuntime, string message)
9+
public static ValueTask<string> Prompt(IJSRuntime jSRuntime, string message)
1010
{
1111
// Implemented in exampleJsInterop.js
1212
return jSRuntime.InvokeAsync<string>(

‎samples/BlazorEmbedContent/App.cshtml

Lines changed: 0 additions & 5 deletions
This file was deleted.

‎samples/BlazorEmbedContent/App.razor

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<Router AppAssembly="@typeof(Program).Assembly">
2+
<Found Context="routeData">
3+
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
4+
</Found>
5+
<NotFound>
6+
<LayoutView Layout="@typeof(MainLayout)">
7+
<p>Sorry, there's nothing at this address.</p>
8+
</LayoutView>
9+
</NotFound>
10+
</Router>

‎samples/BlazorEmbedContent/BlazorEmbedContent.csproj

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22

33
<PropertyGroup>
44
<TargetFramework>netstandard2.0</TargetFramework>
5-
<RunCommand>dotnet</RunCommand>
6-
<RunArguments>blazor serve</RunArguments>
5+
<OutputType>Exe</OutputType>
76
<LangVersion>7.3</LangVersion>
7+
<RazorLangVersion>3.0</RazorLangVersion>
8+
<BlazorLinkOnBuild>false</BlazorLinkOnBuild>
89
</PropertyGroup>
910

1011
<ItemGroup>
11-
<PackageReference Include="Blazored.Toast" Version="1.0.3" />
12-
<PackageReference Include="Microsoft.AspNetCore.Blazor" Version="$(BlazorVersion)" />
13-
<PackageReference Include="Microsoft.AspNetCore.Blazor.Build" Version="$(BlazorVersion)" PrivateAssets="all" />
14-
15-
<DotNetCliToolReference Include="Microsoft.AspNetCore.Blazor.Cli" Version="$(BlazorVersion)" />
12+
<PackageReference Include="Microsoft.AspNetCore.Blazor" Version="3.0.0-preview9.19424.4" />
13+
<PackageReference Include="Microsoft.AspNetCore.Blazor.Build" Version="3.0.0-preview9.19424.4" PrivateAssets="all" />
14+
<PackageReference Include="Microsoft.AspNetCore.Blazor.DevServer" Version="3.0.0-preview9.19424.4" PrivateAssets="all" />
15+
<PackageReference Include="Microsoft.AspNetCore.Blazor.HttpClient" Version="3.0.0-preview9.19424.4" />
1616
</ItemGroup>
1717

1818
<ItemGroup>

‎samples/BlazorEmbedContent/Pages/Counter.cshtml renamed to ‎samples/BlazorEmbedContent/Pages/Counter.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<p>Current count: @currentCount</p>
66

7-
<button class="btn btn-primary" onclick="@IncrementCount">Click me</button>
7+
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
88

99
@functions {
1010
int currentCount = 0;

‎samples/BlazorEmbedContent/Pages/FetchData.cshtml renamed to ‎samples/BlazorEmbedContent/Pages/FetchData.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ else
3737
@functions {
3838
WeatherForecast[] forecasts;
3939

40-
protected override async Task OnInitAsync()
40+
protected override async Task OnInitializedAsync()
4141
{
4242
forecasts = await Http.GetJsonAsync<WeatherForecast[]>("sample-data/weather.json");
4343
}

‎samples/BlazorEmbedContent/Pages/Index.cshtml

Lines changed: 0 additions & 21 deletions
This file was deleted.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
@page "/"
2+
3+
<h1>Hello, world!</h1>
4+
5+
Welcome to your new app.
6+
7+
<SurveyPrompt Title="How is Blazor working for you?" />
8+
9+
<BlazorComponentSample.Component1 />
10+
11+
@*@inject IToastService toastService*@
12+
13+
<h1>Toast Demo</h1>
14+
15+
To show a toast just click one of the buttons below.
16+
17+
@*<button class="btn btn-info" @onclick="@(() => toastService.ShowToast(ToastLevel.Info, "I'm an INFO message"))">Info Toast</button>
18+
<button class="btn btn-success" @onclick="@(() => toastService.ShowToast(ToastLevel.Success, "I'm a SUCCESS message with a custom title", "Congratulations!"))">Success Toast</button>
19+
<button class="btn btn-warning" @onclick="@(() => toastService.ShowToast(ToastLevel.Warning, "I'm a WARNING message"))">Warning Toast</button>
20+
<button class="btn btn-danger" @onclick="@(() => toastService.ShowToast(ToastLevel.Error, "I'm an ERROR message"))">Error Toast</button>*@
21+

‎samples/BlazorEmbedContent/Shared/MainLayout.cshtml renamed to ‎samples/BlazorEmbedContent/Shared/MainLayout.razor

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,37 +12,38 @@
1212
@Body
1313
@**@
1414
<hr />
15-
<button class="btn btn-dark" onclick="@SwitchEmbedding">Switch Embedding Test</button>
15+
<button @ ></button>
16+
<button class="btn btn-dark" @onclick="@(()=>SwitchEmbedding())">Switch Embedding Test</button>
1617
@if (EmbedSwitch)
1718
{
1819
<div>@(new MarkupString("<EmbeddedContent Assemblies=\"@Assemblies\" Debug=\"true\" BlockCssFiles=\"@BlockCss\" />").Value)</div>
1920
<EmbeddedContent Assemblies="@Assemblies" Debug="true" BlockCssFiles="@BlockCss" />
2021
}
2122
else
2223
{
23-
<div>@(new MarkupString("<EmbeddedContent BaseType=\"@(typeof(Blazored.Toast.BlazoredToasts))\" Debug=\"true\" BlockCssFiles=\"@BlockCss\" />").Value)</div>
24-
<EmbeddedContent BaseType="@(typeof(Blazored.Toast.BlazoredToasts))" Debug="true" BlockCssFiles="@BlockCss" />
24+
@*<div>@(new MarkupString("<EmbeddedContent BaseType=\"@(typeof(Blazored.Toast.BlazoredToasts))\" Debug=\"true\" BlockCssFiles=\"@BlockCss\" />").Value)</div>
25+
<EmbeddedContent BaseType="@(typeof(Blazored.Toast.BlazoredToasts))" Debug="true" BlockCssFiles="@BlockCss" />*@
2526
<div>@(new MarkupString("<EmbeddedContent BaseType=\"@(typeof(Component1))\" Debug=\"true\" />").Value)</div>
26-
<EmbeddedContent BaseType="@(typeof(Component1))" Debug="true" />
27+
<EmbeddedContent BaseType="@(typeof(Component1))" Debug="true" />
2728
}
28-
<BlazoredToasts />
29+
@*<BlazoredToasts />*@
2930
</div>
3031
</div>
3132

3233

33-
@functions
34+
@code
3435
{
3536
bool EmbedSwitch;
36-
List<System.Reflection.Assembly> Assemblies = new List<System.Reflection.Assembly>()
37+
List<System.Reflection.Assembly> Assemblies = new List<System.Reflection.Assembly>()
3738
{
3839
typeof(BlazorComponentSample.Component1).Assembly,
39-
typeof(Blazored.Toast.BlazoredToasts).Assembly
40+
//typeof(Blazored.Toast.BlazoredToasts).Assembly
4041
};
41-
List<string> BlockCss = new List<string>()
42+
List<string> BlockCss = new List<string>()
4243
{
4344
"BlazorComponentSample,styles.css"
4445
};
45-
void SwitchEmbedding(UIMouseEventArgs args)
46+
void SwitchEmbedding()
4647
{
4748
EmbedSwitch = !EmbedSwitch;
4849
}

‎samples/BlazorEmbedContent/Shared/NavMenu.cshtml renamed to ‎samples/BlazorEmbedContent/Shared/NavMenu.razor

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
<div class="top-row pl-4 navbar navbar-dark">
1+
2+
<div class="top-row pl-4 navbar navbar-dark">
23
<a class="navbar-brand" href="">BlazorEmbedContent</a>
3-
<button class="navbar-toggler" onclick="@ToggleNavMenu">
4+
<button class="navbar-toggler" @onclick="ToggleNavMenu">
45
<span class="navbar-toggler-icon"></span>
56
</button>
67
</div>
78

8-
<div class="@NavMenuCssClass" onclick="@ToggleNavMenu">
9+
<div class="@NavMenuCssClass" @onclick="ToggleNavMenu">
910
<ul class="nav flex-column">
1011
<li class="nav-item px-3">
1112
<NavLink class="nav-link" href="" Match="NavLinkMatch.All">
@@ -25,7 +26,7 @@
2526
</ul>
2627
</div>
2728

28-
@functions {
29+
@code {
2930
bool collapseNavMenu = true;
3031

3132
string NavMenuCssClass => collapseNavMenu ? "collapse" : null;

‎samples/BlazorEmbedContent/Shared/SurveyPrompt.cshtml renamed to ‎samples/BlazorEmbedContent/Shared/SurveyPrompt.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@
1111

1212
@functions {
1313
// Demonstrates how a parent component can supply parameters
14-
[Parameter] string Title { get; set; }
14+
[Parameter] public string Title { get; set; }
1515
}

‎samples/BlazorEmbedContent/Startup.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Blazored.Toast.Services;
1+
//using Blazored.Toast.Services;
22
using Microsoft.AspNetCore.Components.Builder;
33
using Microsoft.Extensions.DependencyInjection;
44

@@ -8,7 +8,7 @@ public class Startup
88
{
99
public void ConfigureServices(IServiceCollection services)
1010
{
11-
services.AddScoped<IToastService, ToastService>();
11+
//services.AddScoped<IToastService, ToastService>();
1212
}
1313

1414
public void Configure(IComponentsApplicationBuilder app)
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
@using System.Net.Http
2-
@using Microsoft.AspNetCore.Components.Layouts
2+
@using Microsoft.AspNetCore.Components.Forms
33
@using Microsoft.AspNetCore.Components.Routing
4+
@using Microsoft.AspNetCore.Components.Web
45
@using Microsoft.JSInterop
56
@using BlazorEmbedContent
67
@using BlazorEmbedContent.Shared
78
@using BlazorComponentSample
89
@using BlazorEmbedLibrary
9-
@using Blazored.Toast.Services
10-
@addTagHelper *, BlazorComponentSample
11-
@addTagHelper *, BlazorEmbedLibrary
12-
@addTagHelper *, Blazored.Toast
10+
@*@using Blazored.Toast.Services*@
11+

‎samples/BlazorEmbedContent/wwwroot/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111
<body>
1212
<app>Loading...</app>
1313

14-
<script src="_framework/components.webassembly.js"></script>
14+
<script src="_framework/blazor.webassembly.js"></script>
1515
</body>
1616
</html>

‎src/BlazorEmbedLibrary/BlazorEmbedLibrary.csproj

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,27 @@
1-
<Project Sdk="Microsoft.NET.Sdk.Web">
1+
<Project Sdk="Microsoft.NET.Sdk.Razor">
22

33
<PropertyGroup>
44
<TargetFramework>netstandard2.0</TargetFramework>
5-
<OutputType>Library</OutputType>
65
<IsPackable>true</IsPackable>
7-
<RestoreAdditionalProjectSources>
8-
https://dotnet.myget.org/f/blazor-dev/api/v3/index.json;
9-
</RestoreAdditionalProjectSources>
106
<LangVersion>latest</LangVersion>
11-
<BlazorLinkOnBuild>false</BlazorLinkOnBuild>
7+
<BlazorLinkOnBuild>true</BlazorLinkOnBuild>
128
<Authors>Mister Magoo</Authors>
139
<Company>MM</Company>
1410
<Description>A Blazor Component that brings Blazor-style static content to Razor Components</Description>
1511
<Copyright>2019 SQL-MisterMagoo</Copyright>
1612
<PackageProjectUrl>https://github.com/SQL-MisterMagoo/BlazorEmbedLibrary</PackageProjectUrl>
1713
<RepositoryUrl>https://github.com/SQL-MisterMagoo/BlazorEmbedLibrary</RepositoryUrl>
18-
<PackageTags>Razor Components,Embed,Content,Component,css,javascript</PackageTags>
14+
<PackageTags>Blazor,Razor Components,Embed,Content,Component,css,javascript</PackageTags>
1915
<Version>$(ReleaseVersion)</Version>
20-
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
16+
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
2117
<PackageLicenseFile>LICENSE</PackageLicenseFile>
2218
<PackageLicenseExpression></PackageLicenseExpression>
2319
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
2420
</PropertyGroup>
2521

2622
<ItemGroup>
27-
<PackageReference Include="Microsoft.AspNetCore.Blazor" Version="$(BlazorVersion)" />
28-
<PackageReference Include="Microsoft.AspNetCore.Blazor.Build" Version="$(BlazorVersion)" PrivateAssets="all" />
29-
<PackageReference Include="Microsoft.Extensions.FileProviders.Abstractions" Version="2.2.0" />
30-
31-
<DotNetCliToolReference Include="Microsoft.AspNetCore.Blazor.Cli" Version="$(BlazorVersion)" />
23+
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="$(BlazorVersion)" />
24+
<PackageReference Include="Microsoft.Extensions.FileProviders.Abstractions" Version="3.0.0-preview9.19423.4" />
3225
</ItemGroup>
3326

3427
<ItemGroup>

‎src/BlazorEmbedLibrary/EmbeddedContent.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Microsoft.AspNetCore.Components;
2+
using Microsoft.AspNetCore.Components.Rendering;
23
using Microsoft.AspNetCore.Components.RenderTree;
34
using Microsoft.JSInterop;
45
using System;
@@ -15,15 +16,15 @@ public class EmbeddedContent : ComponentBase
1516
/// <summary>
1617
/// Displays a list of the embedded files for each assembly and extra console logging.
1718
/// </summary>
18-
[Parameter] protected bool Debug { get; set; } = false;
19+
[Parameter] public bool Debug { get; set; } = false;
1920
/// <summary>
2021
/// Easy way to enable one Assembly by passing a contained type e.g. BaseType=@(typeof(Mycomponent))
2122
/// </summary>
22-
[Parameter] protected Type BaseType { get; set; }
23+
[Parameter] public Type BaseType { get; set; }
2324
/// <summary>
2425
/// Allows multiple Assemblies to be passed as a list e.g. Assemblies=@ListOfAssemblies (where ListOfAssemblies is List<Assembly>
2526
/// </summary>
26-
[Parameter] protected List<Assembly> Assemblies { get; set; }
27+
[Parameter] public List<Assembly> Assemblies { get; set; }
2728
/// <summary>
2829
/// Allows blocking/removal of any CSS file in this list e.g. BlockCssFiles=@BlockCss (where Css is List<string>)
2930
///
@@ -32,22 +33,22 @@ public class EmbeddedContent : ComponentBase
3233
/// "Blazored.Toast,styles.css" will only block styles.css from the Blazored.Toast assembly
3334
/// "styles.css" will block styles.css from ANY assembly
3435
/// </summary>
35-
[Parameter] protected List<string> BlockCssFiles { get; set; }
36+
[Parameter] public List<string> BlockCssFiles { get; set; }
3637
private bool PreRender { get; set; } = true;
3738
private bool HasRun;
38-
protected override void OnInit()
39+
protected override void OnInitialized()
3940
{
40-
base.OnInit();
41+
base.OnInitialized();
4142
Assemblies = Assemblies ?? new List<Assembly>();
4243
BlockCssFiles = BlockCssFiles ?? new List<string>();
4344
if (!(BaseType is null) && !Assemblies.Contains(BaseType.Assembly))
4445
{
4546
Assemblies.Add(BaseType.Assembly);
4647
}
4748
}
48-
protected override async Task OnAfterRenderAsync()
49+
protected override async Task OnAfterRenderAsync(bool FirstRender)
4950
{
50-
await base.OnAfterRenderAsync();
51+
await base.OnAfterRenderAsync(FirstRender);
5152
if (!PreRender && !HasRun)
5253
{
5354
HasRun = true;

0 commit comments

Comments
 (0)
Please sign in to comment.