Merge branch 'master' into 90-api-enhancements

This commit is contained in:
mathuo 2022-05-01 21:48:42 +01:00 committed by GitHub
commit 77db3adbe9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 55 additions and 42 deletions

View File

@ -1,4 +1,3 @@
import { DockviewComponent } from '../..';
import { import {
SplitviewApi, SplitviewApi,
PaneviewApi, PaneviewApi,
@ -8,6 +7,7 @@ import {
import { GridviewComponent } from '../../gridview/gridviewComponent'; import { GridviewComponent } from '../../gridview/gridviewComponent';
import { PaneviewComponent } from '../../paneview/paneviewComponent'; import { PaneviewComponent } from '../../paneview/paneviewComponent';
import { SplitviewComponent } from '../../splitview/splitviewComponent'; import { SplitviewComponent } from '../../splitview/splitviewComponent';
import { DockviewComponent } from '../../dockview/dockviewComponent';
describe('component.api', () => { describe('component.api', () => {
describe('splitview', () => { describe('splitview', () => {

View File

@ -122,8 +122,8 @@ export class SplitviewApi implements CommonApi<SerializedSplitview> {
return this.component.layout(width, height); return this.component.layout(width, height);
} }
addPanel(options: AddSplitviewComponentOptions): void { addPanel(options: AddSplitviewComponentOptions): ISplitviewPanel {
this.component.addPanel(options); return this.component.addPanel(options);
} }
resizeToFit(): void { resizeToFit(): void {
@ -221,6 +221,10 @@ export class PaneviewApi implements CommonApi<SerializedPaneview> {
this.component.layout(width, height); this.component.layout(width, height);
} }
addPanel(options: AddPaneviewComponentOptions): IPaneviewPanel {
return this.component.addPanel(options);
}
resizeToFit(): void { resizeToFit(): void {
this.component.resizeToFit(); this.component.resizeToFit();
} }
@ -301,8 +305,8 @@ export class GridviewApi implements CommonApi<SerializedGridview> {
this.component.layout(width, height, force); this.component.layout(width, height, force);
} }
addPanel(options: AddComponentOptions): void { addPanel(options: AddComponentOptions): IGridviewPanel {
this.component.addPanel(options); return this.component.addPanel(options);
} }
removePanel(panel: IGridviewPanel, sizing?: Sizing): void { removePanel(panel: IGridviewPanel, sizing?: Sizing): void {

View File

@ -21,7 +21,7 @@ import { createComponent } from '../panel/componentFactory';
import { import {
AddGroupOptions, AddGroupOptions,
AddPanelOptions, AddPanelOptions,
DockviewOptions as DockviewComponentOptions, DockviewComponentOptions,
MovementOptions, MovementOptions,
TabContextMenuEvent, TabContextMenuEvent,
} from './options'; } from './options';

View File

@ -49,12 +49,11 @@ export interface ViewFactoryData {
tab?: string; tab?: string;
} }
export interface DockviewOptions extends DockviewRenderFunctions { export interface DockviewComponentOptions extends DockviewRenderFunctions {
watermarkComponent?: WatermarkConstructor; watermarkComponent?: WatermarkConstructor;
watermarkFrameworkComponent?: any; watermarkFrameworkComponent?: any;
frameworkComponentFactory?: GroupPanelFrameworkComponentFactory; frameworkComponentFactory?: GroupPanelFrameworkComponentFactory;
tabHeight?: number; tabHeight?: number;
debug?: boolean;
orientation?: Orientation; orientation?: Orientation;
styles?: ISplitviewStyles; styles?: ISplitviewStyles;
showDndOverlay?: (event: DragEvent, target: DockviewDropTargets) => boolean; showDndOverlay?: (event: DragEvent, target: DockviewDropTargets) => boolean;

View File

@ -44,7 +44,7 @@ export interface AddComponentOptions extends BaseComponentOptions {
maximumHeight?: number; maximumHeight?: number;
position?: { position?: {
direction: Direction; direction: Direction;
reference: string; referencePanel: string;
}; };
location?: number[]; location?: number[];
} }
@ -62,7 +62,7 @@ export interface IGridviewComponent extends IBaseGrid<GridviewPanel> {
readonly orientation: Orientation; readonly orientation: Orientation;
readonly onDidLayoutFromJSON: Event<void>; readonly onDidLayoutFromJSON: Event<void>;
updateOptions(options: Partial<GridviewComponentUpdateOptions>): void; updateOptions(options: Partial<GridviewComponentUpdateOptions>): void;
addPanel(options: AddComponentOptions): void; addPanel(options: AddComponentOptions): IGridviewPanel;
removePanel(panel: IGridviewPanel, sizing?: Sizing): void; removePanel(panel: IGridviewPanel, sizing?: Sizing): void;
toggleVisibility(panel: IGridviewPanel): void; toggleVisibility(panel: IGridviewPanel): void;
focus(): void; focus(): void;
@ -273,17 +273,17 @@ export class GridviewComponent
this.doAddGroup(removedPanel, relativeLocation, options.size); this.doAddGroup(removedPanel, relativeLocation, options.size);
} }
public addPanel(options: AddComponentOptions): void { public addPanel(options: AddComponentOptions): IGridviewPanel {
let relativeLocation: number[] = options.location || [0]; let relativeLocation: number[] = options.location || [0];
if (options.position?.reference) { if (options.position?.referencePanel) {
const referenceGroup = this._groups.get( const referenceGroup = this._groups.get(
options.position.reference options.position.referencePanel
)?.value; )?.value;
if (!referenceGroup) { if (!referenceGroup) {
throw new Error( throw new Error(
`reference group ${options.position.reference} does not exist` `reference group ${options.position.referencePanel} does not exist`
); );
} }
@ -329,6 +329,8 @@ export class GridviewComponent
this.registerPanel(view); this.registerPanel(view);
this.doAddGroup(view, relativeLocation, options.size); this.doAddGroup(view, relativeLocation, options.size);
return view;
} }
private registerPanel(panel: GridviewPanel) { private registerPanel(panel: GridviewPanel) {

View File

@ -36,11 +36,10 @@ export interface DockviewReadyEvent {
} }
export interface IDockviewReactProps { export interface IDockviewReactProps {
components?: PanelCollection<IDockviewPanelProps>; components: PanelCollection<IDockviewPanelProps>;
tabComponents?: PanelCollection<IDockviewPanelHeaderProps>; tabComponents?: PanelCollection<IDockviewPanelHeaderProps>;
watermarkComponent?: React.FunctionComponent<IWatermarkPanelProps>; watermarkComponent?: React.FunctionComponent<IWatermarkPanelProps>;
onReady?: (event: DockviewReadyEvent) => void; onReady: (event: DockviewReadyEvent) => void;
debug?: boolean;
tabHeight?: number; tabHeight?: number;
onTabContextMenu?: (event: TabContextMenuEvent) => void; onTabContextMenu?: (event: TabContextMenuEvent) => void;
onDidDrop?: (event: DockviewDropEvent) => void; onDidDrop?: (event: DockviewDropEvent) => void;
@ -127,7 +126,6 @@ export const DockviewReact = React.forwardRef(
frameworkComponents: props.components, frameworkComponents: props.components,
frameworkTabComponents: props.tabComponents, frameworkTabComponents: props.tabComponents,
tabHeight: props.tabHeight, tabHeight: props.tabHeight,
debug: props.debug,
watermarkFrameworkComponent: props.watermarkComponent, watermarkFrameworkComponent: props.watermarkComponent,
styles: props.hideBorders styles: props.hideBorders
? { separatorBorder: 'transparent' } ? { separatorBorder: 'transparent' }

View File

@ -22,8 +22,8 @@ export interface IGridviewPanelProps<T extends { [index: string]: any } = any>
} }
export interface IGridviewReactProps { export interface IGridviewReactProps {
orientation: Orientation; orientation?: Orientation;
onReady?: (event: GridviewReadyEvent) => void; onReady: (event: GridviewReadyEvent) => void;
components: PanelCollection<IGridviewPanelProps>; components: PanelCollection<IGridviewPanelProps>;
hideBorders?: boolean; hideBorders?: boolean;
className?: string; className?: string;
@ -64,7 +64,7 @@ export const GridviewReact = React.forwardRef(
typeof props.proportionalLayout === 'boolean' typeof props.proportionalLayout === 'boolean'
? props.proportionalLayout ? props.proportionalLayout
: true, : true,
orientation: props.orientation, orientation: props.orientation || Orientation.HORIZONTAL,
frameworkComponents: props.components, frameworkComponents: props.components,
frameworkComponentFactory: { frameworkComponentFactory: {
createComponent: (id: string, componentId, component) => { createComponent: (id: string, componentId, component) => {

View File

@ -27,8 +27,8 @@ export interface PaneviewDropEvent extends PaneviewDropEvent2 {
} }
export interface IPaneviewReactProps { export interface IPaneviewReactProps {
onReady?: (event: PaneviewReadyEvent) => void; onReady: (event: PaneviewReadyEvent) => void;
components?: PanelCollection<IPaneviewPanelProps>; components: PanelCollection<IPaneviewPanelProps>;
headerComponents?: PanelCollection<IPaneviewPanelProps>; headerComponents?: PanelCollection<IPaneviewPanelProps>;
className?: string; className?: string;
disableAutoResizing?: boolean; disableAutoResizing?: boolean;

View File

@ -22,8 +22,8 @@ export interface ISplitviewPanelProps<T extends { [index: string]: any } = any>
} }
export interface ISplitviewReactProps { export interface ISplitviewReactProps {
orientation: Orientation; orientation?: Orientation;
onReady?: (event: SplitviewReadyEvent) => void; onReady: (event: SplitviewReadyEvent) => void;
components: PanelCollection<ISplitviewPanelProps>; components: PanelCollection<ISplitviewPanelProps>;
proportionalLayout?: boolean; proportionalLayout?: boolean;
hideBorders?: boolean; hideBorders?: boolean;
@ -58,7 +58,7 @@ export const SplitviewReact = React.forwardRef(
React.useEffect(() => { React.useEffect(() => {
const splitview = new SplitviewComponent(domRef.current!, { const splitview = new SplitviewComponent(domRef.current!, {
orientation: props.orientation, orientation: props.orientation || Orientation.HORIZONTAL,
frameworkComponents: props.components, frameworkComponents: props.components,
frameworkWrapper: { frameworkWrapper: {
createComponent: ( createComponent: (

View File

@ -63,7 +63,7 @@ export interface ISplitviewComponent extends IDisposable {
readonly onDidLayoutFromJSON: Event<void>; readonly onDidLayoutFromJSON: Event<void>;
readonly panels: SplitviewPanel[]; readonly panels: SplitviewPanel[];
updateOptions(options: Partial<SplitviewComponentUpdateOptions>): void; updateOptions(options: Partial<SplitviewComponentUpdateOptions>): void;
addPanel(options: AddSplitviewComponentOptions): void; addPanel(options: AddSplitviewComponentOptions): ISplitviewPanel;
layout(width: number, height: number): void; layout(width: number, height: number): void;
onDidLayoutChange: Event<void>; onDidLayoutChange: Event<void>;
toJSON(): SerializedSplitview; toJSON(): SerializedSplitview;
@ -106,15 +106,23 @@ export class SplitviewComponent
return this.splitview.getViews(); return this.splitview.getViews();
} }
get options() { get options(): SplitviewComponentOptions {
return this._options; return this._options;
} }
get orientation() { get panels(): SplitviewPanel[] {
return this.splitview.getViews();
}
get length(): number {
return this._panels.size;
}
get orientation(): Orientation {
return this.splitview.orientation; return this.splitview.orientation;
} }
get splitview() { get splitview(): Splitview {
return this._splitview; return this._splitview;
} }
@ -132,21 +140,21 @@ export class SplitviewComponent
); );
} }
get minimumSize() { get minimumSize(): number {
return this.splitview.minimumSize; return this.splitview.minimumSize;
} }
get maximumSize() { get maximumSize(): number {
return this.splitview.maximumSize; return this.splitview.maximumSize;
} }
get height() { get height(): number {
return this.splitview.orientation === Orientation.HORIZONTAL return this.splitview.orientation === Orientation.HORIZONTAL
? this.splitview.orthogonalSize ? this.splitview.orthogonalSize
: this.splitview.size; : this.splitview.size;
} }
get width() { get width(): number {
return this.splitview.orientation === Orientation.HORIZONTAL return this.splitview.orientation === Orientation.HORIZONTAL
? this.splitview.size ? this.splitview.size
: this.splitview.orthogonalSize; : this.splitview.orthogonalSize;
@ -199,20 +207,20 @@ export class SplitviewComponent
); );
} }
focus() { focus(): void {
this._activePanel?.focus(); this._activePanel?.focus();
} }
movePanel(from: number, to: number) { movePanel(from: number, to: number): void {
this.splitview.moveView(from, to); this.splitview.moveView(from, to);
} }
setVisible(panel: SplitviewPanel, visible: boolean) { setVisible(panel: SplitviewPanel, visible: boolean): void {
const index = this.panels.indexOf(panel); const index = this.panels.indexOf(panel);
this.splitview.setViewVisible(index, visible); this.splitview.setViewVisible(index, visible);
} }
setActive(view: SplitviewPanel, skipFocus?: boolean) { setActive(view: SplitviewPanel, skipFocus?: boolean): void {
this._activePanel = view; this._activePanel = view;
this.panels this.panels
@ -229,7 +237,7 @@ export class SplitviewComponent
} }
} }
removePanel(panel: SplitviewPanel, sizing?: Sizing) { removePanel(panel: SplitviewPanel, sizing?: Sizing): void {
const disposable = this._panels.get(panel.id); const disposable = this._panels.get(panel.id);
if (!disposable) { if (!disposable) {
@ -254,7 +262,7 @@ export class SplitviewComponent
return this.panels.find((view) => view.id === id); return this.panels.find((view) => view.id === id);
} }
addPanel(options: AddSplitviewComponentOptions): void { addPanel(options: AddSplitviewComponentOptions): ISplitviewPanel {
if (this._panels.has(options.id)) { if (this._panels.has(options.id)) {
throw new Error(`panel ${options.id} already exists`); throw new Error(`panel ${options.id} already exists`);
} }
@ -292,6 +300,8 @@ export class SplitviewComponent
this.doAddView(view); this.doAddView(view);
this.setActive(view); this.setActive(view);
return view;
} }
/** /**
@ -314,7 +324,7 @@ export class SplitviewComponent
this.splitview.layout(size, orthogonalSize); this.splitview.layout(size, orthogonalSize);
} }
private doAddView(view: SplitviewPanel) { private doAddView(view: SplitviewPanel): void {
const disposable = view.api.onDidFocusChange((event) => { const disposable = view.api.onDidFocusChange((event) => {
if (!event.isFocused) { if (!event.isFocused) {
return; return;
@ -422,7 +432,7 @@ export class SplitviewComponent
this._onDidLayoutfromJSON.fire(); this._onDidLayoutfromJSON.fire();
} }
dispose() { dispose(): void {
for (const [_, value] of this._panels.entries()) { for (const [_, value] of this._panels.entries()) {
value.disposable.dispose(); value.disposable.dispose();
value.value.dispose(); value.value.dispose();