forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gridstack.d.ts
241 lines (237 loc) · 8.37 KB
/
gridstack.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
// Type definitions for Gridstack
// Project: http://troolee.github.io/gridstack.js/
// Definitions by: Pascal Senn <https://github.com/PascalSenn/>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
interface JQuery {
gridstack (options: IGridstackOptions):GridStack
}
interface GridStack {
/**
* Creates new widget and returns it.
*
* Widget will be always placed even if result height is more than actual grid height. You need to use willItFit method before calling addWidget for additional check.
*
* @param {string} el widget to add
* @param {number} x widget position x
* @param {number} y widget position y
* @param {number} width widget dimension width
* @param {number} height widget dimension height
* @param {boolean} autoPosition if true then x, y parameters will be ignored and widget will be places on the first available position
*/
addWidget(el: string, x: number, y: number, width: number, height: number, autoPosition: boolean): JQuery
/**
* Initializes batch updates. You will see no changes until commit method is called.
*/
batchUpdate():void
/**
* Gets current cell height.
*/
cellHeight():number
/**
* Update current cell height. This method rebuilds an internal CSS style sheet. Note: You can expect performance issues if call this method too often.
* @param {number} val the cell height
*/
cellHeight(val:number):void
/**
* Gets current cell width.
*/
cellWidth():number
/**
* Finishes batch updates. Updates DOM nodes. You must call it after batchUpdate.
*/
commit():void
/**
* Destroys a grid instance.
*/
destroy(): void
/*
* Disables widgets moving/resizing.
*/
disable(): void
/*
* Enables widgets moving/resizing.
*/
enable(): void
/*
* Get the position of the cell under a pixel on screen.
* @param {MousePosition} position the position of the pixel to resolve in absolute coordinates, as an object with top and leftproperties
*/
getCellFromPixel(position: MousePosition): CellPosition,
/*
* Checks if specified area is empty.
* @param {number} x the position x.
* @param {number} y the position y.
* @param {number} width the width of to check
* @param {number} height the height of to check
*/
isAreaEmpty(x: number, y: number, width: number, height: number): void
/*
* Locks/unlocks widget.
* @param {HTMLElement} el widget to modify.
* @param {boolean} val if true widget will be locked.
*/
locked(el: HTMLElement, val: boolean): void
/*
* Set the minWidth for a widget.
* @param {HTMLElement} el widget to modify.
* @param {number} val A numeric value of the number of columns
*/
minWidth(el: HTMLElement, val: number): void
/*
* Set the minHeight for a widget.
* @param {HTMLElement} el widget to modify.
* @param {number} val A numeric value of the number of rows
*/
minHeight(el: HTMLElement, val: number): void
/*
* Enables/Disables moving.
* @param {HTMLElement} el widget to modify.
* @param {number} val if true widget will be draggable.
*/
movable(el: HTMLElement, val: boolean): void
/**
* Changes widget position
* @param {HTMLElement} el widget to modify
* @param {number} x new position x. If value is null or undefined it will be ignored.
* @param {number} y new position y. If value is null or undefined it will be ignored.
*
*/
move(el: HTMLElement, x: number, y: number): void
/**
* Removes widget from the grid.
* @param {HTMLElement} el widget to modify
* @param {boolean} detachNode if false DOM node won't be removed from the tree (Optional. Default true).
*/
removeWidget(el: HTMLElement, detachNode?: boolean): void
/**
* Removes all widgets from the grid.
*/
removeAll(): void
/**
* Changes widget size
* @param {HTMLElement} el widget to modify
* @param {number} width new dimensions width. If value is null or undefined it will be ignored.
* @param {number} height new dimensions height. If value is null or undefined it will be ignored.
*/
resize(el: HTMLElement, width: number, height: number): void
/**
* Enables/Disables resizing.
* @param {HTMLElement} el widget to modify
* @param {boolean} val if true widget will be resizable.
*/
resizable(el: HTMLElement, val: boolean): void
/**
* Toggle the grid static state. Also toggle the grid-stack-static class.
* @param {boolean} staticValue if true the grid become static.
*/
setStatic(staticValue: boolean): void
/**
* Updates widget position/size.
* @param {HTMLElement} el widget to modify
* @param {number} x new position x. If value is null or undefined it will be ignored.
* @param {number} y new position y. If value is null or undefined it will be ignored.
* @param {number} width new dimensions width. If value is null or undefined it will be ignored.
* @param {number} height new dimensions height. If value is null or undefined it will be ignored.
*/
update(el: HTMLElement, x: number, y: number, width: number, height: number): void
/**
* Returns true if the height of the grid will be less the vertical constraint. Always returns true if grid doesn't have height constraint.
* @param {number} x new position x. If value is null or undefined it will be ignored.
* @param {number} y new position y. If value is null or undefined it will be ignored.
* @param {number} width new dimensions width. If value is null or undefined it will be ignored.
* @param {number} height new dimensions height. If value is null or undefined it will be ignored.
* @param {boolean} autoPosition if true then x, y parameters will be ignored and widget will be places on the first available position
*/
willItFit(x: number, y: number, width: number, height: number, autoPosition:boolean):boolean
}
/**
* Defines the coordiantes of a object
*/
interface MousePosition {
top: number,
left:number,
}
/**
* Defines the position of a cell inside the grid
*/
interface CellPosition {
x: number,
y:number
}
declare namespace GridStackUI {
interface Utils {
/**
* Sorts array of nodes
*@param nodes array to sort
*@param dir 1 for asc, -1 for desc (optional)
*@param width width of the grid. If undefined the width will be calculated automatically (optional).
**/
sort(nodes: HTMLElement[], dir: number, width: number): void
}
}
/**
* Gridstack Options
* Defines the options for a Gridstack
*/
interface IGridstackOptions {
/**
* if true the resizing handles are shown even if the user is not hovering over the widget (default: false)
*/
alwaysShowResizeHandle: boolean;
/**
* turns animation on (default: true)
*/
animate: boolean;
/**
* if false gridstack will not initialize existing items (default: true)
*/
auto: boolean;
/**
* one cell height (default: 60)
*/
cellHeight: number;
/**
* allows to override jQuery UI draggable options. (default: { handle: '.grid-stack-item-content', scroll: true, appendTo: 'body' })
*/
draggable: {};
/**
* draggable handle selector (default: '.grid-stack-item-content')
*/
handle: string;
/**
* maximum rows amount.Default is 0 which means no maximum rows
*/
height: number;
/**
* enable floating widgets (default: false) See example
*/
float: boolean;
/**
* widget class (default: 'grid-stack-item')
*/
itemClass: string;
/**
* minimal width.If window width is less, grid will be shown in one - column mode (default: 768)
*/
minWidth: number;
/**
* class for placeholder (default: 'grid-stack-placeholder')
*/
placeholderClass: string;
/**
* allows to override jQuery UI resizable options. (default: { autoHide: true, handles: 'se' })
*/
resizable: {};
/**
* makes grid static (default false).If true widgets are not movable/ resizable.You don't even need jQueryUI draggable/resizable. A CSS class grid-stack-static is also added to the container.
*/
staticGrid: boolean;
/**
* vertical gap size (default: 20)
*/
verticalMargin: number;
/**
* amount of columns (default: 12)
*/
width: number;
}