├── src ├── Sample │ └── BlazorServersideTest │ │ ├── Pages │ │ ├── Index.razor │ │ ├── Counter.razor │ │ ├── Error.razor │ │ ├── _Host.cshtml │ │ └── FetchData.razor │ │ ├── wwwroot │ │ ├── favicon.ico │ │ ├── css │ │ │ ├── open-iconic │ │ │ │ ├── font │ │ │ │ │ ├── fonts │ │ │ │ │ │ ├── open-iconic.eot │ │ │ │ │ │ ├── open-iconic.otf │ │ │ │ │ │ ├── open-iconic.ttf │ │ │ │ │ │ ├── open-iconic.woff │ │ │ │ │ │ └── open-iconic.svg │ │ │ │ │ └── css │ │ │ │ │ │ └── open-iconic-bootstrap.min.css │ │ │ │ ├── ICON-LICENSE │ │ │ │ ├── README.md │ │ │ │ └── FONT-LICENSE │ │ │ └── site.css │ │ └── preview.html │ │ ├── appsettings.json │ │ ├── appsettings.Development.json │ │ ├── BlazorServersideTest.csproj │ │ ├── Shared │ │ ├── MainLayout.razor │ │ └── NavMenu.razor │ │ ├── Data │ │ ├── WeatherForecast.cs │ │ └── WeatherForecastService.cs │ │ ├── _Imports.razor │ │ ├── App.razor │ │ ├── Program.cs │ │ ├── BlazorServersideTest.sln │ │ └── Startup.cs └── RazorComponentsPreview │ ├── Htmlizer │ ├── ComponentRenderedText.cs │ ├── HttpNavigationManager.cs │ ├── UnsupportedJavaScriptRuntime.cs │ ├── RenderedComponentInstance.cs │ ├── TestHost.cs │ ├── TestRenderer.cs │ ├── ContainerComponent.cs │ └── Htmlizer.cs │ ├── RazorComponentsPreview.csproj │ └── Razor │ ├── NotFoundProjectItem.cs │ ├── TestRazorProjectItem.cs │ ├── DefaultRazorProjectItem.cs │ ├── TestRazorProjectFileSystem.cs │ ├── RazorRuntimeCompilationExtensions.cs │ ├── DefaultRazorProjectFileSystem.cs │ ├── Generator.cs │ └── RuntimeComponentsGenerator.cs ├── README.md └── .gitignore /src/Sample/BlazorServersideTest/Pages/Index.razor: -------------------------------------------------------------------------------- 1 | @page "/" 2 | 3 |

Hello, world!

