Skip to content

Commit 525a4ec

Browse files
authored
Merge branch 'main' into main
2 parents 0d6ba2e + 450937c commit 525a4ec

File tree

15 files changed

+81
-50
lines changed

15 files changed

+81
-50
lines changed

src/BootstrapBlazor.Server/Components/Samples/SelectGenerics.razor

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,8 @@
428428
<section ignore>@((MarkupString)Localizer["SelectsGenericDesc"].Value)</section>
429429
<div class="row">
430430
<div class="col-12 col-sm-6">
431-
<SelectGeneric Items="_genericItems" @bind-Value="_selectedFoo" IsEditable="true"></SelectGeneric>
431+
<SelectGeneric Items="_genericItems" @bind-Value="_selectedFoo"
432+
IsEditable="true" TextConvertToValueCallback="TextConvertToValueCallback"></SelectGeneric>
432433
</div>
433434
<div class="col-12 col-sm-6">
434435
<Display Value="_selectedFoo.Address"></Display>

src/BootstrapBlazor.Server/Components/Samples/SelectGenerics.razor.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,27 @@ private Task OnTimeZoneValueChanged(string timeZoneId)
251251

252252
private Foo _selectedFoo = new();
253253

254+
private async Task<Foo> TextConvertToValueCallback(string v)
255+
{
256+
// 模拟异步通讯切换线程
257+
await Task.Delay(10);
258+
259+
Foo? foo = null;
260+
var item = _genericItems.Find(i => i.Text == v);
261+
if (item == null)
262+
{
263+
var id = _genericItems.Count + 1;
264+
foo = new Foo() { Id = id, Address = $"New Address - {id}" };
265+
var fooItem = new SelectedItem<Foo> { Text = v, Value = foo };
266+
_genericItems.Add(fooItem);
267+
}
268+
else
269+
{
270+
foo = item.Value;
271+
}
272+
return foo!;
273+
}
274+
254275
/// <summary>
255276
/// 获得事件方法
256277
/// </summary>

src/BootstrapBlazor.Server/Locales/en-US.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3266,7 +3266,7 @@
32663266
"SelectsVirtualizeDescription": "Component virtual scrolling supports two ways of providing data through <code>Items</code> or <code>OnQueryAsync</code> callback methods",
32673267
"SelectsGenericTitle": "Generic",
32683268
"SelectsGenericIntro": "Data source <code>Items</code> supports generics when using <code>SelectedItem&lt;TValue&gt;</code>",
3269-
"SelectsGenericDesc": "<p>Please refer to <a href=\"https://github.com/dotnetcore/BootstrapBlazor/issues/4497?wt.mc_id=DT-MVP-5004174\" target=\"_blank\">Design Ideas</a> to understand this feature. In this example, by selecting the drop-down box option, the value obtained is the <code>Foo</code> instance, and the value displayed in the text box on the right is the <code>Address</code> value of the <code>Foo</code> attribute</p><p>In this example, the <code>ValueEqualityComparer</code> and <code>CustomKeyAttribute</code> parameters are not set, and the <code>[Key]</code> tag of the <code>Id</code> attribute of <code>Foo</code> is used for equality judgment</p>",
3269+
"SelectsGenericDesc": "<p>Please refer to <a href=\"https://github.com/dotnetcore/BootstrapBlazor/issues/4497?wt.mc_id=DT-MVP-5004174\" target=\"_blank\">Design Ideas</a> to understand this feature. In this example, by selecting the drop-down box option, the value obtained is the <code>Foo</code> instance, and the value displayed in the text box on the right is the <code>Address</code> value of the <code>Foo</code> attribute</p><p>In this example, <code>IsEditable=\"true\"</code> and <code>TextConvertToValueCallback</code> parameters are set. When a <code>Foo</code> that does not exist in the original data source is entered, a new <code>Foo</code> instance is added to the data source in the <code></code> callback method</p>",
32703270
"SelectsOnInputChangedCallback": "Callback method for converting input text into corresponding Value in edit mode",
32713271
"TextConvertToValueCallback": "Callback method when input text changes in edit mode",
32723272
"SelectsIsEditable": "Whether editable",

