Skip to content

Commit 3ad4d86

Browse files
MaxymGornCopilot
andauthored
add receiver components to docs, fix events cropper component desc, fix error during blazor server prerendering in dispose methods (#453)
## Target <!-- Why are you making this change? --> - Add receiver components to docs - Fix events cropper component desc - Fix error during blazor server prerendering in dispose methods #### Open Questions <!-- OPTIONAL - [ ] Use the GitHub checklists to spark discussion on issues that may arise from your approach. Please tick the box and explain your answer. --> ## Checklist <!-- It serves as a gentle reminder for common tasks. Confirm it's done and check everything that applies. --> - [x] Tests cover new or modified code - [x] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [x] I have made corresponding changes to the site documentation - [ ] I have made corresponding changes to the README, NuGet README file - [x] My changes generate no new warnings - [ ] New dependencies added or updated - [ ] Includes breaking changes - [ ] Version bumped ## Visuals <!-- OPTIONAL Show results both before and after this change. When the output changes, it can be a screenshot of a trace, metric, or log illustrating the change. --> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 5972a17 commit 3ad4d86

40 files changed

Lines changed: 994 additions & 561 deletions

.editorconfig

Lines changed: 18 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,5 @@
11
root = true
2-
3-
# All files
4-
[*]
52
indent_style = space
6-
csharp_indent_labels = no_change
7-
csharp_using_directive_placement = outside_namespace:silent
8-
csharp_prefer_simple_using_statement = true:suggestion
9-
csharp_prefer_braces = true:silent
10-
csharp_style_namespace_declarations = block_scoped:silent
11-
csharp_style_prefer_method_group_conversion = true:silent
12-
csharp_style_prefer_top_level_statements = true:silent
13-
csharp_style_prefer_primary_constructors = true:suggestion
14-
csharp_style_expression_bodied_methods = false:silent
15-
csharp_style_expression_bodied_constructors = false:silent
16-
csharp_style_expression_bodied_operators = false:silent
17-
csharp_style_expression_bodied_properties = true:silent
18-
csharp_style_expression_bodied_indexers = true:silent
19-
csharp_style_expression_bodied_accessors = true:silent
20-
csharp_style_expression_bodied_lambdas = true:silent
21-
csharp_style_expression_bodied_local_functions = false:silent
223

234
[*.{csproj,sln,vcxproj,vcxproj.filters,proj,nativeproj,locproj}]
245
indent_size = 4
@@ -44,7 +25,23 @@ indent_style = space
4425
indent_size = 2
4526

4627
[*.{cs,vb}]
47-
#### Naming styles ####
28+
# Naming styles
29+
csharp_indent_labels = no_change
30+
csharp_using_directive_placement = outside_namespace:silent
31+
csharp_prefer_simple_using_statement = true:suggestion
32+
csharp_prefer_braces = true:silent
33+
csharp_style_namespace_declarations = block_scoped:silent
34+
csharp_style_prefer_method_group_conversion = true:silent
35+
csharp_style_prefer_top_level_statements = true:silent
36+
csharp_style_prefer_primary_constructors = true:suggestion
37+
csharp_style_expression_bodied_methods = false:silent
38+
csharp_style_expression_bodied_constructors = false:silent
39+
csharp_style_expression_bodied_operators = false:silent
40+
csharp_style_expression_bodied_properties = true:silent
41+
csharp_style_expression_bodied_indexers = true:silent
42+
csharp_style_expression_bodied_accessors = true:silent
43+
csharp_style_expression_bodied_lambdas = true:silent
44+
csharp_style_expression_bodied_local_functions = false:silent
4845

4946
# Naming rules
5047

@@ -64,33 +61,21 @@ dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case
6461

6562
dotnet_naming_symbols.interface.applicable_kinds = interface
6663
dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
67-
dotnet_naming_symbols.interface.required_modifiers =
6864

6965
dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum
7066
dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
71-
dotnet_naming_symbols.types.required_modifiers =
7267

7368
dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method
7469
dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
75-
dotnet_naming_symbols.non_field_members.required_modifiers =
7670

7771
# Naming styles
7872

7973
dotnet_naming_style.begins_with_i.required_prefix = I
80-
dotnet_naming_style.begins_with_i.required_suffix =
81-
dotnet_naming_style.begins_with_i.word_separator =
8274
dotnet_naming_style.begins_with_i.capitalization = pascal_case
83-
84-
dotnet_naming_style.pascal_case.required_prefix =
85-
dotnet_naming_style.pascal_case.required_suffix =
86-
dotnet_naming_style.pascal_case.word_separator =
8775
dotnet_naming_style.pascal_case.capitalization = pascal_case
88-
89-
dotnet_naming_style.pascal_case.required_prefix =
90-
dotnet_naming_style.pascal_case.required_suffix =
91-
dotnet_naming_style.pascal_case.word_separator =
9276
dotnet_naming_style.pascal_case.capitalization = pascal_case
9377
dotnet_style_operator_placement_when_wrapping = beginning_of_line
78+
9479
tab_width = 4
9580
indent_size = 4
9681
end_of_line = crlf

examples/Cropper.Blazor.MAUI.Net9/Cropper.Blazor.MAUI.Net9.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
<ItemGroup>
6161
<PackageReference Include="Microsoft.Maui.Controls" Version="9.0.120" />
6262
<PackageReference Include="Microsoft.AspNetCore.Components.WebView.Maui" Version="9.0.120" />
63-
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="9.0.11" />
63+
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="9.0.12" />
6464
<PackageReference Include="MudBlazor" Version="8.15.0" />
6565
</ItemGroup>
6666

src/Cropper.Blazor/Client/Components/Docs/ApiMethod.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ public class ApiMethod
1010
public string Documentation { get; set; }
1111
public MethodInfo MethodInfo { get; set; }
1212
public ParameterInfo[] Parameters { get; set; }
13+
public bool IsJsInvokable { get; set; }
1314
}
1415
}

