Skip to content

Commit 2077f8d

Browse files
committed
feat: 增加EmptyContent过滤
1 parent 103f853 commit 2077f8d

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ const removePanel = (branch, panel, parent) => {
198198
const getConfigFromContent = options => {
199199
const { width, height } = { width: 800, height: 600 };
200200
const getGroupId = getGroupIdFunc()
201+
options = filterEmptyContent(options)
201202
const panels = {}, rootType = options.content[0].type
202203
const orientation = rootType === 'column' ? 'VERTICAL' : 'HORIZONTAL';
203204
const root = getTree(options.content[0], { width, height, orientation }, options, panels, getGroupId, options)
@@ -212,7 +213,17 @@ const getGroupIdFunc = () => {
212213
let currentId = 0;
213214
return () => `${currentId++}`;
214215
}
215-
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+
}
216227
const getTree = (contentItem, { width, height, orientation }, parent, panels, getGroupId, options) => {
217228
const length = parent.content.length;
218229
const boxSize = orientation === 'HORIZONTAL' ? width : height;
@@ -233,10 +244,6 @@ const getTree = (contentItem, { width, height, orientation }, parent, panels, ge
233244
if (contentItem.type === 'row' || contentItem.type === 'column') {
234245
obj.type = 'branch';
235246
obj.size = getSize(boxSize, contentItem.width || contentItem.height) || size
236-
if(contentItem.content.length == 0 || contentItem.content.every(item => !item.visible)){
237-
obj.size = 0
238-
}
239-
240247
obj.data = contentItem.content.map(item => getTree(item, { width, height, orientation }, contentItem, panels, getGroupId, options))
241248
}
242249
else if (contentItem.type === 'group') {

0 commit comments

Comments
 (0)