Skip to content

Commit

Permalink
Update bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
albertwoo committed May 17, 2024
1 parent d49a325 commit 49a4623
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ open Fun.Blazor.Operators
open Microsoft.AspNetCore.Components.Authorization.DslInternals

type AuthorizeViewCoreBuilder<'FunBlazorGeneric when 'FunBlazorGeneric :> Microsoft.AspNetCore.Components.IComponent>() =
inherit ComponentWithDomAndChildAttrBuilder<'FunBlazorGeneric>()
inherit ComponentWithDomAttrBuilder<'FunBlazorGeneric>()
[<CustomOperation("ChildContent")>] member inline _.ChildContent ([<InlineIfLambda>] render: AttrRenderFragment, fn: Microsoft.AspNetCore.Components.Authorization.AuthenticationState -> NodeRenderFragment) = render ==> html.renderFragment("ChildContent", fn)
[<CustomOperation("NotAuthorized")>] member inline _.NotAuthorized ([<InlineIfLambda>] render: AttrRenderFragment, fn: Microsoft.AspNetCore.Components.Authorization.AuthenticationState -> NodeRenderFragment) = render ==> html.renderFragment("NotAuthorized", fn)
[<CustomOperation("Authorized")>] member inline _.Authorized ([<InlineIfLambda>] render: AttrRenderFragment, fn: Microsoft.AspNetCore.Components.Authorization.AuthenticationState -> NodeRenderFragment) = render ==> html.renderFragment("Authorized", fn)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<TrimMode>link</TrimMode>
<IsTrimmable>true</IsTrimmable>
<Version>8.0.4</Version>
<Version>8.0.5</Version>
</PropertyGroup>
<ItemGroup>
<Compile Include="Fun.Blazor.Bindings\Microsoft.AspNetCore.Components.Authorization.fs" />
</ItemGroup>
<ItemGroup>
<PackageReference FunBlazor="" FunBlazorNamespace="Microsoft.AspNetCore.Components.Authorization" Include="Microsoft.AspNetCore.Components.Authorization" Version="8.0.4" />
<PackageReference FunBlazor="" FunBlazorNamespace="Microsoft.AspNetCore.Components.Authorization" Include="Microsoft.AspNetCore.Components.Authorization" Version="8.0.5" />
</ItemGroup>
<ItemGroup>
<PackageReference Update="FSharp.Core" Version="6.0.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<TrimMode>link</TrimMode>
<IsTrimmable>true</IsTrimmable>
<Version>8.0.4</Version>
<Version>8.0.5</Version>
</PropertyGroup>
<ItemGroup>
<Compile Include="Fun.Blazor.Bindings\Microsoft.AspNetCore.Components.QuickGrid.fs" />
</ItemGroup>
<ItemGroup>
<PackageReference FunBlazor="" FunBlazorNamespace="Microsoft.AspNetCore.Components.QuickGrid" Include="Microsoft.AspNetCore.Components.QuickGrid" Version="8.0.4" />
<PackageReference FunBlazor="" FunBlazorNamespace="Microsoft.AspNetCore.Components.QuickGrid" Include="Microsoft.AspNetCore.Components.QuickGrid" Version="8.0.5" />
</ItemGroup>
<ItemGroup>
<PackageReference Update="FSharp.Core" Version="6.0.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ open Fun.Blazor.Operators
open Microsoft.AspNetCore.Components.DslInternals

