Apply `strictNullChecks` to `src/resizer/*` (#10378)

pull/28217/head
Kerry 2023-03-16 09:27:59 +13:00 committed by GitHub
parent 37d218eb61
commit 31a959efe9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 8 deletions

View File

@ -21,7 +21,7 @@ import Sizer from "../sizer";
export interface ICollapseConfig extends IConfig {
toggleSize: number;
onCollapsed?(collapsed: boolean, id: string, element: HTMLElement): void;
onCollapsed?(collapsed: boolean, id: string | null, element: HTMLElement): void;
isItemCollapsed(element: HTMLElement): boolean;
}
@ -45,7 +45,7 @@ export default class CollapseDistributor extends FixedDistributor<ICollapseConfi
return new CollapseItem(resizeHandle, resizer, sizer, container);
}
private readonly toggleSize: number;
private readonly toggleSize: number | undefined;
private isCollapsed: boolean;
public constructor(item: CollapseItem) {
@ -55,7 +55,7 @@ export default class CollapseDistributor extends FixedDistributor<ICollapseConfi
}
public resize(newSize: number): void {
const isCollapsedSize = newSize < this.toggleSize;
const isCollapsedSize = !!this.toggleSize && newSize < this.toggleSize;
if (isCollapsedSize !== this.isCollapsed) {
this.isCollapsed = isCollapsedSize;
this.item.notifyCollapsed(isCollapsedSize);

View File

@ -21,9 +21,9 @@ import { IConfig } from "../resizer";
class PercentageSizer extends Sizer {
public start(item: HTMLElement): void {
if (this.vertical) {
item.style.minHeight = null;
item.style.minHeight = "";
} else {
item.style.minWidth = null;
item.style.minWidth = "";
}
}

View File

@ -44,14 +44,16 @@ export default class ResizeItem<C extends IConfig = IConfig> {
private advance(forwards: boolean): ResizeItem | undefined {
// opposite direction from fromResizeHandle to get back to handle
let handle = this.reverse ? this.domNode.previousElementSibling : this.domNode.nextElementSibling;
let handle: Element | null | undefined = this.reverse
? this.domNode.previousElementSibling
: this.domNode.nextElementSibling;
const moveNext = forwards !== this.reverse; // xor
// iterate at least once to avoid infinite loop
do {
if (moveNext) {
handle = handle.nextElementSibling;
handle = handle?.nextElementSibling;
} else {
handle = handle.previousElementSibling;
handle = handle?.previousElementSibling;
}
} while (handle && !this.resizer.isResizeHandle(<HTMLElement>handle));
@ -105,6 +107,9 @@ export default class ResizeItem<C extends IConfig = IConfig> {
}
public first(): ResizeItem | undefined {
if (!this.domNode.parentElement?.children) {
return;
}
const firstHandle = Array.from(this.domNode.parentElement.children).find((el) => {
return this.resizer.isResizeHandle(<HTMLElement>el);
});
@ -114,6 +119,9 @@ export default class ResizeItem<C extends IConfig = IConfig> {
}
public last(): ResizeItem | undefined {
if (!this.domNode.parentElement?.children) {
return;
}
const lastHandle = Array.from(this.domNode.parentElement.children)
.reverse()
.find((el) => {