src/Cropper.Blazor/Client/Components/Docs/DocsApi.razor

Lines changed: 289 additions & 239 deletions
Large diffs are not rendered by default.

src/Cropper.Blazor/Client/Components/Docs/DocsApi.razor.cs

Lines changed: 101 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@ namespace Cropper.Blazor.Client.Components.Docs
1313
{
1414
public partial class DocsApi
1515
{
16+
[Parameter] public Type Type { get; set; }
17+
[Parameter] public bool IsContract { get; set; } = false;
18+
[Parameter] public bool IsHelper { get; set; } = false;
19+
[Parameter] public bool? IsComponentContract { get; set; } = null;
20+
[Inject] NavigationManager NavigationManager { get; set; } = null!;
21+
22+
public DocsPage DocsPage { get; set; }
23+
24+
// used for default value getting
25+
private object CompInstance;
1626
private readonly List<string> _hiddenMethods =
1727
[
1828
"ToString",
@@ -23,17 +33,38 @@ public partial class DocsApi
2333
"ReferenceEquals"
2434
];
2535

26-
[Parameter] public Type Type { get; set; }
27-
[Parameter] public bool IsContract { get; set; } = false;
28-
[Inject] NavigationManager NavigationManager { get; set; } = null!;
36+
protected override async Task OnParametersSetAsync()
37+
{
38+
CompInstance = !Type.IsAssignableTo(typeof(IComponent)) ? null : Activator.CreateInstance(Type);
2939

30-
// used for default value getting
31-
private object CompInstance;
40+
await base.OnParametersSetAsync();
41+
}
3242

33-
public DocsPage DocsPage { get; set; }
43+
private (string? Href, string? Desc) GetHrefPageWithDesc()
44+
{
45+
if (Type == typeof(CropperComponent))
46+
{
47+
return ("examples/cropperusage", "");
48+
}
49+
else if (Type == typeof(CroppedCanvasReceiver))
50+
{
51+
return ("examples/cropping#crop-a-polygon-image-in-background", "See 'Crop in Background' example.");
52+
}
53+
else if (Type == typeof(ImageReceiver))
54+
{
55+
return ("examples/cropping#crop-a-round-image-in-background", "See 'Crop a polygon image in Background' or 'Crop a round image in Background' examples.");
56+
}
57+
58+
return (null, null);
59+
}
3460

3561
private IEnumerable<ApiProperty> GetEventCallbacks()
3662
{
63+
if (Type == null)
64+
{
65+
yield break;
66+
}
67+
3768
string saveTypename = DocStrings.GetSaveTypename(Type);
3869

3970
if (IsContract)
@@ -42,7 +73,10 @@ private IEnumerable<ApiProperty> GetEventCallbacks()
4273
}
4374
else
4475
{
45-
foreach (var info in Type.GetPropertyInfosWithAttribute<ParameterAttribute>().OrderBy(x => x.Name))
76+
IEnumerable<PropertyInfo>? propertyInfos = IsComponentContract == true
77+
? Type.GetPropertyInfos()
78+
: Type.GetPropertyInfosWithAttribute<ParameterAttribute>();
79+
foreach (var info in propertyInfos.OrderBy(x => x.Name))
4680
{
4781
if (IsEventCallback(info))
4882
{
@@ -51,7 +85,7 @@ private IEnumerable<ApiProperty> GetEventCallbacks()
5185
Name = info.Name,
5286
PropertyInfo = info,
5387
Default = string.Empty,
54-
Description = DocStrings.GetMemberDescription(saveTypename, info),
88+
Description = DocStrings.GetMemberDescription(saveTypename, info, IsContract, IsComponentContract),
5589
IsTwoWay = CheckIsTwoWayEventCallback(info),
5690
Type = info.PropertyType,
5791
};
@@ -60,8 +94,35 @@ private IEnumerable<ApiProperty> GetEventCallbacks()
6094
}
6195
}
6296

97+
private string GetClassDescription()
98+
{
99+
if (Type.IsClass)
100+
{
101+
string saveTypename = DocStrings.GetSaveTypename(Type);
102+
103+
return DocStrings.GetClassDescription(saveTypename);
104+
}
105+
else if (Type.IsInterface)
106+
{
107+
string saveTypename = DocStrings.GetSaveTypename(Type);
108+
109+
return DocStrings.GetInterfaceDescription(saveTypename);
110+
}
111+
else if (Type.IsEnum)
112+
{
113+
return DocStrings.GetEnumDescription(Type.Name);
114+
}
115+
116+
return string.Empty;
117+
}
118+
63119
private IEnumerable<ApiMethod> GetMethods()
64120
{
121+
if (Type == null)
122+
{
123+
yield break;
124+
}
125+
65126
string saveTypename = DocStrings.GetSaveTypename(Type);
66127

67128
if (IsContract)
@@ -74,29 +135,29 @@ private IEnumerable<ApiMethod> GetMethods()
74135
{
75136
if (!_hiddenMethods.Any(x => x.Contains(info.Name)) && !info.Name.StartsWith("get_") && !info.Name.StartsWith("set_"))
76137
{
77-
if (info.GetCustomAttributes(typeof(JSInvokableAttribute), true).Length == 0)
138+
bool hasNoJsInvokableAttribute = info.GetCustomAttributes(typeof(JSInvokableAttribute), true).Length == 0;
139+
140+
Attribute? attribute = info
141+
.GetCustomAttribute(typeof(ObsoleteAttribute), true);
142+
string? warningSignatureMessage = null;
143+
144+
if (attribute != null)
78145
{
79-
Attribute? attribute = info
80-
.GetCustomAttribute(typeof(ObsoleteAttribute), true);
81-
string? warningSignatureMessage = null;
82-
83-
if (attribute != null)
84-
{
85-
ObsoleteAttribute obsoleteAttr = (ObsoleteAttribute)attribute;
86-
87-
warningSignatureMessage = obsoleteAttr.Message;
88-
}
89-
90-
yield return new ApiMethod()
91-
{
92-
MethodInfo = info,
93-
WarningSignatureMessage = warningSignatureMessage,
94-
Return = info.ReturnParameter,
95-
Signature = info.GetSignature(),
96-
Parameters = info.GetParameters(),
97-
Documentation = DocStrings.GetMemberDescription(saveTypename, info)
98-
};
146+
ObsoleteAttribute obsoleteAttr = (ObsoleteAttribute)attribute;
147+
148+
warningSignatureMessage = obsoleteAttr.Message;
99149
}
150+
151+
yield return new ApiMethod()
152+
{
153+
MethodInfo = info,
154+
IsJsInvokable = !hasNoJsInvokableAttribute,
155+
WarningSignatureMessage = warningSignatureMessage,
156+
Return = info.ReturnParameter,
157+
Signature = info.GetSignature(),
158+
Parameters = info.GetParameters(),
159+
Documentation = DocStrings.GetMemberDescription(saveTypename, info, IsContract, IsComponentContract)
160+
};
100161
}
101162
}
102163
}
@@ -111,10 +172,15 @@ private static bool IsEventCallback(PropertyInfo? propertyInfo)
111172

112173
private IEnumerable<ApiProperty> GetProperties()
113174
{
175+
if (Type == null)
176+
{
177+
yield break;
178+
}
179+
114180
string saveTypename = DocStrings.GetSaveTypename(Type);
115181
IEnumerable<PropertyInfo> types = null!;
116182

117-
if (IsContract)
183+
if (IsContract || IsComponentContract == true)
118184
{
119185
types = Type
120186
.GetPropertyInfos();
@@ -148,13 +214,15 @@ private IEnumerable<ApiProperty> GetProperties()
148214

149215
private ApiProperty ToApiProperty(PropertyInfo info, string saveTypename)
150216
{
217+
object defaultValue = GetDefaultValue(info);
218+
151219
return new ApiProperty
152220
{
153221
Name = info.Name,
154222
PropertyInfo = info,
155-
Default = GetDefaultValue(info),
223+
Default = defaultValue,
156224
IsTwoWay = CheckIsTwoWayProperty(info),
157-
Description = DocStrings.GetMemberDescription(saveTypename, info, IsContract),
225+
Description = DocStrings.GetMemberDescription(saveTypename, info, IsContract, IsComponentContract),
158226
Type = info.PropertyType
159227
};
160228
}
@@ -166,7 +234,7 @@ private static ApiProperty ToApiProperty(Type type, string? enumDisplayStatus, s
166234
Name = enumDisplayStatus,
167235
PropertyInfo = null,
168236
Default = value,
169-
Description = DocStrings.GetEnumDescription(type.Name, enumDisplayStatus),
237+
Description = DocStrings.GetEnumValueDescription(type.Name, enumDisplayStatus),
170238
Type = type
171239
};
172240
}
@@ -220,18 +288,6 @@ private bool CheckIsTwoWayProperty(PropertyInfo propertyInfo)
220288
eventCallbackInfo.GetCustomAttribute<ObsoleteAttribute>() == null;
221289
}
222290

223-
RenderFragment RenderTheType()
224-
{
225-
if (!Type.IsAssignableTo(typeof(IComponent)))
226-
return null;
227-
return new RenderFragment(builder =>
228-
{
229-
builder.OpenComponent(0, Type);
230-
builder.AddComponentReferenceCapture(1, inst => { CompInstance = inst; });
231-
builder.CloseComponent();
232-
});
233-
}
234-
235291
private async Task OnPageChanged(int newPage)
236292
{
237293
await DocsPage.ContentNavigation.ScrollToSection(new Uri(NavigationManager.BaseUri + "/api#methods"));
@@ -306,19 +362,6 @@ private enum Grouping { Categories, Inheritance, None }
306362

307363
private static bool IsOverridden(PropertyInfo p) => IsOverridden(p.GetMethod ?? p.SetMethod); // used for the "overridden" chip
308364

309-
// used for ordering groups of properties
310-
private static int NumberOfAncestorClasses(Type type)
311-
{
312-
int n = 0;
313-
314-
while ((type = type.BaseType) != null)
315-
{
316-
n++;
317-
}
318-
319-
return n;
320-
}
321-
322365
#endregion
323366
}
324367
}

src/Cropper.Blazor/Client/Cropper.Blazor.Client.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
<!--Packages-->
2020
<ItemGroup>
2121
<PackageReference Include="BlazorWasmPreRendering.Build" Version="7.0.0" />
22-
<PackageReference Include="Microsoft.AspNetCore.WebUtilities" Version="10.0.1" />
23-
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="10.0.1" />
24-
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="10.0.1" PrivateAssets="all" />
22+
<PackageReference Include="Microsoft.AspNetCore.WebUtilities" Version="10.0.2" />
23+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="10.0.2" />
24+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="10.0.2" PrivateAssets="all" />
2525
<PackageReference Include="Blazored.LocalStorage" Version="4.5.0" />
2626
</ItemGroup>
2727

0 commit comments

Comments
 (0)