Skip to content

Commit ab8d438

Browse files
committed
feat: dockview添加就近隐藏
1 parent 2503e86 commit ab8d438

3 files changed

Lines changed: 63 additions & 28 deletions

File tree

src/components/BootstrapBlazor.DockView/wwwroot/js/dockview-core.esm.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7229,6 +7229,7 @@ class Overlay extends CompositeDisposable {
72297229
this.onDidChangeEnd = this._onDidChangeEnd.event;
72307230
this.addDisposables(this._onDidChange, this._onDidChangeEnd);
72317231
this._element.className = 'dv-resize-container';
7232+
this.options.className && this._element.classList.add(this.options.className);
72327233
this._isVisible = true;
72337234
this.setupResize('top');
72347235
this.setupResize('bottom');
@@ -8802,8 +8803,7 @@ class DockviewComponent extends BaseGrid {
88028803
};
88038804
}
88048805
const anchoredBox = getAnchoredBox();
8805-
const overlay = new Overlay(Object.assign(Object.assign({ container: this.gridview.element, content: group.element }, anchoredBox), {
8806-
minimumInViewportWidth: this.options.floatingGroupBounds === 'boundedWithinViewport'
8806+
const overlay = new Overlay(Object.assign(Object.assign({ container: this.gridview.element, content: group.element, className: options === null || options === void 0 ? void 0 : options.className }, anchoredBox), { minimumInViewportWidth: this.options.floatingGroupBounds === 'boundedWithinViewport'
88078807
? undefined
88088808
: (_c = (_b = this.options.floatingGroupBounds) === null || _b === void 0 ? void 0 : _b.minimumWidthWithinViewport) !== null && _c !== void 0 ? _c : DEFAULT_FLOATING_GROUP_OVERFLOW_SIZE, minimumInViewportHeight: this.options.floatingGroupBounds === 'boundedWithinViewport'
88098809
? undefined

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

Lines changed: 51 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const addGroupWithPanel = (dockview, panel, panels, index) => {
3838

3939
const addPanelWidthGroupId = (dockview, panel, index) => {
4040
let group = dockview.api.getGroup(panel.groupId)
41-
let { rect = {}, packup, floatType, drawer } = panel.params || {}
41+
let { rect = {}, packup, floatType, drawer, direction = 'left' } = panel.params || {}
4242
if (!group) {
4343
group = dockview.createGroup({ id: panel.groupId })
4444
// const floatingGroupPosition = isMaximized ? {
@@ -72,7 +72,7 @@ const addPanelWidthGroupId = (dockview, panel, index) => {
7272
observeOverlayChange(overlay, group)
7373
createGroupActions(group, floatType);
7474
if (floatType == 'drawer') {
75-
setTimeout(() => createDrawerHandle(group), 0);
75+
setTimeout(() => createDrawerHandle(group, direction == 'right'), 0);
7676
}
7777
// const floatingGroup = createFloatingGroup(group, floatingGroupRect)
7878
const autoHideBtn = group.header.rightActionsContainer.querySelector('.bb-dockview-control-icon-autohide')
@@ -326,19 +326,27 @@ const autoHide = group => {
326326
if (!canFloat(group)) return;
327327
// 1、点击图标创建浮动窗口并隐藏
328328
const { drawer = { width: 300, visible: true } } = group.getParams()
329+
330+
const left = getOffsetFromDockview(group.element)
331+
const width = group.element.offsetWidth
332+
const dockviewWidth = dockview.element.offsetWidth
333+
const isRight = ((left + width) == dockviewWidth && left > 0) || left > (dockviewWidth / 2)
334+
329335
const rect = {
330336
position: {
331-
left: -9999,
337+
[isRight ? 'right' : 'left']: 0,
332338
top: 0
333339
},
334340
width: drawer.width,
335-
height: '100%'
341+
height: '100%',
342+
className: 'dv-resize-container-drawer'
336343
}
337-
group.setParams({ drawer, floatType: 'drawer' })
344+
group.setParams({ drawer, floatType: 'drawer', direction: isRight ? 'right' : 'left' })
345+
338346
const floatingGroup = createFloatingGroup(group, rect, 'drawer')
339347
if (floatingGroup) {
340348
setTimeout(() => {
341-
createDrawerHandle(floatingGroup)
349+
createDrawerHandle(floatingGroup, isRight)
342350
}, 0);
343351
setTimeout(() => {
344352
saveConfig(dockview)
@@ -347,60 +355,75 @@ const autoHide = group => {
347355
}
348356
}
349357

350-
const createDrawerHandle = (floatingGroup) => {
358+
function getOffsetFromDockview(element) {
359+
let offsetLeft = element.offsetLeft;
360+
let parent = element.offsetParent;
361+
while (parent && !parent.classList.contains('dv-dockview')) {
362+
offsetLeft += parent.offsetLeft;
363+
parent = parent.offsetParent;
364+
}
365+
return offsetLeft
366+
}
367+
368+
const createDrawerHandle = (floatingGroup, isRight) => {
369+
const className = isRight ? 'bb-resize-container-right' : 'bb-resize-container-left'
351370
floatingGroup.element.parentElement.classList.add('dv-resize-container-drawer')
352-
createDrawerBtn(floatingGroup)
371+
floatingGroup.element.parentElement.classList.add(className)
372+
createDrawerBtn(floatingGroup, isRight)
353373
}
354374

355-
const createDrawerBtn = floatingGroup => {
375+
const createDrawerBtn = (floatingGroup, isRight) => {
356376
const dockview = floatingGroup.api.accessor
357377
const btn = document.createElement('div')
358378
const title = floatingGroup.activePanel?.title || floatingGroup.panels[0]?.title
359379
btn.innerHTML = title
360380
btn.setAttribute('groupid', dockview.id + '_' + floatingGroup.id)
361381
btn.classList.add('drawer-btn')
362-
if (floatingGroup.element.parentElement.style.left == '-1px') {
382+
if (floatingGroup.element.parentElement.classList.contains('active')) {
363383
btn.classList.add('active')
364384
}
365385

366386
btn.addEventListener('click', () => {
367387
const fgWrapper = floatingGroup.element.parentElement
368388
const activePanel = floatingGroup.activePanel
369389
const parentElement = activePanel.view.content.element.parentElement
390+
const direction = fgWrapper.style.left == 'auto' ? 'right' : 'left'
370391
dockview.floatingGroups.forEach(item => {
371392
const params = item.group.getParams()
372393
if (params.floatType == 'drawer' && item.group != floatingGroup) {
373-
item.group.element.parentElement.style.left = '-9999px'
394+
item.group.element.parentElement.classList.remove('active')
374395
if (activePanel?.renderer == 'always' && parentElement) {
375-
parentElement.style.left = '-9999px'
396+
parentElement.classList.remove('active');
376397
}
377398
}
378399
})
379-
;[...btn.parentElement.children].forEach(btnEle => {
380-
btnEle.classList.remove('active')
381-
})
382-
if (fgWrapper.style.left == '-1px') {
383-
fgWrapper.style.left = '-9999px'
400+
btn.parentElement.parentElement.querySelectorAll('&>aside>.drawer-btn').forEach(btnEle => {
401+
btnEle.classList.remove('active')
402+
})
403+
404+
if (fgWrapper.classList.contains('active')) {
405+
fgWrapper.classList.remove('active')
384406
if (activePanel?.renderer == 'always' && parentElement) {
385-
parentElement.style.left = '-9999px'
407+
parentElement.classList.remove('active')
386408
}
387409
} else {
388410
btn.classList.add('active')
389-
fgWrapper.style.left = '-1px'
411+
fgWrapper.classList.add('active')
390412
if (parentElement) {
391-
parentElement.style.left = '0'
413+
parentElement.classList.add('active')
392414
}
393415
}
394416
saveConfig(dockview)
395417
})
396418
const dvEleBox = dockview.element.parentElement
397-
let btnWrapper = [...dvEleBox.children].find(item => item.classList.contains('bb-dockview-btn-wrapper'))
419+
const className = `bb-dockview-btn-wrapper-${isRight ? 'right' : 'left'}`
420+
let btnWrapper = dvEleBox.querySelector(`&>.${className}`)
398421
if (!btnWrapper) {
399-
btnWrapper = document.createElement('div')
400-
btnWrapper.className = 'bb-dockview-btn-wrapper'
401-
dvEleBox.prepend(btnWrapper)
422+
btnWrapper = document.createElement('aside')
423+
btnWrapper.className = className + ' bb-dockview-btn-wrapper'
402424
}
403425
btnWrapper.append(btn)
426+
isRight ? dvEleBox.append(btnWrapper) : dvEleBox.prepend(btnWrapper)
404427
}
405428

406429
const removeDrawerBtn = group => {
@@ -508,7 +531,10 @@ const observeOverlayChange = (overlay, group) => {
508531
const parentEle = group.element.parentElement
509532
parentEle.style.height = `${parentEle.getBoundingClientRect().height}px`
510533
parentEle.classList.remove('dv-resize-container-drawer')
534+
parentEle.classList.remove('bb-resize-container-right')
535+
parentEle.classList.remove('bb-resize-container-left')
511536
group.removePropsOfParams('floatType')
537+
group.removePropsOfParams('direction')
512538
group.header.rightActionsContainer.classList.remove('bb-show-autohide')
513539
group.header.rightActionsContainer.classList.add('bb-show-float')
514540
group.header.rightActionsContainer.querySelector('.bb-dockview-control-icon-down').style.display = 'block'
@@ -561,6 +587,7 @@ const dock = (group, floatType) => {
561587
if (floatType == 'drawer') {
562588
group.setParams({ drawer: { ...drawer, width: rect.width } })
563589
group.removePropsOfParams('floatType')
590+
group.removePropsOfParams('direction')
564591
removeDrawerBtn(group)
565592
}
566593
else {

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,9 @@ const initDockview = (dockview, options, template) => {
107107
// saveConfig(dockview);
108108
// })
109109
observeOverlayChange(fg.overlay, fg.group)
110-
const { floatType } = fg.group.getParams();
110+
const { floatType, direction } = fg.group.getParams();
111111
if (floatType == 'drawer') {
112-
createDrawerHandle(fg.group)
112+
createDrawerHandle(fg.group, direction == 'right')
113113
}
114114
else {
115115
const autoHideBtn = fg.group.header.rightActionsContainer.querySelector('.bb-dockview-control-icon-autohide')
@@ -123,6 +123,14 @@ const initDockview = (dockview, options, template) => {
123123
dockview.groups.forEach(group => {
124124
observeGroup(group)
125125
})
126+
dockview.element.querySelector('&>.dv-dockview>.dv-branch-node').addEventListener('click', function (e) {
127+
this.parentElement.querySelectorAll('&>.dv-resize-container-drawer').forEach(item => {
128+
item.classList.remove('active')
129+
})
130+
this.closest('.bb-dockview').querySelectorAll('&>.bb-dockview-btn-wrapper>.drawer-btn').forEach(item => {
131+
item.classList.remove('active')
132+
})
133+
})
126134
dockview._inited = true;
127135
dockview._initialized?.fire();
128136
}, 100);

0 commit comments

Comments
 (0)