Skip to content

Commit

Permalink
Improve externally available types
Browse files Browse the repository at this point in the history
- also add non-null assertion to `DockContextType`
  • Loading branch information
irahopkinson committed May 11, 2023
1 parent 7f3363a commit 13f441e
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 47 deletions.
21 changes: 11 additions & 10 deletions es/DockData.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,15 @@ export interface LayoutData extends LayoutBase {
loadedFrom?: LayoutBase;
}
export declare type DropDirection = 'left' | 'right' | 'bottom' | 'top' | 'middle' | 'remove' | 'before-tab' | 'after-tab' | 'float' | 'front' | 'maximize' | 'new-window' | 'move' | 'active' | 'update';
export interface FloatSize {
width: number;
height: number;
}
export interface FloatPosition extends FloatSize {
left: number;
top: number;
}
export declare type LayoutSize = FloatSize;
export interface DockContext {
/** @ignore */
getDockId(): any;
Expand All @@ -254,10 +263,7 @@ export interface DockContext {
clientY: number;
}, panelSize?: [number, number]): void;
/** @ignore */
getLayoutSize(): {
width: number;
height: number;
};
getLayoutSize(): LayoutSize;
/** @ignore
* When a state change happen to the layout that's handled locally, like inside DockPanel or DockBox.
* It still need to tell the context there is a change so DockLayout can call onLayoutChange callback.
Expand All @@ -276,12 +282,7 @@ export interface DockContext {
* - when direction is 'float', target doesn't matter. If this is called directly from code without any user interaction, source must be PanelData with x,y,w,h properties
* @param floatPosition position of float panel, used only when direction="float"
*/
dockMove(source: TabData | PanelData, target: string | TabData | PanelData | BoxData | null, direction: DropDirection, floatPosition?: {
left: number;
top: number;
width: number;
height: number;
}): void;
dockMove(source: TabData | PanelData, target: string | TabData | PanelData | BoxData | null, direction: DropDirection, floatPosition?: FloatPosition): void;
/**
* Get the TabGroup defined in defaultLayout
*/
Expand Down
14 changes: 3 additions & 11 deletions es/DockLayout.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from "react";
import { BoxData, DockContext, DropDirection, LayoutBase, LayoutData, PanelBase, PanelData, TabBase, TabData, TabGroup, TabPaneCache } from "./DockData";
import { BoxData, DockContext, DropDirection, FloatPosition, LayoutBase, LayoutData, LayoutSize, PanelBase, PanelData, TabBase, TabData, TabGroup, TabPaneCache } from "./DockData";
import * as Algorithm from "./Algorithm";
export interface LayoutProps {
/**
Expand Down Expand Up @@ -109,19 +109,11 @@ export declare class DockLayout extends DockPortalManager implements DockContext
* @param direction @inheritDoc
* @param floatPosition @inheritDoc
*/
dockMove(source: TabData | PanelData, target: string | TabData | PanelData | BoxData | null, direction: DropDirection, floatPosition?: {
left: number;
top: number;
width: number;
height: number;
}): void;
dockMove(source: TabData | PanelData, target: string | TabData | PanelData | BoxData | null, direction: DropDirection, floatPosition?: FloatPosition): void;
/** @inheritDoc */
find(id: string, filter?: Algorithm.Filter): PanelData | TabData | BoxData | undefined;
/** @ignore */
getLayoutSize(): {
width: number;
height: number;
};
getLayoutSize(): LayoutSize;
/** @inheritDoc */
updateTab(id: string, newTab: TabData | null, makeActive?: boolean): boolean;
/** @inheritDoc */
Expand Down
21 changes: 11 additions & 10 deletions lib/DockData.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,15 @@ export interface LayoutData extends LayoutBase {
loadedFrom?: LayoutBase;
}
export declare type DropDirection = 'left' | 'right' | 'bottom' | 'top' | 'middle' | 'remove' | 'before-tab' | 'after-tab' | 'float' | 'front' | 'maximize' | 'new-window' | 'move' | 'active' | 'update';
export interface FloatSize {
width: number;
height: number;
}
export interface FloatPosition extends FloatSize {
left: number;
top: number;
}
export declare type LayoutSize = FloatSize;
export interface DockContext {
/** @ignore */
getDockId(): any;
Expand All @@ -254,10 +263,7 @@ export interface DockContext {
clientY: number;
}, panelSize?: [number, number]): void;
/** @ignore */
getLayoutSize(): {
width: number;
height: number;
};
getLayoutSize(): LayoutSize;
/** @ignore
* When a state change happen to the layout that's handled locally, like inside DockPanel or DockBox.
* It still need to tell the context there is a change so DockLayout can call onLayoutChange callback.
Expand All @@ -276,12 +282,7 @@ export interface DockContext {
* - when direction is 'float', target doesn't matter. If this is called directly from code without any user interaction, source must be PanelData with x,y,w,h properties
* @param floatPosition position of float panel, used only when direction="float"
*/
dockMove(source: TabData | PanelData, target: string | TabData | PanelData | BoxData | null, direction: DropDirection, floatPosition?: {
left: number;
top: number;
width: number;
height: number;
}): void;
dockMove(source: TabData | PanelData, target: string | TabData | PanelData | BoxData | null, direction: DropDirection, floatPosition?: FloatPosition): void;
/**
* Get the TabGroup defined in defaultLayout
*/
Expand Down
14 changes: 3 additions & 11 deletions lib/DockLayout.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from "react";
import { BoxData, DockContext, DropDirection, LayoutBase, LayoutData, PanelBase, PanelData, TabBase, TabData, TabGroup, TabPaneCache } from "./DockData";
import { BoxData, DockContext, DropDirection, FloatPosition, LayoutBase, LayoutData, LayoutSize, PanelBase, PanelData, TabBase, TabData, TabGroup, TabPaneCache } from "./DockData";
import * as Algorithm from "./Algorithm";
export interface LayoutProps {
/**
Expand Down Expand Up @@ -109,19 +109,11 @@ export declare class DockLayout extends DockPortalManager implements DockContext
* @param direction @inheritDoc
* @param floatPosition @inheritDoc
*/
dockMove(source: TabData | PanelData, target: string | TabData | PanelData | BoxData | null, direction: DropDirection, floatPosition?: {
left: number;
top: number;
width: number;
height: number;
}): void;
dockMove(source: TabData | PanelData, target: string | TabData | PanelData | BoxData | null, direction: DropDirection, floatPosition?: FloatPosition): void;
/** @inheritDoc */
find(id: string, filter?: Algorithm.Filter): PanelData | TabData | BoxData | undefined;
/** @ignore */
getLayoutSize(): {
width: number;
height: number;
};
getLayoutSize(): LayoutSize;
/** @inheritDoc */
updateTab(id: string, newTab: TabData | null, makeActive?: boolean): boolean;
/** @inheritDoc */
Expand Down
18 changes: 15 additions & 3 deletions src/DockData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,18 @@ export type DropDirection =
| 'update' // tab updated with updateTab
;

export interface FloatSize {
width: number;
height: number;
}

export interface FloatPosition extends FloatSize {
left: number;
top: number;
}

export type LayoutSize = FloatSize;

export interface DockContext {
/** @ignore */
getDockId(): any;
Expand All @@ -321,7 +333,7 @@ export interface DockContext {
setDropRect(element: HTMLElement, direction?: DropDirection, source?: any, event?: {clientX: number, clientY: number}, panelSize?: [number, number]): void;

/** @ignore */
getLayoutSize(): {width: number, height: number};
getLayoutSize(): LayoutSize;

/** @ignore
* When a state change happen to the layout that's handled locally, like inside DockPanel or DockBox.
Expand All @@ -346,7 +358,7 @@ export interface DockContext {
source: TabData | PanelData,
target: string | TabData | PanelData | BoxData | null,
direction: DropDirection,
floatPosition?: { left: number, top: number, width: number, height: number }
floatPosition?: FloatPosition
): void;

/**
Expand Down Expand Up @@ -389,7 +401,7 @@ export interface DockContext {
}

/** @ignore */
export const DockContextType = React.createContext<DockContext>(null);
export const DockContextType = React.createContext<DockContext>(null!);
/** @ignore */
export const DockContextProvider = DockContextType.Provider;
/** @ignore */
Expand Down
6 changes: 4 additions & 2 deletions src/DockLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import {
DockContext,
DockContextProvider,
DropDirection,
FloatPosition,
LayoutBase,
LayoutData,
LayoutSize,
PanelBase,
PanelData,
placeHolderGroup,
Expand Down Expand Up @@ -215,7 +217,7 @@ export class DockLayout extends DockPortalManager implements DockContext {
source: TabData | PanelData,
target: string | TabData | PanelData | BoxData | null,
direction: DropDirection,
floatPosition?: {left: number, top: number, width: number, height: number}
floatPosition?: FloatPosition
) {
let layout = this.getLayout();
if (direction === 'maximize') {
Expand Down Expand Up @@ -280,7 +282,7 @@ export class DockLayout extends DockPortalManager implements DockContext {
}

/** @ignore */
getLayoutSize() {
getLayoutSize(): LayoutSize {
if (this._ref) {
return {width: this._ref.offsetWidth, height: this._ref.offsetHeight};
}
Expand Down

0 comments on commit 13f441e

Please sign in to comment.