From 88ed77e7aabfa5a7d782c0a6655bb726ee276447 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Wed, 2 Apr 2025 08:56:17 +0800 Subject: [PATCH 1/3] =?UTF-8?q?refactor:=20=E7=B2=BE=E7=AE=80=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/BootstrapBlazor/Components/ContextMenu/ContextMenu.razor | 1 - 1 file changed, 1 deletion(-) diff --git a/src/BootstrapBlazor/Components/ContextMenu/ContextMenu.razor b/src/BootstrapBlazor/Components/ContextMenu/ContextMenu.razor index 624cff6ace2..ab11b13f27e 100644 --- a/src/BootstrapBlazor/Components/ContextMenu/ContextMenu.razor +++ b/src/BootstrapBlazor/Components/ContextMenu/ContextMenu.razor @@ -12,7 +12,6 @@ if (context is ContextMenuDivider) { - continue; } else if (context is ContextMenuItem item) { From e06a96747326d0514497bbd55d37fd8f1d4ab202 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Wed, 2 Apr 2025 09:16:38 +0800 Subject: [PATCH 2/3] =?UTF-8?q?perf(ContextMenu):=20=E6=8F=90=E9=AB=98?= =?UTF-8?q?=E6=80=A7=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ContextMenu/ContextMenu.razor.js | 64 ++++++++----------- .../wwwroot/modules/utility.js | 4 +- 2 files changed, 30 insertions(+), 38 deletions(-) diff --git a/src/BootstrapBlazor/Components/ContextMenu/ContextMenu.razor.js b/src/BootstrapBlazor/Components/ContextMenu/ContextMenu.razor.js index c40b88d108b..be1d38622d8 100644 --- a/src/BootstrapBlazor/Components/ContextMenu/ContextMenu.razor.js +++ b/src/BootstrapBlazor/Components/ContextMenu/ContextMenu.razor.js @@ -1,37 +1,37 @@ import Data from "../../modules/data.js" import EventHandler from "../../modules/event-handler.js" import { createPopper, computePosition } from '../../modules/floating-ui.js' +import { registerBootstrapBlazorModule } from "../../modules/utility.js" export function init(id) { const el = document.getElementById(id) if (el) { - window.bb = window.bb || {}; - if (bb.cancelContextMenuHandler === void 0) { - bb.contextMenus = [] - bb.cancelContextMenuHandler = e => { - const menu = document.querySelector('.bb-cm.show') - if (menu) { - const menuId = menu.getAttribute('id') - const cm = Data.get(menuId) - if (cm.popper) { - cm.popper() - } - - menu.classList.remove('show') - const zone = getZone(menu) - if (zone) { - zone.appendChild(menu) + const cm = { el, zone: getZone(el) }; + Data.set(id, cm); + + registerBootstrapBlazorModule("ContextMenu", id, context => { + if (context.cancelContextMenuHandler === void 0) { + context.cancelContextMenuHandler = e => { + const menu = document.querySelector('.bb-cm.show') + if (menu) { + const menuId = menu.getAttribute('id') + const cm = Data.get(menuId) + if (cm.popper) { + cm.popper() + } + + menu.classList.remove('show') + const zone = getZone(menu) + if (zone) { + zone.appendChild(menu) + } } } } - EventHandler.on(document, 'click', bb.cancelContextMenuHandler) - EventHandler.on(document, 'contextmenu', bb.cancelContextMenuHandler) - } - bb.contextMenus.push(el) - - const cm = { el, zone: getZone(el) } - Data.set(id, cm) + EventHandler.on(document, 'click', context.cancelContextMenuHandler) + EventHandler.on(document, 'contextmenu', context.cancelContextMenuHandler) + }) } } @@ -64,19 +64,11 @@ export function dispose(id) { cm.popper() } - window.bb = window.bb || { contextMenus: [] } - const index = bb.contextMenus.indexOf(el) - if (index > -1) { - bb.contextMenus.splice(index, 1) - } - - if (bb.contextMenus.length === 0) { - if (bb.cancelContextMenuHandler) { - EventHandler.off(document, 'click', bb.cancelContextMenuHandler) - EventHandler.off(document, 'contextmenu', bb.cancelContextMenuHandler) - } - delete bb.cancelContextMenuHandler; - } + const { ContextMenu } = window.BootstrapBlazor; + ContextMenu.dispose(id, context => { + EventHandler.off(document, 'click', context.cancelContextMenuHandler) + EventHandler.off(document, 'contextmenu', context.cancelContextMenuHandler) + }); } } diff --git a/src/BootstrapBlazor/wwwroot/modules/utility.js b/src/BootstrapBlazor/wwwroot/modules/utility.js index f8e6f86aeab..98576bdd756 100644 --- a/src/BootstrapBlazor/wwwroot/modules/utility.js +++ b/src/BootstrapBlazor/wwwroot/modules/utility.js @@ -822,7 +822,7 @@ export function registerBootstrapBlazorModule(name, identifier, callback) { } if (this._init === false) { this._init = true; - cb(); + cb(this); } return this; }, @@ -832,7 +832,7 @@ export function registerBootstrapBlazorModule(name, identifier, callback) { } if (this._items.length === 0 && cb) { this._init = false; - cb(); + cb(this); } } }; From bd59a5df1f5e6cc0142736d98172f58536ffd4e6 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Wed, 2 Apr 2025 09:20:40 +0800 Subject: [PATCH 3/3] =?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/LayoutTest.cs | 2 +- test/UnitTest/Services/ThrottleTest.cs | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/test/UnitTest/Components/LayoutTest.cs b/test/UnitTest/Components/LayoutTest.cs index 2238326bf5e..16e98a8cd76 100644 --- a/test/UnitTest/Components/LayoutTest.cs +++ b/test/UnitTest/Components/LayoutTest.cs @@ -581,7 +581,7 @@ public void Authorized_Ok() pb.Add(a => a.AdditionalAssemblies, new Assembly[] { GetType().Assembly }); pb.Add(a => a.OnAuthorizing, url => Task.FromResult(true)); }); - cut.Contains("
"); + cut.MarkupMatches("
"); Context.DisposeComponents(); } } diff --git a/test/UnitTest/Services/ThrottleTest.cs b/test/UnitTest/Services/ThrottleTest.cs index 7952f092450..bed320429ac 100644 --- a/test/UnitTest/Services/ThrottleTest.cs +++ b/test/UnitTest/Services/ThrottleTest.cs @@ -95,7 +95,6 @@ await Assert.ThrowsAnyAsync(() => dispatcher.Throttle { count++; }); - Assert.Equal(2, count); } [Fact]