Skip to content

[896] Restore Popout content for blocked popouts and emit onDidBlockPopout event #928

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5791,6 +5791,54 @@ describe('dockviewComponent', () => {
]);
});

describe('when browsers block popups', () => {
let container: HTMLDivElement;
let dockview: DockviewComponent;
let panel: DockviewPanel;

beforeEach(() => {
jest.spyOn(window, 'open').mockReturnValue(null);

container = document.createElement('div');

dockview = new DockviewComponent(container, {
createComponent(options) {
switch (options.name) {
case 'default':
return new PanelContentPartTest(
options.id,
options.name
);
default:
throw new Error(`unsupported`);
}
},
});

dockview.layout(1000, 500);

panel = dockview.addPanel({
id: 'panel_1',
component: 'default',
});
});

test('onDidBlockPopout event is emitted', async () => {
const onDidBlockPopoutHandler = jest.fn();
dockview.onDidBlockPopout(onDidBlockPopoutHandler);

await dockview.addPopoutGroup(panel.group);

expect(onDidBlockPopoutHandler).toHaveBeenCalledTimes(1);
});

test('popout group is restored to its original position', async () => {
await dockview.addPopoutGroup(panel.group);

expect(panel.group.api.location.type).toBe('grid');
});
});

test('dispose of dockview instance when popup is open', async () => {
const container = document.createElement('div');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,9 @@ export class Tabs extends CompositeDisposable {
delete(id: string): void {
const index = this.indexOf(id);
const tabToRemove = this._tabs.splice(index, 1)[0];
if (!tabToRemove) {
return;
}

const { value, disposable } = tabToRemove;

Expand Down
50 changes: 33 additions & 17 deletions packages/dockview-core/src/dockview/dockviewComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -718,27 +718,11 @@ export class DockviewComponent
return false;
}

if (popoutContainer === null) {
popoutWindowDisposable.dispose();
this._onDidBlockPopout.fire();
return false;
}

const gready = document.createElement('div');
gready.className = 'dv-overlay-render-container';

const overlayRenderContainer = new OverlayRenderContainer(
gready,
this
);

const referenceGroup =
itemToPopout instanceof DockviewPanel
? itemToPopout.group
: itemToPopout;

const referenceLocation = itemToPopout.api.location.type;

/**
* The group that is being added doesn't already exist within the DOM, the most likely occurrence
* of this case is when being called from the `fromJSON(...)` method
Expand All @@ -754,9 +738,41 @@ export class DockviewComponent
group = options.overridePopoutGroup;
} else {
group = this.createGroup({ id: groupId });
this._onDidAddGroup.fire(group);
if (popoutContainer) {
this._onDidAddGroup.fire(group);
}
}

if (popoutContainer === null) {
popoutWindowDisposable.dispose();
this._onDidBlockPopout.fire();

// if the popout window was blocked, we need to move the group back to the reference group
// and set it to visible
this.movingLock(() =>
moveGroupWithoutDestroying({
from: group,
to: referenceGroup,
})
);

if (!referenceGroup.api.isVisible) {
referenceGroup.api.setVisible(true);
}

return false;
}

const gready = document.createElement('div');
gready.className = 'dv-overlay-render-container';

const overlayRenderContainer = new OverlayRenderContainer(
gready,
this
);

const referenceLocation = itemToPopout.api.location.type;

group.model.renderContainer = overlayRenderContainer;
group.layout(
_window.window!.innerWidth,
Expand Down