mirror of
https://github.com/mathuo/dockview
synced 2025-01-22 17:35:57 +00:00
feat: fix popout group persistance
This commit is contained in:
parent
0bca63b550
commit
c4f46a190a
@ -110,6 +110,7 @@ export interface SerializedFloatingGroup {
|
|||||||
|
|
||||||
export interface SerializedPopoutGroup {
|
export interface SerializedPopoutGroup {
|
||||||
data: GroupPanelViewState;
|
data: GroupPanelViewState;
|
||||||
|
gridReferenceGroup: string;
|
||||||
position: Box | null;
|
position: Box | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -541,17 +542,21 @@ export class DockviewComponent
|
|||||||
}
|
}
|
||||||
|
|
||||||
addPopoutGroup(
|
addPopoutGroup(
|
||||||
item: DockviewPanel | DockviewGroupPanel,
|
itemToPopout: DockviewPanel | DockviewGroupPanel,
|
||||||
options?: {
|
options?: {
|
||||||
skipRemoveGroup?: boolean;
|
skipRemoveGroup?: boolean;
|
||||||
position?: Box;
|
position?: Box;
|
||||||
popoutUrl?: string;
|
popoutUrl?: string;
|
||||||
onDidOpen?: (event: { id: string; window: Window }) => void;
|
onDidOpen?: (event: { id: string; window: Window }) => void;
|
||||||
onWillClose?: (event: { id: string; window: Window }) => void;
|
onWillClose?: (event: { id: string; window: Window }) => void;
|
||||||
|
overridePopoutGroup?: DockviewGroupPanel;
|
||||||
}
|
}
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
if (item instanceof DockviewPanel && item.group.size === 1) {
|
if (
|
||||||
return this.addPopoutGroup(item.group);
|
itemToPopout instanceof DockviewPanel &&
|
||||||
|
itemToPopout.group.size === 1
|
||||||
|
) {
|
||||||
|
return this.addPopoutGroup(itemToPopout.group);
|
||||||
}
|
}
|
||||||
|
|
||||||
const theme = getDockviewTheme(this.gridview.element);
|
const theme = getDockviewTheme(this.gridview.element);
|
||||||
@ -578,21 +583,22 @@ export class DockviewComponent
|
|||||||
return options.position;
|
return options.position;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (item instanceof DockviewGroupPanel) {
|
if (itemToPopout instanceof DockviewGroupPanel) {
|
||||||
return item.element.getBoundingClientRect();
|
return itemToPopout.element.getBoundingClientRect();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (item.group) {
|
if (itemToPopout.group) {
|
||||||
return item.group.element.getBoundingClientRect();
|
return itemToPopout.group.element.getBoundingClientRect();
|
||||||
}
|
}
|
||||||
return element.getBoundingClientRect();
|
return element.getBoundingClientRect();
|
||||||
}
|
}
|
||||||
|
|
||||||
const box: Box = getBox();
|
const box: Box = getBox();
|
||||||
|
|
||||||
const groupId = this.getNextGroupId(); //item.id;
|
const groupId =
|
||||||
|
options?.overridePopoutGroup?.id ?? this.getNextGroupId(); //item.id;
|
||||||
|
|
||||||
item.api.setHidden(true);
|
itemToPopout.api.setHidden(true);
|
||||||
|
|
||||||
const _window = new PopoutWindow(
|
const _window = new PopoutWindow(
|
||||||
`${this.id}-${groupId}`, // unique id
|
`${this.id}-${groupId}`, // unique id
|
||||||
@ -635,13 +641,18 @@ export class DockviewComponent
|
|||||||
);
|
);
|
||||||
|
|
||||||
const referenceGroup =
|
const referenceGroup =
|
||||||
item instanceof DockviewPanel ? item.group : item;
|
itemToPopout instanceof DockviewPanel
|
||||||
|
? itemToPopout.group
|
||||||
|
: itemToPopout;
|
||||||
|
|
||||||
const group = this.createGroup({ id: groupId });
|
const group =
|
||||||
|
options?.overridePopoutGroup ??
|
||||||
|
this.createGroup({ id: groupId });
|
||||||
group.model.renderContainer = overlayRenderContainer;
|
group.model.renderContainer = overlayRenderContainer;
|
||||||
|
|
||||||
if (item instanceof DockviewPanel) {
|
if (itemToPopout instanceof DockviewPanel) {
|
||||||
const panel = referenceGroup.model.removePanel(item);
|
const panel =
|
||||||
|
referenceGroup.model.removePanel(itemToPopout);
|
||||||
group.model.openPanel(panel);
|
group.model.openPanel(panel);
|
||||||
} else {
|
} else {
|
||||||
moveGroupWithoutDestroying({
|
moveGroupWithoutDestroying({
|
||||||
@ -1015,6 +1026,7 @@ export class DockviewComponent
|
|||||||
(group) => {
|
(group) => {
|
||||||
return {
|
return {
|
||||||
data: group.popoutGroup.toJSON() as GroupPanelViewState,
|
data: group.popoutGroup.toJSON() as GroupPanelViewState,
|
||||||
|
gridReferenceGroup: group.referenceGroup.id,
|
||||||
position: group.window.dimensions(),
|
position: group.window.dimensions(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -1142,14 +1154,26 @@ export class DockviewComponent
|
|||||||
const serializedPopoutGroups = data.popoutGroups ?? [];
|
const serializedPopoutGroups = data.popoutGroups ?? [];
|
||||||
|
|
||||||
for (const serializedPopoutGroup of serializedPopoutGroups) {
|
for (const serializedPopoutGroup of serializedPopoutGroups) {
|
||||||
const { data, position } = serializedPopoutGroup;
|
const { data, position, gridReferenceGroup } =
|
||||||
|
serializedPopoutGroup;
|
||||||
|
|
||||||
const group = createGroupFromSerializedState(data);
|
const group = createGroupFromSerializedState(data);
|
||||||
|
|
||||||
this.addPopoutGroup(group, {
|
if (!gridReferenceGroup) {
|
||||||
skipRemoveGroup: true,
|
/**
|
||||||
position: position ?? undefined,
|
* workaround to handle <= v1.9.2
|
||||||
});
|
*/
|
||||||
|
this.doAddGroup(group, [0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.addPopoutGroup(
|
||||||
|
this.getPanel(gridReferenceGroup) ?? group,
|
||||||
|
{
|
||||||
|
skipRemoveGroup: true,
|
||||||
|
position: position ?? undefined,
|
||||||
|
overridePopoutGroup: group,
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const floatingGroup of this._floatingGroups) {
|
for (const floatingGroup of this._floatingGroups) {
|
||||||
@ -1557,7 +1581,9 @@ export class DockviewComponent
|
|||||||
if (selectedGroup) {
|
if (selectedGroup) {
|
||||||
if (!options?.skipDispose) {
|
if (!options?.skipDispose) {
|
||||||
if (!options?.skipPopoutAssociated) {
|
if (!options?.skipPopoutAssociated) {
|
||||||
this.removeGroup(selectedGroup.referenceGroup);
|
if (this._groups.has(selectedGroup.referenceGroup.id)) {
|
||||||
|
this.removeGroup(selectedGroup.referenceGroup);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
selectedGroup.popoutGroup.dispose();
|
selectedGroup.popoutGroup.dispose();
|
||||||
|
Loading…
Reference in New Issue
Block a user