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; let api: PanelApiImpl;
beforeEach(() => { beforeEach(() => {
api = new PanelApiImpl('dummy_id'); api = new PanelApiImpl('dummy_id', 'fake-component');
}); });
test('updateParameters', () => { test('updateParameters', () => {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -164,7 +164,7 @@ export abstract class PaneviewPanel
isExpanded: boolean, isExpanded: boolean,
isHeaderVisible: 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.pane = this; // TODO cannot use 'this' before 'super'
this.api.initialize(this); this.api.initialize(this);

View File

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