Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: priority experiments #591

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ import {
PanelUpdateEvent,
Parameters,
} from '../../panel/types';
import { LayoutPriority, Orientation } from '../../splitview/splitview';
import {
EnhancedLayoutPriority,
LayoutPriority,
Orientation,
} from '../../splitview/splitview';

class TestPanel implements IGridPanelView {
_onDidChange = new Emitter<IViewSize | undefined>();
Expand All @@ -32,7 +36,7 @@ class TestPanel implements IGridPanelView {
public readonly maximumWidth: number,
public readonly minimumHeight: number,
public readonly maximumHeight: number,
public priority: LayoutPriority,
public priority: EnhancedLayoutPriority,
public snap: boolean
) {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@ import { Emitter } from '../../events';
import { CompositeDisposable } from '../../lifecycle';
import {
IView,
LayoutPriority,
EnhancedLayoutPriority,
Orientation,
Sizing,
Splitview,
LayoutPriority,
} from '../../splitview/splitview';
import { fireEvent } from '@testing-library/dom';
class Testview implements IView {
private _element: HTMLElement = document.createElement('div');
private _size = 0;
private _orthogonalSize = 0;
private _priority: LayoutPriority | undefined;
private _priority: EnhancedLayoutPriority | undefined;

private readonly _onDidChange = new Emitter<{
size?: number;
Expand Down Expand Up @@ -54,7 +55,7 @@ class Testview implements IView {
constructor(
private _minimumSize: number,
private _maxiumSize: number,
priority?: LayoutPriority
priority?: EnhancedLayoutPriority
) {
this._priority = priority;
}
Expand Down
4 changes: 4 additions & 0 deletions packages/dockview-core/src/api/dockviewPanelApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ export class DockviewPanelApiImpl
return this._tabComponent;
}

get priority(): number {
return this.panel.priority;
}

constructor(
private panel: DockviewPanel,
group: DockviewGroupPanel,
Expand Down
19 changes: 16 additions & 3 deletions packages/dockview-core/src/api/gridviewPanelApi.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Emitter, Event } from '../events';
import { GridviewPanel } from '../gridview/gridviewPanel';
import { IPanel } from '../panel/types';
import { layoutPriorityAsNumber } from '../splitview/splitview';
import { FunctionOrValue } from '../types';
import { PanelApiImpl, PanelApi } from './panelApi';

Expand All @@ -26,6 +28,7 @@ export interface GridviewPanelApi extends PanelApi {
readonly onDidConstraintsChange: Event<GridConstraintChangeEvent>;
setConstraints(value: GridConstraintChangeEvent2): void;
setSize(event: SizeEvent): void;
readonly priority: number;
}

export class GridviewPanelApiImpl
Expand All @@ -44,7 +47,17 @@ export class GridviewPanelApiImpl
private readonly _onDidSizeChange = new Emitter<SizeEvent>();
readonly onDidSizeChange: Event<SizeEvent> = this._onDidSizeChange.event;

constructor(id: string, component: string, panel?: IPanel) {
get priority(): number {
return this.gridPanel?.priority
? layoutPriorityAsNumber(this.gridPanel.priority)
: 0;
}

constructor(
id: string,
component: string,
private readonly gridPanel?: GridviewPanel
) {
super(id, component);

this.addDisposables(
Expand All @@ -53,8 +66,8 @@ export class GridviewPanelApiImpl
this._onDidSizeChange
);

if (panel) {
this.initialize(panel);
if (gridPanel) {
this.initialize(gridPanel);
}
}

Expand Down
1 change: 1 addition & 0 deletions packages/dockview-core/src/dockview/deserializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export class DefaultDockviewDeserialzier implements IPanelDeserializer {
view,
{
renderer: panelData.renderer,
priority: panelData.priority,
}
);

Expand Down
2 changes: 1 addition & 1 deletion packages/dockview-core/src/dockview/dockviewComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2219,7 +2219,7 @@ export class DockviewComponent
this._api,
group,
view,
{ renderer: options.renderer }
{ renderer: options.renderer, priority: options.priority }
);

panel.init({
Expand Down
11 changes: 11 additions & 0 deletions packages/dockview-core/src/dockview/dockviewGroupPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
DockviewGroupPanelApi,
DockviewGroupPanelApiImpl,
} from '../api/dockviewGroupPanelApi';
import { EnhancedLayoutPriority, LayoutPriority } from '../splitview/splitview';

const MINIMUM_DOCKVIEW_GROUP_PANEL_WIDTH = 100;
const MINIMUM_DOCKVIEW_GROUP_PANEL_HEIGHT = 100;
Expand Down Expand Up @@ -62,6 +63,16 @@ export class DockviewGroupPanel
return this._model.header;
}

get priority(): EnhancedLayoutPriority | undefined {
const activePanel = this.model.activePanel;

if (!activePanel) {
return LayoutPriority.Normal;
}

return activePanel.api.priority;
}

constructor(
accessor: DockviewComponent,
id: string,
Expand Down
9 changes: 8 additions & 1 deletion packages/dockview-core/src/dockview/dockviewPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export class DockviewPanel
private _params?: Parameters;
private _title: string | undefined;
private _renderer: DockviewPanelRenderer | undefined;
private _priority: number | undefined;

get params(): Parameters | undefined {
return this._params;
Expand All @@ -56,6 +57,10 @@ export class DockviewPanel
return this._renderer ?? this.accessor.renderer;
}

get priority(): number {
return this._priority ?? 0;
}

constructor(
public readonly id: string,
component: string,
Expand All @@ -64,10 +69,11 @@ export class DockviewPanel
private readonly containerApi: DockviewApi,
group: DockviewGroupPanel,
readonly view: IDockviewPanelModel,
options: { renderer?: DockviewPanelRenderer }
options: { renderer?: DockviewPanelRenderer; priority?: number }
) {
super();
this._renderer = options.renderer;
this._priority = options.priority;
this._group = group;

this.api = new DockviewPanelApiImpl(
Expand Down Expand Up @@ -129,6 +135,7 @@ export class DockviewPanel
: undefined,
title: this.title,
renderer: this._renderer,
priority: this._priority,
};
}

Expand Down
4 changes: 4 additions & 0 deletions packages/dockview-core/src/dockview/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,10 @@ export type AddPanelOptions<P extends object = Parameters> = {
* Defaults to `false` which forces newly added panels to become active.
*/
inactive?: boolean;
/**
* Panel resizing priority
*/
priority?: number;
} & Partial<AddPanelOptionsUnion>;

type AddGroupOptionsWithPanel = {
Expand Down
1 change: 1 addition & 0 deletions packages/dockview-core/src/dockview/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,6 @@ export interface GroupviewPanelState {
tabComponent?: string;
title?: string;
renderer?: DockviewPanelRenderer;
priority?: number;
params?: { [key: string]: any };
}
29 changes: 23 additions & 6 deletions packages/dockview-core/src/gridview/branchNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import {
Splitview,
Orientation,
Sizing,
LayoutPriority,
EnhancedLayoutPriority,
ISplitviewStyles,
LayoutPriority,
layoutPriorityAsNumber,
} from '../splitview/splitview';
import { Emitter, Event } from '../events';
import { INodeDescriptor } from './gridview';
Expand Down Expand Up @@ -111,7 +113,7 @@ export class BranchNode extends CompositeDisposable implements IView {
: this.maximumOrthogonalSize;
}

get priority(): LayoutPriority {
get priority(): EnhancedLayoutPriority {
if (this.children.length === 0) {
return LayoutPriority.Normal;
}
Expand All @@ -122,10 +124,25 @@ export class BranchNode extends CompositeDisposable implements IView {
: c.priority
);

if (priorities.some((p) => p === LayoutPriority.High)) {
return LayoutPriority.High;
} else if (priorities.some((p) => p === LayoutPriority.Low)) {
return LayoutPriority.Low;
let max: number | undefined;
let min: number | undefined;

for (const p of priorities) {
const i = layoutPriorityAsNumber(p);
if (i > 0) {
max = max === undefined ? i : Math.max(max, i);
}
if (i < 0) {
min = min === undefined ? i : Math.min(min, i);
}
}

if (typeof max === 'number') {
return max;
}

if (typeof min === 'number') {
return min;
}

return LayoutPriority.Normal;
Expand Down
4 changes: 2 additions & 2 deletions packages/dockview-core/src/gridview/gridview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import {
ISplitviewStyles,
LayoutPriority,
EnhancedLayoutPriority,
Orientation,
Sizing,
} from '../splitview/splitview';
Expand Down Expand Up @@ -171,7 +171,7 @@ export interface IGridView {
readonly maximumWidth: number;
readonly minimumHeight: number;
readonly maximumHeight: number;
priority?: LayoutPriority;
priority?: EnhancedLayoutPriority;
layout(width: number, height: number): void;
toJSON(): object;
fromJSON?(json: object): void;
Expand Down
12 changes: 6 additions & 6 deletions packages/dockview-core/src/gridview/gridviewPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
GridviewPanelApi,
GridviewPanelApiImpl,
} from '../api/gridviewPanelApi';
import { LayoutPriority } from '../splitview/splitview';
import { EnhancedLayoutPriority } from '../splitview/splitview';
import { Emitter, Event } from '../events';
import { IViewSize } from './gridview';
import { BaseGrid, IGridPanelView } from './baseComponentGridview';
Expand All @@ -23,7 +23,7 @@ export interface GridviewInitParameters extends PanelInitParameters {
maximumWidth?: number;
minimumHeight?: number;
maximumHeight?: number;
priority?: LayoutPriority;
priority?: EnhancedLayoutPriority;
snap?: boolean;
accessor: BaseGrid<IGridPanelView>;
isVisible?: boolean;
Expand All @@ -35,7 +35,7 @@ export interface IGridviewPanel<T extends GridviewPanelApi = GridviewPanelApi>
readonly maximumWidth: number;
readonly minimumHeight: number;
readonly maximumHeight: number;
readonly priority: LayoutPriority | undefined;
readonly priority: EnhancedLayoutPriority | undefined;
readonly snap: boolean;
}

Expand All @@ -54,14 +54,14 @@ export abstract class GridviewPanel<
private _minimumHeight: FunctionOrValue<number> = 0;
private _maximumWidth: FunctionOrValue<number> = Number.MAX_SAFE_INTEGER;
private _maximumHeight: FunctionOrValue<number> = Number.MAX_SAFE_INTEGER;
private _priority?: LayoutPriority;
protected _priority?: EnhancedLayoutPriority;
private _snap = false;

private readonly _onDidChange = new Emitter<IViewSize | undefined>();
readonly onDidChange: Event<IViewSize | undefined> =
this._onDidChange.event;

get priority(): LayoutPriority | undefined {
get priority(): EnhancedLayoutPriority | undefined {
return this._priority;
}

Expand Down Expand Up @@ -270,5 +270,5 @@ export interface GridPanelViewState extends BasePanelViewState {
minimumWidth?: number;
maximumWidth?: number;
snap?: boolean;
priority?: LayoutPriority;
priority?: EnhancedLayoutPriority;
}
8 changes: 6 additions & 2 deletions packages/dockview-core/src/gridview/leafNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
* https://github.com/microsoft/vscode/tree/main/src/vs/base/browser/ui/grid
*--------------------------------------------------------------------------------------------*/

import { IView, LayoutPriority, Orientation } from '../splitview/splitview';
import {
IView,
EnhancedLayoutPriority,
Orientation,
} from '../splitview/splitview';
import { Emitter, Event } from '../events';
import { IGridView } from './gridview';
import { IDisposable } from '../lifecycle';
Expand Down Expand Up @@ -35,7 +39,7 @@ export class LeafNode implements IView {
return this.view.maximumHeight;
}

get priority(): LayoutPriority | undefined {
get priority(): EnhancedLayoutPriority | undefined {
return this.view.priority;
}

Expand Down
4 changes: 2 additions & 2 deletions packages/dockview-core/src/panel/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { IDisposable } from '../lifecycle';
import { LayoutPriority } from '../splitview/splitview';
import { EnhancedLayoutPriority } from '../splitview/splitview';

/**
* A key-value object of anything that is a valid JavaScript Object.
Expand Down Expand Up @@ -34,6 +34,6 @@ export interface BaseComponentOptions<T extends object = Parameters> {
component: string;
params?: T;
snap?: boolean;
priority?: LayoutPriority;
priority?: EnhancedLayoutPriority;
size?: number;
}
8 changes: 6 additions & 2 deletions packages/dockview-core/src/paneview/paneviewComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import {
IDisposable,
MutableDisposable,
} from '../lifecycle';
import { LayoutPriority, Orientation, Sizing } from '../splitview/splitview';
import {
EnhancedLayoutPriority,
Orientation,
Sizing,
} from '../splitview/splitview';
import { PaneviewComponentOptions } from './options';
import { Paneview } from './paneview';
import {
Expand Down Expand Up @@ -35,7 +39,7 @@ export interface PaneviewDndOverlayEvent {

export interface SerializedPaneviewPanel {
snap?: boolean;
priority?: LayoutPriority;
priority?: EnhancedLayoutPriority;
minimumSize?: number;
maximumSize?: number;
data: {
Expand Down
Loading