Skip to content

Commit ab27114

Browse files
committed
TS: types any cleanup
* fixed many (some remain) of `noImplicitAny=true` case
1 parent 5418a61 commit ab27114

File tree

5 files changed

+25
-22
lines changed

5 files changed

+25
-22
lines changed

src/gridstack-dragdrop-plugin.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export type DDDropOpt = {
2020
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2121
export type DDOpts = 'enable' | 'disable' | 'destroy' | 'option' | string | {} | any;
2222
export type DDKey = 'minWidth' | 'minHeight' | string;
23+
export type DDValue = number | string;
2324

2425
/** drag&drop events callbacks */
2526
export type DDCallback = (event: Event, arg2: GridItemHTMLElement) => void;
@@ -39,15 +40,15 @@ export class GridStackDragDropPlugin {
3940
this.grid = grid;
4041
}
4142

42-
public resizable(el: GridItemHTMLElement, opts: DDOpts, key?: DDKey, value?): GridStackDragDropPlugin {
43+
public resizable(el: GridItemHTMLElement, opts: DDOpts, key?: DDKey, value?: DDValue): GridStackDragDropPlugin {
4344
return this;
4445
}
4546

46-
public draggable(el: GridItemHTMLElement, opts: DDOpts, key?: DDKey, value?): GridStackDragDropPlugin {
47+
public draggable(el: GridItemHTMLElement, opts: DDOpts, key?: DDKey, value?: DDValue): GridStackDragDropPlugin {
4748
return this;
4849
}
4950

50-
public droppable(el: GridItemHTMLElement, opts: DDOpts | DDDropOpt, key?: DDKey, value?): GridStackDragDropPlugin {
51+
public droppable(el: GridItemHTMLElement, opts: DDOpts | DDDropOpt, key?: DDKey, value?: DDValue): GridStackDragDropPlugin {
5152
return this;
5253
}
5354

src/gridstack-engine.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ export class GridStackEngine {
251251
public getDirtyNodes(verify?: boolean): GridStackNode[] {
252252
// compare original X,Y,W,H (or entire node?) instead as _dirty can be a temporary state
253253
if (verify) {
254-
let dirtNodes = [];
254+
let dirtNodes: GridStackNode[] = [];
255255
this.nodes.forEach(n => {
256256
if (n._dirty) {
257257
if (n.y === n._origY && n.x === n._origX && n.width === n._origW && n.height === n._origH) {
@@ -352,7 +352,7 @@ export class GridStackEngine {
352352
return true;
353353
}
354354

355-
let clonedNode;
355+
let clonedNode: GridStackNode;
356356
let clone = new GridStackEngine(
357357
this.column,
358358
null,

src/gridstack.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ export class GridStack {
460460
/** returns an array of grid HTML elements (no placeholder) - used internally to iterate through our children */
461461
public getGridItems(): GridItemHTMLElement[] {
462462
return Array.from(this.el.children)
463-
.filter(el => el.matches('.' + this.opts.itemClass) && !el.matches('.' + this.opts.placeholderClass)) as GridItemHTMLElement[];
463+
.filter((el: HTMLElement) => el.matches('.' + this.opts.itemClass) && !el.matches('.' + this.opts.placeholderClass)) as GridItemHTMLElement[];
464464
}
465465

466466
/**
@@ -781,9 +781,9 @@ export class GridStack {
781781
let noData = (name === 'enable' || name === 'disable');
782782
this._gsEventHandler = this._gsEventHandler || {};
783783
if (noData) {
784-
this._gsEventHandler[name] = (event) => callback(event);
784+
this._gsEventHandler[name] = (event: Event) => callback(event);
785785
} else {
786-
this._gsEventHandler[name] = (event) => callback(event, event.detail);
786+
this._gsEventHandler[name] = (event: CustomEvent) => callback(event, event.detail);
787787
}
788788
this.el.addEventListener(name, this._gsEventHandler[name]);
789789
} else if (name === 'dragstart' || name === 'dragstop' || name === 'resizestart' || name === 'resizestop' || name === 'dropped') {
@@ -1071,11 +1071,11 @@ export class GridStack {
10711071
let margin = this.opts.verticalMargin as number;
10721072

10731073
if (!this.opts.verticalMargin || this.opts.cellHeightUnit === this.opts.verticalMarginUnit) {
1074-
getHeight = (nbRows, nbMargins) => {
1074+
getHeight = (nbRows: number, nbMargins: number) => {
10751075
return (height * nbRows + margin * nbMargins) + this.opts.cellHeightUnit;
10761076
}
10771077
} else {
1078-
getHeight = (nbRows, nbMargins) => {
1078+
getHeight = (nbRows: number, nbMargins: number) => {
10791079
if (!nbRows || !nbMargins) {
10801080
return (height * nbRows + margin * nbMargins) + this.opts.cellHeightUnit;
10811081
}
@@ -1173,8 +1173,8 @@ export class GridStack {
11731173
/** @internal prepares the element for drag&drop **/
11741174
private _prepareElementsByNode(el: GridItemHTMLElement, node: GridStackNode): GridStack {
11751175
// variables used/cashed between the 3 start/move/end methods, in addition to node passed above
1176-
let cellWidth;
1177-
let cellFullHeight; // internal cellHeight + v-margin
1176+
let cellWidth: number;
1177+
let cellFullHeight: number; // internal cellHeight + v-margin
11781178

11791179
/** called when item starts moving/resizing */
11801180
let onStartMoving = (event, ui) => {
@@ -1220,7 +1220,7 @@ export class GridStack {
12201220
}
12211221

12221222
/** called when item is being dragged/resized */
1223-
let dragOrResize = (event, ui) => {
1223+
let dragOrResize = (event: Event, ui) => {
12241224
let x = Math.round(ui.position.left / cellWidth);
12251225
let y = Math.floor((ui.position.top + cellFullHeight / 2) / cellFullHeight);
12261226
let width;
@@ -1281,8 +1281,8 @@ export class GridStack {
12811281
}
12821282

12831283
/** called when the item stops moving/resizing */
1284-
let onEndMoving = (event) => {
1285-
let { target } = event;
1284+
let onEndMoving = (event: Event) => {
1285+
let target: GridItemHTMLElement = event.target as GridItemHTMLElement;
12861286
if (!target.gridstackNode) return;
12871287

12881288
// let forceNotify = false; what is the point of calling 'change' event with no data, when the 'removed' event is already called ?
@@ -1323,7 +1323,7 @@ export class GridStack {
13231323

13241324
// if we re-sized a nested grid item, let the children resize as well
13251325
if (event.type === 'resizestop') {
1326-
target.querySelectorAll('.grid-stack').forEach(el => el.gridstack._onResizeHandler());
1326+
target.querySelectorAll('.grid-stack').forEach((el: GridHTMLElement) => el.gridstack._onResizeHandler());
13271327
}
13281328
}
13291329

src/jq/jqueryui-gridstack-dragdrop-plugin.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
import { GridStack } from '../gridstack';
10-
import { GridStackDragDropPlugin, DDOpts, DDKey, DDDropOpt, DDCallback } from '../gridstack-dragdrop-plugin';
10+
import { GridStackDragDropPlugin, DDOpts, DDKey, DDDropOpt, DDCallback, DDValue } from '../gridstack-dragdrop-plugin';
1111
import { GridItemHTMLElement } from '../types';
1212

1313
// TODO: TEMPORARY until can remove jquery-ui drag&drop and this class and use HTML5 instead !
@@ -23,7 +23,7 @@ export class JQueryUIGridStackDragDropPlugin extends GridStackDragDropPlugin {
2323
super(grid);
2424
}
2525

26-
public resizable(el: GridItemHTMLElement, opts: DDOpts, key?: DDKey, value?): GridStackDragDropPlugin {
26+
public resizable(el: GridItemHTMLElement, opts: DDOpts, key?: DDKey, value?: DDValue): GridStackDragDropPlugin {
2727
let $el: JQuery = $(el);
2828
if (opts === 'disable' || opts === 'enable') {
2929
$el.resizable(opts);
@@ -44,7 +44,7 @@ export class JQueryUIGridStackDragDropPlugin extends GridStackDragDropPlugin {
4444
return this;
4545
}
4646

47-
public draggable(el: GridItemHTMLElement, opts: DDOpts, key?: DDKey, value?): GridStackDragDropPlugin {
47+
public draggable(el: GridItemHTMLElement, opts: DDOpts, key?: DDKey, value?: DDValue): GridStackDragDropPlugin {
4848
let $el: JQuery = $(el);
4949
if (opts === 'disable' || opts === 'enable') {
5050
$el.draggable(opts);
@@ -66,7 +66,7 @@ export class JQueryUIGridStackDragDropPlugin extends GridStackDragDropPlugin {
6666
return this;
6767
}
6868

69-
public droppable(el: GridItemHTMLElement, opts: DDOpts | DDDropOpt, key?: DDKey, value?): GridStackDragDropPlugin {
69+
public droppable(el: GridItemHTMLElement, opts: DDOpts | DDDropOpt, key?: DDKey, value?: DDValue): GridStackDragDropPlugin {
7070
let $el: JQuery = $(el);
7171
if (typeof opts.accept === 'function' && !opts._accept) {
7272
// convert jquery event to generic element

src/utils.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,8 @@ export class Utils {
173173
return Utils.closestByClass(el, name);
174174
}
175175

176-
static throttle(callback, delay) {
176+
/** @internal */
177+
static throttle(callback: () => void, delay: number) {
177178
let isWaiting = false;
178179

179180
return function (...args) {
@@ -204,7 +205,8 @@ export class Utils {
204205
}
205206
}
206207

207-
static getScrollParent(el: HTMLElement) {
208+
/** @internal */
209+
static getScrollParent(el: HTMLElement): HTMLElement {
208210
let returnEl;
209211
if (el === null) {
210212
returnEl = null;

0 commit comments

Comments
 (0)