From c0c9596df4828b2cc7258097d9643c8261fcea0c Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Sun, 2 Mar 2025 10:08:18 +0800 Subject: [PATCH 1/6] =?UTF-8?q?refactor:=20=E5=A2=9E=E5=BC=BA=20deepMerge?= =?UTF-8?q?=20=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/BootstrapBlazor/wwwroot/modules/utility.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/BootstrapBlazor/wwwroot/modules/utility.js b/src/BootstrapBlazor/wwwroot/modules/utility.js index ff76dbff688..2292268a545 100644 --- a/src/BootstrapBlazor/wwwroot/modules/utility.js +++ b/src/BootstrapBlazor/wwwroot/modules/utility.js @@ -802,13 +802,17 @@ export function switchTheme(theme, x = 0, y = 0, sync = true) { } } -const deepMerge = (obj1, obj2) => { - for (let key in obj2) { +const deepMerge = (obj1, obj2, skipNull = true) => { + for (const key in obj2) { if (obj2.hasOwnProperty(key)) { if (obj2[key] instanceof Object && obj1[key] instanceof Object) { obj1[key] = deepMerge(obj1[key], obj2[key]); } else { + const value = obj2[key]; + if (skipNull && value === null) { + continue; + } obj1[key] = obj2[key]; } } From 7a76fab57eb881ba331aeaecf1fb4665c7166d46 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Sun, 2 Mar 2025 10:23:49 +0800 Subject: [PATCH 2/6] =?UTF-8?q?refactor:=20=E5=A2=9E=E5=8A=A0=20registerBo?= =?UTF-8?q?otstrapBlazorModule=20=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/BootstrapBlazor/wwwroot/modules/utility.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/BootstrapBlazor/wwwroot/modules/utility.js b/src/BootstrapBlazor/wwwroot/modules/utility.js index 2292268a545..449f4889321 100644 --- a/src/BootstrapBlazor/wwwroot/modules/utility.js +++ b/src/BootstrapBlazor/wwwroot/modules/utility.js @@ -820,6 +820,11 @@ const deepMerge = (obj1, obj2, skipNull = true) => { return obj1; } +export function registerBootstrapBlazorModule(name, module) { + window.BootstrapBlazor ??= {}; + window.BootstrapBlazor[name] ??= deepMerge(window.BootstrapBlazor[name] ?? {}, module); +} + export function setTitle(title) { document.title = title; } From 006baeda68f975e024d0d3f3925dc9c3168439e2 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Sun, 2 Mar 2025 10:24:07 +0800 Subject: [PATCH 3/6] =?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 --- .../AutoComplete/AutoComplete.razor.js | 47 ++++++++----------- 1 file changed, 20 insertions(+), 27 deletions(-) diff --git a/src/BootstrapBlazor/Components/AutoComplete/AutoComplete.razor.js b/src/BootstrapBlazor/Components/AutoComplete/AutoComplete.razor.js index 6aaa4aee02e..b1c0f2f6954 100644 --- a/src/BootstrapBlazor/Components/AutoComplete/AutoComplete.razor.js +++ b/src/BootstrapBlazor/Components/AutoComplete/AutoComplete.razor.js @@ -1,14 +1,10 @@ -import { debounce } from "../../modules/utility.js" +import { debounce, registerBootstrapBlazorModule } from "../../modules/utility.js" import { handleKeyUp, select, selectAllByFocus, selectAllByEnter } from "../Input/BootstrapInput.razor.js" import Data from "../../modules/data.js" import EventHandler from "../../modules/event-handler.js" import Input from "../../modules/input.js" import Popover from "../../modules/base-popover.js" -if (window.BootstrapBlazor === void 0) { - window.BootstrapBlazor = {}; -} - export function init(id, invoke) { const el = document.getElementById(id) const menu = el.querySelector('.dropdown-menu') @@ -76,31 +72,28 @@ export function init(id, invoke) { filterCallback(v); }); - if (window.BootstrapBlazor.AutoComplete === void 0) { - window.BootstrapBlazor.AutoComplete = { - hooked: false, - registerCloseDropdownHandler: function () { - if (this.hooked === false) { - this.hooked = true; - - EventHandler.on(document, 'click', e => { - [...document.querySelectorAll('.auto-complete.show')].forEach(a => { - const ac = e.target.closest('.auto-complete'); - if (ac === a) { - return; - } - - const el = a.querySelector('[data-bs-toggle="bb.dropdown"]'); - if (el === null) { - a.classList.remove('show'); - } - }); + registerBootstrapBlazorModule('AutoComplete', { + hooked: false, + registerCloseDropdownHandler: function () { + if (this.hooked === false) { + this.hooked = true; + + EventHandler.on(document, 'click', e => { + [...document.querySelectorAll('.auto-complete.show')].forEach(a => { + const ac = e.target.closest('.auto-complete'); + if (ac === a) { + return; + } + + const el = a.querySelector('[data-bs-toggle="bb.dropdown"]'); + if (el === null) { + a.classList.remove('show'); + } }); - } + }); } } - } - + }); window.BootstrapBlazor.AutoComplete.registerCloseDropdownHandler(); } From 917d43c0f2078684617a60e9749bfbc6e8c6c19f Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Sun, 2 Mar 2025 10:31:55 +0800 Subject: [PATCH 4/6] =?UTF-8?q?refactor:=20=E5=A2=9E=E5=8A=A0=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E5=80=BC=E5=87=8F=E5=B0=91=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/BootstrapBlazor/wwwroot/modules/utility.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/BootstrapBlazor/wwwroot/modules/utility.js b/src/BootstrapBlazor/wwwroot/modules/utility.js index 449f4889321..ac2b7b0553a 100644 --- a/src/BootstrapBlazor/wwwroot/modules/utility.js +++ b/src/BootstrapBlazor/wwwroot/modules/utility.js @@ -823,6 +823,7 @@ const deepMerge = (obj1, obj2, skipNull = true) => { export function registerBootstrapBlazorModule(name, module) { window.BootstrapBlazor ??= {}; window.BootstrapBlazor[name] ??= deepMerge(window.BootstrapBlazor[name] ?? {}, module); + return window.BootstrapBlazor[name]; } export function setTitle(title) { From a3d60af41b28f7e3e417289212ff2a226eeb1f1a Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Sun, 2 Mar 2025 10:32:10 +0800 Subject: [PATCH 5/6] =?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 --- .../Components/AutoComplete/AutoComplete.razor.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/BootstrapBlazor/Components/AutoComplete/AutoComplete.razor.js b/src/BootstrapBlazor/Components/AutoComplete/AutoComplete.razor.js index b1c0f2f6954..cfca16f9777 100644 --- a/src/BootstrapBlazor/Components/AutoComplete/AutoComplete.razor.js +++ b/src/BootstrapBlazor/Components/AutoComplete/AutoComplete.razor.js @@ -72,7 +72,7 @@ export function init(id, invoke) { filterCallback(v); }); - registerBootstrapBlazorModule('AutoComplete', { + const module = registerBootstrapBlazorModule('AutoComplete', { hooked: false, registerCloseDropdownHandler: function () { if (this.hooked === false) { @@ -94,7 +94,7 @@ export function init(id, invoke) { } } }); - window.BootstrapBlazor.AutoComplete.registerCloseDropdownHandler(); + module.registerCloseDropdownHandler(); } const handlerKeyup = (ac, e) => { From 02c3340d967e2c249523e3583665475da7d3594b Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Sun, 2 Mar 2025 10:32:25 +0800 Subject: [PATCH 6/6] =?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 --- .../wwwroot/modules/utility.js | 33 ++++++++----------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/src/BootstrapBlazor/wwwroot/modules/utility.js b/src/BootstrapBlazor/wwwroot/modules/utility.js index ac2b7b0553a..7e203f6e7fe 100644 --- a/src/BootstrapBlazor/wwwroot/modules/utility.js +++ b/src/BootstrapBlazor/wwwroot/modules/utility.js @@ -571,28 +571,23 @@ const hackPopover = (popover, css) => { } const hackTooltip = function () { - window.BootstrapBlazor ??= {}; - - if (window.BootstrapBlazor.Tooltip === void 0) { - window.BootstrapBlazor.Tooltip = { - hooked: false, - hackDispose: function () { - if (this.hooked === false) { - this.hooked = true; - - const originalDispose = bootstrap.Tooltip.prototype.dispose; - bootstrap.Tooltip.prototype.dispose = function () { - originalDispose.call(this); - // fix https://github.com/twbs/bootstrap/issues/37474 - this._activeTrigger = {}; - this._element = document.createElement('noscript'); // placeholder with no behavior - } + const tooltip = registerBootstrapBlazorModule('Tooltip', { + hooked: false, + hackDispose: function () { + if (this.hooked === false) { + this.hooked = true; + + const originalDispose = bootstrap.Tooltip.prototype.dispose; + bootstrap.Tooltip.prototype.dispose = function () { + originalDispose.call(this); + // fix https://github.com/twbs/bootstrap/issues/37474 + this._activeTrigger = {}; + this._element = document.createElement('noscript'); // placeholder with no behavior } } } - } - - window.BootstrapBlazor.Tooltip.hackDispose(); + }); + tooltip.hackDispose(); } const setIndeterminate = (object, state) => {