Repository navigation
Expand file tree
/
Copy pathgridstack.d.ts
More file actions
648 lines (563 loc) · 22.5 KB
/
Copy pathgridstack.d.ts
File metadata and controls
648 lines (563 loc) · 22.5 KB
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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
// Type definitions for Gridstack 1.2.1
// Project: https://gridstackjs.com/
// Definitions by: Pascal Senn <https://github.com/PascalSenn>
// Ricky Blankenaufulland <https://github.com/ZoolWay>
// Sl1MBoy <https://github.com/Sl1MBoy>
// John Archer <https://github.com/JohnArcher>
// Alain Dumesny <https://github.com/adumesny>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped initially, but now part of gridstack.js
// TypeScript Version: 2.8
interface Window {
GridStack: GridStack;
}
/* Other items in https://github.com/gridstack/gridstack.js/blob/develop/doc/README.md
* Grid attributes
* Item attributes
* Events
*/
type GridStackElement = string | HTMLElement;
interface GridStackHTMLElement extends HTMLElement {
/** grid's parent DOM element points back to grid class */
gridstack: GridStack;
}
type GridStackEvent = 'added' | 'change' | 'disable' | 'dragstart' | 'dragstop' | 'dropped' |
'enable' | 'removed' | 'resize' | 'resizestart' | 'gsresizestop' | string;
interface GridStack {
/**
* initializing the HTML element, or selector string, into a grid will return the grid. Calling it again will
* simply return the existing instance (ignore any passed options). There is also a version that support
* multiple grids initialization.
* @param options grid options (optional)
* @param el element to convert to a grid (default to '.grid-stack' class selector)
*
* @example
* var grid = window.GridStack.init();
* // Note: the HTMLElement (of type GridStackHTMLElement) will itself store a `gridstack: GridStack` value that can be retrieve later
* var grid = document.querySelector('.grid-stack').gridstack;
*/
init(options?: GridstackOptions, el?: GridStackElement): GridStack;
/**
* Will initialize a list of elements (given a selector) and return an array of grids.
* @param options grid options (optional)
* @param selector element to convert to grids (default to '.grid-stack' class selector)
*
* @example
* var grids = window.GridStack.initAll();
* grids.forEach(...)
*/
initAll(options?: GridstackOptions, selector?: string): GridStack[];
/** the HTML element tied to this grid after it's been initialized */
el: GridStackHTMLElement;
/** engine used to implement non DOM grid functionality */
engine: GridStackEngine;
/**
* 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.
* See also `makeWidget()`.
*
* @example
* var grid = GridStack.init();
* grid.addWidget(el, {width: 3, autoPosition: true});
*
* @param el widget to add
* @param options widget position/size options (optional)
*/
addWidget(el: GridStackElement, options ? : GridstackWidget): HTMLElement;
/**
* Creates new widget and returns it.
* Legacy: Spelled out version of the widgets options, recommend use new version instead.
*
* @example
* var grid = GridStack.init();
* grid.addWidget(el, 0, 0, 3, 2, true);
*
* @param el widget to add
* @param x widget position x (optional)
* @param y widget position y (optional)
* @param width widget dimension width (optional)
* @param height widget dimension height (optional)
* @param autoPosition if true then x, y parameters will be ignored and widget will be places on the first available position (optional)
* @param minWidth minimum width allowed during resize/creation (optional)
* @param maxWidth maximum width allowed during resize/creation (optional)
* @param minHeight minimum height allowed during resize/creation (optional)
* @param maxHeight maximum height allowed during resize/creation (optional)
* @param id value for `data-gs-id` (optional)
*/
addWidget(el: GridStackElement, x ? : number, y ? : number, width ? : number, height ? : number, autoPosition ? : boolean,
minWidth ? : number, maxWidth ? : number, minHeight ? : number, maxHeight ? : number, id ? : number | string): HTMLElement;
/**
* 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 - see `GridstackOptions.cellHeight` for format.
* This method rebuilds an internal CSS style sheet.
* Note: You can expect performance issues if call this method too often.
*
* @param val the cell height
* @param noUpdate (Optional) if true, styles will not be updated
*
* @example
* grid.cellHeight(grid.cellWidth() * 1.2);
*/
cellHeight(val: number | string, noUpdate ? : boolean): void;
/**
* Gets current cell width.
*/
cellWidth(): number;
/**
* Finishes batch updates. Updates DOM nodes. You must call it after batchUpdate.
*/
commit(): void;
/**
* relayout grid items to reclaim any empty space
*/
compact(): void;
/**
* set the number of columns in the grid. Will update existing widgets to conform to new number of columns,
* as well as cache the original layout so you can revert back to previous positions without loss.
* Requires `gridstack-extra.css` or `gridstack-extra.min.css` for [1-11],
* else you will need to generate correct CSS (see https://github.com/gridstack/gridstack.js#change-grid-columns)
* @param column - Integer > 0 (default 12).
* @param doNotPropagate if true existing widgets will not be updated (optional)
*/
column(column: number, doNotPropagate ? : boolean): void;
/**
* get the number of columns in the grid (default 12)
*/
column(): number;
/**
* Destroys a grid instance.
* @param detachGrid if false nodes and grid will not be removed from the DOM (Optional. Default true).
*/
destroy(detachGrid ? : boolean): void;
/**
* Disables widgets moving/resizing. This is a shortcut for:
* @example
* grid.movable('.grid-stack-item', false);
* grid.resizable('.grid-stack-item', false);
*/
disable(): void;
/**
* Enables widgets moving/resizing. This is a shortcut for:
* @example
* grid.movable('.grid-stack-item', true);
* grid.resizable('.grid-stack-item', true);
*/
enable(): void;
/**
* Enables/disables widget moving.
*
* @param doEnable
* @param includeNewWidgets will force new widgets to be draggable as per
* doEnable`s value by changing the disableDrag grid option.
*/
enableMove(doEnable: boolean, includeNewWidgets: boolean): void;
/**
* Enables/disables widget resizing
* @param doEnable
* @param includeNewWidgets will force new widgets to be draggable as per
* doEnable`s value by changing the disableResize grid option.
*/
enableResize(doEnable: boolean, includeNewWidgets: boolean): void;
/**
* enable/disable floating widgets (default: `false`) See [example](http://gridstackjs.com/demo/float.html)
* @param mode
*/
float(mode: boolean): void;
/**
* get the current float mode
*/
float(): boolean;
/**
* Get the position of the cell under a pixel on screen.
* @param position the position of the pixel to resolve in
* absolute coordinates, as an object with top and left properties
* @param useOffset if true, value will be based on offset vs position (Optional. Default false).
* Useful when grid is within `position: relative` element
*
* Returns an object with properties `x` and `y` i.e. the column and row in the grid.
*/
getCellFromPixel(position: MousePosition, useOffset ? : boolean): CellPosition;
/** returns the current number of rows */
getRow(): number;
/**
* Checks if specified area is empty.
* @param x the position x.
* @param y the position y.
* @param width the width of to check
* @param height the height of to check
*/
isAreaEmpty(x: number, y: number, width: number, height: number): void;
/**
* Locks/unlocks widget.
* @param el widget to modify.
* @param val if true widget will be locked.
*/
locked(el: GridStackElement, val: boolean): void;
/**
* If you add elements to your grid by hand, you have to tell gridstack afterwards to make them widgets.
* If you want gridstack to add the elements for you, use addWidget instead.
* Makes the given element a widget and returns it.
* @param el widget to convert.
*
* @example
* var grid = GridStack.init();
* grid.el.appendChild('<div id="gsi-1" data-gs-x="0" data-gs-y="0" data-gs-width="3" data-gs-height="2"
* data-gs-auto-position="true"></div>')
* grid.makeWidget('gsi-1');
*/
makeWidget(el: GridStackElement): HTMLElement;
/**
* Set the maxWidth for a widget.
* @param el widget to modify.
* @param val A numeric value of the number of columns
*/
maxWidth(el: GridStackElement, val: number): void;
/**
* Set the minWidth for a widget.
* @param el widget to modify.
* @param val A numeric value of the number of columns
*/
minWidth(el: GridStackElement, val: number): void;
/**
* Set the maxHeight for a widget.
* @param el widget to modify.
* @param val A numeric value of the number of rows
*/
maxHeight(el: GridStackElement, val: number): void;
/**
* Set the minHeight for a widget.
* @param el widget to modify.
* @param val A numeric value of the number of rows
*/
minHeight(el: GridStackElement, val: number): void;
/**
* Enables/Disables moving.
* @param el widget to modify.
* @param val if true widget will be draggable.
*/
movable(el: GridStackElement, val: boolean): void;
/**
* Changes widget position
* @param el widget to modify
* @param x new position x. If value is null or undefined it will be ignored.
* @param y new position y. If value is null or undefined it will be ignored.
*/
move(el: GridStackElement, x: number, y: number): void;
/**
* unsubscribe from the 'on' event below
* @param name of the event (see possible values)
*/
off(name: GridStackEvent): void;
/**
* Event handler that extracts our CustomEvent data out automatically for receiving custom
* notifications (see doc for supported events)
* @param name of the event (see possible values) or list of names space separated
* @param callback function called with event and optional second/third param
* (see README documentation for each signature).
*
* @example
* grid.on('added', function(e, items) { log('added ', items)} );
* or
* grid.on('added removed change', function(e, items) { log(e.type, items)} );
*
* Note: in some cases it is the same as calling native handler and parsing the event.
* grid.el.addEventListener('added', function(event) { log('added ', event.detail)} );
*/
on(name: GridStackEvent, callback: (event: CustomEvent, arg2?: GridStackNode[] | Object, arg3?: Object) => void): void;
/**
* Removes widget from the grid.
* @param el widget to modify
* @param detachNode if false DOM node won't be removed from the tree (Default? true).
*/
removeWidget(el: GridStackElement, detachNode ? : boolean): void;
/**
* Removes all widgets from the grid.
* @param detachNode if false DOM nodes won't be removed from the tree (Default? true).
*/
removeAll(detachNode ? : boolean): void;
/**
* Changes widget size
* @param el widget to modify
* @param width new dimensions width. If value is null or undefined it will be ignored.
* @param height new dimensions height. If value is null or undefined it will be ignored.
*/
resize(el: GridStackElement, width: number, height: number): void;
/**
* Enables/Disables resizing.
* @param el widget to modify
* @param val if true widget will be resizable.
*/
resizable(el: GridStackElement, val: boolean): void;
/**
* Toggle the grid animation state. Toggles the `grid-stack-animate` class.
* @param doAnimate if true the grid will animate.
*/
setAnimation(doAnimate: boolean): void;
/**
* Toggle the grid static state. Also toggle the grid-stack-static class.
* @param staticValue if true the grid become static.
*/
setStatic(staticValue: boolean): void;
/**
* Updates widget position/size.
* @param el widget to modify
* @param x new position x. If value is null or undefined it will be ignored.
* @param y new position y. If value is null or undefined it will be ignored.
* @param width new dimensions width. If value is null or undefined it will be ignored.
* @param height new dimensions height. If value is null or undefined it will be ignored.
*/
update(el: GridStackElement, x: number, y: number, width: number, height: number): void;
/**
* returns current vertical margin value
*/
verticalMargin(): number;
/**
* Updates the vertical margin - see `GridstackOptions.verticalMargin` for format options.
*
* @param value new vertical margin value
* @param noUpdate (optional) if true, styles will not be updated
*/
verticalMargin(value: number | string, noUpdate ? : boolean): 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 x new position x. If value is null or undefined it will be ignored.
* @param y new position y. If value is null or undefined it will be ignored.
* @param width new dimensions width. If value is null or undefined it will be ignored.
* @param height new dimensions height. If value is null or undefined it will be ignored.
* @param autoPosition if true then x, y parameters will be ignored and widget
* will be places on the first available position
*
* @example
* if (grid.willItFit(newNode.x, newNode.y, newNode.width, newNode.height, true)) {
* grid.addWidget(newNode.el, newNode.x, newNode.y, newNode.width, newNode.height, true);
* } else {
* alert('Not enough free space to place the widget');
* }
*/
willItFit(x: number, y: number, width: number, height: number, autoPosition: boolean): boolean;
}
/**
* Defines the GridStack engine that does most no DOM grid manipulation.
* See GridStack methods and vars for descriptions.
*
* NOTE: values should not be modified - call the GridStack API instead
*/
interface GridStackEngine {
column: number;
float: boolean;
maxRow: number;
nodes: GridStackNode[];
getRow(): number;
}
/**
* Defines the coordinates of an object
*/
interface MousePosition {
top: number;
left: number;
}
/**
* Defines the position of a cell inside the grid
*/
interface CellPosition {
x: number;
y: number;
}
/**
* Gridstack Widget creation options
* @param x widget position x (default?: 0)
* @param y widget position y (default?: 0)
* @param width widget dimension width (default?: 1)
* @param height widget dimension height (default?: 1)
* @param autoPosition if true then x, y parameters will be ignored and widget will be places on the first available position (default?: false)
* @param minWidth minimum width allowed during resize/creation (default?: undefined = un-constrained)
* @param maxWidth maximum width allowed during resize/creation (default?: undefined = un-constrained)
* @param minHeight minimum height allowed during resize/creation (default?: undefined = un-constrained)
* @param maxHeight maximum height allowed during resize/creation (default?: undefined = un-constrained)
* @param noResize prevent resizing (default?: undefined = un-constrained)
* @param noMove prevents moving (default?: undefined = un-constrained)
* @param locked prevents moving and resizing (default?: undefined = un-constrained)
* @param resizeHandles widgets can have their own resize handles. For example 'e,w' will make the particular widget only resize east and west.
* @param id value for `data-gs-id` stored on the widget (default?: undefined)
*/
interface GridstackWidget {
x ? : number;
y ? : number;
width ? : number;
height ? : number;
autoPosition ? : boolean;
minWidth ? : number;
maxWidth ? : number;
minHeight ? : number;
maxHeight ? : number;
noResize ? : boolean;
noMove ? : boolean;
locked ? : boolean;
resizeHandles ?: string;
id ? : number | string;
}
/**
* internal descriptions describing the items in the grid
*/
interface GridStackNode extends GridstackWidget {
el: HTMLElement;
_grid: GridStack;
}
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: GridStackNode[], dir ? : number, width ? : number): void;
}
/**
* Gridstack Options
* Defines the options for a Gridstack
*/
interface GridstackOptions {
/**
* accept widgets dragged from other grids or from outside (default: `false`). Can be:
* `true` (uses `'.grid-stack-item'` class filter) or `false`,
* string for explicit class name,
* function returning a boolean. See [example](http://gridstack.github.io/gridstack.js/demo/two.html)
*/
acceptWidgets ? : boolean | string | ((i: number, element: Element) => boolean);
/**
* 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). Can be:
* an integer (px)
* a string (ex: '100px', '10em', '10rem', '10%')
* 0 or null, in which case the library will not generate styles for rows. Everything must be defined in CSS files.
* 'auto' - height will be calculated to match cell width (initial square grid).
*/
cellHeight ? : number | string;
/**
* (internal) unit for cellHeight (default? 'px') which is set when a string cellHeight with a unit is passed (ex: '10rem')
*/
cellHeightUnit ? : string;
/**
* number of columns (default?: 12). Note: IF you change this, CSS also have to change. See https://github.com/gridstack/gridstack.js#change-grid-columns
*/
column ? : number;
/** class that implement drag'n'drop functionality for gridstack. If false grid will be static.
* (default?: null - first available plugin will be used)
*/
ddPlugin ? : boolean | null | any;
/** disallows dragging of widgets (default?: false) */
disableDrag ? : boolean;
/** disables the onColumnMode when the window width is less than minWidth (default?: false) */
disableOneColumnMode ? : boolean;
/** disallows resizing of widgets (default?: false). */
disableResize ? : boolean;
/**
* allows to override UI draggable options. (default?: { handle?: '.grid-stack-item-content', scroll?: true, appendTo?: 'body', containment: null })
*/
draggable ? : {};
/**
* let user drag nested grid items out of a parent or not (default false)
*/
dragOut ? : boolean;
/**
* enable floating widgets (default?: false) See example (http://gridstack.github.io/gridstack.js/demo/float.html)
*/
float ? : boolean;
/**
* draggable handle selector (default?: '.grid-stack-item-content')
*/
handle ? : string;
/** draggable handle class (e.g. 'grid-stack-item-content'). If set 'handle' is ignored (default?: null) */
handleClass ? : string;
/**
* widget class (default?: 'grid-stack-item')
*/
itemClass ? : string;
/**
* maximum rows amount. Default? is 0 which means no maximum rows
*/
maxRow ? : number;
/**
* minimum rows amount. Default is `0`. You can also do this with `min-height` CSS attribute
* on the grid div in pixels, which will round to the closest row.
*/
minRow?: number;
/**
* minimal width. If window width is less, grid will be shown in one column mode (default?: 768)
*/
minWidth ? : number;
/**
* set to true if you want oneColumnMode to use the DOM order and ignore x,y from normal multi column
* layouts during sorting. This enables you to have custom 1 column layout that differ from the rest. (default?: false)
*/
oneColumnModeDomSort?: boolean;
/**
* class for placeholder (default?: 'grid-stack-placeholder')
*/
placeholderClass ? : string;
/** placeholder default content (default?: '') */
placeholderText ? : string;
/**
* allows to override UI resizable options. (default?: { autoHide?: true, handles?: 'se' })
*/
resizable ? : {};
/**
* if true widgets could be removed by dragging outside of the grid. It could also be a selector string,
* in this case widgets will be removed by dropping them there (default?: false)
* See example (http://gridstack.github.io/gridstack.js/demo/two.html)
*/
removable ? : boolean | string;
/**
* time in milliseconds before widget is being removed while dragging outside of the grid. (default?: 2000)
*/
removeTimeout ? : number;
/**
* fix grid number of rows. This is a shortcut of writing `minRow:N, maxRow:N`.
* (default `0` no constrain)
*/
row?: number;
/**
* if true turns grid to RTL. Possible values are true, false, 'auto' (default?: 'auto')
* See [example](http://gridstack.github.io/gridstack.js/demo/rtl.html)
*/
rtl ? : boolean | 'auto';
/**
* removes drag&drop&resize (default `false`).
* If `true` widgets are not movable/resizable by the user, but code can still move and oneColumnMode will still work.
* You don't even need jQueryUI draggable/resizable.
* A CSS class `grid-stack-static` is also added to the container.
*/
staticGrid ? : boolean;
/** if `true` will add style element to `<head>` otherwise will add it to element's parent node (default `false`). */
styleInHead?: boolean;
/**
* vertical gap size (default?: 20). Can be:
* an integer (px)
* a string (ex: '2em', '20px', '2rem')
*/
verticalMargin ? : number | string;
/**
* (internal) unit for verticalMargin (default? 'px') set when `verticalMargin` is set as string with unit (ex: 2rem')
*/
verticalMarginUnit ? : string;
}