feat: api enhancements

- reduce scope of public api
- expose params field on panel api
This commit is contained in:
mathuo 2022-03-08 22:01:35 +00:00
parent 494def7d3a
commit 4a34374fd8
No known key found for this signature in database
GPG Key ID: C6EEDEFD6CA07281
10 changed files with 50 additions and 39 deletions

View File

@ -13,14 +13,14 @@ import {
IGridviewComponent, IGridviewComponent,
SerializedGridview, SerializedGridview,
} from '../gridview/gridviewComponent'; } from '../gridview/gridviewComponent';
import { GridviewPanel, IGridviewPanel } from '../gridview/gridviewPanel'; import { IGridviewPanel } from '../gridview/gridviewPanel';
import { IGroupPanel } from '../groupview/groupPanel'; import { IGroupPanel } from '../groupview/groupPanel';
import { import {
AddPaneviewCompponentOptions, AddPaneviewCompponentOptions,
SerializedPaneview, SerializedPaneview,
IPaneviewComponent, IPaneviewComponent,
} from '../paneview/paneviewComponent'; } from '../paneview/paneviewComponent';
import { IPaneviewPanel, PaneviewPanel } from '../paneview/paneviewPanel'; import { IPaneviewPanel } from '../paneview/paneviewPanel';
import { import {
AddSplitviewComponentOptions, AddSplitviewComponentOptions,
ISplitviewComponent, ISplitviewComponent,
@ -29,7 +29,7 @@ import {
} from '../splitview/splitviewComponent'; } from '../splitview/splitviewComponent';
import { IView, Orientation, Sizing } from '../splitview/core/splitview'; import { IView, Orientation, Sizing } from '../splitview/core/splitview';
import { ISplitviewPanel } from '../splitview/splitviewPanel'; import { ISplitviewPanel } from '../splitview/splitviewPanel';
import { GroupviewPanel } from '../groupview/groupviewPanel'; import { GroupviewPanel, IGroupviewPanel } from '../groupview/groupviewPanel';
import { Emitter, Event } from '../events'; import { Emitter, Event } from '../events';
import { IDisposable } from '../lifecycle'; import { IDisposable } from '../lifecycle';
import { PaneviewDropEvent } from '../react'; import { PaneviewDropEvent } from '../react';
@ -156,11 +156,11 @@ export class PaneviewApi implements CommonApi {
return this.component.onDidLayoutChange; return this.component.onDidLayoutChange;
} }
get onDidAddView(): Event<PaneviewPanel> { get onDidAddView(): Event<IPaneviewPanel> {
return this.component.onDidAddView; return this.component.onDidAddView;
} }
get onDidRemoveView(): Event<PaneviewPanel> { get onDidRemoveView(): Event<IPaneviewPanel> {
return this.component.onDidRemoveView; return this.component.onDidRemoveView;
} }
@ -255,7 +255,7 @@ export class GridviewApi implements CommonApi {
return this.component.onDidLayoutChange; return this.component.onDidLayoutChange;
} }
get panels(): GridviewPanel[] { get panels(): IGridviewPanel[] {
return this.component.groups; return this.component.groups;
} }
@ -296,7 +296,7 @@ export class GridviewApi implements CommonApi {
this.component.resizeToFit(); this.component.resizeToFit();
} }
getPanel(id: string): GridviewPanel | undefined { getPanel(id: string): IGridviewPanel | undefined {
return this.component.getPanel(id); return this.component.getPanel(id);
} }
@ -366,7 +366,7 @@ export class DockviewApi implements CommonApi {
return this.component.panels; return this.component.panels;
} }
get groups(): GroupviewPanel[] { get groups(): IGroupviewPanel[] {
return this.component.groups; return this.component.groups;
} }
@ -374,7 +374,7 @@ export class DockviewApi implements CommonApi {
return this.component.activePanel; return this.component.activePanel;
} }
get activeGroup(): GroupviewPanel | undefined { get activeGroup(): IGroupviewPanel | undefined {
return this.component.activeGroup; return this.component.activeGroup;
} }
@ -428,15 +428,15 @@ export class DockviewApi implements CommonApi {
return this.component.closeAllGroups(); return this.component.closeAllGroups();
} }
removeGroup(group: GroupviewPanel): void { removeGroup(group: IGroupviewPanel): void {
this.component.removeGroup(group); this.component.removeGroup(<GroupviewPanel>group);
} }
resizeToFit(): void { resizeToFit(): void {
return this.component.resizeToFit(); return this.component.resizeToFit();
} }
getGroup(id: string): GroupviewPanel | undefined { getGroup(id: string): IGroupviewPanel | undefined {
return this.component.getPanel(id); return this.component.getPanel(id);
} }