src/BootstrapBlazor.Server/Locales/zh-CN.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3266,7 +3266,7 @@
32663266
"SelectsVirtualizeDescription": "组件虚拟滚动支持两种形式通过 <code>Items</code> 或者 <code>OnQueryAsync</code> 回调方法提供数据",
32673267
"SelectsGenericTitle": "泛型支持",
32683268
"SelectsGenericIntro": "数据源 <code>Items</code> 使用 <code>SelectedItem&lt;TValue&gt;</code> 时即可支持泛型",
3269-
"SelectsGenericDesc": "<p>请参考 <a href=\"https://github.com/dotnetcore/BootstrapBlazor/issues/4497?wt.mc_id=DT-MVP-5004174\" target=\"_blank\">设计思路</a> 理解此功能。本例中通过选择下拉框选项,得到的值为 <code>Foo</code> 实例,右侧文本框内显示值为 <code>Foo</code> 属性 <code>Address</code> 值</p><p>本例中未设置 <code>ValueEqualityComparer</code> 以及 <code>CustomKeyAttribute</code> 参数,使用 <code>Foo</code> 属性 <code>Id</code> <code>[Key]</code> 标签进行相等判定</p>",
3269+
"SelectsGenericDesc": "<p>请参考 <a href=\"https://github.com/dotnetcore/BootstrapBlazor/issues/4497?wt.mc_id=DT-MVP-5004174\" target=\"_blank\">设计思路</a> 理解此功能。本例中通过选择下拉框选项,得到的值为 <code>Foo</code> 实例,右侧文本框内显示值为 <code>Foo</code> 属性 <code>Address</code> 值</p><p>本例中设置 <code>IsEditable=\"true\"</code> 以及 <code>TextConvertToValueCallback</code> 参数,录入原数据源中不存在的 <code>Foo</code> 时,在 <code></code> 回调方法中添加新 <code>Foo</code> 实例到数据源中</p>",
32703270
"SelectsOnInputChangedCallback": "编辑模式下输入文本转换为对应 Value 回调方法",
32713271
"TextConvertToValueCallback": "编辑模式下输入文本变化时回调方法",
32723272
"SelectsIsEditable": "是否可编辑",

src/BootstrapBlazor/BootstrapBlazor.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.Razor">
22

33
<PropertyGroup>
4-
<Version>9.7.1-beta01</Version>
4+
<Version>9.7.1-beta03</Version>
55
</PropertyGroup>
66

77
<ItemGroup>

src/BootstrapBlazor/Components/BaseComponents/DynamicElement.cs

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,12 @@ protected override void BuildRenderTree(RenderTreeBuilder builder)
9797

9898
if (IsTriggerClick())
9999
{
100-
builder.AddAttribute(2, "onclick", EventCallback.Factory.Create<MouseEventArgs>(this, e => OnClick!()));
100+
builder.AddAttribute(2, "onclick", EventCallback.Factory.Create<MouseEventArgs>(this, OnTriggerClick));
101101
}
102102

103103
if (IsTriggerDoubleClick())
104104
{
105-
builder.AddAttribute(3, "ondblclick", EventCallback.Factory.Create<MouseEventArgs>(this, e => OnDoubleClick!()));
105+
builder.AddAttribute(3, "ondblclick", EventCallback.Factory.Create<MouseEventArgs>(this, OnTriggerDoubleClick));
106106
}
107107

108108
if (IsTriggerClick() || IsTriggerDoubleClick())
@@ -111,9 +111,9 @@ protected override void BuildRenderTree(RenderTreeBuilder builder)
111111
builder.AddEventStopPropagationAttribute(5, "onclick", StopPropagation);
112112
}
113113

114-
if (TriggerContextMenu && OnContextMenu != null)
114+
if (IsTriggerContextMenu())
115115
{
116-
builder.AddAttribute(6, "oncontextmenu", EventCallback.Factory.Create<MouseEventArgs>(this, e => OnContextMenu(e)));
116+
builder.AddAttribute(6, "oncontextmenu", EventCallback.Factory.Create<MouseEventArgs>(this, OnTriggerContextMenu));
117117
builder.AddEventPreventDefaultAttribute(7, "oncontextmenu", true);
118118
}
119119

@@ -123,8 +123,35 @@ protected override void BuildRenderTree(RenderTreeBuilder builder)
123123
{
124124
builder.CloseElement();
125125
}
126+
}
127+
128+
private bool IsTriggerClick() => TriggerClick && OnClick != null;
129+
130+
private bool IsTriggerDoubleClick() => TriggerDoubleClick && OnDoubleClick != null;
131+
132+
private bool IsTriggerContextMenu() => TriggerContextMenu && OnContextMenu != null;
133+
134+
private async Task OnTriggerClick()
135+
{
136+
if (OnClick != null)
137+
{
138+
await OnClick();
139+
}
140+
}
126141

127-
bool IsTriggerClick() => TriggerClick && OnClick != null;
128-
bool IsTriggerDoubleClick() => TriggerDoubleClick && OnDoubleClick != null;
142+
private async Task OnTriggerDoubleClick()
143+
{
144+
if (OnDoubleClick != null)
145+
{
146+
await OnDoubleClick();
147+
}
148+
}
149+
150+
private async Task OnTriggerContextMenu(MouseEventArgs e)
151+
{
152+
if (OnContextMenu != null)
153+
{
154+
await OnContextMenu(e);
155+
}
129156
}
130157
}

src/BootstrapBlazor/Components/BaseComponents/IdComponentBase.cs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,4 @@ protected override void OnInitialized()
3838

3939
Id ??= ComponentIdGenerator.Generate(this);
4040
}
41-
42-
/// <summary>
43-
/// <inheritdoc/>
44-
/// </summary>
45-
protected override void OnParametersSet()
46-
{
47-
base.OnParametersSet();
48-
49-
Id ??= ComponentIdGenerator.Generate(this);
50-
}
5141
}