type VirtualizeBuilder<'FunBlazorGeneric, 'TItem when 'FunBlazorGeneric :> Microsoft.AspNetCore.Components.IComponent>() =
inherit ComponentWithDomAndChildAttrBuilder<'FunBlazorGeneric>()
inherit ComponentWithDomAttrBuilder<'FunBlazorGeneric>()
[<CustomOperation("ChildContent")>] member inline _.ChildContent ([<InlineIfLambda>] render: AttrRenderFragment, fn: 'TItem -> NodeRenderFragment) = render ==> html.renderFragment("ChildContent", fn)
[<CustomOperation("ItemContent")>] member inline _.ItemContent ([<InlineIfLambda>] render: AttrRenderFragment, fn: 'TItem -> NodeRenderFragment) = render ==> html.renderFragment("ItemContent", fn)
[<CustomOperation("Placeholder")>] member inline _.Placeholder ([<InlineIfLambda>] render: AttrRenderFragment, fn: Microsoft.AspNetCore.Components.Web.Virtualization.PlaceholderContext -> NodeRenderFragment) = render ==> html.renderFragment("Placeholder", fn)
Expand All @@ -100,7 +100,7 @@ open Fun.Blazor.Operators
open Microsoft.AspNetCore.Components.DslInternals

type EditFormBuilder<'FunBlazorGeneric when 'FunBlazorGeneric :> Microsoft.AspNetCore.Components.IComponent>() =
inherit ComponentWithDomAndChildAttrBuilder<'FunBlazorGeneric>()
inherit ComponentWithDomAttrBuilder<'FunBlazorGeneric>()
[<CustomOperation("AdditionalAttributes")>] member inline _.AdditionalAttributes ([<InlineIfLambda>] render: AttrRenderFragment, x: System.Collections.Generic.IReadOnlyDictionary<System.String, System.Object>) = render ==> ("AdditionalAttributes" => x)
[<CustomOperation("EditContext")>] member inline _.EditContext ([<InlineIfLambda>] render: AttrRenderFragment, x: Microsoft.AspNetCore.Components.Forms.EditContext) = render ==> ("EditContext" => x)
[<CustomOperation("Enhance")>] member inline _.Enhance ([<InlineIfLambda>] render: AttrRenderFragment, ?x: bool) = render ==> ("Enhance" => (defaultArg x true))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<TrimMode>link</TrimMode>
<IsTrimmable>true</IsTrimmable>
<Version>8.0.4</Version>
<Version>8.0.5</Version>
</PropertyGroup>
<ItemGroup>
<Compile Include="Fun.Blazor.Bindings\Microsoft.AspNetCore.Components.fs" />
</ItemGroup>
<ItemGroup>
<PackageReference FunBlazor="" FunBlazorNamespace="Microsoft.AspNetCore.Components" Include="Microsoft.AspNetCore.Components.Web" Version="8.0.4" />
<PackageReference FunBlazor="" FunBlazorNamespace="Microsoft.AspNetCore.Components" Include="Microsoft.AspNetCore.Components.Web" Version="8.0.5" />
</ItemGroup>
<ItemGroup>
<PackageReference Update="FSharp.Core" Version="6.0.0" />
Expand Down
6 changes: 3 additions & 3 deletions Docs/17 Bindings/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ The bindings will be updated every week.
dotnet add package Fun.Blazor.AntDesign --version 0.19.0
dotnet add package Fun.Blazor.ApexCharts --version 3.3.0
dotnet add package Fun.Blazor.BlazorMonaco --version 3.2.0
dotnet add package Fun.Blazor.Microsoft.Authorization --version 8.0.4
dotnet add package Fun.Blazor.Microsoft.Authorization --version 8.0.5
dotnet add package Fun.Blazor.Microsoft.FluentUI --version 4.7.2
dotnet add package Fun.Blazor.Microsoft.QuickGrid --version 8.0.4
dotnet add package Fun.Blazor.Microsoft.Web --version 8.0.4
dotnet add package Fun.Blazor.Microsoft.QuickGrid --version 8.0.5
dotnet add package Fun.Blazor.Microsoft.Web --version 8.0.5
dotnet add package Fun.Blazor.MudBlazor --version 6.19.1
```
51 changes: 20 additions & 31 deletions Fun.Blazor.Generator/CEGenerator.fs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ open Namotion.Reflection
open Utils

let private makeSummaryDoc indent (doc: string) =
if String.IsNullOrWhiteSpace doc then ""
if String.IsNullOrWhiteSpace doc then
""
else
(let indent = String(' ', indent)
doc.Split "\n"
|> Array.map (fun i -> $"{indent}/// {i}")
|> String.concat "\n") + "\n"
let indent = String(' ', indent)
(doc.Split "\n" |> Array.map (fun i -> $"{indent}/// {i}") |> String.concat "\n") + "\n"

let private getMetaInfo useInline (ty: Type) =
let getTypeMeta (ty: Type) =
Expand All @@ -37,20 +36,11 @@ let private getMetaInfo useInline (ty: Type) =
else
None

let name, generics, inheritInfo =
let _, generics, inheritInfo =
match getTypeMeta ty, inherits with
| (ty, generics), Some (baseTy, baseGenerics) ->
let generics =
List.append baseGenerics generics
|> List.distinctBy (fun x -> x.Name)
|> List.filter (fun x -> (getTypeName x).StartsWith "'")
ty, generics, Some(baseTy, baseGenerics)

| (ty, generics), Some(baseTy, baseGenerics) -> ty, generics, Some(baseTy, baseGenerics)
| (name, generics), None -> name, generics, None

let originalGenerics = generics |> getTypeNames |> createGenerics |> closeGenerics
let originalTypeWithGenerics =
$"{ty.Namespace}.{getTypeShortName ty}{originalGenerics}"
let customOperation name = $"[<CustomOperation(\"{name}\")>]"
let memberStart = if useInline then "member inline _." else "member _."
let contextArg =
Expand All @@ -62,8 +52,6 @@ let private getMetaInfo useInline (ty: Type) =
let rawProps = ty.GetProperties()
let filteredProps = getValidBlazorProps ty rawProps

let formatChildContentName x = if x = "ChildContent" then lowerFirstCase x else x

let props =
filteredProps
|> Seq.map (fun prop ->
Expand Down Expand Up @@ -116,7 +104,6 @@ let private getMetaInfo useInline (ty: Type) =
$"{memberHead} ({contextArg}, fn: {getTypeName prop.PropertyType.GenericTypeArguments.[0]} -> Task<unit>) = render ==> html.callbackTask(\"{prop.Name}\", fn)"
]
elif prop.PropertyType.Name.StartsWith "RenderFragment`" then
let name = formatChildContentName name
[
$"{memberHead} ({contextArg}, fn: {getTypeName prop.PropertyType.GenericTypeArguments.[0]} -> {nameof NodeRenderFragment}) = render ==> html.renderFragment(\"{prop.Name}\", fn)"
]
Expand Down Expand Up @@ -272,24 +259,21 @@ let generateCode (targetNamespace: string) (opens: string) (tys: Type seq) useIn
let code =
metas
|> Seq.map (fun meta ->
let originalGenerics =
meta.generics |> getTypeNames |> createGenerics |> closeGenerics
let originalTypeWithGenerics =
$"{meta.ty.Namespace}.{getTypeShortName meta.ty}{originalGenerics}"
let builderName = makeBuilderName meta.ty

let funBlazorGenericConstraint =
$"{funBlazorGeneric} :> Microsoft.AspNetCore.Components.IComponent"
let builderGenerics =
funBlazorGeneric :: (getTypeNames meta.generics) |> createGenerics |> closeGenerics

let builderGenericsWithContraints =
funBlazorGeneric :: (getTypeNames meta.generics)
|> createGenerics
|> appendStr (createConstraint meta.generics |> appendConstraint funBlazorGenericConstraint)
|> closeGenerics

let inheirit' =
//$"inherit {if meta.addBasicDomAttrs then nameof FunBlazorContextWithAttrs else nameof FunBlazorContext}<{funBlazorGeneric}>()"
match meta.inheritInfo with
| None when meta.props.Contains("CustomOperation(\"ChildContent\")") ->
$"inherit {nameof ComponentWithDomAttrBuilder}<{funBlazorGeneric}>()"
| None ->
// Use ComponentWithDomAndChildAttrBuilder because we cannot do multi inheritance and will endup of a lot of duplication
//$"inherit {match meta.hasChildren, meta.addBasicDomAttrs with
Expand All @@ -298,9 +282,9 @@ let generateCode (targetNamespace: string) (opens: string) (tys: Type seq) useIn
// | false, false -> nameof ComponentBuilder
// | false, true -> nameof ComponentWithDomAttrBuilder}<{funBlazorGeneric}>()"
$"inherit {nameof ComponentWithDomAndChildAttrBuilder}<{funBlazorGeneric}>()"
| Some (baseTy, generics) ->
| Some(baseTy, generics) ->
$"inherit {baseTy.Namespace |> trimNamespace |> appendStrIfNotEmpty (string '.')}{makeBuilderName meta.ty.BaseType}{funBlazorGeneric :: (getTypeNames generics) |> createGenerics |> closeGenerics}()"

$"""{makeSummaryDoc 0 <| meta.ty.GetXmlDocsSummary()}type {builderName}{builderGenericsWithContraints}() =
{inheirit'}
{meta.props}
Expand Down Expand Up @@ -334,7 +318,7 @@ let generateCode (targetNamespace: string) (opens: string) (tys: Type seq) useIn
originalTypeWithGenerics :: (getTypeNames meta.generics) |> createGenerics |> closeGenerics

let typeName = meta.ty |> getTypeShortName
let typeFullName = meta.ty |> getTypeName |> fun x -> x.Split("<")[0]
let typeFullName = meta.ty |> getTypeName |> (fun x -> x.Split("<")[0])

let genericStr =
meta.generics
Expand All @@ -351,8 +335,13 @@ let generateCode (targetNamespace: string) (opens: string) (tys: Type seq) useIn
let linkerAttrStr =
$"[<DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof<{typeFullName}{linkerGenericStr}>)>]"

let typeComment = meta.ty.GetXmlDocsSummary() |> makeSummaryDoc 4 |> addStrIfNotEmpty "\n"
let constructorComment = meta.ty.GetXmlDocsSummary() |> makeSummaryDoc 8 |> addStrIfNotEmpty "\n" |> appendStrIfNotEmpty (String(' ', 8))
let typeComment =
meta.ty.GetXmlDocsSummary() |> makeSummaryDoc 4 |> addStrIfNotEmpty "\n"
let constructorComment =
meta.ty.GetXmlDocsSummary()
|> makeSummaryDoc 8
|> addStrIfNotEmpty "\n"
|> appendStrIfNotEmpty (String(' ', 8))
$"""{typeComment} type {typeName}'{genericStr} {constructorComment}{linkerAttrStr} () = inherit {builderName}{builderGenerics}()"""
)
|> String.concat "\n"
Expand Down
5 changes: 5 additions & 0 deletions Fun.Blazor.Generator/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## [4.0.4] - 2024-05-17

- Fix generic case: CheckboxGroup<TValue> : AntInputComponentBase<TValue[]>
- When a ChildContent is a RenderFragment<'T> we should not inherit ComponentWithDomAndChildAttrBuilder

## [4.0.3] - 2024-02-20

- Support optional for bool property
Expand Down

0 comments on commit 49a4623

Please sign in to comment.