Merge pull request #549 from mathuo/542-access-panel-contentcomponent-via-the-panel-api

feat: expose component string
This commit is contained in:
mathuo 2024-03-11 21:18:50 +00:00 committed by GitHub
commit 451a8579d9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
15 changed files with 114 additions and 36 deletions

View File

@ -5,7 +5,7 @@ describe('api', () => {
let api: PanelApiImpl;
beforeEach(() => {
api = new PanelApiImpl('dummy_id');
api = new PanelApiImpl('dummy_id', 'fake-component');
});
test('updateParameters', () => {

View File

@ -31,7 +31,8 @@ describe('groupPanelApi', () => {
const cut = new DockviewPanelApiImpl(
panel,
group,
<DockviewComponent>accessor
<DockviewComponent>accessor,
'fake-component'
);
cut.setTitle('test_title');
@ -59,7 +60,8 @@ describe('groupPanelApi', () => {
const cut = new DockviewPanelApiImpl(
<DockviewPanel>groupPanel,
<DockviewGroupPanel>groupViewPanel,
<DockviewComponent>accessor
<DockviewComponent>accessor,
'fake-component'
);
cut.updateParameters({ keyA: 'valueA' });
@ -89,7 +91,8 @@ describe('groupPanelApi', () => {
const cut = new DockviewPanelApiImpl(
<DockviewPanel>groupPanel,
<DockviewGroupPanel>groupViewPanel,
<DockviewComponent>accessor
<DockviewComponent>accessor,
'fake-component'
);
let events = 0;

View File

@ -34,9 +34,18 @@ describe('dockviewPanel', () => {
});
const model = <IDockviewPanelModel>new panelModelMock();
const cut = new DockviewPanel('fake-id', accessor, api, group, model, {
renderer: 'onlyWhenVisibile',
});
const cut = new DockviewPanel(
'fake-id',
'fake-component',
undefined,
accessor,
api,
group,
model,
{
renderer: 'onlyWhenVisibile',
}
);
let latestTitle: string | undefined = undefined;
@ -84,9 +93,18 @@ describe('dockviewPanel', () => {
});
const model = <IDockviewPanelModel>new panelModelMock();
const cut = new DockviewPanel('fake-id', accessor, api, group, model, {
renderer: 'onlyWhenVisibile',
});
const cut = new DockviewPanel(
'fake-id',
'fake-component',
undefined,
accessor,
api,
group,
model,
{
renderer: 'onlyWhenVisibile',
}
);
cut.init({ title: 'myTitle', params: {} });
expect(cut.title).toBe('myTitle');
@ -130,9 +148,18 @@ describe('dockviewPanel', () => {
});
const model = <IDockviewPanelModel>new panelModelMock();
const cut = new DockviewPanel('fake-id', accessor, api, group, model, {
renderer: 'onlyWhenVisibile',
});
const cut = new DockviewPanel(
'fake-id',
'fake-component',
undefined,
accessor,
api,
group,
model,
{
renderer: 'onlyWhenVisibile',
}
);
cut.init({ params: {}, title: 'title' });
@ -167,9 +194,18 @@ describe('dockviewPanel', () => {
});
const model = <IDockviewPanelModel>new panelModelMock();
const cut = new DockviewPanel('fake-id', accessor, api, group, model, {
renderer: 'onlyWhenVisibile',
});
const cut = new DockviewPanel(
'fake-id',
'fake-component',
undefined,
accessor,
api,
group,
model,
{
renderer: 'onlyWhenVisibile',
}
);
expect(cut.params).toEqual(undefined);
@ -205,9 +241,18 @@ describe('dockviewPanel', () => {
});
const model = <IDockviewPanelModel>new panelModelMock();
const cut = new DockviewPanel('fake-id', accessor, api, group, model, {
renderer: 'onlyWhenVisibile',
});
const cut = new DockviewPanel(
'fake-id',
'fake-component',
undefined,
accessor,
api,
group,
model,
{
renderer: 'onlyWhenVisibile',
}
);
cut.api.setSize({ height: 123, width: 456 });
@ -241,9 +286,18 @@ describe('dockviewPanel', () => {
});
const model = <IDockviewPanelModel>new panelModelMock();
const cut = new DockviewPanel('fake-id', accessor, api, group, model, {
renderer: 'onlyWhenVisibile',
});
const cut = new DockviewPanel(
'fake-id',
'fake-component',
undefined,
accessor,
api,
group,
model,
{
renderer: 'onlyWhenVisibile',
}
);
cut.init({ params: { a: '1', b: '2' }, title: 'A title' });
expect(cut.params).toEqual({ a: '1', b: '2' });

View File

@ -42,7 +42,7 @@ export class DockviewGroupPanelApiImpl extends GridviewPanelApiImpl {
}
constructor(id: string, private readonly accessor: DockviewComponent) {
super(id);
super(id, '__dockviewgroup__');
this.addDisposables(this._onDidLocationChange);
}

View File

@ -63,6 +63,7 @@ export class DockviewPanelApiImpl
implements DockviewPanelApi
{
private _group: DockviewGroupPanel;
private _tabComponent: string | undefined;
readonly _onDidTitleChange = new Emitter<TitleEvent>();
readonly onDidTitleChange = this._onDidTitleChange.event;
@ -119,12 +120,20 @@ export class DockviewPanelApiImpl
return this._group;
}
get tabComponent(): string | undefined {
return this._tabComponent;
}
constructor(
private panel: DockviewPanel,
group: DockviewGroupPanel,
private readonly accessor: DockviewComponent
private readonly accessor: DockviewComponent,
component: string,
tabComponent?: string
) {
super(panel.id);
super(panel.id, component);
this._tabComponent = tabComponent;
this.initialize(panel);

View File

@ -44,8 +44,8 @@ export class GridviewPanelApiImpl
private readonly _onDidSizeChange = new Emitter<SizeEvent>();
readonly onDidSizeChange: Event<SizeEvent> = this._onDidSizeChange.event;
constructor(id: string, panel?: IPanel) {
super(id);
constructor(id: string, component: string, panel?: IPanel) {
super(id, component);
this.addDisposables(
this._onDidConstraintsChangeInternal,

View File

@ -125,7 +125,7 @@ export class PanelApiImpl extends CompositeDisposable implements PanelApi {
return this._height;
}
constructor(readonly id: string) {
constructor(readonly id: string, readonly component: string) {
super();
this.addDisposables(

View File

@ -35,8 +35,8 @@ export class PaneviewPanelApiImpl
this._pane = pane;
}
constructor(id: string) {
super(id);
constructor(id: string, component: string) {
super(id, component);
this.addDisposables(
this._onDidExpansionChange,

View File

@ -45,8 +45,8 @@ export class SplitviewPanelApiImpl
this._onDidSizeChange.event;
//
constructor(id: string) {
super(id);
constructor(id: string, component: string) {
super(id, component);
this.addDisposables(
this._onDidConstraintsChangeInternal,

View File

@ -49,6 +49,8 @@ export class DefaultDockviewDeserialzier implements IPanelDeserializer {
const panel = new DockviewPanel(
panelId,
contentComponent,
tabComponent,
this.accessor,
new DockviewApi(this.accessor),
group,

View File

@ -2211,6 +2211,8 @@ export class DockviewComponent
const panel = new DockviewPanel(
options.id,
contentComponent,
tabComponent,
this,
this._api,
group,

View File

@ -58,6 +58,8 @@ export class DockviewPanel
constructor(
public readonly id: string,
component: string,
tabComponent: string | undefined,
private readonly accessor: DockviewComponent,
private readonly containerApi: DockviewApi,
group: DockviewGroupPanel,
@ -68,7 +70,13 @@ export class DockviewPanel
this._renderer = options.renderer;
this._group = group;
this.api = new DockviewPanelApiImpl(this, this._group, accessor);
this.api = new DockviewPanelApiImpl(
this,
this._group,
accessor,
component,
tabComponent
);
this.addDisposables(
this.api.onActiveChange(() => {

View File

@ -140,7 +140,7 @@ export abstract class GridviewPanel<
},
api?: T
) {
super(id, component, api ?? <T>new GridviewPanelApiImpl(id));
super(id, component, api ?? <T>new GridviewPanelApiImpl(id, component));
if (typeof options?.minimumWidth === 'number') {
this._minimumWidth = options.minimumWidth;

View File

@ -164,7 +164,7 @@ export abstract class PaneviewPanel
isExpanded: boolean,
isHeaderVisible: boolean
) {
super(id, component, new PaneviewPanelApiImpl(id));
super(id, component, new PaneviewPanelApiImpl(id, component));
this.api.pane = this; // TODO cannot use 'this' before 'super'
this.api.initialize(this);

View File

@ -83,7 +83,7 @@ export abstract class SplitviewPanel
}
constructor(id: string, componentName: string) {
super(id, componentName, new SplitviewPanelApiImpl(id));
super(id, componentName, new SplitviewPanelApiImpl(id, componentName));
this.api.initialize(this);