Skip to content

Commit 25a88e5

Browse files
committed
refactor(DockView): add closePanel rewrite function
1 parent dbe9e03 commit 25a88e5

2 files changed

Lines changed: 22 additions & 20 deletions

File tree

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

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import { DockviewComponent, DockviewGroupPanel, getGridLocation, getRelativeLocation, DockviewEmitter } from "./dockview-core.esm.js"
1+
import { DockviewComponent, DockviewGroupPanel, DockviewGroupPanelModel, getGridLocation, getRelativeLocation, DockviewEmitter } from "./dockview-core.esm.js"
22
import { getConfigFromStorage, saveConfig } from "./dockview-config.js"
33
import { disposeGroup, removeDrawerBtn } from "./dockview-group.js"
44

5-
DockviewComponent.prototype.on = function (eventType, callback) {
5+
DockviewComponent.prototype.on = function(eventType, callback) {
66
this['_' + eventType] = new DockviewEmitter();
77
this['_' + eventType].event(callback)
88
}
99

1010
const dispose = DockviewComponent.prototype.dispose;
11-
DockviewComponent.prototype.dispose = function () {
11+
DockviewComponent.prototype.dispose = function() {
1212
this.params.observer?.disconnect();
1313
this.groups.forEach(group => {
1414
if (group.mutationObserver) {
@@ -20,28 +20,29 @@ DockviewComponent.prototype.dispose = function () {
2020
}
2121

2222
const groupDispose = DockviewGroupPanel.prototype.dispose
23-
DockviewGroupPanel.prototype.dispose = function () {
23+
DockviewGroupPanel.prototype.dispose = function() {
2424
disposeGroup(this)
2525
groupDispose.call(this)
2626
}
27-
DockviewGroupPanel.prototype.getParams = function () {
27+
DockviewGroupPanel.prototype.getParams = function() {
2828
return this.activePanel?.params || {}
2929
}
3030

31-
DockviewGroupPanel.prototype.setParams = function (data) {
31+
DockviewGroupPanel.prototype.setParams = function(data) {
32+
console.log('setParameter', data);
3233
Object.keys(data).forEach(key => {
3334
this.panels.forEach(panel => panel.params[key] = data[key])
3435
})
3536
}
3637

37-
DockviewGroupPanel.prototype.removePropsOfParams = function (keys) {
38+
DockviewGroupPanel.prototype.removePropsOfParams = function(keys) {
3839
return (keys instanceof Array)
3940
? keys.map(key => this.panels.forEach(panel => delete panel.params[key]))
4041
: typeof keys == 'string' ? this.panels.forEach(panel => delete panel.params[keys]) : false
4142
}
4243

4344
const removeGroup = DockviewComponent.prototype.removeGroup
44-
DockviewComponent.prototype.removeGroup = function (...args) {
45+
DockviewComponent.prototype.removeGroup = function(...args) {
4546
if (this.isClearing) {
4647
return removeGroup.apply(this, args)
4748
}
@@ -70,29 +71,31 @@ DockviewComponent.prototype.removeGroup = function (...args) {
7071
}
7172
}
7273

73-
const removePanel = DockviewComponent.prototype.removePanel
74-
DockviewComponent.prototype.removePanel = function (...args) {
75-
const panel = args[0], moveToTemplate = args[1]
74+
const closePanel = DockviewGroupPanelModel.prototype.closePanel;
75+
DockviewGroupPanelModel.prototype.closePanel = function(panel) {
76+
console.log(panel);
7677
if (!panel.group.locked) {
77-
removePanel.apply(this, args)
78-
if (!this.isClearing) {
79-
this._panelVisibleChanged?.fire({ key: panel.params.key, status: false });
78+
closePanel.call(this, panel);
79+
if (!this.accessor.isClearing) {
80+
this.accessor._panelVisibleChanged?.fire({ key: panel.params.key, status: false });
8081
}
8182
}
83+
84+
const moveToTemplate = !this.accessor.firstLoad;
8285
if (moveToTemplate) {
8386
if (panel.view.content.element) {
8487
if (panel.titleMenuEle) {
8588
panel.view.content.element.append(panel.titleMenuEle)
8689
}
87-
if (this.params.template) {
88-
this.params.template.append(panel.view.content.element)
90+
if (this.accessor.params.template) {
91+
this.accessor.params.template.append(panel.view.content.element)
8992
}
9093
}
9194
}
9295
}
9396

9497
const setVisible = DockviewComponent.prototype.setVisible
95-
DockviewComponent.prototype.setVisible = function (...args) {
98+
DockviewComponent.prototype.setVisible = function(...args) {
9699
setVisible.apply(this, args)
97100
const branch = getBranchByGroup(args[0])
98101
const { orientation, splitview: { sashes } } = branch

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ const initDockview = (dockview, options, template) => {
9797
panels.forEach(panel => {
9898
const visible = panel.params.visible
9999
if (!visible) {
100-
dockview.removePanel(panel)
100+
panel.group.model.closePanel(panel)
101101
}
102102
dockview._panelVisibleChanged?.fire({ key: panel.params.key, status: visible });
103103
})
@@ -261,8 +261,7 @@ const toggleComponent = (dockview, options) => {
261261
if (pan === void 0) {
262262
item.group.delPanelIndex = item.group.panels.findIndex(p => p.params.key == item.params.key);
263263
const group = item.group;
264-
const moveToTemplate = !dockview.firstLoad;
265-
dockview.removePanel(item, moveToTemplate)
264+
group.model.closePanel(item)
266265
if (group.panels.length === 0) {
267266
dockview.setVisible(group, false)
268267
}

0 commit comments

Comments
 (0)