gridstack 12.2.1 → 12.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +3 -3
  3. package/dist/angular/README.md +2 -0
  4. package/dist/angular/esm2020/lib/base-widget.mjs +63 -7
  5. package/dist/angular/esm2020/lib/gridstack-item.component.mjs +33 -4
  6. package/dist/angular/esm2020/lib/gridstack.component.mjs +97 -16
  7. package/dist/angular/esm2020/lib/gridstack.module.mjs +25 -3
  8. package/dist/angular/esm2020/lib/types.mjs +2 -2
  9. package/dist/angular/fesm2015/gridstack-angular.mjs +191 -25
  10. package/dist/angular/fesm2015/gridstack-angular.mjs.map +1 -1
  11. package/dist/angular/fesm2020/gridstack-angular.mjs +192 -26
  12. package/dist/angular/fesm2020/gridstack-angular.mjs.map +1 -1
  13. package/dist/angular/lib/base-widget.d.ts +42 -5
  14. package/dist/angular/lib/gridstack-item.component.d.ts +49 -7
  15. package/dist/angular/lib/gridstack.component.d.ts +137 -22
  16. package/dist/angular/lib/gridstack.module.d.ts +23 -0
  17. package/dist/angular/lib/types.d.ts +32 -5
  18. package/dist/angular/package.json +1 -1
  19. package/dist/angular/src/base-widget.ts +68 -9
  20. package/dist/angular/src/gridstack-item.component.ts +49 -7
  21. package/dist/angular/src/gridstack.component.ts +154 -23
  22. package/dist/angular/src/gridstack.module.ts +24 -2
  23. package/dist/angular/src/types.ts +54 -0
  24. package/dist/dd-base-impl.d.ts +52 -3
  25. package/dist/dd-base-impl.js +41 -3
  26. package/dist/dd-base-impl.js.map +1 -1
  27. package/dist/dd-draggable.d.ts +2 -2
  28. package/dist/dd-draggable.js +4 -2
  29. package/dist/dd-draggable.js.map +1 -1
  30. package/dist/dd-droppable.d.ts +2 -2
  31. package/dist/dd-droppable.js +2 -2
  32. package/dist/dd-droppable.js.map +1 -1
  33. package/dist/dd-element.d.ts +2 -2
  34. package/dist/dd-element.js +2 -2
  35. package/dist/dd-element.js.map +1 -1
  36. package/dist/dd-gridstack.d.ts +54 -6
  37. package/dist/dd-gridstack.js +32 -2
  38. package/dist/dd-gridstack.js.map +1 -1
  39. package/dist/dd-manager.d.ts +29 -8
  40. package/dist/dd-manager.js +7 -3
  41. package/dist/dd-manager.js.map +1 -1
  42. package/dist/dd-resizable-handle.d.ts +2 -2
  43. package/dist/dd-resizable-handle.js +2 -2
  44. package/dist/dd-resizable-handle.js.map +1 -1
  45. package/dist/dd-resizable.d.ts +2 -2
  46. package/dist/dd-resizable.js +2 -2
  47. package/dist/dd-resizable.js.map +1 -1
  48. package/dist/dd-touch.d.ts +2 -2
  49. package/dist/dd-touch.js +2 -2
  50. package/dist/dd-touch.js.map +1 -1
  51. package/dist/gridstack-all.js +1 -1
  52. package/dist/gridstack-all.js.LICENSE.txt +2 -2
  53. package/dist/gridstack-all.js.map +1 -1
  54. package/dist/gridstack-engine.d.ts +235 -26
  55. package/dist/gridstack-engine.js +276 -30
  56. package/dist/gridstack-engine.js.map +1 -1
  57. package/dist/gridstack.css +2 -2
  58. package/dist/gridstack.d.ts +424 -82
  59. package/dist/gridstack.js +416 -79
  60. package/dist/gridstack.js.map +1 -1
  61. package/dist/src/gridstack.scss +2 -2
  62. package/dist/types.d.ts +132 -31
  63. package/dist/types.js +6 -3
  64. package/dist/types.js.map +1 -1
  65. package/dist/utils.d.ts +208 -29
  66. package/dist/utils.js +275 -61
  67. package/dist/utils.js.map +1 -1
  68. package/doc/API.md +6192 -0
  69. package/package.json +14 -3
  70. package/doc/CHANGES.md +0 -955
  71. package/doc/README.md +0 -642