src/BootstrapBlazor/Components/ErrorLogger/ErrorLogger.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ public class ErrorLogger : ComponentBase, IErrorLogger
2222
/// <inheritdoc/>
2323
/// </summary>
2424
[Parameter]
25-
public bool EnableErrorLogger { get; set; } = true;
25+
public bool? EnableErrorLogger { get; set; }
2626

2727
/// <summary>
2828
/// <inheritdoc/>
2929
/// </summary>
3030
[Parameter]
31-
public bool ShowToast { get; set; } = true;
31+
public bool? ShowToast { get; set; }
3232

3333
/// <summary>
3434
/// <inheritdoc/>
@@ -62,9 +62,17 @@ public class ErrorLogger : ComponentBase, IErrorLogger
6262
[Parameter]
6363
public Func<ErrorLogger, Task>? OnInitializedCallback { get; set; }
6464

65+
[Inject]
66+
[NotNull]
67+
private IOptionsMonitor<BootstrapBlazorOptions>? Options { get; set; }
68+
6569
[NotNull]
6670
private BootstrapBlazorErrorBoundary? _errorBoundary = default;
6771

72+
private bool _enableErrorLogger => EnableErrorLogger ?? Options.CurrentValue.EnableErrorLogger;
73+
74+
private bool _showToast => ShowToast ?? Options.CurrentValue.ShowErrorLoggerToast;
75+
6876
/// <summary>
6977
/// <inheritdoc/>
7078
/// </summary>
@@ -102,13 +110,13 @@ protected override void BuildRenderTree(RenderTreeBuilder builder)
102110
builder.CloseComponent();
103111
}
104112

105-
private RenderFragment? RenderContent => EnableErrorLogger ? RenderError : ChildContent;
113+
private RenderFragment? RenderContent => _enableErrorLogger ? RenderError : ChildContent;
106114

107115
private RenderFragment RenderError => builder =>
108116
{
109117
builder.OpenComponent<BootstrapBlazorErrorBoundary>(0);
110118
builder.AddAttribute(1, nameof(BootstrapBlazorErrorBoundary.OnErrorHandleAsync), OnErrorHandleAsync);
111-
builder.AddAttribute(2, nameof(BootstrapBlazorErrorBoundary.ShowToast), ShowToast);
119+
builder.AddAttribute(2, nameof(BootstrapBlazorErrorBoundary.ShowToast), _showToast);
112120
builder.AddAttribute(3, nameof(BootstrapBlazorErrorBoundary.ToastTitle), ToastTitle);
113121
builder.AddAttribute(4, nameof(BootstrapBlazorErrorBoundary.ErrorContent), ErrorContent);
114122
builder.AddAttribute(5, nameof(BootstrapBlazorErrorBoundary.ChildContent), ChildContent);

src/BootstrapBlazor/Components/ErrorLogger/IErrorLogger.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ namespace BootstrapBlazor.Components;
1111
public interface IErrorLogger
1212
{
1313
/// <summary>
14-
/// 获得/设置 是否开启全局异常捕获 默认 true
14+
/// 获得/设置 是否开启全局异常捕获 默认 null 使用全局配置 <see cref="BootstrapBlazorOptions.EnableErrorLogger"/> 值
1515
/// </summary>
16-
bool EnableErrorLogger { get; set; }
16+
bool? EnableErrorLogger { get; set; }
1717

1818
/// <summary>
1919
/// 获得/设置 自定义 Error 处理方法 默认 null
@@ -23,9 +23,9 @@ public interface IErrorLogger
2323
Task HandlerExceptionAsync(Exception ex);
2424

2525
/// <summary>
26-
/// 获得 是否显示 Error 提示弹窗 默认 true 显示
26+
/// 获得 是否显示 Error 提示弹窗 默认 null 使用全局配置 <see cref="BootstrapBlazorOptions.ShowErrorLoggerToast"/> 值
2727
/// </summary>
28-
bool ShowToast { get; }
28+
bool? ShowToast { get; }
2929

3030
/// <summary>
3131
/// 获得 Error Toast 弹窗标题 默认读取资源文件内容

src/BootstrapBlazor/Components/Layout/Layout.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@
126126
}
127127
else
128128
{
129-
<ErrorLogger EnableErrorLogger="@_enableErrorLoggerValue" ShowToast="@_showToast" ToastTitle="@ErrorLoggerToastTitle"
129+
<ErrorLogger EnableErrorLogger="@EnableErrorLogger" ShowToast="@ShowErrorLoggerToast" ToastTitle="@ErrorLoggerToastTitle"
130130
OnErrorHandleAsync="OnErrorHandleAsync" OnInitializedCallback="OnErrorLoggerInitialized">
131131
@HandlerMain()
132132
</ErrorLogger>

0 commit comments

Comments
 (0)