Skip to content

Commit 14f2061

Browse files
fix(DockView): wrong position when switch visible (#480)
* fix: 修复dockview默认隐藏的窗口显示时位置和大小不对 * feat: 增加EmptyContent过滤 * chore: bump version 9.1.15 * refactor: 代码格式化 --------- Co-authored-by: zhaijunlei <276318515@qq.com>
1 parent 5ae8d42 commit 14f2061

4 files changed

Lines changed: 30 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>9.1.14</Version>
4+
<Version>9.1.15</Version>
55
</PropertyGroup>
66

77
<PropertyGroup>

src/components/BootstrapBlazor.DockView/wwwroot/js/dockview-config.js

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ const renewConfigFromOptions = (config, options) => {
5555
if (panel) {
5656
optionPanel.params = {
5757
...panel.params,
58-
...optionPanel.params
58+
...optionPanel.params,
59+
visible: panel.params.visible
5960
}
6061
config.panels[panel.id] = optionPanel
6162
}
@@ -197,6 +198,7 @@ const removePanel = (branch, panel, parent) => {
197198
const getConfigFromContent = options => {
198199
const { width, height } = { width: 800, height: 600 };
199200
const getGroupId = getGroupIdFunc()
201+
options = filterEmptyContent(options)
200202
const panels = {}, rootType = options.content[0].type
201203
const orientation = rootType === 'column' ? 'VERTICAL' : 'HORIZONTAL';
202204
const root = getTree(options.content[0], { width, height, orientation }, options, panels, getGroupId, options)
@@ -211,7 +213,17 @@ const getGroupIdFunc = () => {
211213
let currentId = 0;
212214
return () => `${currentId++}`;
213215
}
214-
216+
const filterEmptyContent = function(data) {
217+
if (!data || typeof data !== 'object') return data;
218+
219+
if (Array.isArray(data.content)) {
220+
data.content = data.content
221+
.map(item => filterEmptyContent(item))
222+
.filter(item => !(Array.isArray(item.content) && item.content.length === 0));
223+
}
224+
225+
return data;
226+
}
215227
const getTree = (contentItem, { width, height, orientation }, parent, panels, getGroupId, options) => {
216228
const length = parent.content.length;
217229
const boxSize = orientation === 'HORIZONTAL' ? width : height;
@@ -279,24 +291,22 @@ const getLeafNode = (contentItem, size, boxSize, parent, panels, getGroupId, opt
279291
const visible = contentItem.visible !== false;
280292
const data = {
281293
type: 'leaf',
282-
visible,
294+
visible: true,
283295
size: getSize(boxSize, contentItem.width || contentItem.height) || size,
284296
data: {
285297
id: getGroupId(),
286298
activeView: contentItem.id,
287299
hideHeader: contentItem.showHeader === false,
288-
views: visible ? [contentItem.id] : []
300+
views: [contentItem.id]
289301
}
290302
};
291-
if (visible) {
292-
panels[contentItem.id] = {
293-
id: contentItem.id,
294-
title: contentItem.title,
295-
renderer: contentItem.renderer || options.renderer,
296-
tabComponent: contentItem.componentName,
297-
contentComponent: contentItem.componentName,
298-
params: { ...contentItem, parentId: parent.id }
299-
}
303+
panels[contentItem.id] = {
304+
id: contentItem.id,
305+
title: contentItem.title,
306+
renderer: contentItem.renderer || options.renderer,
307+
tabComponent: contentItem.componentName,
308+
contentComponent: contentItem.componentName,
309+
params: { ...contentItem, parentId: parent.id }
300310
}
301311
return data;
302312
}

src/components/BootstrapBlazor.DockView/wwwroot/js/dockview-group.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ const addPanelWidthGroupId = (dockview, panel, index) => {
9797
renderer: panel.renderer,
9898
component: panel.component,
9999
position: { referenceGroup: group, index: index || 0 },
100-
params: { ...panel.params, rect, packup }
100+
params: { ...panel.params, rect, packup, visible: true }
101101
})
102102
dockview._panelVisibleChanged?.fire({ title: panel.title, status: true });
103103
}

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,11 @@ const initDockview = (dockview, options, template) => {
9191
const delPanelsStr = localStorage.getItem(dockview.params.options.localStorageKey + '-panels')
9292
const delPanels = delPanelsStr && JSON.parse(delPanelsStr) || []
9393
panels.forEach(panel => {
94-
dockview._panelVisibleChanged?.fire({ title: panel.title, status: true });
94+
const visible = panel.params.visible
95+
if (!visible) {
96+
dockview.removePanel(panel)
97+
}
98+
dockview._panelVisibleChanged?.fire({ title: panel.title, status: visible });
9599
})
96100
delPanels.forEach(panel => {
97101
dockview._panelVisibleChanged?.fire({ title: panel.title, status: false });

0 commit comments

Comments
 (0)