package/doc/README.md DELETED
@@ -1,642 +0,0 @@
1
- gridstack.js API
2
- ================
3
-
4
- <!-- START doctoc generated TOC please keep comment here to allow auto update -->
5
- <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
6
- **Table of Contents** *generated with [DocToc](http://doctoc.herokuapp.com/)*
7
-
8
- - [Grid Options](#grid-options)
9
- - [Responsive](#responsive)
10
- - [Breakpoint](#breakpoint)
11
- - [DDDragOpt](#dddragopt)
12
- - [Grid attributes](#grid-attributes)
13
- - [Item Options - GridStackWidget](#item-options---gridstackwidget)
14
- - [Item attributes](#item-attributes)
15
- - [Events](#events)
16
- - [added(event, items)](#addedevent-items)
17
- - [change(event, items)](#changeevent-items)
18
- - [disable(event)](#disableevent)
19
- - [dragstart(event, el)](#dragstartevent-el)
20
- - [drag(event, el)](#dragevent-el)
21
- - [dragstop(event, el)](#dragstopevent-el)
22
- - [dropped(event, previousWidget, newWidget)](#droppedevent-previouswidget-newwidget)
23
- - [enable(event)](#enableevent)
24
- - [removed(event, items)](#removedevent-items)
25
- - [resizestart(event, el)](#resizestartevent-el)
26
- - [resize(event, el)](#resizeevent-el)
27
- - [resizestop(event, el)](#resizestopevent-el)
28
- - [prepareDragDrop(el: GridItemHTMLElement, force = false) : GridStack](#preparedragdropel-griditemhtmlelement-force--false--gridstack)
29
- - [API Global (static)](#api-global-static)
30
- - [`init(options: GridStackOptions = {}, elOrString: GridStackElement = '.grid-stack'): GridStack`](#initoptions-gridstackoptions---elorstring-gridstackelement--grid-stack-gridstack)
31
- - [`initAll(options: GridStackOptions = {}, selector = '.grid-stack'): GridStack[]`](#initalloptions-gridstackoptions---selector--grid-stack-gridstack)
32
- - [`addGrid(parent: HTMLElement, opt: GridStackOptions = {}): GridStack `](#addgridparent-htmlelement-opt-gridstackoptions---gridstack-)
33
- - [`setupDragIn(dragIn?: string | HTMLElement[], dragInOptions?: DDDragOpt, widgets?: GridStackWidget[], root = HTMLElement | Document)`](#setupdragindragin-string--htmlelement-draginoptions-dddragopt-widgets-gridstackwidget-root--htmlelement--document)
34
- - [`GridStack.registerEngine(engineClass: typeof GridStackEngine)`](#gridstackregisterengineengineclass-typeof-gridstackengine)
35
- - [API](#api)
36
- - [`addWidget(w: GridStackWidget): GridItemHTMLElement`](#addwidgetw-gridstackwidget-griditemhtmlelement)
37
- - [`batchUpdate(flag = true)`](#batchupdateflag--true)
38
- - [`compact(layout: CompactOptions = 'compact', doSort = true)`](#compactlayout-compactoptions--compact-dosort--true)
39
- - [`cellHeight(val: number, update = true)`](#cellheightval-number-update--true)
40
- - [`cellWidth()`](#cellwidth)
41
- - [`column(column: number, layout: ColumnOptions = 'moveScale')`](#columncolumn-number-layout-columnoptions--movescale)
42
- - [`destroy([removeDOM])`](#destroyremovedom)
43
- - [`disable()`](#disable)
44
- - [`enable()`](#enable)
45
- - [`enableMove(doEnable)`](#enablemovedoenable)
46
- - [`enableResize(doEnable)`](#enableresizedoenable)
47
- - [`float(val?)`](#floatval)
48
- - [`getCellHeight()`](#getcellheight)
49
- - [`getCellFromPixel(position[, useOffset])`](#getcellfrompixelposition-useoffset)
50
- - [`getColumn(): number`](#getcolumn-number)
51
- - [`getGridItems(): GridItemHTMLElement[]`](#getgriditems-griditemhtmlelement)
52
- - [`getMargin()`](#getmargin)
53
- - [`isAreaEmpty(x, y, width, height)`](#isareaemptyx-y-width-height)
54
- - [`load(items: GridStackWidget[], addRemove: boolean | AddRemoveFcn = GridStack.addRemoveCB || true)`](#loaditems-gridstackwidget-addremove-boolean--addremovefcn--gridstackaddremovecb--true)
55
- - [`makeWidget(el)`](#makewidgetel)
56
- - [`makeSubGrid(el)`](#makesubgridel)
57
- - [`margin(value: numberOrString)`](#marginvalue-numberorstring)
58
- - [`movable(el, val)`](#movableel-val)
59
- - [`removeWidget(el, removeDOM = true, triggerEvent = true)`](#removewidgetel-removedom--true-triggerevent--true)
60
- - [`removeAll(removeDOM = true)`](#removeallremovedom--true)
61
- - [`resizable(el, val)`](#resizableel-val)
62
- - [`resizeToContent(el: GridItemHTMLElement, useAttrSize = false)`](#resizetocontentel-griditemhtmlelement-useattrsize--false)
63
- - [`rotate(els: GridStackElement, relative?: Position)`](#rotateels-gridstackelement-relative-position)
64
- - [`save(saveContent = true, saveGridOpt = false): GridStackWidget[] | GridStackOptions`](#savesavecontent--true-savegridopt--false-gridstackwidget--gridstackoptions)
65
- - [`setAnimation(doAnimate)`](#setanimationdoanimate)
66
- - [`setStatic(staticValue)`](#setstaticstaticvalue)
67
- - [`update(el: GridStackElement, opts: GridStackWidget)`](#updateel-gridstackelement-opts-gridstackwidget)
68
- - [`willItFit(x, y, width, height, autoPosition)`](#willitfitx-y-width-height-autoposition)
69
- - [Utils](#utils)
70
- - [`GridStack.Utils.sort(nodes[, dir])`](#gridstackutilssortnodes-dir)
71
-
72
- <!-- END doctoc generated TOC please keep comment here to allow auto update -->
73
-
74
- ## Grid Options
75
-
76
- - `acceptWidgets` - Accept widgets dragged from other grids or from outside (default: `false`). Can be:
77
- * `true` will accept HTML element having `'grid-stack-item'` as class attribute, else `false`
78
- * string for explicit class name to accept instead
79
- * `function (el: Element): boolean` function called before an item will be accepted when entering a grid. the function will be passed the item being dragged, and should return true | false. See [example](https://github.com/gridstack/gridstack.js/blob/master/demo/two.html#L62)
80
- - `alwaysShowResizeHandle` - possible values (default: `mobile`) - does not apply to non-resizable widgets
81
- * `false` the resizing handles are only shown while hovering over a widget
82
- * `true` the resizing handles are always shown
83
- * `'mobile'` if running on a mobile device, default to `true` (since there is no hovering per say), else `false`.
84
- See [mobile](http://gridstack.github.io/gridstack.js/demo/mobile.html)
85
-
86
-
87
- - `animate` - turns animation on to smooth transitions (default: `true`)
88
- - `auto` - if `false` gridstack will not initialize existing items (default: `true`)
89
- - `cellHeight`- one cell height (default?: 'auto'). Can be:
90
- * an integer (px)
91
- * a string (ex: '100px', '10em', '10rem', '10cm'). Note: % doesn't right - see [CellHeight](http://gridstackjs.com/demo/cell-height.html)
92
- * 0, in which case the library will not generate styles for rows. Everything must be defined in your own CSS files.
93
- * `auto` - height will be calculated for square cells (width / column) and updated live as you resize the window - also see `cellHeightThrottle`
94
- * `initial` - similar to 'auto' (start at square cells) but stay that size during window resizing.
95
- - `cellHeightThrottle`?: number - throttle time delay (in ms) used when cellHeight='auto' to improve performance vs usability (default?: 100).
96
- * A value of 0 will make it instant at a cost of re-creating the CSS file at ever window resize event!
97
- - `children`?: GridStackWidget[] - list of children item to create when calling load() or addGrid()
98
- - `column` - Integer > 0 (default 12) which can change on the fly with `column(N)` API, or `'auto'` for nested grids to size themselves to the parent grid container (to make sub-items are the same size). See [column](http://gridstackjs.com/demo/column.html) and [nested](http://gridstackjs.com/demo/nested.html)
99
- - `columnOpts`?:Responsive - describes the responsive nature of the column grid. see `Responsive` interface.
100
- - `class`?: string - additional class on top of '.grid-stack' (which is required for our CSS) to differentiate this instance
101
- - `disableDrag` - disallows dragging of widgets (default: `false`).
102
- - `disableResize` - disallows resizing of widgets (default: `false`).
103
- - `draggable` - allows to override draggable options - see `DDDragOpt`. (default: `{handle: '.grid-stack-item-content', appendTo: 'body', scroll: true}`)
104
- - `engineClass` - the type of engine to create (so you can subclass) default to GridStackEngine
105
- - `sizeToContent`: boolean - make gridItems size themselves to their content, calling `resizeToContent(el)` whenever the grid or item is resized.
106
- - `float` - enable floating widgets (default: `false`) See [example](http://gridstackjs.com/demo/float.html)
107
- - `handle` - draggable handle selector (default: `'.grid-stack-item-content'`)
108
- - `handleClass` - draggable handle class (e.g. `'grid-stack-item-content'`). If set `handle` is ignored (default: `null`)
109
- - `itemClass` - widget class (default: `'grid-stack-item'`)
110
- - `lazyLoad?`: boolean - true when widgets are only created when they scroll into view (visible). also overridable per widget in `GridStackWidget`
111
- - `margin` - gap size around grid item and content (default: `10`). Can be:
112
- * an integer (px)
113
- * a string (ex: '2em', '20px', '2rem')
114
- - `marginTop`: numberOrString - can set individual settings (defaults to `margin`)
115
- - `marginRight`: numberOrString
116
- - `marginBottom`: numberOrString
117
- - `marginLeft`: numberOrString
118
- - `maxRow` - maximum rows amount. Default is `0` which means no max.
119
- - `minRow` - minimum rows amount which is handy to prevent grid from collapsing when empty. 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.
120
- - `nonce` - If you are using a nonce-based Content Security Policy, pass your nonce here and
121
- GridStack will add it to the `<style>` elements it creates.
122
- - `placeholderClass` - class for placeholder (default: `'grid-stack-placeholder'`)
123
- - `placeholderText` - placeholder default content (default: `''`)
124
- - `resizable` - allows to override resizable options. (default: `{handles: 'se'}`). `handles` can be any combo of `n,ne,e,se,s,sw,w,nw` or `all`.
125
- - `removable` - 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://gridstackjs.com/demo/two.html)
126
- - `removeTimeout` - time in milliseconds before widget is being removed while dragging outside of the grid. (default: `2000`)
127
- - `row` - fix grid number of rows. This is a shortcut of writing `minRow:N, maxRow:N`. (default `0` no constrain)
128
- - `rtl` - if `true` turns grid to RTL. Possible values are `true`, `false`, `'auto'` (default: `'auto'`) See [example](https://gridstackjs.com/demo/right-to-left(rtl).html)
129
- - `staticGrid` - 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 can use the smaller gridstack-static.js lib. A CSS class `grid-stack-static` is also added to the container.
130
-
131
- ### Responsive
132
- v10.x supports a much richer responsive behavior, you can have breakpoints of width:column, or auto column sizing, where no code is longer needed.
133
- - `columnWidth`?: number - wanted width to maintain (+-50%) to dynamically pick a column count
134
- - `columnMax`?: number - maximum number of columns allowed (default: 12). Note: make sure to have correct CSS to support this.
135
- - `layout`?: ColumnOptions - global re-layout mode when changing columns
136
- - `breakpointForWindow`?: boolean - specify if breakpoints are for window size or grid size (default:false = grid)
137
- - `breakpoints`?: Breakpoint[] - explicit width:column breakpoints instead of automatic 'columnWidth'. Note: make sure to have correct CSS to support this.
138
-
139
- #### Breakpoint
140
- - `w`?: number - width
141
- - `c`: number - column
142
- - `layout`?: ColumnOptions - re-layout mode if different from global one
143
-
144
- ### DDDragOpt
145
- - `handle`?: string - class selector of items that can be dragged. default to '.grid-stack-item-content'
146
- - `appendTo`?: string - default to 'body' (TODO: is this even used anymore ?)
147
- - `pause`?: boolean | number - if set (true | msec), dragging placement (collision) will only happen after a pause by the user. Note: this is Global
148
- - `scroll`?: boolean - default to 'true', enable or disable the scroll when an element is dragged on bottom or top of the grid.
149
- - `cancel`?: string - prevents dragging from starting on specified elements, listed as comma separated selectors (eg: '.no-drag'). default built in is 'input,textarea,button,select,option'
150
- - `helper`?: 'clone' | ((el: HTMLElement) => HTMLElement) - helper function when dragging side panel items that need to be cloned before dropping (ex: 'clone' or your own method)
151
-
152
- ## Grid attributes
153
-
154
- most of the above options are also available as HTML attributes using the `gs-` name prefix with standard dash lower case naming convention (ex: `gs-column`, `gs-min-row`, `gs-static`, etc..).
155
-
156
- Extras:
157
- - `gs-current-row` - (internal) current rows amount. Set by the library only. Can be used by the CSS rules.
158
-
159
- ## Item Options - GridStackWidget
160
-
161
- options you can pass when calling `addWidget()`, `update()`, `load()` and many others
162
-
163
- - `autoPosition` - tells to ignore `x` and `y` attributes and to place element to the first available position. Having either one missing will also do that.
164
- - `x`, `y` - (number) element position in column/row. Note: if one is missing this will `autoPosition` the item
165
- - `w`, `h` - (number) element size in column/row (default 1x1)
166
- - `maxW`, `minW`, `maxH`, `minH` - element constraints in column/row (default none)
167
- - `locked` - means another widget wouldn't be able to move it during dragging or resizing.
168
- The widget can still be dragged or resized by the user.
169
- You need to add `noResize` and `noMove` attributes to completely lock the widget.
170
- - `noResize` - disable element resizing
171
- - `noMove` - disable element moving
172
- - `id`- (number | string) good for quick identification (for example in change event)
173
- - `content` - (string) html content to be added when calling `grid.load()/addWidget()` as content inside the item
174
- - `sizeToContent`?: boolean | number - make gridItem size itself to the content, calling `GridStack.resizeToContent(el)` whenever the grid or item is resized.
175
- Note: This also allow you to set a maximum h value (but user changeable during normal resizing) to prevent unlimited content from taking too much space (get scrollbar)
176
- - `subGrid`?: GridStackOptions - optional nested grid options and list of children
177
- - `subGridDynamic`?: boolean - enable/disable the creation of sub-grids on the fly by dragging items completely over others (nest) vs partially (push). Forces `DDDragOpt.pause=true` to accomplish that.
178
- - `lazyLoad?`: boolean - true when widgets are only created when they scroll into view (visible). also optin on entire grid.
179
-
180
- ## Item attributes
181
-
182
- all item options are also available as HTML attributes using the `gs-` name prefix with standard dash lower case naming convention (ex: `gs-x`, `gs-min-w`, etc..).
183
-
184
- ## Events
185
-
186
- Those are events generated by the grid when items are added/removed/changed or drag&drop interaction. In general they pass list of nodes that changed (id, x, y, width, height, etc...) or individual DOM element
187
- that is affected.
188
-
189
- You can call it on a single event name, or space separated list like:
190
- `grid.on('added removed change', ...)`
191
-
192
- The Typescript `GridStackEvent` list all possible values, and nothing else is supported by the `grid.on()` method, though it's possible to register directly for other events generated by the drag&drop plugging implementation detail (if jquery-ui based you can still use `$(".grid-stack").on(...)`).
193
-
194
- ### added(event, items)
195
-
196
- Called when widgets are being added to a grid
197
-
198
- ```js
199
- grid.on('added', function(event: Event, items: GridStackNode[]) {
200
- items.forEach(function(item) {...});
201
- });
202
- ```
203
-
204
- ### change(event, items)
205
-
206
- Occurs when widgets change their position/size due to constrain or direct changes
207
-
208
- ```js
209
- grid.on('change', function(event: Event, items: GridStackNode[]) {
210
- items.forEach(function(item) {...});
211
- });
212
- ```
213
-
214
- ### disable(event)
215
-
216
- ```js
217
- grid.on('disable', function(event: Event) {
218
- let grid: GridStack = event.target.gridstack;
219
- });
220
- ```
221
-
222
- ### dragstart(event, el)
223
-
224
- called when grid item is starting to be dragged
225
-
226
- ```js
227
- grid.on('dragstart', function(event: Event, el: GridItemHTMLElement) {
228
- });
229
- ```
230
-
231
- ### drag(event, el)
232
-
233
- called while grid item is being dragged, for each new row/column value (not every pixel)
234
-
235
- ```js
236
- grid.on('drag', function(event: Event, el: GridItemHTMLElement) {
237
- });
238
- ```
239
-
240
- ### dragstop(event, el)
241
- called after the user is done moving the item, with updated DOM attributes.
242
-
243
- ```js
244
- grid.on('dragstop', function(event: Event, el: GridItemHTMLElement) {
245
- let x = parseInt(el.getAttribute('gs-x')) || 0;
246
- // or all values...
247
- let node: GridStackNode = el.gridstackNode; // {x, y, width, height, id, ....}
248
- });
249
- ```
250
-
251
- ### dropped(event, previousWidget, newWidget)
252
-
253
- called when an item has been dropped and accepted over a grid. If the item came from another grid, the previous widget node info will also be sent (but dom item long gone).
254
-
255
- ```js
256
- grid.on('dropped', function(event: Event, previousWidget: GridStackNode, newWidget: GridStackNode) {
257
- console.log('Removed widget that was dragged out of grid:', previousWidget);
258
- console.log('Added widget in dropped grid:', newWidget);
259
- });
260
- ```
261
-
262
- ### enable(event)
263
-
264
- ```js
265
- grid.on('enable', function(event: Event) {
266
- let grid: GridStack = event.target.gridstack;
267
- });
268
- ```
269
-
270
- ### removed(event, items)
271
-
272
- Called when items are being removed from the grid
273
-
274
- ```js
275
- grid.on('removed', function(event: Event, items: GridStackNode[]) {
276
- items.forEach(function(item) {...});
277
- });
278
- ```
279
-
280
- ### resizestart(event, el)
281
-
282
- called before the user starts resizing an item
283
-
284
- ```js
285
- grid.on('resizestart', function(event: Event, el: GridItemHTMLElement) {
286
- });
287
- ```
288
-
289
- ### resize(event, el)
290
-
291
- called while grid item is being resized, for each new row/column value (not every pixel)
292
-
293
- ```js
294
- grid.on('resize', function(event: Event, el: GridItemHTMLElement) {
295
- });
296
- ```
297
-
298
- ### resizestop(event, el)
299
-
300
- called after the user is done resizing the item, with updated DOM attributes.
301
-
302
- ```js
303
- grid.on('resizestop', function(event: Event, el: GridItemHTMLElement) {
304
- let width = parseInt(el.getAttribute('gs-w')) || 0;
305
- // or all values...
306
- let node: GridStackNode = el.gridstackNode; // {x, y, width, height, id, ....}
307
- });
308
- ```
309
-
310
- ### prepareDragDrop(el: GridItemHTMLElement, force = false) : GridStack
311
- prepares the element for drag&drop - this is normally called by makeWiget() unless are are delay loading
312
- * @param el GridItemHTMLElement of the widget
313
- * @param [force=false]
314
-
315
-
316
- ## API Global (static)
317
-
318
- ### `init(options: GridStackOptions = {}, elOrString: GridStackElement = '.grid-stack'): GridStack`
319
-
320
- * initializing the HTML element, or selector string, into a grid will return the grid. Calling it again will
321
- simply return the existing instance (ignore any passed options). There is also an initAll() version that support multiple grids initialization at once. Or you can use addGrid() to create the entire grid from JSON.
322
- * @param options grid options (optional)
323
- * @param elOrString element or CSS selector (first one used) to convert to a grid (default to `'.grid-stack'` class selector)
324
- ```js
325
- let grid = GridStack.init();
326
- // Note: the HTMLElement (of type GridHTMLElement) will store a `gridstack: GridStack` value that can be retrieve later
327
- let grid = document.querySelector('.grid-stack').gridstack;
328
- ```
329
-
330
- ### `initAll(options: GridStackOptions = {}, selector = '.grid-stack'): GridStack[]`
331
-
332
- * Will initialize a list of elements (given a selector) and return an array of grids.
333
- * @param options grid options (optional)
334
- * @param selector elements selector to convert to grids (default to '.grid-stack' class selector)
335
-
336
- ```js
337
- let grids = GridStack.initAll();
338
- grids.forEach(...)
339
- ```
340
-
341
- ### `addGrid(parent: HTMLElement, opt: GridStackOptions = {}): GridStack `
342
-
343
- * call to create a grid with the given options, including loading any children from JSON structure. This will call `GridStack.init()`, then `grid.load()` on any passed children (recursively). Great alternative to calling `init()` if you want entire grid to come from JSON serialized data, including options.
344
- * @param parent HTML element parent to the grid
345
- * @param opt grids options used to initialize the grid, and list of children
346
- * see [nested.html](https://github.com/gridstack/gridstack.js/tree/master/demo/nested.html) demo
347
-
348
- ### `setupDragIn(dragIn?: string | HTMLElement[], dragInOptions?: DDDragOpt, widgets?: GridStackWidget[], root = HTMLElement | Document)`
349
-
350
- * call to setup dragging in from the outside (say toolbar), by specifying the class selection and options.
351
- Called during `GridStack.init()` as options, but can also be called directly (last param are cached) in case the toolbar is dynamically create and needs to change later.
352
- * @param `dragIn` string selector (ex: `'.sidebar-item'`) or list of dom elements
353
- * @param `dragInOptions` options - see `DDDragOpt`. default: `{appendTo: 'body', helper: 'clone'}`
354
- * @param `widgets` GridStackWidget def to assign to each element which defines what to create on drop
355
- Note: you can instead use DOM attr `data-gs-widget` for complete JSON string of that GridStackWidget.
356
- * @param `root` optional root which defaults to document (for shadow dom pass the parent HTMLDocument)
357
-
358
- ### `GridStack.registerEngine(engineClass: typeof GridStackEngine)`
359
-
360
- * call to specify global custom engine subclass - see instead `GridStackOptions.engineClass` if you only need to replace just one instance.
361
- ## API
362
-
363
- ### `addWidget(w: GridStackWidget): GridItemHTMLElement`
364
-
365
- Creates new widget and returns it.
366
-
367
- Parameters:
368
-
369
- - `w`: GridStackWidget - widget position/size options - see GridStackWidget
370
-
371
- Widget will be always placed even if result height is more than actual grid height. You need to use `willItFit` method
372
- before calling `addWidget` for additional check.
373
-
374
- ```js
375
- let grid = GridStack.init();
376
- grid.addWidget({w: 3, content: 'hello'});
377
- ```
378
-
379
- ### `batchUpdate(flag = true)`
380
-
381
- use before calling a bunch of `addWidget()` to prevent un-necessary relayouts in between (more efficient) and get a single event callback. You will see no changes until `batchUpdate(false)` is called.
382
-
383
- ### `compact(layout: CompactOptions = 'compact', doSort = true)`
384
-
385
- re-layout grid items to reclaim any empty space. Options are:
386
- - `'list'` keep the widget left->right order the same, even if that means leaving an empty slot if things don't fit
387
- - `'compact'` might re-order items to fill any empty space
388
-
389
- - `doSort` - `false` to let you do your own sorting ahead in case you need to control a different order. (default to sort)
390
-
391
-
392
- ### `cellHeight(val: number, update = true)`
393
-
394
- Update current cell height (see - `cellHeight` options format). This method rebuilds an internal CSS stylesheet (unless optional update=false). Note: You can expect performance issues if call this method too often.
395
-
396
- ```js
397
- grid.cellHeight(grid.cellWidth() * 1.2);
398
- ```
399
-
400
- ### `cellWidth()`
401
-
402
- Gets current cell width (grid width / # of columns).
403
-
404
- ### `column(column: number, layout: ColumnOptions = 'moveScale')`
405
-
406
- set the number of columns in the grid. Will update existing widgets to conform to new number of columns,
407
- as well as cache the original layout so you can revert back to previous positions without loss.
408
-
409
- - `column` - Integer > 0 (default 12)
410
- - `layout` - specify the type of re-layout that will happen (position, size, etc...). Values are: `'list' | 'compact' | 'moveScale' | 'move' | 'scale' | 'none' | ((column: number, oldColumn: number, nodes: GridStackNode[], oldNodes: GridStackNode[]) => void);`
411
-
412
- * `'list'` - treat items as sorted list, keeping items (un-sized unless too big for column count) sequentially reflowing them
413
- * `'compact'` - similar to list, but using compact() method which will possibly re-order items if an empty slots are available due to a larger item needing to be pushed to next row
414
- * `'moveScale'` - will scale and move items by the ratio new newColumnCount / oldColumnCount
415
- * `'move'` | `'scale'` - will only size or move items
416
- * `'none'` will leave items unchanged, unless they don't fit in column count
417
- * custom function that takes new/old column count, and array of new/old positions
418
- Note: new list may be partially already filled if we have a partial cache of the layout at that size (items were added later). If complete cache is present this won't get called at all.
419
-
420
- ### `destroy([removeDOM])`
421
-
422
- Destroys a grid instance.
423
-
424
- Parameters:
425
-
426
- - `removeDOM` - if `false` nodes and grid will not be removed from the DOM (Optional. Default `true`).
427
-
428
- ### `disable()`
429
-
430
- Disables widgets moving/resizing. This is a shortcut for:
431
-
432
- ```js
433
- grid.enableMove(false);
434
- grid.enableResize(false);
435
- ```
436
-
437
- ### `enable()`
438
-
439
- Enables widgets moving/resizing. This is a shortcut for:
440
-
441
- ```js
442
- grid.enableMove(true);
443
- grid.enableResize(true);
444
- ```
445
-
446
- ### `enableMove(doEnable)`
447
-
448
- Enables/disables widget moving (default: true), and setting the `disableDrag` grid option. This is a shortcut for:
449
-
450
- ```js
451
- grid.opts.disableDrag = !doEnable;
452
- grid.movable('.grid-stack-item', doEnable);
453
- ```
454
-
455
- ### `enableResize(doEnable)`
456
-
457
- Enables/disables widget sizing (default: true), and setting the `disableResize` grid option. This is a shortcut for:
458
-
459
- ```js
460
- grid.opts.disableResize = !doEnable;
461
- grid.resizable('.grid-stack-item', doEnable);
462
- ```
463
-
464
- ### `float(val?)`
465
-
466
- set/get floating widgets (default: `false`)
467
-
468
- - `val` - boolean to set true/false, else get the current value
469
-
470
- ### `getCellHeight()`
471
-
472
- Gets current cell height.
473
-
474
-
475
- ### `getCellFromPixel(position[, useOffset])`
476
-
477
- Get the position of the cell under a pixel on screen.
478
-
479
- Parameters :
480
-
481
- - `position` - the position of the pixel to resolve in absolute coordinates, as an object with `top` and `left` properties
482
- - `useOffset` - if `true`, value will be based on offset vs position (Optional. Default `false`). Useful when grid is within `position: relative` element.
483
-
484
- Returns an object with properties `x` and `y` i.e. the column and row in the grid.
485
-
486
- ### `getColumn(): number`
487
-
488
- returns the number of columns in the grid.
489
-
490
- ### `getGridItems(): GridItemHTMLElement[]`
491
-
492
- Return list of GridItem HTML elements (excluding temporary placeholder) in DOM order, wether they are node items yet or not (looks by class)
493
-
494
- ### `getMargin()`
495
-
496
- returns current margin value (undefined if all 4 sides don't match).
497
-
498
- ### `isAreaEmpty(x, y, width, height)`
499
-
500
- Checks if specified area is empty.
501
-
502
- ### `load(items: GridStackWidget[], addRemove: boolean | AddRemoveFcn = GridStack.addRemoveCB || true)`
503
-
504
- - load the widgets from a list (see `save()`). This will call `update()` on each (matching by id) or add/remove widgets that are not there.
505
- - Optional `addRemove` boolean (default true) or callback method can be passed to control if and how missing widgets can be added/removed, giving the user control of insertion.
506
-
507
- - used to restore a grid layout for a saved layout list (see `save()`).
508
- - `addRemove` boolean (default true) or callback method can be passed to control if and how missing widgets can be added/removed, giving the user control of insertion.
509
- - see [example](http://gridstackjs.com/demo/serialization.html)
510
-
511
- ### `makeWidget(el)`
512
-
513
- If you add elements to your gridstack container 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.
514
- Makes the given element a widget and returns it.
515
-
516
- Parameters:
517
-
518
- - `el` - element to convert to a widget
519
-
520
- ```js
521
- let grid = GridStack.init();
522
- // ...create some html content, possibly looking like:
523
- // <div id="item-1" gs-x="0" gs-y="0" gs-w="3" gs-h="2"></div>'
524
- grid.makeWidget('#item-1');
525
- ```
526
- ### `makeSubGrid(el)`
527
- Used to add a subgrid into an existing grid.
528
- ```js
529
- const grid = Gridstack.init()
530
- // ...create some html content, possibly looking like:
531
- // <div id="gsi-1" gs-x="0" gs-y="0" gs-w="3" gs-h="2">
532
- // <div class="grid-stack" id="nested-grid">
533
- // <div id="gsi-2" gs-w="3" gs-h="2"></div>
534
- // </div>
535
- //</div>
536
- grid.makeSubGrid(grid.el.getElementById('nested-grid'))
537
- ```
538
- Make sure that the subgrid is inside of a grid item. It is important to remember that subgrids are themselves grid items capable of containing other grid items.
539
- ### `margin(value: numberOrString)`
540
-
541
- gap between grid item and content (default?: 10). This will set all 4 sides and support the CSS formats below
542
- - an `integer` (px)
543
- - a string with possible units (ex: `'5'`, `'2em'`, `'20px'`, `'2rem'`)
544
- - string with space separated values (ex: `'5px 10px 0 20px'` for all 4 sides, or `'5em 10em'` for top/bottom and left/right pairs like CSS).
545
- - Note: all sides must have same units (last one wins, default px)
546
-
547
- ### `movable(el, val)`
548
-
549
- Enables/Disables dragging by the user of specific grid element. If you want all items, and have it affect future items, use enableMove() instead. No-op for static grids.
550
- IF you are looking to prevent an item from moving (due to being pushed around by another during collision) use locked property instead.
551
-
552
- - `el` - widget to modify
553
- - `val` - if `true` widget will be draggable.
554
-
555
- ### `removeWidget(el, removeDOM = true, triggerEvent = true)`
556
-
557
- Removes widget from the grid.
558
-
559
- Parameters:
560
-
561
- - `el` - widget to remove.
562
- - `removeDOM` - if `false` node won't be removed from the DOM (Optional. Default `true`).
563
- - `triggerEvent` if `false` (quiet mode) element will not be added to removed list and no 'removed' callbacks will be called (Default `true`).
564
-
565
- ### `removeAll(removeDOM = true)`
566
-
567
- Removes all widgets from the grid.
568
-
569
- Parameters:
570
-
571
- - `removeDOM` - if `false` nodes won't be removed from the DOM (Optional. Default `true`).
572
-
573
- ### `resizable(el, val)`
574
-
575
- Enables/Disables user resizing of specific grid element. If you want all items, and have it affect future items, use enableResize() instead. No-op for static grids.
576
-
577
- - `el` - widget to modify
578
- - `val` - if `true` widget will be resizable.
579
-
580
- ### `resizeToContent(el: GridItemHTMLElement, useAttrSize = false)`
581
-
582
- Updates widget height to match the content height to avoid v-scrollbar or dead space.
583
- Note: this assumes only 1 child under `resizeToContentParent='.grid-stack-item-content'` (sized to gridItem minus padding) that is at the entire content size wanted.
584
- - `useAttrSize` set to `true` if GridStackNode.h should be used instead of actual container height when we don't need to wait for animation to finish to get actual DOM heights
585
-
586
- ### `rotate(els: GridStackElement, relative?: Position)`
587
- rotate (by swapping w & h) the passed in node - called when user press 'r' during dragging
588
-
589
- - `els` - widget or selector of objects to modify
590
- - `relative` - optional pixel coord relative to upper/left corner to rotate around (will keep that cell under cursor)
591
-
592
- ### `save(saveContent = true, saveGridOpt = false): GridStackWidget[] | GridStackOptions`
593
-
594
- saves the current layout returning a list of widgets for serialization which might include any nested grids.
595
- - `saveContent` if true (default) the latest html inside `.grid-stack-content` will be saved to `GridStackWidget.content` field, else it will be removed.
596
- - `saveGridOpt` if true (default `false`), save the grid options itself, so you can call the new `GridStack.addGrid()` to recreate everything from scratch. GridStackOptions.children would then contain the widget list instead.
597
- - returns list of widgets or full grid option, including .children list of widgets
598
- - see [serialization](http://gridstackjs.com/demo/serialization.html) and [nested](http://gridstackjs.com/demo/nested.html)
599
-
600
- ### `setAnimation(doAnimate)`
601
-
602
- Toggle the grid animation state. Toggles the `grid-stack-animate` class.
603
-
604
- - `doAnimate` - if `true` the grid will animate.
605
-
606
- ### `setStatic(staticValue)`
607
-
608
- Toggle the grid static state. Also toggle the `grid-stack-static` class.
609
-
610
- - `staticValue` - if `true` the grid becomes static.
611
-
612
- ### `update(el: GridStackElement, opts: GridStackWidget)`
613
-
614
- Parameters:
615
-
616
- - `el` - widget to move (element or class string)
617
- - `opts` - updates all the possible item attributes passed in the structure (x, y, h, w, etc..). Only those set will be updated.
618
-
619
- Updates widget position/size and other info. Note: if you need to call this on all nodes, use load() instead which will update what changed and more.
620
-
621
- ### `willItFit(x, y, width, height, autoPosition)`
622
-
623
- Returns `true` if the `height` of the grid will be less the vertical constraint. Always returns `true` if grid doesn't
624
- have `height` constraint.
625
-
626
- ```js
627
- if (grid.willItFit(newNode.x, newNode.y, newNode.w, newNode.h, newNode.autoPosition)) {
628
- grid.addWidget(newNode.el, newNode);
629
- }
630
- else {
631
- alert('Not enough free space to place the widget');
632
- }
633
- ```
634
-
635
- ## Utils
636
-
637
- ### `GridStack.Utils.sort(nodes[, dir])`
638
-
639
- Sorts array of nodes
640
-
641
- - `nodes` - array to sort
642
- - `dir` - `1` for ascending, `-1` for descending (optional)