Skip to content

Commit 601ea24

Browse files
fix(DockView): persist active panel when renderer is always (#1284)
* fix(DockView): persist active panel when renderer is always (#IKGH29) * chore: bump version 11.0.0-rc.3 * chore: 清理注释 --------- Co-authored-by: Argo Zhang <argo@live.ca>
1 parent d135fbe commit 601ea24

3 files changed

Lines changed: 19 additions & 16 deletions

File tree

‎src/components/BootstrapBlazor.DockView/BootstrapBlazor.DockView.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>11.0.0-rc.2.1</Version>
4+
<Version>11.0.0-rc.3</Version>
55
</PropertyGroup>
66

77
<PropertyGroup>

‎src/components/BootstrapBlazor.DockView/wwwroot/js/dockview-panel.js‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ const observePanelActiveChange = panel => {
1515
const renderer = dockview.params.options.renderer;
1616
if (renderer === 'onlyWhenVisible' && dockview.params.inited) {
1717
if (isVisible) {
18-
saveConfig(panel.accessor)
19-
const visiblePanels = dockview.groups.map(g => g.panels.find(p => p.params.isActive) || g.panels.find(p => p.api.isVisible))
18+
const visiblePanels = dockview.groups.map(g => g.activePanel)
2019
dockview._loadTabs?.fire(visiblePanels.filter(p => Boolean(p)).map(p => p.params.key));
2120
}
2221
else {

‎src/components/BootstrapBlazor.DockView/wwwroot/js/dockview-utils.js‎

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ const cerateDockview = (el, options) => {
2626
return dockview;
2727
}
2828

29-
// Carry the `maximizing` flag on EVERY exit-maximize, not just the toggle button: the core also exits
30-
// maximize when a group is removed/hidden/moved/added, and without the flag the restored siblings blank.
3129
const guardMaximizeExit = dockview => {
3230
const gridview = dockview.gridview;
3331
if (!gridview) return;
@@ -45,15 +43,11 @@ const guardMaximizeExit = dockview => {
4543
};
4644
}
4745

48-
// Fix "groups evenly split after refresh": while collapsed (size 0) skip overwriting existing
49-
// proportions, else saveProportions freezes the collapsed equal-minimums as the split. _proportions is
50-
// undefined only on the first deserialize save — let that through. Upstream fix: add `size > 0` to
51-
// dockview-core's Splitview.saveProportions, then drop this patch.
5246
const guardCollapsedSaveProportions = dockview => {
5347
const splitview = dockview.gridview?.root?.splitview;
5448
if (!splitview) return;
5549
const proto = Object.getPrototypeOf(splitview);
56-
if (proto.__bbCollapseGuard) return; // Splitview.prototype is shared by all instances; patch once
50+
if (proto.__bbCollapseGuard) return;
5751
proto.__bbCollapseGuard = true;
5852
const original = proto.saveProportions;
5953
proto.saveProportions = function () {
@@ -123,8 +117,8 @@ const postLayoutInit = (dockview, options) => {
123117
})
124118

125119
if (options.renderer === 'onlyWhenVisible') {
126-
const visiblePanels = dockview.groups.filter(g => g.isVisible).map(g => g.panels.find(p => p.params.isActive) || g.panels.find(p => p.api.isVisible))
127-
dockview._loadTabs?.fire(visiblePanels.filter(p => p.params.key).map(p => p.params.key));
120+
const visiblePanels = dockview.groups.filter(g => g.isVisible).map(g => g.activePanel)
121+
dockview._loadTabs?.fire(visiblePanels.filter(p => p && p.params.key).map(p => p.params.key));
128122
}
129123
dockview._initialized?.fire();
130124
})
@@ -213,6 +207,20 @@ const initDockview = (dockview, options, template) => {
213207
saveConfig(dockview)
214208
})
215209

210+
dockview.onDidActivePanelChange(() => {
211+
saveConfig(dockview)
212+
})
213+
214+
let movePanelTimer = null
215+
dockview.onDidMovePanel(() => {
216+
if (movePanelTimer) return
217+
movePanelTimer = setTimeout(() => {
218+
movePanelTimer = null
219+
if (dockview._isDisposed) return
220+
saveConfig(dockview)
221+
}, 0)
222+
})
223+
216224
dockview._rootDropTarget.onDrop(() => {
217225
saveConfig(dockview)
218226
})
@@ -249,15 +257,12 @@ const setWidth = (target, dockview) => {
249257
let dropdown = header.querySelector('.dv-right-actions-container>.dropdown')
250258
if (!dropdown) return
251259
let dropMenu = dropdown.querySelector('.dropdown-menu')
252-
// `shrinking` (a strict width drop) gates the active-panel switch below — it must NOT fire during the
253-
// transient expand a group goes through when a hidden view becomes visible (would switch + blank it).
254260
const group = dockview.params.inited ? dockview.groups.find(g => g.element === header.parentElement) : null
255261
const shrinking = group && group._lastHeaderWidth !== undefined && header.offsetWidth < group._lastHeaderWidth
256262
if (group) group._lastHeaderWidth = header.offsetWidth
257263

258264
if (voidWidth === 0) {
259265
if (tabsContainer.children.length <= 1) return
260-
// On shrink, if the active tab would overflow, switch to the first panel before tucking it away.
261266
if (shrinking) {
262267
const activeTab = tabsContainer.querySelector('.dv-tab.dv-active-tab')
263268
if (activeTab && activeTab.offsetLeft + activeTab.offsetWidth > tabsContainer.offsetWidth) {
@@ -288,7 +293,6 @@ const setWidth = (target, dockview) => {
288293
}
289294
}
290295
}
291-
// Fallback: keep an active panel when the group has none (e.g. the active one was closed).
292296
if (group && !group.activePanel) {
293297
group.panels[0]?.api.setActive()
294298
}

0 commit comments

Comments
 (0)