mirror of
https://github.com/mathuo/dockview
synced 2025-05-07 12:08:26 +00:00
Merge pull request #92 from mathuo/90-api-enhancements
feat: api improvements
This commit is contained in:
commit
1627dacd50
@ -24,7 +24,6 @@ describe('component.api', () => {
|
|||||||
'onDidRemoveView',
|
'onDidRemoveView',
|
||||||
'panels',
|
'panels',
|
||||||
'focus',
|
'focus',
|
||||||
'resizeToFit',
|
|
||||||
'toJSON',
|
'toJSON',
|
||||||
];
|
];
|
||||||
|
|
||||||
@ -54,9 +53,8 @@ describe('component.api', () => {
|
|||||||
'onDidLayoutChange',
|
'onDidLayoutChange',
|
||||||
'onDidAddView',
|
'onDidAddView',
|
||||||
'onDidRemoveView',
|
'onDidRemoveView',
|
||||||
'getPanels',
|
'panels',
|
||||||
'focus',
|
'focus',
|
||||||
'resizeToFit',
|
|
||||||
'toJSON',
|
'toJSON',
|
||||||
];
|
];
|
||||||
|
|
||||||
@ -88,7 +86,6 @@ describe('component.api', () => {
|
|||||||
'onDidLayoutChange',
|
'onDidLayoutChange',
|
||||||
'orientation',
|
'orientation',
|
||||||
'focus',
|
'focus',
|
||||||
'resizeToFit',
|
|
||||||
'toJSON',
|
'toJSON',
|
||||||
'onDidActiveGroupChange',
|
'onDidActiveGroupChange',
|
||||||
'onDidAddGroup',
|
'onDidAddGroup',
|
||||||
@ -130,7 +127,6 @@ describe('component.api', () => {
|
|||||||
'activePanel',
|
'activePanel',
|
||||||
'focus',
|
'focus',
|
||||||
'closeAllGroups',
|
'closeAllGroups',
|
||||||
'resizeToFit',
|
|
||||||
'toJSON',
|
'toJSON',
|
||||||
'onDidActiveGroupChange',
|
'onDidActiveGroupChange',
|
||||||
'onDidAddGroup',
|
'onDidAddGroup',
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import {
|
import {
|
||||||
|
DockviewDropEvent,
|
||||||
IDockviewComponent,
|
IDockviewComponent,
|
||||||
SerializedDockview,
|
SerializedDockview,
|
||||||
} from '../dockview/dockviewComponent';
|
} from '../dockview/dockviewComponent';
|
||||||
@ -40,9 +41,7 @@ export interface CommonApi<T = any> {
|
|||||||
readonly onDidLayoutFromJSON: Event<void>;
|
readonly onDidLayoutFromJSON: Event<void>;
|
||||||
focus(): void;
|
focus(): void;
|
||||||
layout(width: number, height: number): void;
|
layout(width: number, height: number): void;
|
||||||
resizeToFit(): void;
|
|
||||||
fromJSON(data: T): void;
|
fromJSON(data: T): void;
|
||||||
|
|
||||||
toJSON(): T;
|
toJSON(): T;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,6 +70,10 @@ export class SplitviewApi implements CommonApi<SerializedSplitview> {
|
|||||||
return this.component.orientation;
|
return this.component.orientation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get panels(): ISplitviewPanel[] {
|
||||||
|
return this.component.panels;
|
||||||
|
}
|
||||||
|
|
||||||
get onDidLayoutFromJSON(): Event<void> {
|
get onDidLayoutFromJSON(): Event<void> {
|
||||||
return this.component.onDidLayoutFromJSON;
|
return this.component.onDidLayoutFromJSON;
|
||||||
}
|
}
|
||||||
@ -101,10 +104,6 @@ export class SplitviewApi implements CommonApi<SerializedSplitview> {
|
|||||||
this.component.setVisible(panel, isVisible);
|
this.component.setVisible(panel, isVisible);
|
||||||
}
|
}
|
||||||
|
|
||||||
getPanels(): ISplitviewPanel[] {
|
|
||||||
return this.component.panels;
|
|
||||||
}
|
|
||||||
|
|
||||||
focus(): void {
|
focus(): void {
|
||||||
this.component.focus();
|
this.component.focus();
|
||||||
}
|
}
|
||||||
@ -125,10 +124,6 @@ export class SplitviewApi implements CommonApi<SerializedSplitview> {
|
|||||||
return this.component.addPanel(options);
|
return this.component.addPanel(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
resizeToFit(): void {
|
|
||||||
this.component.resizeToFit();
|
|
||||||
}
|
|
||||||
|
|
||||||
movePanel(from: number, to: number): void {
|
movePanel(from: number, to: number): void {
|
||||||
this.component.movePanel(from, to);
|
this.component.movePanel(from, to);
|
||||||
}
|
}
|
||||||
@ -159,6 +154,10 @@ export class PaneviewApi implements CommonApi<SerializedPaneview> {
|
|||||||
return this.component.width;
|
return this.component.width;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get panels(): IPaneviewPanel[] {
|
||||||
|
return this.component.panels;
|
||||||
|
}
|
||||||
|
|
||||||
get onDidLayoutChange(): Event<void> {
|
get onDidLayoutChange(): Event<void> {
|
||||||
return this.component.onDidLayoutChange;
|
return this.component.onDidLayoutChange;
|
||||||
}
|
}
|
||||||
@ -192,10 +191,6 @@ export class PaneviewApi implements CommonApi<SerializedPaneview> {
|
|||||||
|
|
||||||
constructor(private readonly component: IPaneviewComponent) {}
|
constructor(private readonly component: IPaneviewComponent) {}
|
||||||
|
|
||||||
getPanels(): IPaneviewPanel[] {
|
|
||||||
return this.component.getPanels();
|
|
||||||
}
|
|
||||||
|
|
||||||
removePanel(panel: IPaneviewPanel): void {
|
removePanel(panel: IPaneviewPanel): void {
|
||||||
this.component.removePanel(panel);
|
this.component.removePanel(panel);
|
||||||
}
|
}
|
||||||
@ -220,10 +215,6 @@ export class PaneviewApi implements CommonApi<SerializedPaneview> {
|
|||||||
return this.component.addPanel(options);
|
return this.component.addPanel(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
resizeToFit(): void {
|
|
||||||
this.component.resizeToFit();
|
|
||||||
}
|
|
||||||
|
|
||||||
fromJSON(data: SerializedPaneview): void {
|
fromJSON(data: SerializedPaneview): void {
|
||||||
this.component.fromJSON(data);
|
this.component.fromJSON(data);
|
||||||
}
|
}
|
||||||
@ -315,10 +306,6 @@ export class GridviewApi implements CommonApi<SerializedGridview> {
|
|||||||
this.component.movePanel(panel, options);
|
this.component.movePanel(panel, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
resizeToFit(): void {
|
|
||||||
this.component.resizeToFit();
|
|
||||||
}
|
|
||||||
|
|
||||||
getPanel(id: string): IGridviewPanel | undefined {
|
getPanel(id: string): IGridviewPanel | undefined {
|
||||||
return this.component.getPanel(id);
|
return this.component.getPanel(id);
|
||||||
}
|
}
|
||||||
@ -409,6 +396,10 @@ export class DockviewApi implements CommonApi<SerializedDockview> {
|
|||||||
return this.component.onDidLayoutChange;
|
return this.component.onDidLayoutChange;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get onDidDrop(): Event<DockviewDropEvent> {
|
||||||
|
return this.component.onDidDrop;
|
||||||
|
}
|
||||||
|
|
||||||
get panels(): IGroupPanel[] {
|
get panels(): IGroupPanel[] {
|
||||||
return this.component.panels;
|
return this.component.panels;
|
||||||
}
|
}
|
||||||
@ -471,10 +462,6 @@ export class DockviewApi implements CommonApi<SerializedDockview> {
|
|||||||
this.component.removeGroup(<GroupviewPanel>group);
|
this.component.removeGroup(<GroupviewPanel>group);
|
||||||
}
|
}
|
||||||
|
|
||||||
resizeToFit(): void {
|
|
||||||
return this.component.resizeToFit();
|
|
||||||
}
|
|
||||||
|
|
||||||
getGroup(id: string): IGroupviewPanel | undefined {
|
getGroup(id: string): IGroupviewPanel | undefined {
|
||||||
return this.component.getPanel(id);
|
return this.component.getPanel(id);
|
||||||
}
|
}
|
||||||
|
@ -16,8 +16,7 @@ export interface SuppressClosableEvent {
|
|||||||
* omit visibility modifiers since the visibility of a single group doesn't make sense
|
* omit visibility modifiers since the visibility of a single group doesn't make sense
|
||||||
* because it belongs to a groupview
|
* because it belongs to a groupview
|
||||||
*/
|
*/
|
||||||
export interface DockviewPanelApi
|
export interface DockviewPanelApi extends Omit<GridviewPanelApi, 'setVisible'> {
|
||||||
extends Omit<GridviewPanelApi, 'setVisible' | 'visible'> {
|
|
||||||
readonly group: GroupviewPanel | undefined;
|
readonly group: GroupviewPanel | undefined;
|
||||||
readonly isGroupActive: boolean;
|
readonly isGroupActive: boolean;
|
||||||
readonly title: string;
|
readonly title: string;
|
||||||
|
@ -62,7 +62,6 @@ export interface IBaseGrid<T extends IGridPanelView> {
|
|||||||
toJSON(): object;
|
toJSON(): object;
|
||||||
fromJSON(data: any): void;
|
fromJSON(data: any): void;
|
||||||
layout(width: number, height: number, force?: boolean): void;
|
layout(width: number, height: number, force?: boolean): void;
|
||||||
resizeToFit(): void;
|
|
||||||
setVisible(panel: T, visible: boolean): void;
|
setVisible(panel: T, visible: boolean): void;
|
||||||
isVisible(panel: T): boolean;
|
isVisible(panel: T): boolean;
|
||||||
}
|
}
|
||||||
@ -299,18 +298,6 @@ export abstract class BaseGrid<T extends IGridPanelView>
|
|||||||
this.gridview.layout(width, height);
|
this.gridview.layout(width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Resize the layout to fit the parent container
|
|
||||||
*/
|
|
||||||
public resizeToFit(): void {
|
|
||||||
if (!this.element.parentElement) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const { width, height } =
|
|
||||||
this.element.parentElement.getBoundingClientRect();
|
|
||||||
this.layout(width, height);
|
|
||||||
}
|
|
||||||
|
|
||||||
public dispose(): void {
|
public dispose(): void {
|
||||||
super.dispose();
|
super.dispose();
|
||||||
|
|
||||||
|
@ -115,10 +115,10 @@ export abstract class DraggablePaneviewPanel extends PaneviewPanel {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const allPanels = containerApi.getPanels();
|
const allPanels = containerApi.panels;
|
||||||
|
|
||||||
const fromIndex = allPanels.indexOf(existingPanel);
|
const fromIndex = allPanels.indexOf(existingPanel);
|
||||||
let toIndex = containerApi.getPanels().indexOf(this);
|
let toIndex = containerApi.panels.indexOf(this);
|
||||||
|
|
||||||
if (
|
if (
|
||||||
event.position === Position.Left ||
|
event.position === Position.Left ||
|
||||||
|
@ -98,6 +98,7 @@ export interface IPaneviewComponent extends IDisposable {
|
|||||||
readonly height: number;
|
readonly height: number;
|
||||||
readonly minimumSize: number;
|
readonly minimumSize: number;
|
||||||
readonly maximumSize: number;
|
readonly maximumSize: number;
|
||||||
|
readonly panels: IPaneviewPanel[];
|
||||||
readonly onDidAddView: Event<PaneviewPanel>;
|
readonly onDidAddView: Event<PaneviewPanel>;
|
||||||
readonly onDidRemoveView: Event<PaneviewPanel>;
|
readonly onDidRemoveView: Event<PaneviewPanel>;
|
||||||
readonly onDidDrop: Event<PaneviewDropEvent2>;
|
readonly onDidDrop: Event<PaneviewDropEvent2>;
|
||||||
@ -107,9 +108,7 @@ export interface IPaneviewComponent extends IDisposable {
|
|||||||
layout(width: number, height: number): void;
|
layout(width: number, height: number): void;
|
||||||
toJSON(): SerializedPaneview;
|
toJSON(): SerializedPaneview;
|
||||||
fromJSON(serializedPaneview: SerializedPaneview): void;
|
fromJSON(serializedPaneview: SerializedPaneview): void;
|
||||||
resizeToFit(): void;
|
|
||||||
focus(): void;
|
focus(): void;
|
||||||
getPanels(): IPaneviewPanel[];
|
|
||||||
removePanel(panel: IPaneviewPanel): void;
|
removePanel(panel: IPaneviewPanel): void;
|
||||||
getPanel(id: string): IPaneviewPanel | undefined;
|
getPanel(id: string): IPaneviewPanel | undefined;
|
||||||
movePanel(from: number, to: number): void;
|
movePanel(from: number, to: number): void;
|
||||||
@ -139,6 +138,10 @@ export class PaneviewComponent
|
|||||||
private readonly _onDidRemoveView = new Emitter<PaneviewPanel>();
|
private readonly _onDidRemoveView = new Emitter<PaneviewPanel>();
|
||||||
readonly onDidRemoveView = this._onDidRemoveView.event;
|
readonly onDidRemoveView = this._onDidRemoveView.event;
|
||||||
|
|
||||||
|
get panels(): PaneviewPanel[] {
|
||||||
|
return this.paneview.getPanes();
|
||||||
|
}
|
||||||
|
|
||||||
set paneview(value: Paneview) {
|
set paneview(value: Paneview) {
|
||||||
this._paneview = value;
|
this._paneview = value;
|
||||||
|
|
||||||
@ -288,12 +291,8 @@ export class PaneviewComponent
|
|||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
getPanels(): PaneviewPanel[] {
|
|
||||||
return this.paneview.getPanes();
|
|
||||||
}
|
|
||||||
|
|
||||||
removePanel(panel: PaneviewPanel) {
|
removePanel(panel: PaneviewPanel) {
|
||||||
const views = this.getPanels();
|
const views = this.panels;
|
||||||
const index = views.findIndex((_) => _ === panel);
|
const index = views.findIndex((_) => _ === panel);
|
||||||
this.paneview.removePane(index);
|
this.paneview.removePane(index);
|
||||||
|
|
||||||
@ -305,7 +304,7 @@ export class PaneviewComponent
|
|||||||
}
|
}
|
||||||
|
|
||||||
getPanel(id: string): PaneviewPanel | undefined {
|
getPanel(id: string): PaneviewPanel | undefined {
|
||||||
return this.getPanels().find((view) => view.id === id);
|
return this.panels.find((view) => view.id === id);
|
||||||
}
|
}
|
||||||
|
|
||||||
layout(width: number, height: number): void {
|
layout(width: number, height: number): void {
|
||||||
@ -316,18 +315,6 @@ export class PaneviewComponent
|
|||||||
this.paneview.layout(size, orthogonalSize);
|
this.paneview.layout(size, orthogonalSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Resize the layout to fit the parent container
|
|
||||||
*/
|
|
||||||
resizeToFit(): void {
|
|
||||||
if (!this.element.parentElement) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const { width, height } =
|
|
||||||
this.element.parentElement.getBoundingClientRect();
|
|
||||||
this.layout(width, height);
|
|
||||||
}
|
|
||||||
|
|
||||||
toJSON(): SerializedPaneview {
|
toJSON(): SerializedPaneview {
|
||||||
const maximum = (value: number) =>
|
const maximum = (value: number) =>
|
||||||
value === Number.MAX_SAFE_INTEGER ||
|
value === Number.MAX_SAFE_INTEGER ||
|
||||||
|
@ -68,12 +68,10 @@ export interface ISplitviewComponent extends IDisposable {
|
|||||||
onDidLayoutChange: Event<void>;
|
onDidLayoutChange: Event<void>;
|
||||||
toJSON(): SerializedSplitview;
|
toJSON(): SerializedSplitview;
|
||||||
fromJSON(serializedSplitview: SerializedSplitview): void;
|
fromJSON(serializedSplitview: SerializedSplitview): void;
|
||||||
resizeToFit(): void;
|
|
||||||
focus(): void;
|
focus(): void;
|
||||||
getPanel(id: string): ISplitviewPanel | undefined;
|
getPanel(id: string): ISplitviewPanel | undefined;
|
||||||
setActive(view: ISplitviewPanel, skipFocus?: boolean): void;
|
setActive(view: ISplitviewPanel, skipFocus?: boolean): void;
|
||||||
removePanel(panel: ISplitviewPanel, sizing?: Sizing): void;
|
removePanel(panel: ISplitviewPanel, sizing?: Sizing): void;
|
||||||
|
|
||||||
setVisible(panel: ISplitviewPanel, visible: boolean): void;
|
setVisible(panel: ISplitviewPanel, visible: boolean): void;
|
||||||
movePanel(from: number, to: number): void;
|
movePanel(from: number, to: number): void;
|
||||||
}
|
}
|
||||||
@ -103,14 +101,14 @@ export class SplitviewComponent
|
|||||||
private readonly _onDidLayoutChange = new Emitter<void>();
|
private readonly _onDidLayoutChange = new Emitter<void>();
|
||||||
readonly onDidLayoutChange: Event<void> = this._onDidLayoutChange.event;
|
readonly onDidLayoutChange: Event<void> = this._onDidLayoutChange.event;
|
||||||
|
|
||||||
get options(): SplitviewComponentOptions {
|
|
||||||
return this._options;
|
|
||||||
}
|
|
||||||
|
|
||||||
get panels(): SplitviewPanel[] {
|
get panels(): SplitviewPanel[] {
|
||||||
return this.splitview.getViews();
|
return this.splitview.getViews();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get options(): SplitviewComponentOptions {
|
||||||
|
return this._options;
|
||||||
|
}
|
||||||
|
|
||||||
get length(): number {
|
get length(): number {
|
||||||
return this._panels.size;
|
return this._panels.size;
|
||||||
}
|
}
|
||||||
@ -297,18 +295,6 @@ export class SplitviewComponent
|
|||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Resize the layout to fit the parent container
|
|
||||||
*/
|
|
||||||
resizeToFit(): void {
|
|
||||||
if (!this.element.parentElement) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const { width, height } =
|
|
||||||
this.element.parentElement.getBoundingClientRect();
|
|
||||||
this.layout(width, height);
|
|
||||||
}
|
|
||||||
|
|
||||||
layout(width: number, height: number): void {
|
layout(width: number, height: number): void {
|
||||||
const [size, orthogonalSize] =
|
const [size, orthogonalSize] =
|
||||||
this.splitview.orientation === Orientation.HORIZONTAL
|
this.splitview.orientation === Orientation.HORIZONTAL
|
||||||
|
Loading…
Reference in New Issue
Block a user