4 | 5 | Welcome to your new app. 6 | 7 | -------------------------------------------------------------------------------- /src/Sample/BlazorServersideTest/wwwroot/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martasp/BlazorLiveReload/HEAD/src/Sample/BlazorServersideTest/wwwroot/favicon.ico -------------------------------------------------------------------------------- /src/Sample/BlazorServersideTest/wwwroot/css/open-iconic/font/fonts/open-iconic.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martasp/BlazorLiveReload/HEAD/src/Sample/BlazorServersideTest/wwwroot/css/open-iconic/font/fonts/open-iconic.eot -------------------------------------------------------------------------------- /src/Sample/BlazorServersideTest/wwwroot/css/open-iconic/font/fonts/open-iconic.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martasp/BlazorLiveReload/HEAD/src/Sample/BlazorServersideTest/wwwroot/css/open-iconic/font/fonts/open-iconic.otf -------------------------------------------------------------------------------- /src/Sample/BlazorServersideTest/wwwroot/css/open-iconic/font/fonts/open-iconic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martasp/BlazorLiveReload/HEAD/src/Sample/BlazorServersideTest/wwwroot/css/open-iconic/font/fonts/open-iconic.ttf -------------------------------------------------------------------------------- /src/Sample/BlazorServersideTest/wwwroot/css/open-iconic/font/fonts/open-iconic.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martasp/BlazorLiveReload/HEAD/src/Sample/BlazorServersideTest/wwwroot/css/open-iconic/font/fonts/open-iconic.woff -------------------------------------------------------------------------------- /src/Sample/BlazorServersideTest/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | }, 9 | "AllowedHosts": "*" 10 | } 11 | -------------------------------------------------------------------------------- /src/Sample/BlazorServersideTest/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "DetailedErrors": true, 3 | "Logging": { 4 | "LogLevel": { 5 | "Default": "Information", 6 | "Microsoft": "Warning", 7 | "Microsoft.Hosting.Lifetime": "Information" 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/Sample/BlazorServersideTest/BlazorServersideTest.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp3.1 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /src/Sample/BlazorServersideTest/Pages/Counter.razor: -------------------------------------------------------------------------------- 1 | @page "/counter" 2 | 3 |

Counter test

4 | 5 |

Current count: @currentCount

6 | 7 | 8 | 9 | @code { 10 | private int currentCount = 0; 11 | 12 | private void IncrementCount() 13 | { 14 | currentCount++; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Sample/BlazorServersideTest/Shared/MainLayout.razor: -------------------------------------------------------------------------------- 1 | @inherits LayoutComponentBase 2 | 3 | 6 | 7 |
8 |
9 | About 10 |
11 | 12 |
13 | @Body 14 |
15 |
16 | -------------------------------------------------------------------------------- /src/Sample/BlazorServersideTest/Data/WeatherForecast.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace BlazorServersideTest.Data 4 | { 5 | public class WeatherForecast 6 | { 7 | public DateTime Date { get; set; } 8 | 9 | public int TemperatureC { get; set; } 10 | 11 | public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); 12 | 13 | public string Summary { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Sample/BlazorServersideTest/_Imports.razor: -------------------------------------------------------------------------------- 1 | @using System.Net.Http 2 | @using Microsoft.AspNetCore.Authorization 3 | @using Microsoft.AspNetCore.Components.Authorization 4 | @using Microsoft.AspNetCore.Components.Forms 5 | @using Microsoft.AspNetCore.Components.Routing 6 | @using Microsoft.AspNetCore.Components.Web 7 | @using Microsoft.JSInterop 8 | @using BlazorServersideTest 9 | @using BlazorServersideTest.Shared 10 | -------------------------------------------------------------------------------- /src/Sample/BlazorServersideTest/App.razor: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 |

Sorry, there's nothing at this address.

8 |
9 |
10 |
11 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # (Hot reload is suported in .net core out of the box, so this library is obsolete) 2 | 3 | # BlazorLiveReload 4 | Blazor Live Reload without refreshing page 5 | ### Installing 6 | 1.Add package: 7 | ``` 8 | dotnet add package RazorComponentsPreview --version 0.6.0 9 | ``` 10 | 2.Add to startup: 11 | ``` 12 | services.AddRazorComponentsRuntimeCompilation(); 13 | app.UseRazorComponentsRuntimeCompilation(); 14 | ``` 15 | 3.run project go to /preview and change razor file components 16 | 17 | ### Demo 18 | ![Alt Text](https://media.giphy.com/media/QVhHivBsXgSctpqt4s/giphy.gif) 19 | 20 | 21 | -------------------------------------------------------------------------------- /src/RazorComponentsPreview/Htmlizer/ComponentRenderedText.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System.Collections.Generic; 5 | 6 | namespace RazorComponentsPreview 7 | { 8 | public readonly struct ComponentRenderedText 9 | { 10 | public ComponentRenderedText(int componentId, IEnumerable tokens) 11 | { 12 | ComponentId = componentId; 13 | Tokens = tokens; 14 | } 15 | 16 | public int ComponentId { get; } 17 | 18 | public IEnumerable Tokens { get; } 19 | } 20 | } -------------------------------------------------------------------------------- /src/Sample/BlazorServersideTest/Pages/Error.razor: -------------------------------------------------------------------------------- 1 | @page "/error" 2 | 3 | 4 |

Error.

5 |

An error occurred while processing your request.

6 | 7 |

Development Mode

8 |

9 | Swapping to Development environment will display more detailed information about the error that occurred. 10 |

11 |

12 | The Development environment shouldn't be enabled for deployed applications. 13 | It can result in displaying sensitive information from exceptions to end users. 14 | For local debugging, enable the Development environment by setting the ASPNETCORE_ENVIRONMENT environment variable to Development 15 | and restarting the app. 16 |

-------------------------------------------------------------------------------- /src/Sample/BlazorServersideTest/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | using Microsoft.AspNetCore; 7 | using Microsoft.AspNetCore.Hosting; 8 | using Microsoft.Extensions.Configuration; 9 | using Microsoft.Extensions.Hosting; 10 | using Microsoft.Extensions.Logging; 11 | 12 | namespace BlazorServersideTest 13 | { 14 | public class Program 15 | { 16 | public static void Main(string[] args) 17 | { 18 | CreateHostBuilder(args).Build().Run(); 19 | } 20 | 21 | public static IHostBuilder CreateHostBuilder(string[] args) => 22 | Host.CreateDefaultBuilder(args) 23 | .ConfigureWebHostDefaults(webBuilder => 24 | { 25 | webBuilder.UseStartup(); 26 | }); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Sample/BlazorServersideTest/Data/WeatherForecastService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Threading.Tasks; 4 | 5 | namespace BlazorServersideTest.Data 6 | { 7 | public class WeatherForecastService 8 | { 9 | private static readonly string[] Summaries = new[] 10 | { 11 | "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" 12 | }; 13 | 14 | public Task GetForecastAsync(DateTime startDate) 15 | { 16 | var rng = new Random(); 17 | return Task.FromResult(Enumerable.Range(1, 5).Select(index => new WeatherForecast 18 | { 19 | Date = startDate.AddDays(index), 20 | TemperatureC = rng.Next(-20, 55), 21 | Summary = Summaries[rng.Next(Summaries.Length)] 22 | }).ToArray()); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/RazorComponentsPreview/Htmlizer/HttpNavigationManager.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using Microsoft.AspNetCore.Components; 5 | using Microsoft.AspNetCore.Components.Routing; 6 | 7 | namespace RazorComponentsPreview 8 | { 9 | public class HttpNavigationManager : NavigationManager, IHostEnvironmentNavigationManager 10 | { 11 | void IHostEnvironmentNavigationManager.Initialize(string baseUri, string uri) => Initialize(baseUri, uri); 12 | 13 | public HttpNavigationManager(string baseUri, string uri) 14 | { 15 | base.BaseUri = baseUri; 16 | base.Uri = uri; 17 | Initialize(baseUri, uri); 18 | } 19 | protected override void NavigateToCore(string uri, bool forceLoad) 20 | { 21 | throw new NavigationException(uri); 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /src/Sample/BlazorServersideTest/wwwroot/css/open-iconic/ICON-LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Waybury 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. -------------------------------------------------------------------------------- /src/RazorComponentsPreview/Htmlizer/UnsupportedJavaScriptRuntime.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading; 3 | using System.Threading.Tasks; 4 | using Microsoft.JSInterop; 5 | 6 | namespace RazorComponentsPreview 7 | { 8 | public class UnsupportedJavaScriptRuntime : IJSRuntime 9 | { 10 | public ValueTask InvokeAsync(string identifier, CancellationToken cancellationToken, object[] args) 11 | { 12 | throw new InvalidOperationException("JavaScript interop calls cannot be issued during server-side prerendering, because the page has not yet loaded in the browser. Prerendered components must wrap any JavaScript interop calls in conditional logic to ensure those interop calls are not attempted during prerendering."); 13 | } 14 | 15 | ValueTask IJSRuntime.InvokeAsync(string identifier, object[] args) 16 | { 17 | throw new InvalidOperationException("JavaScript interop calls cannot be issued during server-side prerendering, because the page has not yet loaded in the browser. Prerendered components must wrap any JavaScript interop calls in conditional logic to ensure those interop calls are not attempted during prerendering."); 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /src/Sample/BlazorServersideTest/BlazorServersideTest.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.29709.97 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlazorServersideTest", "BlazorServersideTest.csproj", "{9347C174-A0BB-4F36-9D4D-58B9862FE602}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {9347C174-A0BB-4F36-9D4D-58B9862FE602}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {9347C174-A0BB-4F36-9D4D-58B9862FE602}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {9347C174-A0BB-4F36-9D4D-58B9862FE602}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {9347C174-A0BB-4F36-9D4D-58B9862FE602}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {B8E50075-A5FA-4412-8E3C-82F8580A8D1D} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /src/Sample/BlazorServersideTest/Pages/_Host.cshtml: -------------------------------------------------------------------------------- 1 | @page "/" 2 | @namespace BlazorServersideTest.Pages 3 | @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers 4 | @{ 5 | Layout = null; 6 | } 7 | 8 | 9 | 10 | 11 | 12 | 13 | BlazorServersideTest 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | An error has occurred. This application may no longer respond until reloaded. 26 | 27 | 28 | An unhandled exception has occurred. See browser dev tools for details. 29 | 30 | Reload 31 | 🗙 32 |
33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /src/Sample/BlazorServersideTest/Pages/FetchData.razor: -------------------------------------------------------------------------------- 1 | @page "/fetchdata" 2 | 3 | @using BlazorServersideTest.Data 4 | @inject WeatherForecastService ForecastService 5 | 6 |

Weather fot

7 | 8 |

Thisssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssce.

9 | @if (forecasts == null) 10 | { 11 |

Loading...

12 | } 13 | else 14 | { 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | @foreach (var forecast in forecasts) 26 | { 27 | 28 | 29 | 30 | 31 | 32 | 33 | } 34 | 35 |
Temp. (C)Temp. (F)Summary
@forecast.Date.ToShortDateString()@forecast.TemperatureC@forecast.TemperatureF@forecast.Summary
36 | } 37 | 38 | @code { 39 | private WeatherForecast[] forecasts; 40 | 41 | protected override async Task OnInitializedAsync() 42 | { 43 | forecasts = await ForecastService.GetForecastAsync(DateTime.Now); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/RazorComponentsPreview/RazorComponentsPreview.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.1 5 | MIT 6 | live,reload,blazor,preview,hot,module,replacement,razor 7 | false 8 | Razor components preview. 9 | 0.6.0 10 | https://github.com/martasp/BlazorLiveReload 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /src/Sample/BlazorServersideTest/Shared/NavMenu.razor: -------------------------------------------------------------------------------- 1 | 7 | 8 |
9 | 26 |
27 | 28 | @code { 29 | private bool collapseNavMenu = true; 30 | 31 | private string NavMenuCssClass => collapseNavMenu ? "collapse" : null; 32 | 33 | private void ToggleNavMenu() 34 | { 35 | collapseNavMenu = !collapseNavMenu; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/RazorComponentsPreview/Htmlizer/RenderedComponentInstance.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Components; 2 | 3 | namespace RazorComponentsPreview 4 | { 5 | public class RenderedComponentInstance 6 | { 7 | private readonly TestRenderer _renderer; 8 | private readonly ContainerComponent _containerTestRootComponent; 9 | private int _testComponentId; 10 | private IComponent _testComponentInstance; 11 | 12 | internal RenderedComponentInstance(TestRenderer renderer, IComponent componentInstance) 13 | { 14 | _renderer = renderer; 15 | _containerTestRootComponent = new ContainerComponent(_renderer); 16 | _testComponentInstance = componentInstance; 17 | } 18 | 19 | public IComponent Instance => _testComponentInstance; 20 | 21 | public string GetMarkup() 22 | { 23 | return Htmlizer.GetHtml(_renderer, _testComponentId); 24 | } 25 | 26 | internal void SetParametersAndRender(ParameterView parameters) 27 | { 28 | _containerTestRootComponent.RenderComponentUnderTest( 29 | _testComponentInstance.GetType(), parameters); 30 | var foundTestComponent = _containerTestRootComponent.FindComponentUnderTest(); 31 | _testComponentId = foundTestComponent.Item1; 32 | _testComponentInstance = (IComponent)foundTestComponent.Item2; 33 | } 34 | 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/RazorComponentsPreview/Razor/NotFoundProjectItem.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | using System.IO; 6 | using Microsoft.AspNetCore.Razor.Language; 7 | 8 | namespace RazorComponentsPreview 9 | { 10 | /// 11 | /// A that does not exist. 12 | /// 13 | internal class NotFoundProjectItem : RazorProjectItem 14 | { 15 | /// 16 | /// Initializes a new instance of . 17 | /// 18 | /// The base path. 19 | /// The path. 20 | /// The file kind 21 | public NotFoundProjectItem(string basePath, string path, string fileKind) 22 | { 23 | BasePath = basePath; 24 | FilePath = path; 25 | FileKind = fileKind ?? FileKinds.GetFileKindFromFilePath(path); 26 | } 27 | 28 | /// 29 | public override string BasePath { get; } 30 | 31 | /// 32 | public override string FilePath { get; } 33 | 34 | /// 35 | public override string FileKind { get; } 36 | 37 | /// 38 | public override bool Exists => false; 39 | 40 | /// 41 | public override string PhysicalPath => throw new NotSupportedException(); 42 | 43 | /// 44 | public override Stream Read() => throw new NotSupportedException(); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/RazorComponentsPreview/Razor/TestRazorProjectItem.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using Microsoft.AspNetCore.Razor.Language; 5 | using System.IO; 6 | using System.Text; 7 | 8 | namespace RazorComponentsPreview 9 | { 10 | public class TestRazorProjectItem : RazorProjectItem 11 | { 12 | private readonly string _fileKind; 13 | 14 | public TestRazorProjectItem( 15 | string filePath, 16 | string physicalPath = null, 17 | string relativePhysicalPath = null, 18 | string basePath = "/", 19 | string fileKind = null) 20 | { 21 | FilePath = filePath; 22 | PhysicalPath = physicalPath; 23 | RelativePhysicalPath = relativePhysicalPath; 24 | BasePath = basePath; 25 | _fileKind = fileKind; 26 | } 27 | 28 | public override string BasePath { get; } 29 | 30 | public override string FileKind => _fileKind ?? base.FileKind; 31 | 32 | public override string FilePath { get; } 33 | 34 | public override string PhysicalPath { get; } 35 | 36 | public override string RelativePhysicalPath { get; } 37 | 38 | public override bool Exists { get; } = true; 39 | 40 | public string Content { get; set; } = ""; 41 | public override Stream Read() 42 | { 43 | // Act like a file and have a UTF8 BOM. 44 | var preamble = Encoding.UTF8.GetPreamble(); 45 | var contentBytes = Encoding.UTF8.GetBytes(Content); 46 | var buffer = new byte[preamble.Length + contentBytes.Length]; 47 | preamble.CopyTo(buffer, 0); 48 | contentBytes.CopyTo(buffer, preamble.Length); 49 | 50 | var stream = new MemoryStream(buffer); 51 | 52 | return stream; 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/RazorComponentsPreview/Razor/DefaultRazorProjectItem.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System.IO; 5 | using Microsoft.AspNetCore.Razor.Language; 6 | 7 | namespace RazorComponentsPreview 8 | { 9 | internal class DefaultRazorProjectItem : RazorProjectItem 10 | { 11 | private readonly string _fileKind; 12 | 13 | /// 14 | /// Initializes a new instance of . 15 | /// 16 | /// The base path. 17 | /// The physical path of the base path. 18 | /// The path. 19 | /// The file kind. If null, the document kind will be inferred from the file extension. 20 | /// The . 21 | public DefaultRazorProjectItem(string basePath, string filePath, string relativePhysicalPath, string fileKind, FileInfo file) 22 | { 23 | BasePath = basePath; 24 | FilePath = filePath; 25 | RelativePhysicalPath = relativePhysicalPath; 26 | _fileKind = fileKind; 27 | File = file; 28 | } 29 | 30 | public FileInfo File { get; } 31 | 32 | public override string BasePath { get; } 33 | 34 | public override string FilePath { get; } 35 | 36 | public override bool Exists => File.Exists; 37 | 38 | public override string PhysicalPath => File.FullName; 39 | 40 | public override string RelativePhysicalPath { get; } 41 | 42 | public override string FileKind => _fileKind ?? base.FileKind; 43 | 44 | public override Stream Read() => new FileStream(PhysicalPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete); 45 | } 46 | } -------------------------------------------------------------------------------- /src/RazorComponentsPreview/Razor/TestRazorProjectFileSystem.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using Microsoft.AspNetCore.Razor.Language; 8 | 9 | namespace RazorComponentsPreview 10 | { 11 | internal class TestRazorProjectFileSystem : DefaultRazorProjectFileSystem 12 | { 13 | public static RazorProjectFileSystem Empty = new TestRazorProjectFileSystem(); 14 | 15 | private readonly Dictionary _lookup; 16 | 17 | public TestRazorProjectFileSystem() 18 | : this(new RazorProjectItem[0]) 19 | { 20 | } 21 | 22 | public TestRazorProjectFileSystem(IList items) 23 | : base("/") 24 | { 25 | _lookup = items.ToDictionary(item => item.FilePath); 26 | } 27 | 28 | public void Add(RazorProjectItem item) 29 | { 30 | _lookup.Add(item.FilePath, item); 31 | } 32 | 33 | public void Remove(RazorProjectItem item) 34 | { 35 | _lookup.Remove(item.FilePath); 36 | } 37 | 38 | public override IEnumerable EnumerateItems(string basePath) 39 | { 40 | throw new NotImplementedException(); 41 | } 42 | 43 | [Obsolete("Use GetItem(string path, string fileKind) instead.")] 44 | public override RazorProjectItem GetItem(string path) 45 | { 46 | return GetItem(path, fileKind: null); 47 | } 48 | 49 | public override RazorProjectItem GetItem(string path, string fileKind) 50 | { 51 | if (!_lookup.TryGetValue(path, out var value)) 52 | { 53 | value = new NotFoundProjectItem("", path, fileKind); 54 | } 55 | 56 | return value; 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/Sample/BlazorServersideTest/Startup.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Builder; 6 | using Microsoft.AspNetCore.Components; 7 | using Microsoft.AspNetCore.Hosting; 8 | using Microsoft.AspNetCore.HttpsPolicy; 9 | using Microsoft.Extensions.Configuration; 10 | using Microsoft.Extensions.DependencyInjection; 11 | using Microsoft.Extensions.Hosting; 12 | using BlazorServersideTest.Data; 13 | using RazorComponentsPreview; 14 | 15 | namespace BlazorServersideTest 16 | { 17 | public class Startup 18 | { 19 | public Startup(IConfiguration configuration) 20 | { 21 | Configuration = configuration; 22 | } 23 | 24 | public IConfiguration Configuration { get; } 25 | 26 | // This method gets called by the runtime. Use this method to add services to the container. 27 | // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 28 | public void ConfigureServices(IServiceCollection services) 29 | { 30 | services.AddRazorPages(); 31 | services.AddServerSideBlazor(); 32 | services.AddSingleton(); 33 | services.AddRazorComponentsRuntimeCompilation(); 34 | } 35 | 36 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. 37 | public void Configure(IApplicationBuilder app, IWebHostEnvironment env) 38 | { 39 | if (env.IsDevelopment()) 40 | { 41 | app.UseDeveloperExceptionPage(); 42 | app.UseRazorComponentsRuntimeCompilation(); 43 | } 44 | else 45 | { 46 | app.UseExceptionHandler("/Error"); 47 | // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. 48 | app.UseHsts(); 49 | } 50 | 51 | app.UseHttpsRedirection(); 52 | app.UseStaticFiles(); 53 | 54 | app.UseRouting(); 55 | 56 | app.UseEndpoints(endpoints => 57 | { 58 | endpoints.MapBlazorHub(); 59 | endpoints.MapFallbackToPage("/_Host"); 60 | }); 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/Sample/BlazorServersideTest/wwwroot/preview.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | BlazorServersideTest 5 | 6 | 7 | 8 | 9 | 37 | 38 |
39 |
40 | About 41 |
42 | 43 |
44 |

Hello, world!

45 | 46 | Welcome to your new app. 47 | 48 | 49 |
50 |
51 |
52 | -------------------------------------------------------------------------------- /src/RazorComponentsPreview/Htmlizer/TestHost.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Components; 2 | using Microsoft.Extensions.DependencyInjection; 3 | using Microsoft.Extensions.Logging; 4 | using Microsoft.Extensions.Logging.Abstractions; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Threading.Tasks; 8 | 9 | namespace RazorComponentsPreview 10 | { 11 | public class TestHost 12 | { 13 | private readonly IServiceCollection _serviceCollection; 14 | private readonly Lazy _renderer; 15 | private readonly Lazy _serviceProvider; 16 | 17 | public TestHost(IServiceCollection serviceCollection) 18 | { 19 | _serviceCollection = serviceCollection; 20 | 21 | _serviceProvider = new Lazy(() => 22 | { 23 | return _serviceCollection.BuildServiceProvider(); 24 | }); 25 | 26 | _renderer = new Lazy(() => 27 | { 28 | var loggerFactory = Services.GetService() ?? new NullLoggerFactory(); 29 | return new TestRenderer(Services, loggerFactory); 30 | }); 31 | } 32 | 33 | public IServiceProvider Services => _serviceProvider.Value; 34 | 35 | public void AddService(T implementation) 36 | => AddService(implementation); 37 | 38 | public void AddService(TImplementation implementation) where TImplementation: TContract 39 | { 40 | if (_renderer.IsValueCreated) 41 | { 42 | throw new InvalidOperationException("Cannot configure services after the host has started operation"); 43 | } 44 | 45 | _serviceCollection.AddSingleton(typeof(TContract), implementation); 46 | } 47 | 48 | public void WaitForNextRender(Action trigger) 49 | { 50 | var task = Renderer.NextRender; 51 | trigger(); 52 | task.Wait(millisecondsTimeout: 1000); 53 | 54 | if (!task.IsCompleted) 55 | { 56 | throw new TimeoutException("No render occurred within the timeout period."); 57 | } 58 | } 59 | 60 | public RenderedComponentInstance AddComponent(IComponent ComponentInstance) 61 | { 62 | var result = new RenderedComponentInstance(Renderer, ComponentInstance); 63 | result.SetParametersAndRender(ParameterView.Empty); 64 | 65 | return result; 66 | } 67 | 68 | private TestRenderer Renderer => _renderer.Value; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/RazorComponentsPreview/Htmlizer/TestRenderer.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Components; 2 | using Microsoft.AspNetCore.Components.RenderTree; 3 | using Microsoft.Extensions.Logging; 4 | using System; 5 | using System.Diagnostics.CodeAnalysis; 6 | using System.Runtime.ExceptionServices; 7 | using System.Threading.Tasks; 8 | 9 | namespace RazorComponentsPreview 10 | { 11 | [SuppressMessage("Usage", "BL0006:Do not use RenderTree types", Justification = "")] 12 | internal class TestRenderer : Renderer 13 | { 14 | private Exception _unhandledException; 15 | private TaskCompletionSource _nextRenderTcs = new TaskCompletionSource(); 16 | 17 | public TestRenderer(IServiceProvider serviceProvider, ILoggerFactory loggerFactory) 18 | : base(serviceProvider, loggerFactory) 19 | { 20 | } 21 | 22 | public new ArrayRange GetCurrentRenderTreeFrames(int componentId) 23 | => base.GetCurrentRenderTreeFrames(componentId); 24 | 25 | public int AttachTestRootComponent(ContainerComponent testRootComponent) 26 | => AssignRootComponentId(testRootComponent); 27 | 28 | public new Task DispatchEventAsync(ulong eventHandlerId, EventFieldInfo fieldInfo, EventArgs eventArgs) 29 | { 30 | var task = Dispatcher.InvokeAsync( 31 | () => base.DispatchEventAsync(eventHandlerId, fieldInfo, eventArgs)); 32 | AssertNoSynchronousErrors(); 33 | return task; 34 | } 35 | 36 | public override Dispatcher Dispatcher { get; } = Dispatcher.CreateDefault(); 37 | 38 | public Task NextRender => _nextRenderTcs.Task; 39 | 40 | protected override void HandleException(Exception exception) 41 | { 42 | _unhandledException = exception; 43 | } 44 | 45 | protected override Task UpdateDisplayAsync(in RenderBatch renderBatch) 46 | { 47 | // TODO: Capture batches (and the state of component output) for individual inspection 48 | var prevTcs = _nextRenderTcs; 49 | _nextRenderTcs = new TaskCompletionSource(); 50 | prevTcs.SetResult(null); 51 | return Task.CompletedTask; 52 | } 53 | 54 | public void DispatchAndAssertNoSynchronousErrors(Action callback) 55 | { 56 | Dispatcher.InvokeAsync(callback).Wait(); 57 | AssertNoSynchronousErrors(); 58 | } 59 | 60 | private void AssertNoSynchronousErrors() 61 | { 62 | if (_unhandledException != null) 63 | { 64 | //ExceptionDispatchInfo.Capture(_unhandledException).Throw(); 65 | } 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/RazorComponentsPreview/Htmlizer/ContainerComponent.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Components; 2 | using Microsoft.AspNetCore.Components.RenderTree; 3 | using Microsoft.AspNetCore.Components.Routing; 4 | using System; 5 | using System.Diagnostics; 6 | using System.Diagnostics.CodeAnalysis; 7 | using System.Threading.Tasks; 8 | 9 | namespace RazorComponentsPreview 10 | { 11 | // This provides the ability for test code to trigger rendering at arbitrary times, 12 | // and to supply arbitrary parameters to the component being tested (including ones 13 | // flagged as 'cascading'). 14 | // 15 | // This also avoids the use of Renderer's RenderRootComponentAsync APIs, which are 16 | // not a good entrypoint for unit tests, because their asynchrony is all about waiting 17 | // for quiescence. We don't want that in tests because we want to assert about all 18 | // possible states, including loading states. 19 | 20 | 21 | 22 | [SuppressMessage("Usage", "BL0006:Do not use RenderTree types", Justification = "")] 23 | internal class ContainerComponent : IComponent 24 | { 25 | private readonly TestRenderer _renderer; 26 | private RenderHandle _renderHandle; 27 | private string _location; 28 | private int _componentId; 29 | 30 | public ContainerComponent(TestRenderer renderer) 31 | { 32 | _renderer = renderer; 33 | _componentId = renderer.AttachTestRootComponent(this); 34 | } 35 | 36 | public void Attach(RenderHandle renderHandle) 37 | { 38 | _renderHandle = renderHandle; 39 | 40 | } 41 | private void HandleLocationChanged(object sender, LocationChangedEventArgs args) 42 | { 43 | _location = args.Location; 44 | } 45 | 46 | 47 | public Task SetParametersAsync(ParameterView parameters) 48 | { 49 | throw new NotImplementedException($"{nameof(ContainerComponent)} shouldn't receive any parameters"); 50 | } 51 | 52 | public (int, object) FindComponentUnderTest() 53 | { 54 | var ownFrames = _renderer.GetCurrentRenderTreeFrames(_componentId); 55 | if (ownFrames.Count == 0) 56 | { 57 | throw new InvalidOperationException($"{nameof(ContainerComponent)} hasn't yet rendered"); 58 | } 59 | 60 | ref var childComponentFrame = ref ownFrames.Array[0]; 61 | Debug.Assert(childComponentFrame.FrameType == RenderTreeFrameType.Component); 62 | Debug.Assert(childComponentFrame.Component != null); 63 | return (childComponentFrame.ComponentId, childComponentFrame.Component); 64 | } 65 | 66 | public void RenderComponentUnderTest(Type componentType, ParameterView parameters) 67 | { 68 | _renderer.DispatchAndAssertNoSynchronousErrors(() => 69 | { 70 | _renderHandle.Render(builder => 71 | { 72 | builder.OpenComponent(0, componentType); 73 | 74 | foreach (var parameterValue in parameters) 75 | { 76 | builder.AddAttribute(1, parameterValue.Name, parameterValue.Value); 77 | } 78 | 79 | builder.CloseComponent(); 80 | }); 81 | }); 82 | } 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/RazorComponentsPreview/Razor/RazorRuntimeCompilationExtensions.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Builder; 2 | using Microsoft.AspNetCore.Http; 3 | using Microsoft.Extensions.DependencyInjection; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.IO; 7 | using System.Linq; 8 | using System.Net.WebSockets; 9 | using System.Threading; 10 | using System.Threading.Tasks; 11 | 12 | namespace RazorComponentsPreview 13 | { 14 | public static class RazorRuntimeCompilationExtensions 15 | { 16 | private static IServiceCollection _serviceCollection; 17 | 18 | public static void AddRazorComponentsRuntimeCompilation(this IServiceCollection services) //Todo need serviceCollection, how to make without this function?? 19 | { 20 | _serviceCollection = services; 21 | } 22 | 23 | public static void UseRazorComponentsRuntimeCompilation(this IApplicationBuilder app) 24 | { 25 | var webSocketOptions = new WebSocketOptions() 26 | { 27 | KeepAliveInterval = TimeSpan.FromSeconds(120), 28 | ReceiveBufferSize = 4 * 1024 29 | }; 30 | webSocketOptions.AllowedOrigins.Add("https://localhost:5001"); 31 | webSocketOptions.AllowedOrigins.Add("https://localhost:5000"); 32 | webSocketOptions.AllowedOrigins.Add("http://localhost:5000"); 33 | app.UseWebSockets(webSocketOptions); 34 | 35 | 36 | var runtimeComponentsGenerator = new RuntimeComponentsGenerator(_serviceCollection); 37 | var firstTimeRender = runtimeComponentsGenerator.FirstTimeRender(); 38 | runtimeComponentsGenerator.AddRazorStaticRuntimeGeneration(); 39 | app.Use(async (context, next) => 40 | { 41 | if (context.Request.Path == "/preview") 42 | { 43 | await context.Response.WriteAsync(firstTimeRender); 44 | } 45 | else if (context.Request.Path == "/ws") 46 | { 47 | if (context.WebSockets.IsWebSocketRequest) 48 | { 49 | WebSocket webSocket = await context.WebSockets.AcceptWebSocketAsync(); 50 | runtimeComponentsGenerator.AttachWebsocket(webSocket); 51 | await KeepAlive(context, webSocket); 52 | } 53 | else 54 | { 55 | context.Response.StatusCode = 400; 56 | } 57 | } 58 | else 59 | { 60 | await next(); 61 | } 62 | }); 63 | } 64 | private static async Task KeepAlive(HttpContext context, WebSocket webSocket) 65 | { 66 | var buffer = new byte[1024 * 4]; 67 | WebSocketReceiveResult result = await webSocket.ReceiveAsync(new ArraySegment(buffer), CancellationToken.None); 68 | while (!result.CloseStatus.HasValue) 69 | { 70 | await webSocket.SendAsync(new ArraySegment(buffer, 0, result.Count), result.MessageType, result.EndOfMessage, CancellationToken.None); 71 | 72 | result = await webSocket.ReceiveAsync(new ArraySegment(buffer), CancellationToken.None); 73 | } 74 | await webSocket.CloseAsync(result.CloseStatus.Value, result.CloseStatusDescription, CancellationToken.None); 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/Sample/BlazorServersideTest/wwwroot/css/open-iconic/README.md: -------------------------------------------------------------------------------- 1 | [Open Iconic v1.1.1](http://useiconic.com/open) 2 | =========== 3 | 4 | ### Open Iconic is the open source sibling of [Iconic](http://useiconic.com). It is a hyper-legible collection of 223 icons with a tiny footprint—ready to use with Bootstrap and Foundation. [View the collection](http://useiconic.com/open#icons) 5 | 6 | 7 | 8 | ## What's in Open Iconic? 9 | 10 | * 223 icons designed to be legible down to 8 pixels 11 | * Super-light SVG files - 61.8 for the entire set 12 | * SVG sprite—the modern replacement for icon fonts 13 | * Webfont (EOT, OTF, SVG, TTF, WOFF), PNG and WebP formats 14 | * Webfont stylesheets (including versions for Bootstrap and Foundation) in CSS, LESS, SCSS and Stylus formats 15 | * PNG and WebP raster images in 8px, 16px, 24px, 32px, 48px and 64px. 16 | 17 | 18 | ## Getting Started 19 | 20 | #### For code samples and everything else you need to get started with Open Iconic, check out our [Icons](http://useiconic.com/open#icons) and [Reference](http://useiconic.com/open#reference) sections. 21 | 22 | ### General Usage 23 | 24 | #### Using Open Iconic's SVGs 25 | 26 | We like SVGs and we think they're the way to display icons on the web. Since Open Iconic are just basic SVGs, we suggest you display them like you would any other image (don't forget the `alt` attribute). 27 | 28 | ``` 29 | icon name 30 | ``` 31 | 32 | #### Using Open Iconic's SVG Sprite 33 | 34 | Open Iconic also comes in a SVG sprite which allows you to display all the icons in the set with a single request. It's like an icon font, without being a hack. 35 | 36 | Adding an icon from an SVG sprite is a little different than what you're used to, but it's still a piece of cake. *Tip: To make your icons easily style able, we suggest adding a general class to the* `` *tag and a unique class name for each different icon in the* `` *tag.* 37 | 38 | ``` 39 | 40 | 41 | 42 | ``` 43 | 44 | Sizing icons only needs basic CSS. All the icons are in a square format, so just set the `` tag with equal width and height dimensions. 45 | 46 | ``` 47 | .icon { 48 | width: 16px; 49 | height: 16px; 50 | } 51 | ``` 52 | 53 | Coloring icons is even easier. All you need to do is set the `fill` rule on the `` tag. 54 | 55 | ``` 56 | .icon-account-login { 57 | fill: #f00; 58 | } 59 | ``` 60 | 61 | To learn more about SVG Sprites, read [Chris Coyier's guide](http://css-tricks.com/svg-sprites-use-better-icon-fonts/). 62 | 63 | #### Using Open Iconic's Icon Font... 64 | 65 | 66 | ##### …with Bootstrap 67 | 68 | You can find our Bootstrap stylesheets in `font/css/open-iconic-bootstrap.{css, less, scss, styl}` 69 | 70 | 71 | ``` 72 | 73 | ``` 74 | 75 | 76 | ``` 77 | 78 | ``` 79 | 80 | ##### …with Foundation 81 | 82 | You can find our Foundation stylesheets in `font/css/open-iconic-foundation.{css, less, scss, styl}` 83 | 84 | ``` 85 | 86 | ``` 87 | 88 | 89 | ``` 90 | 91 | ``` 92 | 93 | ##### …on its own 94 | 95 | You can find our default stylesheets in `font/css/open-iconic.{css, less, scss, styl}` 96 | 97 | ``` 98 | 99 | ``` 100 | 101 | ``` 102 | 103 | ``` 104 | 105 | 106 | ## License 107 | 108 | ### Icons 109 | 110 | All code (including SVG markup) is under the [MIT License](http://opensource.org/licenses/MIT). 111 | 112 | ### Fonts 113 | 114 | All fonts are under the [SIL Licensed](http://scripts.sil.org/cms/scripts/page.php?item_id=OFL_web). 115 | -------------------------------------------------------------------------------- /src/Sample/BlazorServersideTest/wwwroot/css/site.css: -------------------------------------------------------------------------------- 1 | @import url('open-iconic/font/css/open-iconic-bootstrap.min.css'); 2 | 3 | html, body { 4 | font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; 5 | } 6 | 7 | a, .btn-link { 8 | color: #0366d6; 9 | } 10 | 11 | .btn-primary { 12 | color: #fff; 13 | background-color: #1b6ec2; 14 | border-color: #1861ac; 15 | } 16 | 17 | app { 18 | position: relative; 19 | display: flex; 20 | flex-direction: column; 21 | } 22 | 23 | .top-row { 24 | height: 3.5rem; 25 | display: flex; 26 | align-items: center; 27 | } 28 | 29 | .main { 30 | flex: 1; 31 | } 32 | 33 | .main .top-row { 34 | background-color: #f7f7f7; 35 | border-bottom: 1px solid #d6d5d5; 36 | justify-content: flex-end; 37 | } 38 | 39 | .main .top-row > a, .main .top-row .btn-link { 40 | white-space: nowrap; 41 | margin-left: 1.5rem; 42 | } 43 | 44 | .main .top-row a:first-child { 45 | overflow: hidden; 46 | text-overflow: ellipsis; 47 | } 48 | 49 | .sidebar { 50 | background-image: linear-gradient(180deg, rgb(5, 39, 103) 0%, #3a0647 70%); 51 | } 52 | 53 | .sidebar .top-row { 54 | background-color: rgba(0,0,0,0.4); 55 | } 56 | 57 | .sidebar .navbar-brand { 58 | font-size: 1.1rem; 59 | } 60 | 61 | .sidebar .oi { 62 | width: 2rem; 63 | font-size: 1.1rem; 64 | vertical-align: text-top; 65 | top: -2px; 66 | } 67 | 68 | .sidebar .nav-item { 69 | font-size: 0.9rem; 70 | padding-bottom: 0.5rem; 71 | } 72 | 73 | .sidebar .nav-item:first-of-type { 74 | padding-top: 1rem; 75 | } 76 | 77 | .sidebar .nav-item:last-of-type { 78 | padding-bottom: 1rem; 79 | } 80 | 81 | .sidebar .nav-item a { 82 | color: #d7d7d7; 83 | border-radius: 4px; 84 | height: 3rem; 85 | display: flex; 86 | align-items: center; 87 | line-height: 3rem; 88 | } 89 | 90 | .sidebar .nav-item a.active { 91 | background-color: rgba(255,255,255,0.25); 92 | color: white; 93 | } 94 | 95 | .sidebar .nav-item a:hover { 96 | background-color: rgba(255,255,255,0.1); 97 | color: white; 98 | } 99 | 100 | .content { 101 | padding-top: 1.1rem; 102 | } 103 | 104 | .navbar-toggler { 105 | background-color: rgba(255, 255, 255, 0.1); 106 | } 107 | 108 | .valid.modified:not([type=checkbox]) { 109 | outline: 1px solid #26b050; 110 | } 111 | 112 | .invalid { 113 | outline: 1px solid red; 114 | } 115 | 116 | .validation-message { 117 | color: red; 118 | } 119 | 120 | #blazor-error-ui { 121 | background: lightyellow; 122 | bottom: 0; 123 | box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2); 124 | display: none; 125 | left: 0; 126 | padding: 0.6rem 1.25rem 0.7rem 1.25rem; 127 | position: fixed; 128 | width: 100%; 129 | z-index: 1000; 130 | } 131 | 132 | #blazor-error-ui .dismiss { 133 | cursor: pointer; 134 | position: absolute; 135 | right: 0.75rem; 136 | top: 0.5rem; 137 | } 138 | 139 | @media (max-width: 767.98px) { 140 | .main .top-row:not(.auth) { 141 | display: none; 142 | } 143 | 144 | .main .top-row.auth { 145 | justify-content: space-between; 146 | } 147 | 148 | .main .top-row a, .main .top-row .btn-link { 149 | margin-left: 0; 150 | } 151 | } 152 | 153 | @media (min-width: 768px) { 154 | app { 155 | flex-direction: row; 156 | } 157 | 158 | .sidebar { 159 | width: 250px; 160 | height: 100vh; 161 | position: sticky; 162 | top: 0; 163 | } 164 | 165 | .main .top-row { 166 | position: sticky; 167 | top: 0; 168 | } 169 | 170 | .main > div { 171 | padding-left: 2rem !important; 172 | padding-right: 1.5rem !important; 173 | } 174 | 175 | .navbar-toggler { 176 | display: none; 177 | } 178 | 179 | .sidebar .collapse { 180 | /* Never collapse the sidebar for wide screens */ 181 | display: block; 182 | } 183 | } 184 | -------------------------------------------------------------------------------- /src/Sample/BlazorServersideTest/wwwroot/css/open-iconic/FONT-LICENSE: -------------------------------------------------------------------------------- 1 | SIL OPEN FONT LICENSE Version 1.1 2 | 3 | Copyright (c) 2014 Waybury 4 | 5 | PREAMBLE 6 | The goals of the Open Font License (OFL) are to stimulate worldwide 7 | development of collaborative font projects, to support the font creation 8 | efforts of academic and linguistic communities, and to provide a free and 9 | open framework in which fonts may be shared and improved in partnership 10 | with others. 11 | 12 | The OFL allows the licensed fonts to be used, studied, modified and 13 | redistributed freely as long as they are not sold by themselves. The 14 | fonts, including any derivative works, can be bundled, embedded, 15 | redistributed and/or sold with any software provided that any reserved 16 | names are not used by derivative works. The fonts and derivatives, 17 | however, cannot be released under any other type of license. The 18 | requirement for fonts to remain under this license does not apply 19 | to any document created using the fonts or their derivatives. 20 | 21 | DEFINITIONS 22 | "Font Software" refers to the set of files released by the Copyright 23 | Holder(s) under this license and clearly marked as such. This may 24 | include source files, build scripts and documentation. 25 | 26 | "Reserved Font Name" refers to any names specified as such after the 27 | copyright statement(s). 28 | 29 | "Original Version" refers to the collection of Font Software components as 30 | distributed by the Copyright Holder(s). 31 | 32 | "Modified Version" refers to any derivative made by adding to, deleting, 33 | or substituting -- in part or in whole -- any of the components of the 34 | Original Version, by changing formats or by porting the Font Software to a 35 | new environment. 36 | 37 | "Author" refers to any designer, engineer, programmer, technical 38 | writer or other person who contributed to the Font Software. 39 | 40 | PERMISSION & CONDITIONS 41 | Permission is hereby granted, free of charge, to any person obtaining 42 | a copy of the Font Software, to use, study, copy, merge, embed, modify, 43 | redistribute, and sell modified and unmodified copies of the Font 44 | Software, subject to the following conditions: 45 | 46 | 1) Neither the Font Software nor any of its individual components, 47 | in Original or Modified Versions, may be sold by itself. 48 | 49 | 2) Original or Modified Versions of the Font Software may be bundled, 50 | redistributed and/or sold with any software, provided that each copy 51 | contains the above copyright notice and this license. These can be 52 | included either as stand-alone text files, human-readable headers or 53 | in the appropriate machine-readable metadata fields within text or 54 | binary files as long as those fields can be easily viewed by the user. 55 | 56 | 3) No Modified Version of the Font Software may use the Reserved Font 57 | Name(s) unless explicit written permission is granted by the corresponding 58 | Copyright Holder. This restriction only applies to the primary font name as 59 | presented to the users. 60 | 61 | 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font 62 | Software shall not be used to promote, endorse or advertise any 63 | Modified Version, except to acknowledge the contribution(s) of the 64 | Copyright Holder(s) and the Author(s) or with their explicit written 65 | permission. 66 | 67 | 5) The Font Software, modified or unmodified, in part or in whole, 68 | must be distributed entirely under this license, and must not be 69 | distributed under any other license. The requirement for fonts to 70 | remain under this license does not apply to any document created 71 | using the Font Software. 72 | 73 | TERMINATION 74 | This license becomes null and void if any of the above conditions are 75 | not met. 76 | 77 | DISCLAIMER 78 | THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 79 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF 80 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT 81 | OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE 82 | COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 83 | INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL 84 | DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 85 | FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM 86 | OTHER DEALINGS IN THE FONT SOFTWARE. 87 | -------------------------------------------------------------------------------- /src/RazorComponentsPreview/Razor/DefaultRazorProjectFileSystem.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using System; 5 | using System.Collections.Generic; 6 | using System.IO; 7 | using System.Linq; 8 | using Microsoft.AspNetCore.Razor.Language; 9 | 10 | namespace RazorComponentsPreview 11 | { 12 | internal class DefaultRazorProjectFileSystem : RazorProjectFileSystem 13 | { 14 | public DefaultRazorProjectFileSystem(string root) 15 | { 16 | if (string.IsNullOrEmpty(root)) 17 | { 18 | throw new ArgumentException("no way!"); 19 | } 20 | 21 | Root = root.Replace('\\', '/').TrimEnd('/'); 22 | } 23 | 24 | public string Root { get; } 25 | 26 | public override IEnumerable EnumerateItems(string basePath) 27 | { 28 | var absoluteBasePath = NormalizeAndEnsureValidPath(basePath); 29 | 30 | var directory = new DirectoryInfo(absoluteBasePath); 31 | if (!directory.Exists) 32 | { 33 | return Enumerable.Empty(); 34 | } 35 | 36 | return directory 37 | .EnumerateFiles("*.cshtml", SearchOption.AllDirectories) 38 | .Concat(directory.EnumerateFiles("*.razor", SearchOption.AllDirectories)) 39 | .Select(file => 40 | { 41 | var relativePhysicalPath = file.FullName.Substring(absoluteBasePath.Length + 1); // Include leading separator 42 | var filePath = "/" + relativePhysicalPath.Replace(Path.DirectorySeparatorChar, '/'); 43 | 44 | return new DefaultRazorProjectItem(basePath, filePath, relativePhysicalPath, fileKind: null, file); 45 | }); 46 | } 47 | 48 | public override RazorProjectItem GetItem(string path, string fileKind) 49 | { 50 | var absoluteBasePath = NormalizeAndEnsureValidPath("/"); 51 | var absolutePath = NormalizeAndEnsureValidPath(path); 52 | 53 | var file = new FileInfo(absolutePath); 54 | if (!absolutePath.StartsWith(absoluteBasePath, StringComparison.OrdinalIgnoreCase)) 55 | { 56 | throw new InvalidOperationException($"The file '{absolutePath}' is not a descendent of the base path '{absoluteBasePath}'."); 57 | } 58 | 59 | var relativePhysicalPath = file.FullName.Substring(absoluteBasePath.Length + 1); // Include leading separator 60 | var filePath = "/" + relativePhysicalPath.Replace(Path.DirectorySeparatorChar, '/'); 61 | 62 | return new DefaultRazorProjectItem("/", filePath, relativePhysicalPath, fileKind, new FileInfo(absolutePath)); 63 | } 64 | 65 | [Obsolete("Use GetItem(string path, string fileKind) instead.")] 66 | public override RazorProjectItem GetItem(string path) 67 | { 68 | return GetItem(path, fileKind: null); 69 | } 70 | 71 | protected override string NormalizeAndEnsureValidPath(string path) 72 | { 73 | if (string.IsNullOrEmpty(path)) 74 | { 75 | throw new ArgumentException("no way!"); 76 | } 77 | 78 | var absolutePath = path.Replace('\\', '/'); 79 | 80 | // Check if the given path is an absolute path. It is absolute if, 81 | // 1. It starts with Root or 82 | // 2. It is a network share path and starts with a '//'. Eg. //servername/some/network/folder 83 | if (!absolutePath.StartsWith(Root, StringComparison.OrdinalIgnoreCase) && 84 | !absolutePath.StartsWith("//", StringComparison.OrdinalIgnoreCase)) 85 | { 86 | // This is not an absolute path. Strip the leading slash if any and combine it with Root. 87 | if (path[0] == '/' || path[0] == '\\') 88 | { 89 | path = path.Substring(1); 90 | } 91 | 92 | absolutePath = Path.Combine(Root, path); 93 | } 94 | 95 | absolutePath = absolutePath.Replace('\\', '/'); 96 | 97 | return absolutePath; 98 | } 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /src/RazorComponentsPreview/Razor/Generator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Concurrent; 3 | using System.Collections.Generic; 4 | using System.IO; 5 | using System.Linq; 6 | using System.Reflection; 7 | using Microsoft.AspNetCore.Components; 8 | using Microsoft.AspNetCore.Components.Forms; 9 | using Microsoft.AspNetCore.Components.Web; 10 | using Microsoft.AspNetCore.Razor.Language; 11 | using Microsoft.CodeAnalysis; 12 | using Microsoft.CodeAnalysis.CSharp; 13 | using Microsoft.CodeAnalysis.Razor; 14 | 15 | namespace RazorComponentsPreview 16 | { 17 | public class Generator 18 | { 19 | public Generator() 20 | { 21 | Declarations = new Dictionary(); 22 | References = new List(); 23 | 24 | GC.KeepAlive(typeof(EditForm)); 25 | 26 | foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies()) 27 | { 28 | if (!assembly.IsDynamic && assembly.Location != null) 29 | { 30 | References.Add(MetadataReference.CreateFromFile(assembly.Location)); 31 | } 32 | } 33 | 34 | BaseCompilation = CSharpCompilation.Create( 35 | assemblyName: "__Test", 36 | Array.Empty(), 37 | References.ToArray(), 38 | new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary)); 39 | References.Add(BaseCompilation.ToMetadataReference()); 40 | 41 | FileSystem = new TestRazorProjectFileSystem(); 42 | Engine = RazorProjectEngine.Create(RazorConfiguration.Default, FileSystem, builder => 43 | { 44 | builder.Features.Add(new CompilationTagHelperFeature()); 45 | builder.Features.Add(new DefaultMetadataReferenceFeature() { References = References, }); 46 | CompilerFeatures.Register(builder); 47 | }); 48 | } 49 | 50 | private RazorProjectEngine Engine { get; } 51 | private TestRazorProjectFileSystem FileSystem { get; } 52 | private Dictionary Declarations { get; } 53 | private CSharpCompilation BaseCompilation { get; } 54 | private List References { get; } 55 | public CSharpCompilation GetBaseCompilation => BaseCompilation; 56 | public List GetReferences => References; 57 | 58 | private Dictionary RazorCodeDocumentCache { get; } = new Dictionary(); 59 | public void Add(string filePath, string content) 60 | { 61 | if (filePath is null) 62 | { 63 | throw new ArgumentNullException(nameof(filePath)); 64 | } 65 | 66 | var item = new TestRazorProjectItem(filePath, fileKind: FileKinds.Component) 67 | { 68 | Content = content ?? string.Empty, 69 | }; 70 | 71 | FileSystem.Add(item); 72 | } 73 | 74 | 75 | public RazorCodeDocument Update(string filePath, string content) 76 | { 77 | //RazorCodeDocument razorCodeDocument; 78 | //if (RazorCodeDocumentCache.TryGetValue(content,out razorCodeDocument)) 79 | //{ 80 | // return RazorCodeDocumentCache.GetValueOrDefault(content); 81 | //} 82 | 83 | var obj = FileSystem.GetItem(filePath, fileKind: FileKinds.Component); 84 | if (obj.Exists && obj is TestRazorProjectItem item) 85 | { 86 | Declarations.TryGetValue(filePath, out var existing); 87 | 88 | var declaration = Engine.ProcessDeclarationOnly(item); 89 | var declarationText = declaration.GetCSharpDocument().GeneratedCode; 90 | 91 | // Updating a declaration, create a new compilation 92 | if (!string.Equals(existing, declarationText, StringComparison.Ordinal)) 93 | { 94 | Declarations[filePath] = declarationText; 95 | 96 | // Yeet the old one. 97 | References.RemoveAt(References.Count - 1); 98 | 99 | var compilation = BaseCompilation.AddSyntaxTrees(Declarations.Select(kvp => 100 | { 101 | return CSharpSyntaxTree.ParseText(kvp.Value, path: kvp.Key); 102 | })); 103 | References.Add(compilation.ToMetadataReference()); 104 | } 105 | 106 | item.Content = content ?? string.Empty; 107 | var generated = Engine.Process(item); 108 | //RazorCodeDocumentCache.Add(content, generated); 109 | return generated; 110 | } 111 | 112 | throw new InvalidOperationException($"Cannot find item '{filePath}'."); 113 | } 114 | } 115 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.suo 8 | *.user 9 | *.userosscache 10 | *.sln.docstates 11 | 12 | # User-specific files (MonoDevelop/Xamarin Studio) 13 | *.userprefs 14 | 15 | # Build results 16 | [Dd]ebug/ 17 | [Dd]ebugPublic/ 18 | [Rr]elease/ 19 | [Rr]eleases/ 20 | x64/ 21 | x86/ 22 | bld/ 23 | [Bb]in/ 24 | [Oo]bj/ 25 | [Ll]og/ 26 | 27 | # Visual Studio 2015/2017 cache/options directory 28 | .vs/ 29 | # Uncomment if you have tasks that create the project's static files in wwwroot 30 | #wwwroot/ 31 | 32 | # Visual Studio 2017 auto generated files 33 | Generated\ Files/ 34 | 35 | # MSTest test Results 36 | [Tt]est[Rr]esult*/ 37 | [Bb]uild[Ll]og.* 38 | 39 | # NUNIT 40 | *.VisualState.xml 41 | TestResult.xml 42 | 43 | # Build Results of an ATL Project 44 | [Dd]ebugPS/ 45 | [Rr]eleasePS/ 46 | dlldata.c 47 | 48 | # Benchmark Results 49 | BenchmarkDotNet.Artifacts/ 50 | 51 | # .NET Core 52 | project.lock.json 53 | project.fragment.lock.json 54 | artifacts/ 55 | **/Properties/launchSettings.json 56 | 57 | # StyleCop 58 | StyleCopReport.xml 59 | 60 | # Files built by Visual Studio 61 | *_i.c 62 | *_p.c 63 | *_i.h 64 | *.ilk 65 | *.meta 66 | *.obj 67 | *.iobj 68 | *.pch 69 | *.pdb 70 | *.ipdb 71 | *.pgc 72 | *.pgd 73 | *.rsp 74 | *.sbr 75 | *.tlb 76 | *.tli 77 | *.tlh 78 | *.tmp 79 | *.tmp_proj 80 | *.log 81 | *.vspscc 82 | *.vssscc 83 | .builds 84 | *.pidb 85 | *.svclog 86 | *.scc 87 | 88 | # Chutzpah Test files 89 | _Chutzpah* 90 | 91 | # Visual C++ cache files 92 | ipch/ 93 | *.aps 94 | *.ncb 95 | *.opendb 96 | *.opensdf 97 | *.sdf 98 | *.cachefile 99 | *.VC.db 100 | *.VC.VC.opendb 101 | 102 | # Visual Studio profiler 103 | *.psess 104 | *.vsp 105 | *.vspx 106 | *.sap 107 | 108 | # Visual Studio Trace Files 109 | *.e2e 110 | 111 | # TFS 2012 Local Workspace 112 | $tf/ 113 | 114 | # Guidance Automation Toolkit 115 | *.gpState 116 | 117 | # ReSharper is a .NET coding add-in 118 | _ReSharper*/ 119 | *.[Rr]e[Ss]harper 120 | *.DotSettings.user 121 | 122 | # JustCode is a .NET coding add-in 123 | .JustCode 124 | 125 | # TeamCity is a build add-in 126 | _TeamCity* 127 | 128 | # DotCover is a Code Coverage Tool 129 | *.dotCover 130 | 131 | # AxoCover is a Code Coverage Tool 132 | .axoCover/* 133 | !.axoCover/settings.json 134 | 135 | # Visual Studio code coverage results 136 | *.coverage 137 | *.coveragexml 138 | 139 | # NCrunch 140 | _NCrunch_* 141 | .*crunch*.local.xml 142 | nCrunchTemp_* 143 | 144 | # MightyMoose 145 | *.mm.* 146 | AutoTest.Net/ 147 | 148 | # Web workbench (sass) 149 | .sass-cache/ 150 | 151 | # Installshield output folder 152 | [Ee]xpress/ 153 | 154 | # DocProject is a documentation generator add-in 155 | DocProject/buildhelp/ 156 | DocProject/Help/*.HxT 157 | DocProject/Help/*.HxC 158 | DocProject/Help/*.hhc 159 | DocProject/Help/*.hhk 160 | DocProject/Help/*.hhp 161 | DocProject/Help/Html2 162 | DocProject/Help/html 163 | 164 | # Click-Once directory 165 | publish/ 166 | 167 | # Publish Web Output 168 | *.[Pp]ublish.xml 169 | *.azurePubxml 170 | # Note: Comment the next line if you want to checkin your web deploy settings, 171 | # but database connection strings (with potential passwords) will be unencrypted 172 | *.pubxml 173 | *.publishproj 174 | 175 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 176 | # checkin your Azure Web App publish settings, but sensitive information contained 177 | # in these scripts will be unencrypted 178 | PublishScripts/ 179 | 180 | # NuGet Packages 181 | *.nupkg 182 | # The packages folder can be ignored because of Package Restore 183 | **/[Pp]ackages/* 184 | # except build/, which is used as an MSBuild target. 185 | !**/[Pp]ackages/build/ 186 | # Uncomment if necessary however generally it will be regenerated when needed 187 | #!**/[Pp]ackages/repositories.config 188 | # NuGet v3's project.json files produces more ignorable files 189 | *.nuget.props 190 | *.nuget.targets 191 | 192 | # Microsoft Azure Build Output 193 | csx/ 194 | *.build.csdef 195 | 196 | # Microsoft Azure Emulator 197 | ecf/ 198 | rcf/ 199 | 200 | # Windows Store app package directories and files 201 | AppPackages/ 202 | BundleArtifacts/ 203 | Package.StoreAssociation.xml 204 | _pkginfo.txt 205 | *.appx 206 | 207 | # Visual Studio cache files 208 | # files ending in .cache can be ignored 209 | *.[Cc]ache 210 | # but keep track of directories ending in .cache 211 | !*.[Cc]ache/ 212 | 213 | # Others 214 | ClientBin/ 215 | ~$* 216 | *~ 217 | *.dbmdl 218 | *.dbproj.schemaview 219 | *.jfm 220 | *.pfx 221 | *.publishsettings 222 | orleans.codegen.cs 223 | 224 | # Including strong name files can present a security risk 225 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 226 | #*.snk 227 | 228 | # Since there are multiple workflows, uncomment next line to ignore bower_components 229 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 230 | #bower_components/ 231 | 232 | # RIA/Silverlight projects 233 | Generated_Code/ 234 | 235 | # Backup & report files from converting an old project file 236 | # to a newer Visual Studio version. Backup files are not needed, 237 | # because we have git ;-) 238 | _UpgradeReport_Files/ 239 | Backup*/ 240 | UpgradeLog*.XML 241 | UpgradeLog*.htm 242 | ServiceFabricBackup/ 243 | *.rptproj.bak 244 | 245 | # SQL Server files 246 | *.mdf 247 | *.ldf 248 | *.ndf 249 | 250 | # Business Intelligence projects 251 | *.rdl.data 252 | *.bim.layout 253 | *.bim_*.settings 254 | *.rptproj.rsuser 255 | 256 | # Microsoft Fakes 257 | FakesAssemblies/ 258 | 259 | # GhostDoc plugin setting file 260 | *.GhostDoc.xml 261 | 262 | # Node.js Tools for Visual Studio 263 | .ntvs_analysis.dat 264 | node_modules/ 265 | 266 | # Visual Studio 6 build log 267 | *.plg 268 | 269 | # Visual Studio 6 workspace options file 270 | *.opt 271 | 272 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 273 | *.vbw 274 | 275 | # Visual Studio LightSwitch build output 276 | **/*.HTMLClient/GeneratedArtifacts 277 | **/*.DesktopClient/GeneratedArtifacts 278 | **/*.DesktopClient/ModelManifest.xml 279 | **/*.Server/GeneratedArtifacts 280 | **/*.Server/ModelManifest.xml 281 | _Pvt_Extensions 282 | 283 | # Paket dependency manager 284 | .paket/paket.exe 285 | paket-files/ 286 | 287 | # FAKE - F# Make 288 | .fake/ 289 | 290 | # JetBrains Rider 291 | .idea/ 292 | *.sln.iml 293 | 294 | # CodeRush 295 | .cr/ 296 | 297 | # Python Tools for Visual Studio (PTVS) 298 | __pycache__/ 299 | *.pyc 300 | 301 | # Cake - Uncomment if you are using it 302 | # tools/** 303 | # !tools/packages.config 304 | 305 | # Tabs Studio 306 | *.tss 307 | 308 | # Telerik's JustMock configuration file 309 | *.jmconfig 310 | 311 | # BizTalk build output 312 | *.btp.cs 313 | *.btm.cs 314 | *.odx.cs 315 | *.xsd.cs 316 | 317 | # OpenCover UI analysis results 318 | OpenCover/ 319 | 320 | # Azure Stream Analytics local run output 321 | ASALocalRun/ 322 | 323 | # MSBuild Binary and Structured Log 324 | *.binlog 325 | 326 | # NVidia Nsight GPU debugger configuration file 327 | *.nvuser 328 | 329 | # MFractors (Xamarin productivity tool) working folder 330 | .mfractor/ 331 | -------------------------------------------------------------------------------- /src/Sample/BlazorServersideTest/wwwroot/css/open-iconic/font/css/open-iconic-bootstrap.min.css: -------------------------------------------------------------------------------- 1 | @font-face{font-family:Icons;src:url(../fonts/open-iconic.eot);src:url(../fonts/open-iconic.eot?#iconic-sm) format('embedded-opentype'),url(../fonts/open-iconic.woff) format('woff'),url(../fonts/open-iconic.ttf) format('truetype'),url(../fonts/open-iconic.otf) format('opentype'),url(../fonts/open-iconic.svg#iconic-sm) format('svg');font-weight:400;font-style:normal}.oi{position:relative;top:1px;display:inline-block;speak:none;font-family:Icons;font-style:normal;font-weight:400;line-height:1;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}.oi:empty:before{width:1em;text-align:center;box-sizing:content-box}.oi.oi-align-center:before{text-align:center}.oi.oi-align-left:before{text-align:left}.oi.oi-align-right:before{text-align:right}.oi.oi-flip-horizontal:before{-webkit-transform:scale(-1,1);-ms-transform:scale(-1,1);transform:scale(-1,1)}.oi.oi-flip-vertical:before{-webkit-transform:scale(1,-1);-ms-transform:scale(-1,1);transform:scale(1,-1)}.oi.oi-flip-horizontal-vertical:before{-webkit-transform:scale(-1,-1);-ms-transform:scale(-1,1);transform:scale(-1,-1)}.oi-account-login:before{content:'\e000'}.oi-account-logout:before{content:'\e001'}.oi-action-redo:before{content:'\e002'}.oi-action-undo:before{content:'\e003'}.oi-align-center:before{content:'\e004'}.oi-align-left:before{content:'\e005'}.oi-align-right:before{content:'\e006'}.oi-aperture:before{content:'\e007'}.oi-arrow-bottom:before{content:'\e008'}.oi-arrow-circle-bottom:before{content:'\e009'}.oi-arrow-circle-left:before{content:'\e00a'}.oi-arrow-circle-right:before{content:'\e00b'}.oi-arrow-circle-top:before{content:'\e00c'}.oi-arrow-left:before{content:'\e00d'}.oi-arrow-right:before{content:'\e00e'}.oi-arrow-thick-bottom:before{content:'\e00f'}.oi-arrow-thick-left:before{content:'\e010'}.oi-arrow-thick-right:before{content:'\e011'}.oi-arrow-thick-top:before{content:'\e012'}.oi-arrow-top:before{content:'\e013'}.oi-audio-spectrum:before{content:'\e014'}.oi-audio:before{content:'\e015'}.oi-badge:before{content:'\e016'}.oi-ban:before{content:'\e017'}.oi-bar-chart:before{content:'\e018'}.oi-basket:before{content:'\e019'}.oi-battery-empty:before{content:'\e01a'}.oi-battery-full:before{content:'\e01b'}.oi-beaker:before{content:'\e01c'}.oi-bell:before{content:'\e01d'}.oi-bluetooth:before{content:'\e01e'}.oi-bold:before{content:'\e01f'}.oi-bolt:before{content:'\e020'}.oi-book:before{content:'\e021'}.oi-bookmark:before{content:'\e022'}.oi-box:before{content:'\e023'}.oi-briefcase:before{content:'\e024'}.oi-british-pound:before{content:'\e025'}.oi-browser:before{content:'\e026'}.oi-brush:before{content:'\e027'}.oi-bug:before{content:'\e028'}.oi-bullhorn:before{content:'\e029'}.oi-calculator:before{content:'\e02a'}.oi-calendar:before{content:'\e02b'}.oi-camera-slr:before{content:'\e02c'}.oi-caret-bottom:before{content:'\e02d'}.oi-caret-left:before{content:'\e02e'}.oi-caret-right:before{content:'\e02f'}.oi-caret-top:before{content:'\e030'}.oi-cart:before{content:'\e031'}.oi-chat:before{content:'\e032'}.oi-check:before{content:'\e033'}.oi-chevron-bottom:before{content:'\e034'}.oi-chevron-left:before{content:'\e035'}.oi-chevron-right:before{content:'\e036'}.oi-chevron-top:before{content:'\e037'}.oi-circle-check:before{content:'\e038'}.oi-circle-x:before{content:'\e039'}.oi-clipboard:before{content:'\e03a'}.oi-clock:before{content:'\e03b'}.oi-cloud-download:before{content:'\e03c'}.oi-cloud-upload:before{content:'\e03d'}.oi-cloud:before{content:'\e03e'}.oi-cloudy:before{content:'\e03f'}.oi-code:before{content:'\e040'}.oi-cog:before{content:'\e041'}.oi-collapse-down:before{content:'\e042'}.oi-collapse-left:before{content:'\e043'}.oi-collapse-right:before{content:'\e044'}.oi-collapse-up:before{content:'\e045'}.oi-command:before{content:'\e046'}.oi-comment-square:before{content:'\e047'}.oi-compass:before{content:'\e048'}.oi-contrast:before{content:'\e049'}.oi-copywriting:before{content:'\e04a'}.oi-credit-card:before{content:'\e04b'}.oi-crop:before{content:'\e04c'}.oi-dashboard:before{content:'\e04d'}.oi-data-transfer-download:before{content:'\e04e'}.oi-data-transfer-upload:before{content:'\e04f'}.oi-delete:before{content:'\e050'}.oi-dial:before{content:'\e051'}.oi-document:before{content:'\e052'}.oi-dollar:before{content:'\e053'}.oi-double-quote-sans-left:before{content:'\e054'}.oi-double-quote-sans-right:before{content:'\e055'}.oi-double-quote-serif-left:before{content:'\e056'}.oi-double-quote-serif-right:before{content:'\e057'}.oi-droplet:before{content:'\e058'}.oi-eject:before{content:'\e059'}.oi-elevator:before{content:'\e05a'}.oi-ellipses:before{content:'\e05b'}.oi-envelope-closed:before{content:'\e05c'}.oi-envelope-open:before{content:'\e05d'}.oi-euro:before{content:'\e05e'}.oi-excerpt:before{content:'\e05f'}.oi-expand-down:before{content:'\e060'}.oi-expand-left:before{content:'\e061'}.oi-expand-right:before{content:'\e062'}.oi-expand-up:before{content:'\e063'}.oi-external-link:before{content:'\e064'}.oi-eye:before{content:'\e065'}.oi-eyedropper:before{content:'\e066'}.oi-file:before{content:'\e067'}.oi-fire:before{content:'\e068'}.oi-flag:before{content:'\e069'}.oi-flash:before{content:'\e06a'}.oi-folder:before{content:'\e06b'}.oi-fork:before{content:'\e06c'}.oi-fullscreen-enter:before{content:'\e06d'}.oi-fullscreen-exit:before{content:'\e06e'}.oi-globe:before{content:'\e06f'}.oi-graph:before{content:'\e070'}.oi-grid-four-up:before{content:'\e071'}.oi-grid-three-up:before{content:'\e072'}.oi-grid-two-up:before{content:'\e073'}.oi-hard-drive:before{content:'\e074'}.oi-header:before{content:'\e075'}.oi-headphones:before{content:'\e076'}.oi-heart:before{content:'\e077'}.oi-home:before{content:'\e078'}.oi-image:before{content:'\e079'}.oi-inbox:before{content:'\e07a'}.oi-infinity:before{content:'\e07b'}.oi-info:before{content:'\e07c'}.oi-italic:before{content:'\e07d'}.oi-justify-center:before{content:'\e07e'}.oi-justify-left:before{content:'\e07f'}.oi-justify-right:before{content:'\e080'}.oi-key:before{content:'\e081'}.oi-laptop:before{content:'\e082'}.oi-layers:before{content:'\e083'}.oi-lightbulb:before{content:'\e084'}.oi-link-broken:before{content:'\e085'}.oi-link-intact:before{content:'\e086'}.oi-list-rich:before{content:'\e087'}.oi-list:before{content:'\e088'}.oi-location:before{content:'\e089'}.oi-lock-locked:before{content:'\e08a'}.oi-lock-unlocked:before{content:'\e08b'}.oi-loop-circular:before{content:'\e08c'}.oi-loop-square:before{content:'\e08d'}.oi-loop:before{content:'\e08e'}.oi-magnifying-glass:before{content:'\e08f'}.oi-map-marker:before{content:'\e090'}.oi-map:before{content:'\e091'}.oi-media-pause:before{content:'\e092'}.oi-media-play:before{content:'\e093'}.oi-media-record:before{content:'\e094'}.oi-media-skip-backward:before{content:'\e095'}.oi-media-skip-forward:before{content:'\e096'}.oi-media-step-backward:before{content:'\e097'}.oi-media-step-forward:before{content:'\e098'}.oi-media-stop:before{content:'\e099'}.oi-medical-cross:before{content:'\e09a'}.oi-menu:before{content:'\e09b'}.oi-microphone:before{content:'\e09c'}.oi-minus:before{content:'\e09d'}.oi-monitor:before{content:'\e09e'}.oi-moon:before{content:'\e09f'}.oi-move:before{content:'\e0a0'}.oi-musical-note:before{content:'\e0a1'}.oi-paperclip:before{content:'\e0a2'}.oi-pencil:before{content:'\e0a3'}.oi-people:before{content:'\e0a4'}.oi-person:before{content:'\e0a5'}.oi-phone:before{content:'\e0a6'}.oi-pie-chart:before{content:'\e0a7'}.oi-pin:before{content:'\e0a8'}.oi-play-circle:before{content:'\e0a9'}.oi-plus:before{content:'\e0aa'}.oi-power-standby:before{content:'\e0ab'}.oi-print:before{content:'\e0ac'}.oi-project:before{content:'\e0ad'}.oi-pulse:before{content:'\e0ae'}.oi-puzzle-piece:before{content:'\e0af'}.oi-question-mark:before{content:'\e0b0'}.oi-rain:before{content:'\e0b1'}.oi-random:before{content:'\e0b2'}.oi-reload:before{content:'\e0b3'}.oi-resize-both:before{content:'\e0b4'}.oi-resize-height:before{content:'\e0b5'}.oi-resize-width:before{content:'\e0b6'}.oi-rss-alt:before{content:'\e0b7'}.oi-rss:before{content:'\e0b8'}.oi-script:before{content:'\e0b9'}.oi-share-boxed:before{content:'\e0ba'}.oi-share:before{content:'\e0bb'}.oi-shield:before{content:'\e0bc'}.oi-signal:before{content:'\e0bd'}.oi-signpost:before{content:'\e0be'}.oi-sort-ascending:before{content:'\e0bf'}.oi-sort-descending:before{content:'\e0c0'}.oi-spreadsheet:before{content:'\e0c1'}.oi-star:before{content:'\e0c2'}.oi-sun:before{content:'\e0c3'}.oi-tablet:before{content:'\e0c4'}.oi-tag:before{content:'\e0c5'}.oi-tags:before{content:'\e0c6'}.oi-target:before{content:'\e0c7'}.oi-task:before{content:'\e0c8'}.oi-terminal:before{content:'\e0c9'}.oi-text:before{content:'\e0ca'}.oi-thumb-down:before{content:'\e0cb'}.oi-thumb-up:before{content:'\e0cc'}.oi-timer:before{content:'\e0cd'}.oi-transfer:before{content:'\e0ce'}.oi-trash:before{content:'\e0cf'}.oi-underline:before{content:'\e0d0'}.oi-vertical-align-bottom:before{content:'\e0d1'}.oi-vertical-align-center:before{content:'\e0d2'}.oi-vertical-align-top:before{content:'\e0d3'}.oi-video:before{content:'\e0d4'}.oi-volume-high:before{content:'\e0d5'}.oi-volume-low:before{content:'\e0d6'}.oi-volume-off:before{content:'\e0d7'}.oi-warning:before{content:'\e0d8'}.oi-wifi:before{content:'\e0d9'}.oi-wrench:before{content:'\e0da'}.oi-x:before{content:'\e0db'}.oi-yen:before{content:'\e0dc'}.oi-zoom-in:before{content:'\e0dd'}.oi-zoom-out:before{content:'\e0de'} -------------------------------------------------------------------------------- /src/RazorComponentsPreview/Htmlizer/Htmlizer.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) .NET Foundation. All rights reserved. 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 | 4 | using Microsoft.AspNetCore.Components.RenderTree; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Diagnostics; 8 | using System.Diagnostics.CodeAnalysis; 9 | using System.Text.Encodings.Web; 10 | 11 | namespace RazorComponentsPreview 12 | { 13 | [SuppressMessage("Usage", "BL0006:Do not use RenderTree types", Justification = "")] 14 | internal class Htmlizer 15 | { 16 | private static readonly HtmlEncoder _htmlEncoder = HtmlEncoder.Default; 17 | 18 | private static readonly HashSet _selfClosingElements = new HashSet(StringComparer.OrdinalIgnoreCase) 19 | { 20 | "area", "base", "br", "col", "embed", "hr", "img", "input", "link", "meta", "param", "source", "track", "wbr" 21 | }; 22 | 23 | public static string GetHtml(TestRenderer renderer, int componentId) 24 | { 25 | var frames = renderer.GetCurrentRenderTreeFrames(componentId); 26 | 27 | var kk = ""; 28 | for (int i = 0; i < frames.Count; i++) 29 | { 30 | kk += frames.Array[i].AttributeName; 31 | } 32 | 33 | var context = new HtmlRenderingContext(renderer); 34 | var newPosition = RenderFrames(context, frames, 0, frames.Count); 35 | Debug.Assert(newPosition == frames.Count); 36 | 37 | return string.Join(string.Empty, context.Result); 38 | } 39 | 40 | private static int RenderFrames(HtmlRenderingContext context, ArrayRange frames, int position, int maxElements) 41 | { 42 | var nextPosition = position; 43 | var endPosition = position + maxElements; 44 | while (position < endPosition) 45 | { 46 | nextPosition = RenderCore(context, frames, position); 47 | if (position == nextPosition) 48 | { 49 | throw new InvalidOperationException("We didn't consume any input."); 50 | } 51 | position = nextPosition; 52 | } 53 | 54 | return nextPosition; 55 | } 56 | 57 | private static int RenderCore( 58 | HtmlRenderingContext context, 59 | ArrayRange frames, 60 | int position) 61 | { 62 | ref var frame = ref frames.Array[position]; 63 | switch (frame.FrameType) 64 | { 65 | case RenderTreeFrameType.Element: 66 | return RenderElement(context, frames, position); 67 | case RenderTreeFrameType.Attribute: 68 | throw new InvalidOperationException($"Attributes should only be encountered within {nameof(RenderElement)}"); 69 | case RenderTreeFrameType.Text: 70 | context.Result.Add(_htmlEncoder.Encode(frame.TextContent)); 71 | return ++position; 72 | case RenderTreeFrameType.Markup: 73 | context.Result.Add(frame.MarkupContent); 74 | return ++position; 75 | case RenderTreeFrameType.Component: 76 | return RenderChildComponent(context, frames, position); 77 | case RenderTreeFrameType.Region: 78 | return RenderFrames(context, frames, position + 1, frame.RegionSubtreeLength - 1); 79 | case RenderTreeFrameType.ElementReferenceCapture: 80 | case RenderTreeFrameType.ComponentReferenceCapture: 81 | return ++position; 82 | default: 83 | throw new InvalidOperationException($"Invalid element frame type '{frame.FrameType}'."); 84 | } 85 | } 86 | 87 | private static int RenderChildComponent( 88 | HtmlRenderingContext context, 89 | ArrayRange frames, 90 | int position) 91 | { 92 | ref var frame = ref frames.Array[position]; 93 | var childFrames = context.Renderer.GetCurrentRenderTreeFrames(frame.ComponentId); 94 | RenderFrames(context, childFrames, 0, childFrames.Count); 95 | return position + frame.ComponentSubtreeLength; 96 | } 97 | 98 | private static int RenderElement( 99 | HtmlRenderingContext context, 100 | ArrayRange frames, 101 | int position) 102 | { 103 | ref var frame = ref frames.Array[position]; 104 | var result = context.Result; 105 | result.Add("<"); 106 | result.Add(frame.ElementName); 107 | var afterAttributes = RenderAttributes(context, frames, position + 1, frame.ElementSubtreeLength - 1, out var capturedValueAttribute); 108 | 109 | // When we see an