From b3d2c4fbbbe88ab304e9f606220448a12ec268c3 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Tue, 25 Mar 2025 11:06:43 +0800 Subject: [PATCH 1/6] =?UTF-8?q?refactor:=20=E4=BB=A3=E7=A0=81=E9=87=8D?= =?UTF-8?q?=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BootstrapBlazor.DockView/Components/DockViewV2.razor.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/components/BootstrapBlazor.DockView/Components/DockViewV2.razor.cs b/src/components/BootstrapBlazor.DockView/Components/DockViewV2.razor.cs index f025e7f5..3c763e98 100644 --- a/src/components/BootstrapBlazor.DockView/Components/DockViewV2.razor.cs +++ b/src/components/BootstrapBlazor.DockView/Components/DockViewV2.razor.cs @@ -16,9 +16,7 @@ public partial class DockViewV2 /// 获得/设置 DockView 名称 默认 null 用于本地存储识别 /// [Parameter] -#if NET6_0_OR_GREATER [EditorRequired] -#endif [NotNull] public string? Name { get; set; } From 0696acb0d0249558a6259479547987d42dc42550 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Tue, 25 Mar 2025 12:30:23 +0800 Subject: [PATCH 2/6] =?UTF-8?q?refactor:=20=E6=94=AF=E6=8C=81=E6=9A=97?= =?UTF-8?q?=E9=BB=91=E4=B8=BB=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/DockViewV2.razor.cs | 33 +++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/src/components/BootstrapBlazor.DockView/Components/DockViewV2.razor.cs b/src/components/BootstrapBlazor.DockView/Components/DockViewV2.razor.cs index 3c763e98..f1a3f025 100644 --- a/src/components/BootstrapBlazor.DockView/Components/DockViewV2.razor.cs +++ b/src/components/BootstrapBlazor.DockView/Components/DockViewV2.razor.cs @@ -10,7 +10,7 @@ namespace BootstrapBlazor.Components; /// /// DockViewV2 组件 /// -public partial class DockViewV2 +public partial class DockViewV2 : IDisposable { /// /// 获得/设置 DockView 名称 默认 null 用于本地存储识别 @@ -137,6 +137,10 @@ public partial class DockViewV2 [NotNull] private IConfiguration? Configuration { get; set; } + [Inject] + [NotNull] + private IThemeProvider? ThemeProviderService { get; set; } + private string? ClassString => CssBuilder.Default("bb-dockview") .AddClassFromAttributes(AdditionalAttributes) .Build(); @@ -144,7 +148,7 @@ public partial class DockViewV2 private readonly List _components = []; [NotNull] - private DockViewOptions? _options = default!; + private DockViewOptions? _options = null; /// /// @@ -155,6 +159,8 @@ protected override void OnInitialized() var section = Configuration.GetSection(nameof(DockViewOptions)); _options = section.Exists() ? section.Get() : new(); + + ThemeProviderService.ThemeChangedAsync += OnThemeChangedAsync; } /// @@ -222,6 +228,12 @@ public async Task Reset(string? layoutConfig = null) /// public Task SaveLayout() => InvokeAsync("save", Id); + private Task OnThemeChangedAsync(string themeName) + { + Theme = themeName == "dark" ? DockViewTheme.Dark : DockViewTheme.Light; + return Task.CompletedTask; + } + /// /// 标签页关闭回调方法 由 JavaScript 调用 /// @@ -269,4 +281,21 @@ public async Task SplitterCallbackAsync() await OnSplitterCallbackAsync(); } } + + private void Dispose(bool disposing) + { + if (disposing) + { + ThemeProviderService.ThemeChangedAsync -= OnThemeChangedAsync; + } + } + + /// + /// + /// + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } } From c8c12b6edc418cb2490b9f9fa1689404d4e6387d Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Tue, 25 Mar 2025 13:07:09 +0800 Subject: [PATCH 3/6] =?UTF-8?q?refactor:=20=E5=A2=9E=E5=8A=A0=20switchThem?= =?UTF-8?q?e=20=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wwwroot/js/dockview-utils.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/components/BootstrapBlazor.DockView/wwwroot/js/dockview-utils.js b/src/components/BootstrapBlazor.DockView/wwwroot/js/dockview-utils.js index beaf9e22..bfbe378a 100644 --- a/src/components/BootstrapBlazor.DockView/wwwroot/js/dockview-utils.js +++ b/src/components/BootstrapBlazor.DockView/wwwroot/js/dockview-utils.js @@ -6,12 +6,13 @@ import { getConfig, reloadFromConfig, loadPanelsFromLocalstorage, saveConfig } f import './dockview-extensions.js' const cerateDockview = (el, options) => { + const theme = options.theme || "dockview-theme-light"; const template = el.querySelector('template'); const dockview = new DockviewComponent(el, { parentElement: el, theme: { name: "bb-dockview", - className: options.theme || "dockview-theme-light", + className: theme, dndOverlayMounting: 'absolute', dndPanelOverlay: 'group' }, @@ -35,6 +36,14 @@ const initDockview = (dockview, options, template) => { window.dockview = dockview; } + dockview.switchTheme = theme => { + const themeName = `dockview-theme-${theme}`; + if (dockview.options.theme.className !== themeName) { + dockview.options.theme.className = themeName; + dockview.updateTheme(); + } + } + dockview.update = options => { if (options.layoutConfig) { reloadFromConfig(dockview, options); From 554eafa1107d0044a87cda3f2dbdc5c0ae33dd3a Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Tue, 25 Mar 2025 13:07:46 +0800 Subject: [PATCH 4/6] =?UTF-8?q?refactor:=20=E5=A2=9E=E5=8A=A0=E4=B8=BB?= =?UTF-8?q?=E9=A2=98=E5=93=8D=E5=BA=94=E5=BC=8F=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BootstrapBlazor.DockView/Components/DockViewV2.razor.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/components/BootstrapBlazor.DockView/Components/DockViewV2.razor.js b/src/components/BootstrapBlazor.DockView/Components/DockViewV2.razor.js index 470f800b..e321bd62 100644 --- a/src/components/BootstrapBlazor.DockView/Components/DockViewV2.razor.js +++ b/src/components/BootstrapBlazor.DockView/Components/DockViewV2.razor.js @@ -1,6 +1,7 @@ import { addLink } from '../../BootstrapBlazor/modules/utility.js' import { cerateDockview } from '../js/dockview-utils.js' import Data from '../../BootstrapBlazor/modules/data.js' +import EventHandler from "../../BootstrapBlazor/modules/event-handler.js" export async function init(id, invoke, options) { await addLink("./_content/BootstrapBlazor.DockView/css/dockview-bb.css") @@ -24,6 +25,8 @@ export async function init(id, invoke, options) { dockview.on('groupSizeChanged', () => { invoke.invokeMethodAsync(options.splitterCallback); }); + + EventHandler.on(document, 'changed.bb.theme', updateTheme); } export function update(id, options) { @@ -57,6 +60,8 @@ export function dispose(id) { Data.remove(id); if (dock) { + EventHandler.off(document, 'changed.bb.theme', dock.updateTheme); + const { dockview } = dock; if (dockview) { dockview.dispose(); From 5031aa992d589ca4487422523907247af0b1f937 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Tue, 25 Mar 2025 13:08:03 +0800 Subject: [PATCH 5/6] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E5=8A=A0?= =?UTF-8?q?=E8=BD=BD=E6=97=B6=E6=A3=80=E6=B5=8B=E4=B8=BB=E9=A2=98=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/DockViewV2.razor.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/components/BootstrapBlazor.DockView/Components/DockViewV2.razor.js b/src/components/BootstrapBlazor.DockView/Components/DockViewV2.razor.js index e321bd62..06440b21 100644 --- a/src/components/BootstrapBlazor.DockView/Components/DockViewV2.razor.js +++ b/src/components/BootstrapBlazor.DockView/Components/DockViewV2.razor.js @@ -1,4 +1,4 @@ -import { addLink } from '../../BootstrapBlazor/modules/utility.js' +import { addLink, getTheme } from '../../BootstrapBlazor/modules/utility.js' import { cerateDockview } from '../js/dockview-utils.js' import Data from '../../BootstrapBlazor/modules/data.js' import EventHandler from "../../BootstrapBlazor/modules/event-handler.js" @@ -10,8 +10,15 @@ export async function init(id, invoke, options) { return; } - const dockview = cerateDockview(el, options) - Data.set(id, { el, dockview }); + if(options.theme === 'dockview-theme-light') { + let theme = getTheme(); + if (theme === 'dark') { + options.theme = `dockview-theme-dark`; + } + } + const dockview = cerateDockview(el, options); + const updateTheme = e => dockview.switchTheme(e.theme); + Data.set(id, { el, dockview, updateTheme }); dockview.on('initialized', () => { invoke.invokeMethodAsync(options.initializedCallback); From 408c69f95a7a662139dd4ccc29ce406abb63e39e Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Tue, 25 Mar 2025 13:08:18 +0800 Subject: [PATCH 6/6] chore: bump version 9.1.8 --- .../BootstrapBlazor.DockView.csproj | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/BootstrapBlazor.DockView/BootstrapBlazor.DockView.csproj b/src/components/BootstrapBlazor.DockView/BootstrapBlazor.DockView.csproj index b6b7b0a2..05dd23b3 100644 --- a/src/components/BootstrapBlazor.DockView/BootstrapBlazor.DockView.csproj +++ b/src/components/BootstrapBlazor.DockView/BootstrapBlazor.DockView.csproj @@ -1,7 +1,7 @@ - + - 9.1.7 + 9.1.8 @@ -10,7 +10,7 @@ - +