mirror of
https://github.com/mathuo/dockview
synced 2025-05-02 01:28:28 +00:00
refactor: reduce code smells
This commit is contained in:
parent
02568345b6
commit
b5de6c7e43
@ -262,7 +262,7 @@ export class DockviewComponent
|
||||
},
|
||||
options: (() => PanelOptions) | PanelOptions
|
||||
): IDisposable {
|
||||
const disposables = new CompositeDisposable(
|
||||
return new CompositeDisposable(
|
||||
addDisposableListener(target.element, 'dragstart', (event) => {
|
||||
if (!event.dataTransfer) {
|
||||
throw new Error('unsupported');
|
||||
@ -305,8 +305,6 @@ export class DockviewComponent
|
||||
this.drag.dispose();
|
||||
})
|
||||
);
|
||||
|
||||
return disposables;
|
||||
}
|
||||
|
||||
setActivePanel(panel: IGroupPanel): void {
|
||||
@ -514,7 +512,7 @@ export class DockviewComponent
|
||||
|
||||
public async closeAllGroups(): Promise<boolean> {
|
||||
for (const entry of this.groups.entries()) {
|
||||
const [key, group] = entry;
|
||||
const [_, group] = entry;
|
||||
|
||||
const didCloseAll = await group.value.group.closeAllPanels();
|
||||
if (!didCloseAll) {
|
||||
|
@ -105,16 +105,12 @@ export abstract class BasePanelView<T extends PanelApi>
|
||||
toJSON(): BasePanelViewState {
|
||||
const state = this.api.getState();
|
||||
|
||||
const params = this.params?.params
|
||||
? Object.keys(this.params.params).length > 0
|
||||
? this.params.params
|
||||
: undefined
|
||||
: undefined;
|
||||
const params = this.params?.params ?? {};
|
||||
|
||||
return {
|
||||
id: this.id,
|
||||
component: this.component,
|
||||
params,
|
||||
params: Object.keys(params).length > 0 ? params : undefined,
|
||||
state: Object.keys(state).length === 0 ? undefined : state,
|
||||
};
|
||||
}
|
||||
|
@ -108,7 +108,7 @@ export class BranchNode extends CompositeDisposable implements IView {
|
||||
readonly orientation: Orientation,
|
||||
readonly proportionalLayout: boolean,
|
||||
readonly styles: ISplitviewStyles | undefined,
|
||||
size = 0,
|
||||
size: number,
|
||||
orthogonalSize: number,
|
||||
childDescriptors?: INodeDescriptor[]
|
||||
) {
|
||||
|
@ -124,7 +124,7 @@ export class GridviewComponent
|
||||
*
|
||||
* @returns A JSON respresentation of the layout
|
||||
*/
|
||||
public toJSON() {
|
||||
public toJSON(): SerializedGridview {
|
||||
const data = this.gridview.serialize() as {
|
||||
height: number;
|
||||
width: number;
|
||||
@ -132,11 +132,10 @@ export class GridviewComponent
|
||||
root: SerializedGridObject<GridPanelViewState>;
|
||||
};
|
||||
|
||||
const serializedData: SerializedGridview = {
|
||||
return {
|
||||
grid: data,
|
||||
activePanel: this.activeGroup?.id,
|
||||
};
|
||||
return serializedData;
|
||||
}
|
||||
|
||||
setVisible(panel: GridviewPanel, visible: boolean): void {
|
||||
|
@ -95,15 +95,17 @@ export class LeafNode implements IView {
|
||||
this._orthogonalSize = orthogonalSize;
|
||||
this._size = size;
|
||||
|
||||
this._disposable = this.view.onDidChange((event) =>
|
||||
this._onDidChange.fire(
|
||||
event
|
||||
? this.orientation === Orientation.VERTICAL
|
||||
this._disposable = this.view.onDidChange((event) => {
|
||||
if (event) {
|
||||
this._onDidChange.fire(
|
||||
this.orientation === Orientation.VERTICAL
|
||||
? event.width
|
||||
: event.height
|
||||
: undefined
|
||||
)
|
||||
);
|
||||
);
|
||||
} else {
|
||||
this._onDidChange.fire(undefined);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public setVisible(visible: boolean) {
|
||||
|
@ -5,8 +5,6 @@ import {
|
||||
} from '../../lifecycle';
|
||||
import { Emitter, Event } from '../../events';
|
||||
import { trackFocus } from '../../dom';
|
||||
import { HostedContainer } from '../../hostedContainer';
|
||||
import { IDockviewPanelApi } from '../../api/groupPanelApi';
|
||||
import { IGroupPanel } from '../groupPanel';
|
||||
|
||||
export interface IRenderable {
|
||||
|
@ -538,8 +538,6 @@ export class GroupComponent extends CompositeDisposable implements IGroupview {
|
||||
}
|
||||
|
||||
private _removePanel(panel: IGroupPanel) {
|
||||
const index = this._panels.indexOf(panel);
|
||||
|
||||
const isActivePanel = this._activePanel === panel;
|
||||
|
||||
this.doRemovePanel(panel);
|
||||
|
@ -32,12 +32,11 @@ export function createComponent<T>(
|
||||
`Cannot create '${id}' for framework component '${componentName}'. you must register a frameworkPanelWrapper to use framework components`
|
||||
);
|
||||
}
|
||||
const wrappedComponent = createFrameworkComponent.createComponent(
|
||||
return createFrameworkComponent.createComponent(
|
||||
id,
|
||||
componentName!,
|
||||
FrameworkComponent
|
||||
);
|
||||
return wrappedComponent;
|
||||
}
|
||||
|
||||
if (!Component) {
|
||||
|
@ -1,7 +1,6 @@
|
||||
import * as React from 'react';
|
||||
import {
|
||||
IContentRenderer,
|
||||
GroupPanelPartInitParameters,
|
||||
GroupPanelContentPartInitParameters,
|
||||
} from '../../groupview/types';
|
||||
import { ReactPart, ReactPortalStore } from '../react';
|
||||
@ -9,7 +8,6 @@ import { IDockviewPanelProps } from '../dockview/dockview';
|
||||
import { PanelUpdateEvent } from '../../panel/types';
|
||||
import { IDockviewPanelApi } from '../../api/groupPanelApi';
|
||||
import { DockviewApi } from '../../api/component.api';
|
||||
import { HostedContainer } from '../../hostedContainer';
|
||||
import { GroupviewPanel } from '../../groupview/v2/groupviewPanel';
|
||||
import { Emitter, Event } from '../../events';
|
||||
import { WrappedTab } from '../../dockview/components/tab/defaultTab';
|
||||
@ -19,78 +17,6 @@ export interface IGroupPanelActionbarProps {
|
||||
containerApi: DockviewApi;
|
||||
}
|
||||
|
||||
class BasePanelContentPart implements IContentRenderer {
|
||||
protected _element: HTMLElement;
|
||||
protected _group: GroupviewPanel | undefined;
|
||||
//
|
||||
protected _actionsElement: HTMLElement;
|
||||
|
||||
protected parameters: GroupPanelPartInitParameters | undefined;
|
||||
|
||||
private readonly _onDidFocus = new Emitter<void>();
|
||||
readonly onDidFocus: Event<void> = this._onDidFocus.event;
|
||||
|
||||
private readonly _onDidBlur = new Emitter<void>();
|
||||
readonly onDidBlur: Event<void> = this._onDidBlur.event;
|
||||
|
||||
get element(): HTMLElement {
|
||||
return this._element;
|
||||
}
|
||||
|
||||
get actions(): HTMLElement {
|
||||
return this._actionsElement;
|
||||
}
|
||||
|
||||
constructor(public readonly id: string) {
|
||||
this._element = document.createElement('div');
|
||||
this._element.style.height = '100%';
|
||||
this._element.style.width = '100%';
|
||||
|
||||
this._actionsElement = document.createElement('div');
|
||||
this._actionsElement.style.height = '100%';
|
||||
this._actionsElement.style.width = '100%';
|
||||
}
|
||||
|
||||
focus() {
|
||||
// this._element.focus();
|
||||
}
|
||||
|
||||
public init(parameters: GroupPanelPartInitParameters): void {
|
||||
this.parameters = parameters;
|
||||
}
|
||||
|
||||
public toJSON() {
|
||||
return {
|
||||
id: this.id,
|
||||
};
|
||||
}
|
||||
|
||||
public update(params: PanelUpdateEvent) {
|
||||
if (this.parameters) {
|
||||
this.parameters.params = params.params;
|
||||
}
|
||||
}
|
||||
|
||||
public updateParentGroup(
|
||||
group: GroupviewPanel,
|
||||
isPanelVisible: boolean
|
||||
): void {
|
||||
this._group = group;
|
||||
}
|
||||
|
||||
public layout(width: number, height: number): void {
|
||||
// noop
|
||||
}
|
||||
|
||||
public close(): Promise<boolean> {
|
||||
return Promise.resolve(true);
|
||||
}
|
||||
|
||||
public dispose() {
|
||||
//
|
||||
}
|
||||
}
|
||||
|
||||
export interface ReactContentPartContext {
|
||||
api: IDockviewPanelApi;
|
||||
containerApi: DockviewApi;
|
||||
|
@ -55,6 +55,15 @@ export const PaneviewReact = React.forwardRef(
|
||||
}, [props.disableAutoResizing]);
|
||||
|
||||
React.useEffect(() => {
|
||||
const createComponent = (
|
||||
id: string,
|
||||
componentId: string,
|
||||
component: any
|
||||
) =>
|
||||
new PanePanelSection(id, component, {
|
||||
addPortal,
|
||||
});
|
||||
|
||||
const paneview = new PaneviewComponent(domRef.current!, {
|
||||
frameworkComponents: props.components,
|
||||
components: {},
|
||||
@ -62,26 +71,10 @@ export const PaneviewReact = React.forwardRef(
|
||||
headerframeworkComponents: props.headerComponents,
|
||||
frameworkWrapper: {
|
||||
header: {
|
||||
createComponent: (
|
||||
id: string,
|
||||
componentId,
|
||||
component: any
|
||||
) => {
|
||||
return new PanePanelSection(id, component, {
|
||||
addPortal,
|
||||
});
|
||||
},
|
||||
createComponent,
|
||||
},
|
||||
body: {
|
||||
createComponent: (
|
||||
id: string,
|
||||
componentId,
|
||||
component: any
|
||||
) => {
|
||||
return new PanePanelSection(id, component, {
|
||||
addPortal,
|
||||
});
|
||||
},
|
||||
createComponent,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user