Commit Graph

755 Commits

Author SHA1 Message Date
Steve Sanderson 18df30568c Support "Fixed" mode for <CascadingValue> 2018-10-18 09:57:41 +01:00
Steve Sanderson 4a6f471d12 Add Cascading flag to Parameter (#1564)
... so that components that pass through an arbitrary set of parameters can choose to filter out cascading ones if they want.
2018-10-18 09:37:46 +01:00
Meir Blachman dd807a6d70 using Microsoft.Extensions.CommandLineUtils for blazor-cli 2018-10-17 22:33:03 -07:00
Lukas Bickel fb6427a46a escape quotes in event handler attribute content 2018-10-17 14:18:22 -07:00
Steve Sanderson efbf2c5678 When tracing dependencies *without* linking, don't fail the build if there are unresolved dependencies
There are legitimate use cases for referencing BCL assemblies that *aren't* in the Mono WebAssembly BCL, particularly for Blazor-on-the-server which runs on CoreCLR (and hence supports a broader BCL) anyway.
2018-10-16 23:57:40 +01:00
Zou Wei 7918fe2c39 Update README.md
Add links to the docs.
2018-10-15 13:12:56 +01:00
Steve Sanderson 211ad636fd Cascading parameters (#1545)
* Add Provider component

* Implement discovery and matching rules for tree parameters

* Remove artificial component hierarchy unit tests now they are redundant

* Refactor: Have RenderTreeFrame point to the ComponentState instead of IComponent

... so we can more quickly find associated tree param state without having to do lookups based on the componentId.

Also rename AssignComponentId to AttachAndInitComponent to be more descriptive.

* Refactor: Add shared code path for updating parameters so there's only one place to attach tree parameters

Now framework code should no longer call IComponent.SetParameters directly, except if it knows it's definitely dealing with a root component.

* Refactor: Simplify Parameter by making it hold the name/value directly

This will be necessary for tree parameters, which don't correspond to any RenderTreeFrame

* Refactor: Wrap ParameterEnumerator logic in extra level of iterator so we can also add one for iterating tree params

* Extend ParameterEnumerator to list tree parameters too

* Include tree parameters in SetParameters calls

* Refactor: Move parameter change detection logic into separate utility class

... so we include https://github.com/dotnet/jsinterop/pull/3

* Refactor: Move tree parameter tests from RendererTest.cs their own file

* Have Provider re-render consumers when value changes. Unit tests in next
commit.

* Components that accept tree parameters need to snapshot their direct params for later replay

* Empty commit to reawaken CI

* CR: Make name matching case-insensitive

* Refactor: Rename Provider/TreeParameter to
CascadingValue/CascadingParameter

* Add dedicated [CascadingParameter] attribute. Remove FromTree flag.

* CR: CascadingParameterState cleanups

* CR: Extra unit test

* CR: arguments/parameters

* CR: Enumerator improvements

* Fix test
2018-10-15 11:11:46 +01:00
Steve Sanderson fa2b61773a In ComponentState, track parent ComponentState. Be explicit that Renderer only lets you attach root components. 2018-10-12 09:49:28 +01:00
Steve Sanderson c05b98f9cb Update to latest JSInterop
... so we include https://github.com/dotnet/jsinterop/pull/3
2018-10-10 09:54:27 +01:00
Steve Sanderson 7012ea9d03 Avoid OnAfterRender allocating to capture 'this' 2018-10-08 09:39:18 +01:00
alenros d414ed107f updated MSRC link 2018-10-05 14:46:52 +01:00
simpman4 88cd4573a6 Added a "." to the end of ln. 41 2018-10-05 14:45:48 +01:00
Daniel Roth 04b87ef066 Update Microsoft.AspNetCore.Blazor.Templates.nuspec 2018-10-02 16:59:47 +01:00
Ryan Nowak 737a6003f5 Add required fields to build nuspec 2018-10-02 10:39:21 +01:00
Nate McMaster f6b64e5d26 Upgrade KoreBuild (#1498)
* remove sources.props and use NuGet.config. Source.props is only necessary for products that bulid in ProdCon, which Blazor does not
* Remove code signing glue code. This is part of KoreBuild now
* Update SDK to 2.1.400
* Update certificate names used for code-signing to use SHA2
2018-10-01 11:13:09 -07:00
Steve Sanderson 234f089a0a Always use forward-slashes in template primaryOutputs. Fixes #1497. 2018-10-01 13:17:11 +01:00
Steve Sanderson 0ca361a78a Make HttpClientHandler wiping more conservative. Fixes #1484 2018-10-01 12:44:05 +01:00
Nate McMaster 074f2a423d Switch queue name for dnceng and rename yaml files directory (#1481)
Update queue names to to work on https://dev.azure.com/dnceng. Also, react to VSTS => Azure DevOps rebranding.
2018-09-25 17:24:04 -07:00
Ryan Nowak 31b5119c64 fix build of VSIX 2018-09-25 13:52:25 -07:00
Steve Sanderson 824e0097f5 Bump version to 0.7.0-preview1-* 2018-09-25 16:24:23 +01:00
Ryan Nowak 959b45f4e6 Fix #1478 - Razor.Design not getting replaced in templates (#1479)
* Fix #1478 - Razor.Design not getting replaced in templates
2018-09-25 09:27:28 +01:00
Ryan Nowak 6f383a0f0f Adds support for 'Context' parameters on components (#1470)
Adds support for 'Context' parameters on components

This change allows you to set the parameter name of a parameterized child content by using the `Context` attribute on the component. The `Context` attribute will be defined (and shown by completion) when the component has one or more declared parameterized (`RenderFragment<>`) child content parameters.

This is nice for cases where you are using implicit child content:

```
<ol>
  <Repeater Items="People" Context="person">
    <li>@person.FirstName</li>
  </Repeater>
</ol>
```

 or, when you have multiple child content elements and want them all to have the same parameter name:

 ```
<MyComponent Items="People" Context="person">
    <ChildContent1><div>@person.FirstName</div></ChildContent1>
    <ChildContent2><div>@person.LastName</div></ChildContent2>
</Repeater>
```

The parameter name can be overridden by using the `Context` parameter on the child content element:

 ```
<MyComponent Items="People" Context="person">
    <ChildContent1 Context="item"><div>@item.FirstName</div></ChildContent1>
    <ChildContent2><div>@person.LastName</div></ChildContent2>
</Repeater>
```

If the component defines a `Context` parameter already then we won't synthesize one - your component's parameter will work exactly as it did before this feature.
2018-09-24 12:22:16 -07:00
Ryan Nowak 984fabb89f Correct template package reference 2018-09-24 10:42:59 -07:00
KristianJakubik 067d245f94 Fix negative route params. Fixes #1437 2018-09-24 17:55:21 +01:00
Steve Sanderson 0942b5aa0d Switch Hosted template to UseBlazor<Startup> for consistency with server-side template. Fixes #1473 2018-09-24 17:54:46 +01:00
Ryan Nowak 86b532cd47 Undo hardcoded Razor.Design in templates 2018-09-22 16:39:27 -07:00
Ryan Nowak 5459107832 Fix #1298 (#1309)
* Fix #1298

This change lifts our Razor dependencies to 2.1.1. This is needed
because by default ASP.NET Core projects will depend on 2.1.1 - which
results in a conflict trying to use the Blazor compiler. The Blazor
compiler will load the 2.1.0 msbuild tasks, which then break loading the
2.1.1 tasks.

Since this is happening in the MSBuild process, we can't really write
any code to sort this out. We have to make sure the versions match.

In general the guidance for ASP.NET Core is that projects will **compile
against** 2.1.1 so this won't be a problem in the future unless a user
project specifically lifts ASP.NET Core to a higher version. If that's
the case they will also have to live `Microsoft.AspNetCore.Razor.Design`
to match.
2018-09-21 13:29:40 -07:00
Ryan Nowak 4f51d90157 Fix #1399 - crash on start-end syntax for void element
We weren't correctly recovering when a void element is written as a
start-end pair. This change cleans up some of the plumbing around
end-tag handling and adds recognition for this case.

Added a new bespoke diagnostic for the void element case.
2018-09-21 12:54:44 -07:00
Ryan Nowak f601b6d3d2 Fix #1450 Skip compilation on non-C# projects
This change skips our 'temp' compilation that we do to implement 2-phase
build for defining components in .cshtml when the project is not C# OR
when the project has no .cshtml files.

This should make the rest of the build-time Blazor functionality work
for non-C# projects.

This should also make the build faster when you have the Blazor targets
imported in a C# project with no .cshtml files.
2018-09-20 14:27:08 -07:00
Ryan Nowak 100382bf71 Add Type Inference for Generic-Typed Components
This change allows you to use generic-typed components without
explicitly specify type arguments.

**Before:**
```
<Grid Items="@MyItems" TItem="Person">
...
</Grid>
```

**After:**
```
<Grid Items="@MyItems">
...
</Grid>
```

Where possible, the type of the component will be inferred based on the
values passed to component parameters. This won't work like magic, you
have to specify parameters that provide type arguments for all of the
component's type parameters.

This is a best effort system, and it's largely based on the limitations
and behaviours of generic type inference in C#. We think it will work
well with most Blazor features and for most reasonable components. You
should not forget it's easy to specify type arguments, because you may
still have to in some cases.

In particular you may notice issues if you are trying to use a generic
typed component where all of the parameters are delegates or templates.
Type inference for delegates/lambdas in C# is based on the context. Any
time you combine generics and delegates it's easy to get into a scenario
where the compiler won't infer the correct type, or will give up.

----
The type inference feature works by generating a 'thunk' method in
*caller* that can act as a site for type inference (C# does not support
inference on constructors).

For our grid example above, the non-inferenced code will look something
like:
```
builder.OpenComponent<Grid<Person>>(0);
builder.AddAttribute(1, "Items", MyItems);
builder.CloseComponent();
```

Note that we can only write the type `Grid<Person>` because you wrote
`Person` in your code. What you type in the `TItem` attribute value gets
inserted into the generated code such that it fills in the generic type
parameter.

On the other hand, if you want is to infer the type, we have to do some
compiler magic. That looks like:
```
__Blazor.(long generated name).TypeInference.CreateGrid_0();
...

// elsewhere in the file
internal static class TypeInference
{
    public static void CreateGrid_0<TItem>(RenderTreeBuilder builder,
    int seq, int __seq0, global::System.Collections.Generic.List<TItem>
    __arg0)
        {
	        builder.OpenComponent<Grid<TItem>>(seq);
		        builder.AddAttribute(__seq0, "Items", __arg0);
			        builder.CloseComponent();
				    }
				    }
				    ```

				    This allows us to rely on the C#
				    compiler for itype inference.
2018-09-20 12:19:26 -07:00
Steve Sanderson b2f73492f5 Fix method wiping (#1448)
* Fix wiping assemblies that contain references to others in same directory

* Fix generated IL for reporting calls to wiped methods

* Add E2E test for method wiping
2018-09-20 10:20:37 +01:00
Howard Richards d4e2c28145 Amend link for [docs]
The current link for docs points to the wiki which does not have a lot of documentation. Suggest pointing to https://blazor.net/docs/index.html
2018-09-19 11:36:14 -07:00
Steve Sanderson 0fd0fa3b79 Include TPN file in VSIX and all nupkg files built from "src" directory 2018-09-19 13:35:01 +01:00
Steve Sanderson 2f69aa90e5 Revert "Update VSTS queue name", because that change is intended for a
different VSTS instance only.

This reverts commit 32681bf44fc44c2711b5598d5c2481e6accf1ce0.
2018-09-18 22:21:38 +01:00
Steve Sanderson 52d8d4a00f Update VSTS queue name 2018-09-18 22:16:38 +01:00
Steve Sanderson 27189875fb Fix build targets bug (incremental build input was based on wrong property name) 2018-09-18 12:57:50 +01:00
Ryan Nowak 354752cf16 Add support for generic-typed components (#1417)
* Add the ability to discover generic types/properties

* Add @typeparam directive

Adds the ability to declare a generic-typed component using Razor.

* Add a 'type parameter' property to generic components

* Adds the ability to consume generic-typed components
2018-09-16 14:01:15 -07:00
Suchiman b99d805bc0 ILWipe: Remove AsyncStateMachineAttribute 2018-09-14 10:33:32 +01:00
Steve Sanderson fa19f1c4ac Update linker config following upgrade to linker 07c0d489b2c335d0ecddc5a427ef29d39afc8d84 2018-09-13 12:44:08 +01:00
Steve Sanderson 6ff3674b16 Refactor server-side blazor startup to allow Azure SignalR. Fixes #1227 (#1396)
* Move startup action config into AddServerSideBlazor, so that UseServerSideBlazor is reduced to trivial shorthand that can become optional

* Make BlazorHub public so developers can use it with UseAzureSignalR

* Move BlazorHub to Microsoft.AspNetCore.Blazor.Server namespace for easier consumption

* Add notes

* Have E2E tests validate that devs don't have to call UseServerSideBlazor

* Add forgotten tweak

* CR: Document that BlazorHub methods are not intended for application use.

* CR: Rename extension method to UseSignalRWithBlazorHub

* CR: TryAdd
2018-09-11 09:55:27 +01:00
Ryan Nowak d4cbb86f46 Add Support for Templated Components (#1404)
* Test namespace cleanup

* Add recognication for RenderFragment in tag helpers

* Remove dead code from node writers

* refactor type check

* Continue to treat child content as a delegate in codegen

* Add extension to enumerate child content

* Reorganize code generation tests

These were growing a bit disorganized, and weren't really result in good
code reuse.

* fix test base class

* Add some child-content tests

* Add an explicit node for ChildContent

Adds a strongly typed node to represent a 'ChildContent' and what it
contains. This allows us to simplify the code generation path,
detect/processes more issues in IR passes, and will be essential for
supporting multiple child content.

* Ignore ChildContent in components when it's just whitespace

* Add diagnostic for duplicate child content

* Add support for explicit child content elements

Precursor to support for multiple child content items

* Add support for multiple child-content elements

* Change delegate signature for RenderFragment<T>

* Clean up Tag Helper constants

* Allow RenderFragment<T> as a child content

* Allow renaming the template parameter

* Improve error message for invalid child content

* Add diagnostic for repeated child content parameter names
2018-09-10 18:59:51 -07:00
Andrii Kurdiumov 6546c55f4c Removal of global.json from the template
I remove only global.json from the template, and leave global.json in the repository root, since it is required for the build.
See #1324
2018-09-07 12:44:52 +01:00
Ryan Nowak 953479ce21 Fix path to our templates 2018-09-05 14:00:35 -07:00
Steve Sanderson facc1e466e Pre-trim Mono BCL (#1382)
* Add "ilwipe" build command

* Perform BCL wipe as part of build

* Simplify by converting ilwipe command to process entire directories

* Clean up the build
2018-09-05 10:03:54 +01:00
Steve Sanderson b004ffdc24 Set BrowserHttpMessageHandler as the default handler when running on Mono WebAssembly 2018-09-03 17:47:05 +01:00
Steve Sanderson 03ff6ca022 Update jsinterop to version that supports Mono bfc35fc6e65 2018-09-03 17:47:05 +01:00
Steve Sanderson 38b45d82c7 Update linker config following update to Mono bfc35fc6e65 2018-09-03 17:47:05 +01:00
Steve Sanderson 0aa7f13008 Update Mono to bfc35fc6e65 - have not yet rebuilt binaries 2018-09-03 17:47:05 +01:00
cores-system 223a2fed97 Don't intercept clicks for links that open in external frames #1352 (#1354) 2018-09-03 10:31:37 +01:00
Ryan Nowak c97cb8c18b Add support for Razor templates
Adds support for Razor templates and RenderFragment<T>.

Razor templates are a little-known Razor feature that looks like:
```
@<tag>....<tag>
```

It's so little known that it's not even covered in our docs, but it's
been around for many many years. This features hasn't been implemented
until now for Blazor, and this feature brings it back as a build
building block for templated components (more to come).

In Blazor land a template like:
```
@{ RenderFragment<Person> template = @<div>@item.Name</div>; }
```

complies to code like:
```
RenderFragment<Person> template = (__builder, item) =>
{
    __builder.OpenElement(...);
    ...
    __builder.CloseElement(...);
}
```

Since the declaration always has a generic type parameter inside, it
needs to be in a context where the type is known.. ie: not with `var`.

See tests for ways to consume templates.

NOTE: There are the following caveats for templates
- Templates require a single root element.
- Templates don't work in the `@functions { }` block

These limitations are baked into the core of Razor and will take a while
for us to address (v3.0).
2018-08-31 19:10:42 -07:00