View File

@ -61,9 +61,9 @@ export class Emitter<T> implements IDisposable {
public fire(e: T) { public fire(e: T) {
this._last = e; this._last = e;
this._listeners.forEach((listener) => { for (const listener of this._listeners) {
listener(e); listener(e);
}); }
} }
public dispose() { public dispose() {

View File

@ -11,8 +11,8 @@ import { PanelApiImpl } from '../api/panelApi';
export interface BasePanelViewState { export interface BasePanelViewState {
id: string; id: string;
component: string; component: string;
params?: { [key: string]: any }; params?: Record<string, any>;
state?: { [key: string]: any }; state?: Record<string, any>;
} }
export interface BasePanelViewExported<T extends PanelApiImpl> { export interface BasePanelViewExported<T extends PanelApiImpl> {
@ -20,9 +20,9 @@ export interface BasePanelViewExported<T extends PanelApiImpl> {
readonly api: T; readonly api: T;
readonly width: number; readonly width: number;
readonly height: number; readonly height: number;
readonly params: Record<string, any> | undefined;
focus(): void; focus(): void;
toJSON(): object; toJSON(): object;
update(params: PanelUpdateEvent): void;
} }
export abstract class BasePanelView<T extends PanelApiImpl> export abstract class BasePanelView<T extends PanelApiImpl>
@ -33,7 +33,7 @@ export abstract class BasePanelView<T extends PanelApiImpl>
private _width = 0; private _width = 0;
private _element: HTMLElement; private _element: HTMLElement;
protected part?: IFrameworkPart; protected part?: IFrameworkPart;
protected params?: PanelInitParameters; protected _params?: PanelInitParameters;
/** /**
* Provide an IFrameworkPart that will determine the rendered UI of this view piece. * Provide an IFrameworkPart that will determine the rendered UI of this view piece.
@ -52,6 +52,10 @@ export abstract class BasePanelView<T extends PanelApiImpl>
return this._height; return this._height;
} }
get params(): Record<string, any> | undefined {
return this._params?.params;
}
constructor( constructor(
public readonly id: string, public readonly id: string,
protected readonly component: string, protected readonly component: string,
@ -89,32 +93,32 @@ export abstract class BasePanelView<T extends PanelApiImpl>
this.api._onDidPanelDimensionChange.fire({ width, height }); this.api._onDidPanelDimensionChange.fire({ width, height });
if (this.part) { if (this.part) {
if (this.params) { if (this._params) {
this.part.update(this.params.params); this.part.update(this._params.params);
} }
} }
} }
init(parameters: PanelInitParameters): void { init(parameters: PanelInitParameters): void {
this.params = parameters; this._params = parameters;
this.part = this.getComponent(); this.part = this.getComponent();
} }
update(event: PanelUpdateEvent) { update(event: PanelUpdateEvent) {
this.params = { this._params = {
...this.params, ...this._params,
params: { params: {
...this.params?.params, ...this._params?.params,
...event.params, ...event.params,
}, },
}; };
this.part?.update({ params: this.params.params }); this.part?.update({ params: this._params.params });
} }
toJSON(): BasePanelViewState { toJSON(): BasePanelViewState {
const state = this.api.getState(); const state = this.api.getState();
const params = this.params?.params ?? {}; const params = this._params?.params ?? {};
return { return {
id: this.id, id: this.id,

View File

@ -131,11 +131,11 @@ export abstract class GridviewPanel
this.addDisposables( this.addDisposables(
this.api.onVisibilityChange((event) => { this.api.onVisibilityChange((event) => {
const { isVisible } = event; const { isVisible } = event;
const { containerApi } = this.params as GridviewInitParameters; const { containerApi } = this._params as GridviewInitParameters;
containerApi.setVisible(this, isVisible); containerApi.setVisible(this, isVisible);
}), }),
this.api.onActiveChange(() => { this.api.onActiveChange(() => {
const { containerApi } = this.params as GridviewInitParameters; const { containerApi } = this._params as GridviewInitParameters;
containerApi.setActive(this); containerApi.setActive(this);
}), }),
this.api.onDidConstraintsChangeInternal((event) => { this.api.onDidConstraintsChangeInternal((event) => {

View File

@ -2,9 +2,13 @@ import { IFrameworkPart } from '../panel/types';
import { IDockviewComponent } from '../dockview/dockviewComponent'; import { IDockviewComponent } from '../dockview/dockviewComponent';
import { GridviewPanelApiImpl } from '../api/gridviewPanelApi'; import { GridviewPanelApiImpl } from '../api/gridviewPanelApi';
import { Groupview, GroupOptions } from './groupview'; import { Groupview, GroupOptions } from './groupview';
import { GridviewPanel } from '../gridview/gridviewPanel'; import { GridviewPanel, IGridviewPanel } from '../gridview/gridviewPanel';
export class GroupviewPanel extends GridviewPanel { export interface IGroupviewPanel extends IGridviewPanel {
model: Groupview;
}
export class GroupviewPanel extends GridviewPanel implements IGroupviewPanel {
private readonly _model: Groupview; private readonly _model: Groupview;
get model(): Groupview { get model(): Groupview {

View File

@ -112,7 +112,7 @@ export abstract class DraggablePaneviewPanel extends PaneviewPanel {
return; return;
} }
const containerApi = (this.params! as PanePanelInitParameter) const containerApi = (this._params! as PanePanelInitParameter)
.containerApi; .containerApi;
const panelId = data.paneId; const panelId = data.paneId;

View File

@ -285,7 +285,7 @@ export abstract class PaneviewPanel
} }
toJSON(): PanePanelViewState { toJSON(): PanePanelViewState {
const params = this.params as PanePanelInitParameter; const params = this._params as PanePanelInitParameter;
return { return {
...super.toJSON(), ...super.toJSON(),
headerComponent: this.headerComponent, headerComponent: this.headerComponent,

View File

@ -21,9 +21,9 @@ export class ReactGridPanelView extends GridviewPanel {
this.reactPortalStore, this.reactPortalStore,
this.reactComponent, this.reactComponent,
{ {
params: this.params?.params || {}, params: this._params?.params || {},
api: this.api, api: this.api,
containerApi: (this.params as GridviewInitParameters) containerApi: (this._params as GridviewInitParameters)
.containerApi, .containerApi,
} }
); );

View File

@ -19,9 +19,9 @@ export class ReactPanelView extends SplitviewPanel {
this.reactPortalStore, this.reactPortalStore,
this.reactComponent, this.reactComponent,
{ {
params: this.params?.params || {}, params: this._params?.params || {},
api: this.api, api: this.api,
containerApi: (this.params as PanelViewInitParameters) containerApi: (this._params as PanelViewInitParameters)
.containerApi, .containerApi,
} }
); );

View File

@ -19,7 +19,8 @@ export interface ISplitviewPanel
export abstract class SplitviewPanel export abstract class SplitviewPanel
extends BasePanelView<SplitviewPanelApiImpl> extends BasePanelView<SplitviewPanelApiImpl>
implements ISerializableView, ISplitviewPanel { implements ISerializableView, ISplitviewPanel
{
private _evaluatedMinimumSize = 0; private _evaluatedMinimumSize = 0;
private _evaluatedMaximumSize = Number.POSITIVE_INFINITY; private _evaluatedMaximumSize = Number.POSITIVE_INFINITY;
@ -83,11 +84,13 @@ export abstract class SplitviewPanel
this.addDisposables( this.addDisposables(
this.api.onVisibilityChange((event) => { this.api.onVisibilityChange((event) => {
const { isVisible } = event; const { isVisible } = event;
const { containerApi } = this.params as PanelViewInitParameters; const { containerApi } = this
._params as PanelViewInitParameters;
containerApi.setVisible(this, isVisible); containerApi.setVisible(this, isVisible);
}), }),
this.api.onActiveChange(() => { this.api.onActiveChange(() => {
const { containerApi } = this.params as PanelViewInitParameters; const { containerApi } = this
._params as PanelViewInitParameters;
containerApi.setActive(this); containerApi.setActive(this);
}), }),
this.api.onDidConstraintsChangeInternal((event) => { this.api.onDidConstraintsChangeInternal((event) => {