Conform more of the code base to strict null checking (#10147)
* Conform more of the code base to strict null checking * More strict fixes * More strict work * Fix missing optional type * Iterate
This commit is contained in:
parent
fa036a5080
commit
da7aa4055e
380 changed files with 682 additions and 694 deletions
|
@ -27,15 +27,11 @@ export interface ICollapseConfig extends IConfig {
|
|||
|
||||
class CollapseItem extends ResizeItem<ICollapseConfig> {
|
||||
public notifyCollapsed(collapsed: boolean): void {
|
||||
const callback = this.resizer.config.onCollapsed;
|
||||
if (callback) {
|
||||
callback(collapsed, this.id, this.domNode);
|
||||
}
|
||||
this.resizer.config?.onCollapsed?.(collapsed, this.id, this.domNode);
|
||||
}
|
||||
|
||||
public get isCollapsed(): boolean {
|
||||
const isItemCollapsed = this.resizer.config.isItemCollapsed;
|
||||
return isItemCollapsed(this.domNode);
|
||||
return this.resizer.config?.isItemCollapsed?.(this.domNode) ?? false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ export default class ResizeItem<C extends IConfig = IConfig> {
|
|||
return new Ctor(handle, resizer, sizer, container);
|
||||
}
|
||||
|
||||
private advance(forwards: boolean): ResizeItem {
|
||||
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;
|
||||
const moveNext = forwards !== this.reverse; // xor
|
||||
|
@ -62,11 +62,11 @@ export default class ResizeItem<C extends IConfig = IConfig> {
|
|||
}
|
||||
}
|
||||
|
||||
public next(): ResizeItem {
|
||||
public next(): ResizeItem | undefined {
|
||||
return this.advance(true);
|
||||
}
|
||||
|
||||
public previous(): ResizeItem {
|
||||
public previous(): ResizeItem | undefined {
|
||||
return this.advance(false);
|
||||
}
|
||||
|
||||
|
@ -96,21 +96,15 @@ export default class ResizeItem<C extends IConfig = IConfig> {
|
|||
|
||||
public setSize(size: number): void {
|
||||
this.setRawSize(`${Math.round(size)}px`);
|
||||
const callback = this.resizer.config.onResized;
|
||||
if (callback) {
|
||||
callback(size, this.id, this.domNode);
|
||||
}
|
||||
this.resizer.config?.onResized?.(size, this.id, this.domNode);
|
||||
}
|
||||
|
||||
public clearSize(): void {
|
||||
this.sizer.clearItemSize(this.domNode);
|
||||
const callback = this.resizer.config.onResized;
|
||||
if (callback) {
|
||||
callback(null, this.id, this.domNode);
|
||||
}
|
||||
this.resizer.config?.onResized?.(null, this.id, this.domNode);
|
||||
}
|
||||
|
||||
public first(): ResizeItem {
|
||||
public first(): ResizeItem | undefined {
|
||||
const firstHandle = Array.from(this.domNode.parentElement.children).find((el) => {
|
||||
return this.resizer.isResizeHandle(<HTMLElement>el);
|
||||
});
|
||||
|
@ -119,7 +113,7 @@ export default class ResizeItem<C extends IConfig = IConfig> {
|
|||
}
|
||||
}
|
||||
|
||||
public last(): ResizeItem {
|
||||
public last(): ResizeItem | undefined {
|
||||
const lastHandle = Array.from(this.domNode.parentElement.children)
|
||||
.reverse()
|
||||
.find((el) => {
|
||||
|
|
|
@ -87,7 +87,7 @@ export default class Resizer<C extends IConfig = IConfig> {
|
|||
@param {number} handleIndex the index of the resize handle in the container
|
||||
@return {FixedDistributor} a new distributor for the given handle
|
||||
*/
|
||||
public forHandleAt(handleIndex: number): FixedDistributor<C> {
|
||||
public forHandleAt(handleIndex: number): FixedDistributor<C> | undefined {
|
||||
const handles = this.getResizeHandles();
|
||||
const handle = handles[handleIndex];
|
||||
if (handle) {
|
||||
|
@ -96,7 +96,7 @@ export default class Resizer<C extends IConfig = IConfig> {
|
|||
}
|
||||
}
|
||||
|
||||
public forHandleWithId(id: string): FixedDistributor<C> {
|
||||
public forHandleWithId(id: string): FixedDistributor<C> | undefined {
|
||||
const handles = this.getResizeHandles();
|
||||
const handle = handles.find((h) => h.getAttribute("data-id") === id);
|
||||
if (handle) {
|
||||
|
@ -106,11 +106,11 @@ export default class Resizer<C extends IConfig = IConfig> {
|
|||
}
|
||||
|
||||
public isReverseResizeHandle(el: HTMLElement): boolean {
|
||||
return el && el.classList.contains(this.classNames.reverse);
|
||||
return el.classList.contains(this.classNames.reverse!);
|
||||
}
|
||||
|
||||
public isResizeHandle(el: HTMLElement): boolean {
|
||||
return el && el.classList.contains(this.classNames.handle);
|
||||
return el.classList.contains(this.classNames.handle!);
|
||||
}
|
||||
|
||||
private onMouseDown = (event: MouseEvent): void => {
|
||||
|
@ -136,9 +136,7 @@ export default class Resizer<C extends IConfig = IConfig> {
|
|||
if (this.classNames.resizing) {
|
||||
this.container?.classList?.add(this.classNames.resizing);
|
||||
}
|
||||
if (this.config.onResizeStart) {
|
||||
this.config.onResizeStart();
|
||||
}
|
||||
this.config?.onResizeStart?.();
|
||||
|
||||
const { sizer, distributor } = this.createSizerAndDistributor(<HTMLDivElement>resizeHandle);
|
||||
distributor.start();
|
||||
|
@ -154,9 +152,7 @@ export default class Resizer<C extends IConfig = IConfig> {
|
|||
this.container?.classList?.remove(this.classNames.resizing);
|
||||
}
|
||||
distributor.finish();
|
||||
if (this.config.onResizeStop) {
|
||||
this.config.onResizeStop();
|
||||
}
|
||||
this.config?.onResizeStop?.();
|
||||
body.removeEventListener("mouseup", finishResize, false);
|
||||
document.removeEventListener("mouseleave", finishResize, false);
|
||||
body.removeEventListener("mousemove", onMouseMove, false);
|
||||
|
@ -189,10 +185,10 @@ export default class Resizer<C extends IConfig = IConfig> {
|
|||
sizer: Sizer;
|
||||
distributor: FixedDistributor<any>;
|
||||
} {
|
||||
const vertical = resizeHandle.classList.contains(this.classNames.vertical);
|
||||
const vertical = resizeHandle.classList.contains(this.classNames.vertical!);
|
||||
const reverse = this.isReverseResizeHandle(resizeHandle);
|
||||
const Distributor = this.distributorCtor;
|
||||
const useItemContainer = this.config && this.config.handler ? this.container : undefined;
|
||||
const useItemContainer = this.config?.handler ? this.container : undefined;
|
||||
const sizer = Distributor.createSizer(this.container, vertical, reverse);
|
||||
const item = Distributor.createItem(resizeHandle, this, sizer, useItemContainer);
|
||||
const distributor = new Distributor(item);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue