From edd17507b3b75d3b04fd90e5d415c881d0c02aba Mon Sep 17 00:00:00 2001 From: lee Date: Thu, 22 Aug 2024 09:43:01 +0800 Subject: [PATCH 01/15] Add OnClickBefore callback event --- .../Components/ContextMenu/ContextMenuZone.razor.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/BootstrapBlazor/Components/ContextMenu/ContextMenuZone.razor.cs b/src/BootstrapBlazor/Components/ContextMenu/ContextMenuZone.razor.cs index 26990109adf..f149737720a 100644 --- a/src/BootstrapBlazor/Components/ContextMenu/ContextMenuZone.razor.cs +++ b/src/BootstrapBlazor/Components/ContextMenu/ContextMenuZone.razor.cs @@ -17,6 +17,12 @@ public partial class ContextMenuZone [Parameter] public RenderFragment? ChildContent { get; set; } + /// + /// 获得/设置 弹出前回调方法 默认 null + /// + [Parameter] + public Func? OnClickBefore { get; set; } + /// /// 获得/设置 上下文菜单组件集合 /// @@ -37,6 +43,10 @@ internal async Task OnContextMenu(MouseEventArgs args, object? contextItem) // 弹出关联菜单 if (ContextMenu != null) { + if (OnClickBefore is not null) + { + await OnClickBefore(contextItem); + } await ContextMenu.Show(args, contextItem); } } From 1b3de9c1ef1ce08ee3d3fadae444075711bd5b24 Mon Sep 17 00:00:00 2001 From: Argo-AscioTech Date: Thu, 22 Aug 2024 10:00:24 +0800 Subject: [PATCH 02/15] =?UTF-8?q?refactor:=20=E7=A7=BB=E5=8A=A8=20OnBefore?= =?UTF-8?q?ShowCallback=20=E5=88=B0=20ContextMenu=20=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E4=B8=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/ContextMenu/ContextMenu.razor.cs | 10 ++++++++++ .../Components/ContextMenu/ContextMenuZone.razor.cs | 10 ---------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/BootstrapBlazor/Components/ContextMenu/ContextMenu.razor.cs b/src/BootstrapBlazor/Components/ContextMenu/ContextMenu.razor.cs index 00a5e1d7114..664adf0d7cb 100644 --- a/src/BootstrapBlazor/Components/ContextMenu/ContextMenu.razor.cs +++ b/src/BootstrapBlazor/Components/ContextMenu/ContextMenu.razor.cs @@ -34,6 +34,12 @@ public partial class ContextMenu [Parameter] public bool ShowShadow { get; set; } = true; + /// + /// 获得/设置 弹出前回调方法 默认 null + /// + [Parameter] + public Func? OnBeforeShowCallback { get; set; } + private string ZoneId => ContextMenuZone.Id; /// @@ -55,6 +61,10 @@ protected override void OnInitialized() internal async Task Show(MouseEventArgs args, object? contextItem) { ContextItem = contextItem; + if (OnBeforeShowCallback != null) + { + await OnBeforeShowCallback(contextItem); + } await InvokeVoidAsync("show", Id, args); } diff --git a/src/BootstrapBlazor/Components/ContextMenu/ContextMenuZone.razor.cs b/src/BootstrapBlazor/Components/ContextMenu/ContextMenuZone.razor.cs index f149737720a..26990109adf 100644 --- a/src/BootstrapBlazor/Components/ContextMenu/ContextMenuZone.razor.cs +++ b/src/BootstrapBlazor/Components/ContextMenu/ContextMenuZone.razor.cs @@ -17,12 +17,6 @@ public partial class ContextMenuZone [Parameter] public RenderFragment? ChildContent { get; set; } - /// - /// 获得/设置 弹出前回调方法 默认 null - /// - [Parameter] - public Func? OnClickBefore { get; set; } - /// /// 获得/设置 上下文菜单组件集合 /// @@ -43,10 +37,6 @@ internal async Task OnContextMenu(MouseEventArgs args, object? contextItem) // 弹出关联菜单 if (ContextMenu != null) { - if (OnClickBefore is not null) - { - await OnClickBefore(contextItem); - } await ContextMenu.Show(args, contextItem); } } From 9977f12dbae55cee52711082b031b215815c3980 Mon Sep 17 00:00:00 2001 From: Argo-AscioTech Date: Thu, 22 Aug 2024 10:14:11 +0800 Subject: [PATCH 03/15] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=20OnDisabledCa?= =?UTF-8?q?llback=20=E5=9B=9E=E8=B0=83=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ContextMenu/ContextMenuItem.razor | 5 ++-- .../ContextMenu/ContextMenuItem.razor.cs | 26 ++++++++++++++++++- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/BootstrapBlazor/Components/ContextMenu/ContextMenuItem.razor b/src/BootstrapBlazor/Components/ContextMenu/ContextMenuItem.razor index 19b16041749..bb66aff0d1d 100644 --- a/src/BootstrapBlazor/Components/ContextMenu/ContextMenuItem.razor +++ b/src/BootstrapBlazor/Components/ContextMenu/ContextMenuItem.razor @@ -1,7 +1,8 @@ @namespace BootstrapBlazor.Components @inherits BootstrapComponentBase -
+ @Text -
+ diff --git a/src/BootstrapBlazor/Components/ContextMenu/ContextMenuItem.razor.cs b/src/BootstrapBlazor/Components/ContextMenu/ContextMenuItem.razor.cs index 0ebf5bcec22..b16ba690aa1 100644 --- a/src/BootstrapBlazor/Components/ContextMenu/ContextMenuItem.razor.cs +++ b/src/BootstrapBlazor/Components/ContextMenu/ContextMenuItem.razor.cs @@ -22,11 +22,17 @@ public partial class ContextMenuItem public string? Icon { get; set; } /// - /// 获得/设置 是否被禁用 默认 false + /// 获得/设置 是否被禁用 默认 false 优先级低于 /// [Parameter] public bool Disabled { get; set; } + /// + /// 获得/设置 是否被禁用回调方法 默认 null 优先级高于 + /// + [Parameter] + public Func>? OnDisabledCallback { get; set; } + /// /// 获得/设置 点击回调方法 默认 null /// @@ -37,7 +43,10 @@ public partial class ContextMenuItem [NotNull] private ContextMenu? ContextMenu { get; set; } + private bool _disabled; + private string? ClassString => CssBuilder.Default("dropdown-item") + .AddClass("disabled", _disabled) .AddClassFromAttributes(AdditionalAttributes) .Build(); @@ -45,6 +54,21 @@ public partial class ContextMenuItem .AddClass(Icon, !string.IsNullOrEmpty(Icon)) .Build(); + /// + /// + /// + /// + protected override async Task OnParametersSetAsync() + { + await base.OnParametersSetAsync(); + + _disabled = Disabled; + if (OnDisabledCallback != null) + { + _disabled = await OnDisabledCallback(ContextMenu.GetContextItem()); + } + } + private async Task OnClickItem() { if (!Disabled && OnClick != null) From f3cec72490f1daa5645f4a0f38505afc86572da4 Mon Sep 17 00:00:00 2001 From: Argo-AscioTech Date: Thu, 22 Aug 2024 11:45:14 +0800 Subject: [PATCH 04/15] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=20OnDisabledCa?= =?UTF-8?q?llback=20=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/ContextMenu/ContextMenu.razor | 10 +++ .../ContextMenu/ContextMenu.razor.cs | 79 +++++++++++++++---- ...xtMenuItem.razor.cs => ContextMenuItem.cs} | 49 ++++++------ .../ContextMenu/ContextMenuItem.razor | 8 -- 4 files changed, 98 insertions(+), 48 deletions(-) rename src/BootstrapBlazor/Components/ContextMenu/{ContextMenuItem.razor.cs => ContextMenuItem.cs} (59%) delete mode 100644 src/BootstrapBlazor/Components/ContextMenu/ContextMenuItem.razor diff --git a/src/BootstrapBlazor/Components/ContextMenu/ContextMenu.razor b/src/BootstrapBlazor/Components/ContextMenu/ContextMenu.razor index eaadf1deab7..d08829a5289 100644 --- a/src/BootstrapBlazor/Components/ContextMenu/ContextMenu.razor +++ b/src/BootstrapBlazor/Components/ContextMenu/ContextMenu.razor @@ -6,4 +6,14 @@ @ChildContent + + @foreach (var item in _contextMenuItems) + { + + + @item.Text + + } + diff --git a/src/BootstrapBlazor/Components/ContextMenu/ContextMenu.razor.cs b/src/BootstrapBlazor/Components/ContextMenu/ContextMenu.razor.cs index 664adf0d7cb..18e92d2b572 100644 --- a/src/BootstrapBlazor/Components/ContextMenu/ContextMenu.razor.cs +++ b/src/BootstrapBlazor/Components/ContextMenu/ContextMenu.razor.cs @@ -11,6 +11,18 @@ namespace BootstrapBlazor.Components; ///
public partial class ContextMenu { + /// + /// 获得/设置 是否显示阴影 默认 true + /// + [Parameter] + public bool ShowShadow { get; set; } = true; + + /// + /// 获得/设置 弹出前回调方法 默认 null + /// + [Parameter] + public Func? OnBeforeShowCallback { get; set; } + /// /// 获得/设置 子组件 /// @@ -26,21 +38,23 @@ public partial class ContextMenu .AddClassFromAttributes(AdditionalAttributes) .Build(); - private object? ContextItem { get; set; } + private string ZoneId => ContextMenuZone.Id; - /// - /// 获得/设置 是否显示阴影 默认 true - /// - [Parameter] - public bool ShowShadow { get; set; } = true; + private List _contextMenuItems = []; - /// - /// 获得/设置 弹出前回调方法 默认 null - /// - [Parameter] - public Func? OnBeforeShowCallback { get; set; } + private string? GetItemClassString(ContextMenuItem item) => CssBuilder.Default("dropdown-item") + .AddClass("disabled", GetItemTriggerClick(item)) + .Build(); - private string ZoneId => ContextMenuZone.Id; + private bool GetItemTriggerClick(ContextMenuItem item) => item.OnDisabledCallback?.Invoke(item, _contextItem) ?? item.Disabled; + + private static string? GetItemIconString(ContextMenuItem item) => CssBuilder.Default("cm-icon") + .AddClass(item.Icon, !string.IsNullOrEmpty(item.Icon)) + .Build(); + + private MouseEventArgs? _mouseEventArgs; + + private object? _contextItem; /// /// @@ -52,6 +66,22 @@ protected override void OnInitialized() ContextMenuZone.RegisterContextMenu(this); } + /// + /// + /// + /// + /// + protected override async Task OnAfterRenderAsync(bool firstRender) + { + await base.OnAfterRenderAsync(firstRender); + + if (_mouseEventArgs != null) + { + await InvokeVoidAsync("show", Id, _mouseEventArgs); + _mouseEventArgs = null; + } + } + /// /// 弹出 ContextMenu /// @@ -60,17 +90,32 @@ protected override void OnInitialized() /// internal async Task Show(MouseEventArgs args, object? contextItem) { - ContextItem = contextItem; + _contextItem = contextItem; + _mouseEventArgs = args; if (OnBeforeShowCallback != null) { await OnBeforeShowCallback(contextItem); } - await InvokeVoidAsync("show", Id, args); + StateHasChanged(); + } + + private async Task OnClickItem(ContextMenuItem item) + { + if (item.OnClick != null) + { + await item.OnClick(item, _contextItem); + } } /// - /// 获取 ContextItem 值 + /// 增加 ContextMenuItem 方法 /// - /// - internal object? GetContextItem() => ContextItem; + /// + internal void AddItem(ContextMenuItem item) => _contextMenuItems.Add(item); + + /// + /// 移除 ContextMenuItem 方法 + /// + /// + internal void RemoveItem(ContextMenuItem item) => _contextMenuItems.Remove(item); } diff --git a/src/BootstrapBlazor/Components/ContextMenu/ContextMenuItem.razor.cs b/src/BootstrapBlazor/Components/ContextMenu/ContextMenuItem.cs similarity index 59% rename from src/BootstrapBlazor/Components/ContextMenu/ContextMenuItem.razor.cs rename to src/BootstrapBlazor/Components/ContextMenu/ContextMenuItem.cs index b16ba690aa1..01cb6302dea 100644 --- a/src/BootstrapBlazor/Components/ContextMenu/ContextMenuItem.razor.cs +++ b/src/BootstrapBlazor/Components/ContextMenu/ContextMenuItem.cs @@ -7,7 +7,7 @@ namespace BootstrapBlazor.Components; /// /// ContextMenuItem 类 /// -public partial class ContextMenuItem +public class ContextMenuItem : ComponentBase, IDisposable { /// /// 获得/设置 显示文本 @@ -31,7 +31,7 @@ public partial class ContextMenuItem /// 获得/设置 是否被禁用回调方法 默认 null 优先级高于 /// [Parameter] - public Func>? OnDisabledCallback { get; set; } + public Func? OnDisabledCallback { get; set; } /// /// 获得/设置 点击回调方法 默认 null @@ -43,37 +43,40 @@ public partial class ContextMenuItem [NotNull] private ContextMenu? ContextMenu { get; set; } - private bool _disabled; + /// + /// + /// + protected override void OnInitialized() + { + base.OnInitialized(); - private string? ClassString => CssBuilder.Default("dropdown-item") - .AddClass("disabled", _disabled) - .AddClassFromAttributes(AdditionalAttributes) - .Build(); + ContextMenu.AddItem(this); + } - private string? IconString => CssBuilder.Default("cm-icon") - .AddClass(Icon, !string.IsNullOrEmpty(Icon)) - .Build(); + private bool disposedValue; /// - /// + /// 释放资源方法 /// - /// - protected override async Task OnParametersSetAsync() + /// + protected virtual void Dispose(bool disposing) { - await base.OnParametersSetAsync(); - - _disabled = Disabled; - if (OnDisabledCallback != null) + if (!disposedValue) { - _disabled = await OnDisabledCallback(ContextMenu.GetContextItem()); + if (disposing) + { + ContextMenu.RemoveItem(this); + } + disposedValue = true; } } - private async Task OnClickItem() + /// + /// + /// + public void Dispose() { - if (!Disabled && OnClick != null) - { - await OnClick(this, ContextMenu.GetContextItem()); - } + Dispose(disposing: true); + GC.SuppressFinalize(this); } } diff --git a/src/BootstrapBlazor/Components/ContextMenu/ContextMenuItem.razor b/src/BootstrapBlazor/Components/ContextMenu/ContextMenuItem.razor deleted file mode 100644 index bb66aff0d1d..00000000000 --- a/src/BootstrapBlazor/Components/ContextMenu/ContextMenuItem.razor +++ /dev/null @@ -1,8 +0,0 @@ -@namespace BootstrapBlazor.Components -@inherits BootstrapComponentBase - - - - @Text - From a75583171f56907ef1baecd0d4892b54443d966b Mon Sep 17 00:00:00 2001 From: Argo-AscioTech Date: Thu, 22 Aug 2024 11:45:24 +0800 Subject: [PATCH 05/15] =?UTF-8?q?doc:=20=E5=A2=9E=E5=8A=A0=E7=A4=BA?= =?UTF-8?q?=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/Samples/ContextMenus.razor | 28 +++++++++++++++++++ .../Components/Samples/ContextMenus.razor.cs | 24 ++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/src/BootstrapBlazor.Server/Components/Samples/ContextMenus.razor b/src/BootstrapBlazor.Server/Components/Samples/ContextMenus.razor index ad70bd22cb9..5642f1eddea 100644 --- a/src/BootstrapBlazor.Server/Components/Samples/ContextMenus.razor +++ b/src/BootstrapBlazor.Server/Components/Samples/ContextMenus.razor @@ -53,3 +53,31 @@ + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ +
diff --git a/src/BootstrapBlazor.Server/Components/Samples/ContextMenus.razor.cs b/src/BootstrapBlazor.Server/Components/Samples/ContextMenus.razor.cs index 4333decc722..c8a8b0702ce 100644 --- a/src/BootstrapBlazor.Server/Components/Samples/ContextMenus.razor.cs +++ b/src/BootstrapBlazor.Server/Components/Samples/ContextMenus.razor.cs @@ -7,6 +7,10 @@ public partial class ContextMenus { private List> TreeItems { get; set; } = TreeFoo.GetTreeItems(); + private ConsoleLogger _callbackLogger = default!; + + private ConsoleLogger _disabledLogger = default!; + private static Task OnCopy(ContextMenuItem item, object value) { return Task.CompletedTask; @@ -31,4 +35,24 @@ protected override void OnInitialized() Foo = Foo.Generate(LocalizerFoo); Items = Foo.GenerateFoo(LocalizerFoo); } + + private Task OnBeforeShowCallback(object? item) + { + if (item is TreeFoo foo) + { + _callbackLogger.Log($"{foo.Text} trigger"); + } + return Task.CompletedTask; + } + + private bool OnDisabledCallback(object? item) + { + var ret = false; + if (item is Foo foo) + { + ret = foo.Id == 1; + _disabledLogger.Log($"{foo.Name} trigger Disabled: {ret}"); + } + return ret; + } } From cd062c8bb6cac2fc9470d4ab96838697c8d63853 Mon Sep 17 00:00:00 2001 From: Argo-AscioTech Date: Thu, 22 Aug 2024 11:46:51 +0800 Subject: [PATCH 06/15] =?UTF-8?q?doc:=20=E6=9B=B4=E6=96=B0=E7=A4=BA?= =?UTF-8?q?=E4=BE=8B=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/Samples/ContextMenus.razor.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/BootstrapBlazor.Server/Components/Samples/ContextMenus.razor.cs b/src/BootstrapBlazor.Server/Components/Samples/ContextMenus.razor.cs index c8a8b0702ce..c5eba3fd554 100644 --- a/src/BootstrapBlazor.Server/Components/Samples/ContextMenus.razor.cs +++ b/src/BootstrapBlazor.Server/Components/Samples/ContextMenus.razor.cs @@ -45,10 +45,10 @@ private Task OnBeforeShowCallback(object? item) return Task.CompletedTask; } - private bool OnDisabledCallback(object? item) + private bool OnDisabledCallback(ContextMenuItem item, object? context) { var ret = false; - if (item is Foo foo) + if (context is Foo foo) { ret = foo.Id == 1; _disabledLogger.Log($"{foo.Name} trigger Disabled: {ret}"); From 2f45883b2ad93b6b1630baa87bc582562d26de45 Mon Sep 17 00:00:00 2001 From: Argo-AscioTech Date: Thu, 22 Aug 2024 11:47:41 +0800 Subject: [PATCH 07/15] =?UTF-8?q?doc:=20=E6=9B=B4=E6=96=B0=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E7=A4=BA=E4=BE=8B=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/Samples/ContextMenus.razor.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/BootstrapBlazor.Server/Components/Samples/ContextMenus.razor.cs b/src/BootstrapBlazor.Server/Components/Samples/ContextMenus.razor.cs index c5eba3fd554..ca63d8acc29 100644 --- a/src/BootstrapBlazor.Server/Components/Samples/ContextMenus.razor.cs +++ b/src/BootstrapBlazor.Server/Components/Samples/ContextMenus.razor.cs @@ -51,7 +51,7 @@ private bool OnDisabledCallback(ContextMenuItem item, object? context) if (context is Foo foo) { ret = foo.Id == 1; - _disabledLogger.Log($"{foo.Name} trigger Disabled: {ret}"); + _disabledLogger.Log($"{foo.Name} trigger {item.Text} Disabled: {ret}"); } return ret; } From 1afc9623fa1eba47c99495e0959ae455072084a3 Mon Sep 17 00:00:00 2001 From: Argo-AscioTech Date: Thu, 22 Aug 2024 11:56:51 +0800 Subject: [PATCH 08/15] =?UTF-8?q?refactor:=20=E7=B2=BE=E7=AE=80=E9=80=BB?= =?UTF-8?q?=E8=BE=91=E6=8F=90=E9=AB=98=E6=80=A7=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/BootstrapBlazor/Components/ContextMenu/ContextMenu.razor | 5 +++-- .../Components/ContextMenu/ContextMenu.razor.cs | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/BootstrapBlazor/Components/ContextMenu/ContextMenu.razor b/src/BootstrapBlazor/Components/ContextMenu/ContextMenu.razor index d08829a5289..d140b3ead61 100644 --- a/src/BootstrapBlazor/Components/ContextMenu/ContextMenu.razor +++ b/src/BootstrapBlazor/Components/ContextMenu/ContextMenu.razor @@ -9,8 +9,9 @@ @foreach (var item in _contextMenuItems) { - + var disabled = GetItemTriggerClick(item); + @item.Text diff --git a/src/BootstrapBlazor/Components/ContextMenu/ContextMenu.razor.cs b/src/BootstrapBlazor/Components/ContextMenu/ContextMenu.razor.cs index 18e92d2b572..d53b39ea1ba 100644 --- a/src/BootstrapBlazor/Components/ContextMenu/ContextMenu.razor.cs +++ b/src/BootstrapBlazor/Components/ContextMenu/ContextMenu.razor.cs @@ -42,8 +42,8 @@ public partial class ContextMenu private List _contextMenuItems = []; - private string? GetItemClassString(ContextMenuItem item) => CssBuilder.Default("dropdown-item") - .AddClass("disabled", GetItemTriggerClick(item)) + private static string? GetItemClassString(bool disabled) => CssBuilder.Default("dropdown-item") + .AddClass("disabled", disabled) .Build(); private bool GetItemTriggerClick(ContextMenuItem item) => item.OnDisabledCallback?.Invoke(item, _contextItem) ?? item.Disabled; From 786f3974d82f32be1dcd980bc5a7621c41b4b892 Mon Sep 17 00:00:00 2001 From: Argo-AscioTech Date: Thu, 22 Aug 2024 11:57:02 +0800 Subject: [PATCH 09/15] =?UTF-8?q?refactor:=20=E5=A2=9E=E5=8A=A0=E5=8F=AA?= =?UTF-8?q?=E8=AF=BB=E5=85=B3=E9=94=AE=E5=AD=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/Samples/ContextMenus.razor.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/BootstrapBlazor.Server/Components/Samples/ContextMenus.razor.cs b/src/BootstrapBlazor.Server/Components/Samples/ContextMenus.razor.cs index ca63d8acc29..08e9381380e 100644 --- a/src/BootstrapBlazor.Server/Components/Samples/ContextMenus.razor.cs +++ b/src/BootstrapBlazor.Server/Components/Samples/ContextMenus.razor.cs @@ -7,9 +7,9 @@ public partial class ContextMenus { private List> TreeItems { get; set; } = TreeFoo.GetTreeItems(); - private ConsoleLogger _callbackLogger = default!; + private readonly ConsoleLogger _callbackLogger = default!; - private ConsoleLogger _disabledLogger = default!; + private readonly ConsoleLogger _disabledLogger = default!; private static Task OnCopy(ContextMenuItem item, object value) { From 655c2ded59ec34bb932eae2f90b51057ae60ef6e Mon Sep 17 00:00:00 2001 From: Argo-AscioTech Date: Thu, 22 Aug 2024 11:57:47 +0800 Subject: [PATCH 10/15] =?UTF-8?q?revert:=20=E7=A7=BB=E9=99=A4=E5=85=B3?= =?UTF-8?q?=E9=94=AE=E5=AD=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/Samples/ContextMenus.razor.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/BootstrapBlazor.Server/Components/Samples/ContextMenus.razor.cs b/src/BootstrapBlazor.Server/Components/Samples/ContextMenus.razor.cs index 08e9381380e..ca63d8acc29 100644 --- a/src/BootstrapBlazor.Server/Components/Samples/ContextMenus.razor.cs +++ b/src/BootstrapBlazor.Server/Components/Samples/ContextMenus.razor.cs @@ -7,9 +7,9 @@ public partial class ContextMenus { private List> TreeItems { get; set; } = TreeFoo.GetTreeItems(); - private readonly ConsoleLogger _callbackLogger = default!; + private ConsoleLogger _callbackLogger = default!; - private readonly ConsoleLogger _disabledLogger = default!; + private ConsoleLogger _disabledLogger = default!; private static Task OnCopy(ContextMenuItem item, object value) { From dcdfb4c6f07bad1325b3abb83576aa183ed480df Mon Sep 17 00:00:00 2001 From: Argo-AscioTech Date: Thu, 22 Aug 2024 12:09:37 +0800 Subject: [PATCH 11/15] =?UTF-8?q?test:=20=E6=9B=B4=E6=96=B0=E5=8D=95?= =?UTF-8?q?=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/UnitTest/Components/ContextMenuTest.cs | 101 ++++++++------------ 1 file changed, 41 insertions(+), 60 deletions(-) diff --git a/test/UnitTest/Components/ContextMenuTest.cs b/test/UnitTest/Components/ContextMenuTest.cs index 6cc8e929ec1..519ec710c1e 100644 --- a/test/UnitTest/Components/ContextMenuTest.cs +++ b/test/UnitTest/Components/ContextMenuTest.cs @@ -13,12 +13,10 @@ namespace UnitTest.Components; public class ContextMenuTest : BootstrapBlazorTestBase { [Fact] - public async Task ContextMenu_Ok() + public void ContextMenu_Ok() { var localizer = Context.Services.GetRequiredService>(); var foo = Foo.Generate(localizer); - var clicked = false; - var cut = Context.RenderComponent(pb => { pb.AddChildContent(pb => @@ -43,36 +41,25 @@ public async Task ContextMenu_Ok() pb.Add(a => a.Disabled, true); pb.Add(a => a.OnClick, (item, value) => { - clicked = true; return Task.CompletedTask; }); }); }); }); - await cut.InvokeAsync(async () => - { - var row = cut.Find(".context-trigger"); - row.ContextMenu(0, 10, 10, 10, 10, 2, 2); - - var menu = cut.FindComponent(); - menu.Contains("shadow"); - var pi = typeof(ContextMenu).GetProperty("ContextItem", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); - Assert.NotNull(pi); - - var v = pi.GetValue(menu.Instance); - Assert.NotNull(v); + var row = cut.Find(".context-trigger"); + row.ContextMenu(0, 10, 10, 10, 10, 2, 2); - var item = menu.Find(".dropdown-item"); - item.Click(); - Assert.False(clicked); + var menu = cut.FindComponent(); + menu.Contains("shadow"); + var pi = typeof(ContextMenu).GetField("_contextItem", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); + Assert.NotNull(pi); - // 测试 Touch 事件 - TriggerTouchStart(row); + var v = pi.GetValue(menu.Instance); + Assert.NotNull(v); - await Task.Delay(500); - row.TouchEnd(); - }); + var item = menu.Find(".dropdown-item"); + Assert.DoesNotContain("blazor:onclick", item.OuterHtml); } [Theory] @@ -114,29 +101,26 @@ public async Task ContextMenu_Table(TableRenderMode renderMode) }); }); - await cut.InvokeAsync(async () => - { - var row = renderMode == TableRenderMode.CardView ? cut.Find(".table-row") : cut.Find("tbody tr"); - row.ContextMenu(0, 10, 10, 10, 10, 2, 2); + var row = renderMode == TableRenderMode.CardView ? cut.Find(".table-row") : cut.Find("tbody tr"); + row.ContextMenu(0, 10, 10, 10, 10, 2, 2); - var menu = cut.FindComponent(); - var pi = typeof(ContextMenu).GetProperty("ContextItem", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); - Assert.NotNull(pi); + var menu = cut.FindComponent(); + var pi = typeof(ContextMenu).GetField("_contextItem", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); + Assert.NotNull(pi); - var v = pi.GetValue(menu.Instance); - Assert.NotNull(v); + var v = pi.GetValue(menu.Instance); + Assert.NotNull(v); - var item = menu.Find(".dropdown-item"); - item.Click(); - Assert.True(clicked); + var item = menu.Find(".dropdown-item"); + item.Click(); + Assert.True(clicked); - TriggerTouchStart(row); - TriggerTouchStart(row); + TriggerTouchStart(row); + TriggerTouchStart(row); - var options = Context.Services.GetRequiredService>(); - await Task.Delay(100 + options.Value.ContextMenuOptions.OnTouchDelay); - row.TouchEnd(); - }); + var options = Context.Services.GetRequiredService>(); + await Task.Delay(100 + options.Value.ContextMenuOptions.OnTouchDelay); + row.TouchEnd(); } [Fact] @@ -180,29 +164,26 @@ public async Task ContextMenu_TreeView() }); }); - await cut.InvokeAsync(async () => - { - var row = cut.Find(".tree-content"); - row.ContextMenu(0, 10, 10, 10, 10, 2, 2); + var row = cut.Find(".tree-content"); + row.ContextMenu(0, 10, 10, 10, 10, 2, 2); - var menu = cut.FindComponent(); - var pi = typeof(ContextMenu).GetProperty("ContextItem", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); - Assert.NotNull(pi); + var menu = cut.FindComponent(); + var pi = typeof(ContextMenu).GetField("_contextItem", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); + Assert.NotNull(pi); - var v = pi.GetValue(menu.Instance); - Assert.NotNull(v); + var v = pi.GetValue(menu.Instance); + Assert.NotNull(v); - var item = menu.Find(".dropdown-item"); - item.Click(); - Assert.True(clicked); + var item = menu.Find(".dropdown-item"); + item.Click(); + Assert.True(clicked); - TriggerTouchStart(row); - TriggerTouchStart(row); + TriggerTouchStart(row); + TriggerTouchStart(row); - var options = Context.Services.GetRequiredService>(); - await Task.Delay(100 + options.Value.ContextMenuOptions.OnTouchDelay); - row.TouchEnd(); - }); + var options = Context.Services.GetRequiredService>(); + await Task.Delay(100 + options.Value.ContextMenuOptions.OnTouchDelay); + row.TouchEnd(); } private void TriggerTouchStart(IElement row) From a63a6732a10d7426132cc841756df19d376015ad Mon Sep 17 00:00:00 2001 From: Argo-AscioTech Date: Thu, 22 Aug 2024 12:20:17 +0800 Subject: [PATCH 12/15] =?UTF-8?q?test:=20=E6=9B=B4=E6=96=B0=E5=8D=95?= =?UTF-8?q?=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/UnitTest/Components/ContextMenuTest.cs | 44 ++++++++++++++++++++- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/test/UnitTest/Components/ContextMenuTest.cs b/test/UnitTest/Components/ContextMenuTest.cs index 519ec710c1e..84ff1254b29 100644 --- a/test/UnitTest/Components/ContextMenuTest.cs +++ b/test/UnitTest/Components/ContextMenuTest.cs @@ -13,7 +13,7 @@ namespace UnitTest.Components; public class ContextMenuTest : BootstrapBlazorTestBase { [Fact] - public void ContextMenu_Ok() + public async Task ContextMenu_Ok() { var localizer = Context.Services.GetRequiredService>(); var foo = Foo.Generate(localizer); @@ -59,7 +59,47 @@ public void ContextMenu_Ok() Assert.NotNull(v); var item = menu.Find(".dropdown-item"); - Assert.DoesNotContain("blazor:onclick", item.OuterHtml); + Assert.DoesNotContain("blazor:onclick", item.InnerHtml); + + var contextItem = cut.FindComponent(); + contextItem.SetParametersAndRender(pb => + { + pb.Add(a => a.Disabled, false); + pb.Add(a => a.OnDisabledCallback, (item, v) => + { + return true; + }); + }); + item = menu.Find(".dropdown-item"); + Assert.DoesNotContain("blazor:onclick", item.InnerHtml); + + // trigger OnBeforeShowCallback + bool menuCallback = false; + contextItem.SetParametersAndRender(pb => + { + pb.Add(a => a.Disabled, false); + pb.Add(a => a.OnDisabledCallback, (item, v) => + { + menuCallback = true; + return false; + }); + }); + menu.SetParametersAndRender(pb => + { + pb.Add(a => a.OnBeforeShowCallback, v => + { + return Task.CompletedTask; + }); + }); + item = menu.Find(".dropdown-item"); + item.Click(); + Assert.True(menuCallback); + + // 测试 Touch 事件 + TriggerTouchStart(row); + + await Task.Delay(500); + row.TouchEnd(); } [Theory] From ae3b4c7dcd89dafa4473fbaca3d6088c9d3f0bb3 Mon Sep 17 00:00:00 2001 From: Argo-AscioTech Date: Thu, 22 Aug 2024 12:22:07 +0800 Subject: [PATCH 13/15] =?UTF-8?q?test:=20=E5=A2=9E=E5=8A=A0=E5=8D=95?= =?UTF-8?q?=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/UnitTest/Components/ContextMenuTest.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/UnitTest/Components/ContextMenuTest.cs b/test/UnitTest/Components/ContextMenuTest.cs index 84ff1254b29..1e86bbf8d3c 100644 --- a/test/UnitTest/Components/ContextMenuTest.cs +++ b/test/UnitTest/Components/ContextMenuTest.cs @@ -17,6 +17,8 @@ public async Task ContextMenu_Ok() { var localizer = Context.Services.GetRequiredService>(); var foo = Foo.Generate(localizer); + var clicked = false; + var cut = Context.RenderComponent(pb => { pb.AddChildContent(pb => @@ -41,6 +43,7 @@ public async Task ContextMenu_Ok() pb.Add(a => a.Disabled, true); pb.Add(a => a.OnClick, (item, value) => { + clicked = true; return Task.CompletedTask; }); }); @@ -100,6 +103,7 @@ public async Task ContextMenu_Ok() await Task.Delay(500); row.TouchEnd(); + Assert.True(clicked); } [Theory] From 671e48d024aceb2d70f6813a22e17f6313c874dc Mon Sep 17 00:00:00 2001 From: Argo-AscioTech Date: Thu, 22 Aug 2024 12:29:37 +0800 Subject: [PATCH 14/15] =?UTF-8?q?doc:=20=E5=A2=9E=E5=8A=A0=E7=A4=BA?= =?UTF-8?q?=E4=BE=8B=E6=9C=AC=E5=9C=B0=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/BootstrapBlazor.Server/Locales/en-US.json | 6 +++++- src/BootstrapBlazor.Server/Locales/zh-CN.json | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/BootstrapBlazor.Server/Locales/en-US.json b/src/BootstrapBlazor.Server/Locales/en-US.json index dbe7513a698..ce2fc59d1c4 100644 --- a/src/BootstrapBlazor.Server/Locales/en-US.json +++ b/src/BootstrapBlazor.Server/Locales/en-US.json @@ -6042,7 +6042,11 @@ "ContextMenuTableTitle": "Table", "ContextMenuTableIntro": "Right click on the Table to pop up a context menu", "ContextMenuTreeTitle": "Tree", - "ContextMenuTreeIntro": "Right click on the Tree to pop up a context menu" + "ContextMenuTreeIntro": "Right click on the Tree to pop up a context menu", + "ContextMenuCallbackTitle": "ContextMenu Callback", + "ContextMenuCallbackIntro": "By setting the ContextMenu component parameter OnBeforeShowCallback, you can get the callback event before the right-click menu pops up, which can be used for data preparation", + "ContextMenuDisabledTitle": "OnDisabledCallback", + "ContextMenuDisabledIntro": "By setting the ContextMenuItem component parameter OnDisabledCallback callback method, you can set whether the current right-click option is disabled." }, "BootstrapBlazor.Server.Components.Samples.DockViews.Index": { "DockViewTitle": "DockView", diff --git a/src/BootstrapBlazor.Server/Locales/zh-CN.json b/src/BootstrapBlazor.Server/Locales/zh-CN.json index 8a82345a873..6b41e59614a 100644 --- a/src/BootstrapBlazor.Server/Locales/zh-CN.json +++ b/src/BootstrapBlazor.Server/Locales/zh-CN.json @@ -6042,7 +6042,11 @@ "ContextMenuTableTitle": "Table 组件", "ContextMenuTableIntro": "点击 Table 组件行数据右键,弹出上下文关联菜单", "ContextMenuTreeTitle": "Tree 组件", - "ContextMenuTreeIntro": "点击 Tree 组件行数据右键,弹出上下文关联菜单" + "ContextMenuTreeIntro": "点击 Tree 组件行数据右键,弹出上下文关联菜单", + "ContextMenuCallbackTitle": "ContextMenu 回调", + "ContextMenuCallbackIntro": "通过设置 ContextMenu 组件参数 OnBeforeShowCallback 获得右键菜单弹出前回调事件,可用于数据准备工作", + "ContextMenuDisabledTitle": "禁止回调方法", + "ContextMenuDisabledIntro": "通过设置 ContextMenuItem 组件参数 OnDisabledCallback 回调方法可用于设置当前右键选项是否禁用逻辑" }, "BootstrapBlazor.Server.Components.Samples.DockViews.Index": { "DockViewTitle": "DockView 可停靠视图", From 1c84739ea337a754d8b1cafd169a5b7a9ab50757 Mon Sep 17 00:00:00 2001 From: Argo-AscioTech Date: Thu, 22 Aug 2024 12:30:05 +0800 Subject: [PATCH 15/15] chore: bump version 8.8.4-beta03 --- src/BootstrapBlazor/BootstrapBlazor.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/BootstrapBlazor/BootstrapBlazor.csproj b/src/BootstrapBlazor/BootstrapBlazor.csproj index cd098e01e96..137af407982 100644 --- a/src/BootstrapBlazor/BootstrapBlazor.csproj +++ b/src/BootstrapBlazor/BootstrapBlazor.csproj @@ -1,7 +1,7 @@ - 8.8.4-beta02 + 8.8.4-beta03