gridstack 5.0.0 → 6.0.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 (168) hide show
  1. package/README.md +78 -53
  2. package/dist/{h5/dd-base-impl.d.ts → dd-base-impl.d.ts} +2 -2
  3. package/dist/{h5/dd-base-impl.js → dd-base-impl.js} +2 -4
  4. package/dist/dd-base-impl.js.map +1 -0
  5. package/dist/{es5/h5/dd-draggable.d.ts → dd-draggable.d.ts} +7 -8
  6. package/dist/dd-draggable.js +313 -0
  7. package/dist/dd-draggable.js.map +1 -0
  8. package/dist/{es5/h5/dd-droppable.d.ts → dd-droppable.d.ts} +4 -3
  9. package/dist/dd-droppable.js +149 -0
  10. package/dist/dd-droppable.js.map +1 -0
  11. package/dist/{es5/h5/dd-element.d.ts → dd-element.d.ts} +2 -2
  12. package/dist/{h5/dd-element.js → dd-element.js} +1 -1
  13. package/dist/dd-element.js.map +1 -0
  14. package/dist/dd-gridstack.d.ts +36 -0
  15. package/dist/{gridstack-dd.js → dd-gridstack.js} +154 -52
  16. package/dist/dd-gridstack.js.map +1 -0
  17. package/dist/dd-manager.d.ts +17 -0
  18. package/dist/{h5/dd-manager.js → dd-manager.js} +4 -1
  19. package/dist/dd-manager.js.map +1 -0
  20. package/dist/{es5/h5/dd-resizable-handle.d.ts → dd-resizable-handle.d.ts} +2 -2
  21. package/dist/{h5/dd-resizable-handle.js → dd-resizable-handle.js} +33 -9
  22. package/dist/dd-resizable-handle.js.map +1 -0
  23. package/dist/{h5/dd-resizable.d.ts → dd-resizable.d.ts} +3 -3
  24. package/dist/{h5/dd-resizable.js → dd-resizable.js} +29 -28
  25. package/dist/dd-resizable.js.map +1 -0
  26. package/dist/dd-touch.d.ts +33 -0
  27. package/dist/dd-touch.js +179 -0
  28. package/dist/dd-touch.js.map +1 -0
  29. package/dist/es5/{h5/dd-base-impl.d.ts → dd-base-impl.d.ts} +2 -2
  30. package/dist/es5/{h5/dd-base-impl.js → dd-base-impl.js} +2 -4
  31. package/dist/es5/dd-base-impl.js.map +1 -0
  32. package/dist/{h5 → es5}/dd-draggable.d.ts +7 -8
  33. package/dist/es5/dd-draggable.js +335 -0
  34. package/dist/es5/dd-draggable.js.map +1 -0
  35. package/dist/{h5 → es5}/dd-droppable.d.ts +4 -3
  36. package/dist/es5/dd-droppable.js +180 -0
  37. package/dist/es5/dd-droppable.js.map +1 -0
  38. package/dist/{h5 → es5}/dd-element.d.ts +2 -2
  39. package/dist/es5/{h5/dd-element.js → dd-element.js} +1 -1
  40. package/dist/es5/dd-element.js.map +1 -0
  41. package/dist/es5/dd-gridstack.d.ts +36 -0
  42. package/dist/es5/{gridstack-dd.js → dd-gridstack.js} +164 -71
  43. package/dist/es5/dd-gridstack.js.map +1 -0
  44. package/dist/es5/dd-manager.d.ts +17 -0
  45. package/dist/es5/{h5/dd-manager.js → dd-manager.js} +4 -1
  46. package/dist/es5/dd-manager.js.map +1 -0
  47. package/dist/{h5 → es5}/dd-resizable-handle.d.ts +2 -2
  48. package/dist/es5/{h5/dd-resizable-handle.js → dd-resizable-handle.js} +33 -9
  49. package/dist/es5/dd-resizable-handle.js.map +1 -0
  50. package/dist/es5/{h5/dd-resizable.d.ts → dd-resizable.d.ts} +3 -3
  51. package/dist/es5/{h5/dd-resizable.js → dd-resizable.js} +29 -28
  52. package/dist/es5/dd-resizable.js.map +1 -0
  53. package/dist/es5/dd-touch.d.ts +33 -0
  54. package/dist/es5/dd-touch.js +182 -0
  55. package/dist/es5/dd-touch.js.map +1 -0
  56. package/dist/es5/gridstack-all.js +3 -0
  57. package/dist/{gridstack-static.js.LICENSE.txt → es5/gridstack-all.js.LICENSE.txt} +2 -2
  58. package/dist/es5/gridstack-all.js.map +1 -0
  59. package/dist/es5/gridstack-engine.d.ts +12 -9
  60. package/dist/es5/gridstack-engine.js +45 -55
  61. package/dist/es5/gridstack-engine.js.map +1 -1
  62. package/dist/es5/gridstack-poly.js +1 -1
  63. package/dist/es5/gridstack.d.ts +17 -12
  64. package/dist/es5/gridstack.js +70 -43
  65. package/dist/es5/gridstack.js.map +1 -1
  66. package/dist/es5/types.d.ts +19 -20
  67. package/dist/es5/types.js +1 -1
  68. package/dist/es5/types.js.map +1 -1
  69. package/dist/es5/utils.d.ts +12 -2
  70. package/dist/es5/utils.js +79 -18
  71. package/dist/es5/utils.js.map +1 -1
  72. package/dist/gridstack-all.js +3 -0
  73. package/dist/{es5/gridstack-h5.js.LICENSE.txt → gridstack-all.js.LICENSE.txt} +2 -2
  74. package/dist/gridstack-all.js.map +1 -0
  75. package/dist/gridstack-engine.d.ts +12 -9
  76. package/dist/gridstack-engine.js +44 -54
  77. package/dist/gridstack-engine.js.map +1 -1
  78. package/dist/gridstack.css +21 -9
  79. package/dist/gridstack.d.ts +17 -12
  80. package/dist/gridstack.js +68 -43
  81. package/dist/gridstack.js.map +1 -1
  82. package/dist/gridstack.min.css +1 -1
  83. package/dist/src/gridstack.scss +19 -12
  84. package/dist/types.d.ts +19 -20
  85. package/dist/types.js +1 -1
  86. package/dist/types.js.map +1 -1
  87. package/dist/utils.d.ts +12 -2
  88. package/dist/utils.js +75 -17
  89. package/dist/utils.js.map +1 -1
  90. package/doc/CHANGES.md +21 -2
  91. package/doc/README.md +29 -24
  92. package/package.json +5 -5
  93. package/dist/es5/gridstack-dd.d.ts +0 -35
  94. package/dist/es5/gridstack-dd.js.map +0 -1
  95. package/dist/es5/gridstack-ddi.d.ts +0 -17
  96. package/dist/es5/gridstack-ddi.js +0 -31
  97. package/dist/es5/gridstack-ddi.js.map +0 -1
  98. package/dist/es5/gridstack-h5.d.ts +0 -10
  99. package/dist/es5/gridstack-h5.js +0 -3
  100. package/dist/es5/gridstack-h5.js.map +0 -1
  101. package/dist/es5/gridstack-jq.d.ts +0 -10
  102. package/dist/es5/gridstack-jq.js +0 -3
  103. package/dist/es5/gridstack-jq.js.LICENSE.txt +0 -99
  104. package/dist/es5/gridstack-jq.js.map +0 -1
  105. package/dist/es5/gridstack-static.d.ts +0 -9
  106. package/dist/es5/gridstack-static.js +0 -3
  107. package/dist/es5/gridstack-static.js.LICENSE.txt +0 -7
  108. package/dist/es5/gridstack-static.js.map +0 -1
  109. package/dist/es5/h5/dd-base-impl.js.map +0 -1
  110. package/dist/es5/h5/dd-draggable.js +0 -329
  111. package/dist/es5/h5/dd-draggable.js.map +0 -1
  112. package/dist/es5/h5/dd-droppable.js +0 -199
  113. package/dist/es5/h5/dd-droppable.js.map +0 -1
  114. package/dist/es5/h5/dd-element.js.map +0 -1
  115. package/dist/es5/h5/dd-manager.d.ts +0 -8
  116. package/dist/es5/h5/dd-manager.js.map +0 -1
  117. package/dist/es5/h5/dd-resizable-handle.js.map +0 -1
  118. package/dist/es5/h5/dd-resizable.js.map +0 -1
  119. package/dist/es5/h5/dd-utils.d.ts +0 -19
  120. package/dist/es5/h5/dd-utils.js +0 -111
  121. package/dist/es5/h5/dd-utils.js.map +0 -1
  122. package/dist/es5/h5/gridstack-dd-native.d.ts +0 -26
  123. package/dist/es5/h5/gridstack-dd-native.js +0 -175
  124. package/dist/es5/h5/gridstack-dd-native.js.map +0 -1
  125. package/dist/es5/jq/gridstack-dd-jqueryui.d.ts +0 -22
  126. package/dist/es5/jq/gridstack-dd-jqueryui.js +0 -162
  127. package/dist/es5/jq/gridstack-dd-jqueryui.js.map +0 -1
  128. package/dist/gridstack-dd.d.ts +0 -35
  129. package/dist/gridstack-dd.js.map +0 -1
  130. package/dist/gridstack-ddi.d.ts +0 -17
  131. package/dist/gridstack-ddi.js +0 -28
  132. package/dist/gridstack-ddi.js.map +0 -1
  133. package/dist/gridstack-h5.d.ts +0 -10
  134. package/dist/gridstack-h5.js +0 -3
  135. package/dist/gridstack-h5.js.LICENSE.txt +0 -7
  136. package/dist/gridstack-h5.js.map +0 -1
  137. package/dist/gridstack-jq.d.ts +0 -10
  138. package/dist/gridstack-jq.js +0 -3
  139. package/dist/gridstack-jq.js.LICENSE.txt +0 -99
  140. package/dist/gridstack-jq.js.map +0 -1
  141. package/dist/gridstack-static.d.ts +0 -9
  142. package/dist/gridstack-static.js +0 -3
  143. package/dist/gridstack-static.js.map +0 -1
  144. package/dist/h5/dd-base-impl.js.map +0 -1
  145. package/dist/h5/dd-draggable.js +0 -305
  146. package/dist/h5/dd-draggable.js.map +0 -1
  147. package/dist/h5/dd-droppable.js +0 -168
  148. package/dist/h5/dd-droppable.js.map +0 -1
  149. package/dist/h5/dd-element.js.map +0 -1
  150. package/dist/h5/dd-manager.d.ts +0 -8
  151. package/dist/h5/dd-manager.js.map +0 -1
  152. package/dist/h5/dd-resizable-handle.js.map +0 -1
  153. package/dist/h5/dd-resizable.js.map +0 -1
  154. package/dist/h5/dd-utils.d.ts +0 -19
  155. package/dist/h5/dd-utils.js +0 -94
  156. package/dist/h5/dd-utils.js.map +0 -1
  157. package/dist/h5/gridstack-dd-native.d.ts +0 -26
  158. package/dist/h5/gridstack-dd-native.js +0 -140
  159. package/dist/h5/gridstack-dd-native.js.map +0 -1
  160. package/dist/jq/gridstack-dd-jqueryui.d.ts +0 -22
  161. package/dist/jq/gridstack-dd-jqueryui.js +0 -133
  162. package/dist/jq/gridstack-dd-jqueryui.js.map +0 -1
  163. package/dist/jq/jquery-ui.js +0 -2
  164. package/dist/jq/jquery-ui.js.map +0 -1
  165. package/dist/jq/jquery.js +0 -2
  166. package/dist/jq/jquery.js.map +0 -1
  167. package/dist/jq/jquery.ui.touch-punch.js +0 -2
  168. package/dist/jq/jquery.ui.touch-punch.js.map +0 -1
package/README.md CHANGED
@@ -1,8 +1,6 @@
1
1
  # gridstack.js
2
2
 
3
3
  [![NPM version](https://img.shields.io/npm/v/gridstack.svg)](https://www.npmjs.com/package/gridstack)
4
- [![Dependency Status](https://david-dm.org/gridstack/gridstack.js.svg)](https://david-dm.org/gridstack/gridstack.js)
5
- [![devDependency Status](https://david-dm.org/gridstack/gridstack.js/dev-status.svg)](https://david-dm.org/gridstack/gridstack.js#info=devDependencies)
6
4
  [![Coverage Status](https://coveralls.io/repos/github/gridstack/gridstack.js/badge.svg?branch=develop)](https://coveralls.io/github/gridstack/gridstack.js?branch=develop)
7
5
  [![downloads](https://img.shields.io/npm/dm/gridstack.svg)](https://www.npmjs.com/package/gridstack)
8
6
 
@@ -17,22 +15,21 @@ If you find this lib useful, please donate [PayPal](https://www.paypal.me/alaind
17
15
  [![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.me/alaind831)
18
16
  [![Donate](https://img.shields.io/badge/Donate-Venmo-g.svg)](https://www.venmo.com/adumesny)
19
17
 
20
- Join us on Slack: https://gridstackjs.troolee.com
21
-
22
- [![Slack Status](https://gridstackjs.troolee.com/badge.svg)](https://gridstackjs.troolee.com)
18
+ Join us on Slack: https://gridstackjs.slack.com
23
19
 
20
+ [![Slack Status](https://gridstackjs.troolee.com/badge.svg)](https://gridstackjs.slack.com)
24
21
  <!-- START doctoc generated TOC please keep comment here to allow auto update -->
25
22
  <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
26
23
  **Table of Contents** *generated with [DocToc](http://doctoc.herokuapp.com/)*
27
24
 
28
- - [Demo and examples](#demo-and-examples)
25
+ - [Demo and API Documentation](#demo-and-api-documentation)
29
26
  - [Usage](#usage)
30
27
  - [Install](#install)
31
28
  - [Include](#include)
32
29
  - [Basic usage](#basic-usage)
33
30
  - [Requirements](#requirements)
34
- - [API Documentation](#api-documentation)
35
31
  - [Extend Library](#extend-library)
32
+ - [Extend Engine](#extend-engine)
36
33
  - [Change grid columns](#change-grid-columns)
37
34
  - [Custom columns CSS](#custom-columns-css)
38
35
  - [Override resizable/draggable options](#override-resizabledraggable-options)
@@ -45,6 +42,7 @@ Join us on Slack: https://gridstackjs.troolee.com
45
42
  - [Migrating to v3](#migrating-to-v3)
46
43
  - [Migrating to v4](#migrating-to-v4)
47
44
  - [Migrating to v5](#migrating-to-v5)
45
+ - [Migrating to v6](#migrating-to-v6)
48
46
  - [jQuery Application](#jquery-application)
49
47
  - [Changes](#changes)
50
48
  - [The Team](#the-team)
@@ -52,10 +50,9 @@ Join us on Slack: https://gridstackjs.troolee.com
52
50
  <!-- END doctoc generated TOC please keep comment here to allow auto update -->
53
51
 
54
52
 
55
- # Demo and examples
56
-
57
- Please visit http://gridstackjs.com and [these demos](http://gridstackjs.com/demo/)
53
+ # Demo and API Documentation
58
54
 
55
+ Please visit http://gridstackjs.com and [these demos](http://gridstackjs.com/demo/), and complete [API documentation](https://github.com/gridstack/gridstack.js/tree/master/doc)
59
56
 
60
57
  # Usage
61
58
 
@@ -75,44 +72,21 @@ ES6 or Typescript
75
72
  ```js
76
73
  import 'gridstack/dist/gridstack.min.css';
77
74
  import { GridStack } from 'gridstack';
78
- // THEN to get HTML5 drag&drop
79
- import 'gridstack/dist/h5/gridstack-dd-native';
80
- // OR to get legacy jquery-ui drag&drop (support Mobile touch devices, h5 does not yet)
81
- import 'gridstack/dist/jq/gridstack-dd-jqueryui';
82
- // OR nothing to get static grids (API driven, no user drag&drop)
83
75
  ```
84
76
 
85
- **Note**: `jquery` & `jquery-ui` are imported by name, so you will have to specify their location in your webpack (or equivalent) config file,
86
- which means you can possibly bring your own version
87
- ```js
88
- alias: {
89
- 'jquery': 'gridstack/dist/jq/jquery.js',
90
- 'jquery-ui': 'gridstack/dist/jq/jquery-ui.js',
91
- 'jquery.ui': 'gridstack/dist/jq/jquery-ui.js',
92
- 'jquery.ui.touch-punch': 'gridstack/dist/jq/jquery.ui.touch-punch.js',
93
- },
94
- ```
95
-
96
- Alternatively (single combined file) in html
77
+ Alternatively (single combined file, notice the -all.js) in html
97
78
 
98
79
  ```html
99
80
  <link href="node_modules/gridstack/dist/gridstack.min.css" rel="stylesheet"/>
100
- <!-- HTML5 drag&drop (70k) -->
101
- <script src="node_modules/gridstack/dist/gridstack-h5.js"></script>
102
- <!-- OR jquery-ui drag&drop (195k) -->
103
- <script src="node_modules/gridstack/dist/gridstack-jq.js"></script>
104
- <!-- OR static grid (40k) -->
105
- <script src="node_modules/gridstack/dist/gridstack-static.js"></script>
81
+ <script src="node_modules/gridstack/dist/gridstack-all.js"></script>
106
82
  ```
107
83
 
108
- **Note**: the API is the same, regardless of the plugin (or lack thereof) so you can switch at any time. The Jquery version will export $ that it bundles and currently the only one to support mobile/touch devices through `jquery.ui.touch-punch` (h5 version is planned). Read more at [migrating to v3](#migrating-to-v3)
109
-
110
- **Note2**: IE support was dropped in v2, but restored in v4.4 by an external contributor (I have no interest in testing+supporting obsolete browser so this might break in the future).
84
+ **Note**: IE support was dropped in v2, but restored in v4.4 by an external contributor (I have no interest in testing+supporting obsolete browser so this likely will break again in the future).
111
85
  You can use the es5 files and polyfill (larger) for older browser instead. For example:
112
86
  ```html
113
87
  <link href="node_modules/gridstack/dist/gridstack.min.css" rel="stylesheet"/>
114
88
  <script src="node_modules/gridstack/dist/es5/gridstack-poly.js"></script>
115
- <script src="node_modules/gridstack/dist/es5/gridstack-jq.js"></script>
89
+ <script src="node_modules/gridstack/dist/es5/gridstack-all.js"></script>
116
90
  ```
117
91
 
118
92
 
@@ -159,16 +133,13 @@ grid.load(serializedData);
159
133
  GridStack.init();
160
134
  ```
161
135
 
136
+ ...or see list of all [API and options](https://github.com/gridstack/gridstack.js/tree/master/doc) available.
137
+
162
138
  see [jsfiddle sample](https://jsfiddle.net/adumesny/jqhkry7g) as running example too.
163
139
 
164
140
  ## Requirements
165
141
 
166
- GridStack no longer requires external dependencies as of v1.0.0 (lodash was removed in v0.5.0 and jquery API in v1.0.0). v3.0.0 is a complete HTML5 re-write which removes all jquery dependency (still available for legacy apps). All you need to include now is `gridstack-h5.js` and `gridstack.min.css` (layouts are done using CSS column based %).
167
-
168
- ## API Documentation
169
-
170
- Documentation can be found [here](https://github.com/gridstack/gridstack.js/tree/master/doc).
171
-
142
+ GridStack no longer requires external dependencies as of v1.0.0 (lodash was removed in v0.5.0 and jquery API in v1.0.0). v3 is a complete HTML5 re-write removing need for jquery (still available for legacy apps). v6 is native mouse and touch event for mobile support, and no longer have jquery-ui version. All you need to include now is `gridstack-all.js` and `gridstack.min.css` (layouts are done using CSS column based %).
172
143
 
173
144
  ## Extend Library
174
145
 
@@ -186,6 +157,27 @@ let grid = GridStack.init();
186
157
  grid.printCount();
187
158
  ```
188
159
 
160
+ ## Extend Engine
161
+
162
+ You can now (5.1+) easily create your own layout engine to further customize you usage. Here is a typescript example
163
+
164
+ ```ts
165
+ import { GridStack, GridStackEngine, GridStackNod, GridStackMoveOpts } from 'gridstack';
166
+
167
+ class CustomEngine extends GridStackEngine {
168
+
169
+ /** refined this to move the node to the given new location */
170
+ public moveNode(node: GridStackNode, o: GridStackMoveOpts): boolean {
171
+ // keep the same original X and Width and let base do it all...
172
+ o.x = node.x;
173
+ o.w = node.w;
174
+ return super.moveNode(node, o);
175
+ }
176
+ }
177
+
178
+ GridStack.registerEngine(CustomEngine); // globally set our custom class
179
+ ```
180
+
189
181
  ## Change grid columns
190
182
 
191
183
  GridStack makes it very easy if you need [1-12] columns out of the box (default is 12), but you always need **2 things** if you need to customize this:
@@ -239,7 +231,7 @@ and so on.
239
231
  Better yet, here is a SASS code snippet which can make life much easier (Thanks to @ascendantofrain, [#81](https://github.com/gridstack/gridstack.js/issues/81) and @StefanM98, [#868](https://github.com/gridstack/gridstack.js/issues/868)) and you can use sites like [sassmeister.com](https://www.sassmeister.com/) to generate the CSS for you instead:
240
232
 
241
233
  ```sass
242
- @use "sass;math";
234
+ @use "sass:math";
243
235
  .grid-stack > .grid-stack-item {
244
236
 
245
237
  $gridstack-columns: 12;
@@ -281,21 +273,19 @@ GridStack.init({
281
273
 
282
274
  ## Touch devices support
283
275
 
284
- gridstack v3.2 jq version compiles touch support (html5 version does not yet support `touchmove` events. This will be added in a future release), so it works out of the box, no need for anything.
285
- You **used** to need [jQuery UI Touch Punch](https://github.com/RWAP/jquery-ui-touch-punch) to make jQuery UI Draggable/Resizable
286
- work on touch-based devices (now distributed as `dist/jq/jquery.ui.touch-punch.js` for reference).
287
-
276
+ gridstack v6+ now support mobile out of the box, with the addition of native touch event (along with mouse event) for drag&drop and resize.
277
+ Older versions (3.2+) required the jq version with added touch punch, but doesn't work well with nested grids.
288
278
 
289
- This option will be useful:
279
+ This option is now the default:
290
280
 
291
281
  ```js
292
282
  let options = {
293
- alwaysShowResizeHandle: /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)
283
+ alwaysShowResizeHandle: 'mobile' // which defaults to /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)
294
284
  };
295
285
  GridStack.init(options);
296
286
  ```
297
287
 
298
- See [example](http://gridstack.github.io/gridstack.js/demo/mobile.html). If you're still experiencing issues on touch devices please check [#444](https://github.com/gridstack/gridstack.js/issues/444)
288
+ See [example](http://gridstack.github.io/gridstack.js/demo/mobile.html).
299
289
 
300
290
  # gridstack.js for specific frameworks
301
291
 
@@ -387,7 +377,7 @@ v2 is a Typescript rewrite of 1.x, removing all jquery events, using classes and
387
377
 
388
378
  2. event signatures are generic and not jquery-ui dependent anymore. `gsresizestop` has been removed as `resizestop|dragstop` are now called **after** the DOM attributes have been updated.
389
379
 
390
- 3. `oneColumnMode` would trigger when `window.width` < 768px by default. We now check for grid width instead (more correct and supports nesting). You might need to adjust grid `minWidth` or `disableOneColumnMode`.
380
+ 3. `oneColumnMode` would trigger when `window.width` < 768px by default. We now check for grid width instead (more correct and supports nesting). You might need to adjust grid `oneColumnSize` or `disableOneColumnMode`.
391
381
 
392
382
  **Note:** 2.x no longer support legacy IE11 and older due to using more compact ES6 output and typecsript native code. You will need to stay at 1.x
393
383
 
@@ -443,9 +433,44 @@ make sure to read v4 migration first!
443
433
  v5 does not have any breaking changes from v4, but a focus on nested grids in h5 mode:
444
434
  You can now drag in/out of parent into nested child, with new API parameters values. See the release notes.
445
435
 
436
+ ## Migrating to v6
437
+
438
+ the API did not really change from v5, but a complete re-write of Drag&Drop to use native mouseevent (instead of HTML draggable=true which is buggy on Mac Safari, and doesn't work on mobile devices) and touchevent (mobile), and we no longer have jquery ui option (wasn't working well for nested grids, didn't want to maintain legacy lib).
439
+
440
+ The main difference is you only need to include gridstack.js and get D&D (desktop and mobile) out of the box for the same size as h5 version.
441
+
446
442
  # jQuery Application
447
443
 
448
- We now have a native HTML5 drag'n'drop through the plugin system (default), but the jquery-ui version can be used instead. It will bundle `jquery` (3.5.1) + `jquery-ui` (1.12.1 minimal drag|drop|resize) + `jquery-ui-touch-punch` (1.0.8 for mobile support) in `gridstack-jq.js`.
444
+ This is **old and no longer apply to v6+**. You'll need to use v5.1.1 and before
445
+
446
+ ```js
447
+ import 'gridstack/dist/gridstack.min.css';
448
+ import { GridStack } from 'gridstack';
449
+ import 'gridstack/dist/jq/gridstack-dd-jqueryui';
450
+ ```
451
+ **Note**: `jquery` & `jquery-ui` are imported by name, so you will have to specify their location in your webpack (or equivalent) config file,
452
+ which means you can possibly bring your own version
453
+ ```js
454
+ alias: {
455
+ 'jquery': 'gridstack/dist/jq/jquery.js',
456
+ 'jquery-ui': 'gridstack/dist/jq/jquery-ui.js',
457
+ 'jquery.ui': 'gridstack/dist/jq/jquery-ui.js',
458
+ 'jquery.ui.touch-punch': 'gridstack/dist/jq/jquery.ui.touch-punch.js',
459
+ },
460
+ ```
461
+ Alternatively (single combined file) in html
462
+
463
+ ```html
464
+ <link href="node_modules/gridstack/dist/gridstack.min.css" rel="stylesheet"/>
465
+ <!-- HTML5 drag&drop (70k) -->
466
+ <script src="node_modules/gridstack/dist/gridstack-h5.js"></script>
467
+ <!-- OR jquery-ui drag&drop (195k) -->
468
+ <script src="node_modules/gridstack/dist/gridstack-jq.js"></script>
469
+ <!-- OR static grid (40k) -->
470
+ <script src="node_modules/gridstack/dist/gridstack-static.js"></script>
471
+ ```
472
+
473
+ We have a native HTML5 drag'n'drop through the plugin system (default), but the jquery-ui version can be used instead. It will bundle `jquery` (3.5.1) + `jquery-ui` (1.13.1 minimal drag|drop|resize) + `jquery-ui-touch-punch` (1.0.8 for mobile support) in `gridstack-jq.js`.
449
474
 
450
475
  **NOTE: in v4, v3**: we ES6 module import jquery & jquery-ui by name, so you need to specify location of those .js files, which means you might be able to bring your own version as well. See the include instructions.
451
476
 
@@ -1,6 +1,6 @@
1
1
  /**
2
- * dd-base-impl.ts 5.0
3
- * Copyright (c) 2021 Alain Dumesny - see GridStack root license
2
+ * dd-base-impl.ts 6.0.0
3
+ * Copyright (c) 2021-2022 Alain Dumesny - see GridStack root license
4
4
  */
5
5
  export declare type EventCallback = (event: Event) => boolean | void;
6
6
  export declare abstract class DDBaseImplement {
@@ -1,14 +1,12 @@
1
1
  "use strict";
2
2
  /**
3
- * dd-base-impl.ts 5.0
4
- * Copyright (c) 2021 Alain Dumesny - see GridStack root license
3
+ * dd-base-impl.ts 6.0.0
4
+ * Copyright (c) 2021-2022 Alain Dumesny - see GridStack root license
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.DDBaseImplement = void 0;
8
8
  class DDBaseImplement {
9
9
  constructor() {
10
- /** @internal */
11
- this._disabled = false;
12
10
  /** @internal */
13
11
  this._eventRegister = {};
14
12
  }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dd-base-impl.js","sourceRoot":"","sources":["../src/dd-base-impl.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,MAAsB,eAAe;IAArC;QAME,gBAAgB;QACN,mBAAc,GAEpB,EAAE,CAAC;IA0BT,CAAC;IAlCC,mHAAmH;IACnH,IAAW,QAAQ,KAAgB,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;IASpD,EAAE,CAAC,KAAa,EAAE,QAAuB;QAC9C,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,GAAG,QAAQ,CAAC;IACxC,CAAC;IAEM,GAAG,CAAC,KAAa;QACtB,OAAO,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC;IAEM,MAAM;QACX,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC;IACzB,CAAC;IAEM,OAAO;QACZ,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;IACxB,CAAC;IAEM,OAAO;QACZ,OAAO,IAAI,CAAC,cAAc,CAAC;IAC7B,CAAC;IAEM,YAAY,CAAC,SAAiB,EAAE,KAAY;QACjD,IAAI,CAAC,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,cAAc,IAAI,IAAI,CAAC,cAAc,CAAC,SAAS,CAAC;YACzE,OAAO,IAAI,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC,CAAC;IACjD,CAAC;CACF;AAnCD,0CAmCC","sourcesContent":["/**\n * dd-base-impl.ts 6.0.0\n * Copyright (c) 2021-2022 Alain Dumesny - see GridStack root license\n */\n\nexport type EventCallback = (event: Event) => boolean|void;\nexport abstract class DDBaseImplement {\n /** returns the enable state, but you have to call enable()/disable() to change (as other things need to happen) */\n public get disabled(): boolean { return this._disabled; }\n\n /** @internal */\n protected _disabled: boolean; // initial state to differentiate from false\n /** @internal */\n protected _eventRegister: {\n [eventName: string]: EventCallback;\n } = {};\n\n public on(event: string, callback: EventCallback): void {\n this._eventRegister[event] = callback;\n }\n\n public off(event: string): void {\n delete this._eventRegister[event];\n }\n\n public enable(): void {\n this._disabled = false;\n }\n\n public disable(): void {\n this._disabled = true;\n }\n\n public destroy(): void {\n delete this._eventRegister;\n }\n\n public triggerEvent(eventName: string, event: Event): boolean|void {\n if (!this.disabled && this._eventRegister && this._eventRegister[eventName])\n return this._eventRegister[eventName](event);\n }\n}\n\nexport interface HTMLElementExtendOpt<T> {\n el: HTMLElement;\n option: T;\n updateOption(T): DDBaseImplement;\n}\n"]}
@@ -1,29 +1,28 @@
1
1
  /**
2
- * dd-draggable.ts 5.0
3
- * Copyright (c) 2021 Alain Dumesny - see GridStack root license
2
+ * dd-draggable.ts 6.0.0
3
+ * Copyright (c) 2021-2022 Alain Dumesny - see GridStack root license
4
4
  */
5
5
  import { DDBaseImplement, HTMLElementExtendOpt } from './dd-base-impl';
6
- import { DDUIData } from '../types';
6
+ import { DDUIData } from './types';
7
7
  export interface DDDraggableOpt {
8
8
  appendTo?: string | HTMLElement;
9
- containment?: string | HTMLElement;
10
9
  handle?: string;
11
- revert?: string | boolean | unknown;
12
- scroll?: boolean;
13
10
  helper?: string | HTMLElement | ((event: Event) => HTMLElement);
14
11
  start?: (event: Event, ui: DDUIData) => void;
15
12
  stop?: (event: Event) => void;
16
13
  drag?: (event: Event, ui: DDUIData) => void;
17
14
  }
15
+ declare type DDDragEvent = 'drag' | 'dragstart' | 'dragstop';
18
16
  export declare class DDDraggable extends DDBaseImplement implements HTMLElementExtendOpt<DDDraggableOpt> {
19
17
  el: HTMLElement;
20
18
  option: DDDraggableOpt;
21
19
  helper: HTMLElement;
22
20
  constructor(el: HTMLElement, option?: DDDraggableOpt);
23
- on(event: 'drag' | 'dragstart' | 'dragstop', callback: (event: DragEvent) => void): void;
24
- off(event: 'drag' | 'dragstart' | 'dragstop'): void;
21
+ on(event: DDDragEvent, callback: (event: DragEvent) => void): void;
22
+ off(event: DDDragEvent): void;
25
23
  enable(): void;
26
24
  disable(forDestroy?: boolean): void;
27
25
  destroy(): void;
28
26
  updateOption(opts: DDDraggableOpt): DDDraggable;
29
27
  }
28
+ export {};
@@ -0,0 +1,313 @@
1
+ "use strict";
2
+ /**
3
+ * dd-draggable.ts 6.0.0
4
+ * Copyright (c) 2021-2022 Alain Dumesny - see GridStack root license
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.DDDraggable = void 0;
8
+ const dd_manager_1 = require("./dd-manager");
9
+ const utils_1 = require("./utils");
10
+ const dd_base_impl_1 = require("./dd-base-impl");
11
+ const dd_touch_1 = require("./dd-touch");
12
+ // let count = 0; // TEST
13
+ class DDDraggable extends dd_base_impl_1.DDBaseImplement {
14
+ constructor(el, option = {}) {
15
+ super();
16
+ this.el = el;
17
+ this.option = option;
18
+ // get the element that is actually supposed to be dragged by
19
+ let className = option.handle.substring(1);
20
+ this.dragEl = el.classList.contains(className) ? el : el.querySelector(option.handle) || el;
21
+ // create var event binding so we can easily remove and still look like TS methods (unlike anonymous functions)
22
+ this._mouseDown = this._mouseDown.bind(this);
23
+ this._mouseMove = this._mouseMove.bind(this);
24
+ this._mouseUp = this._mouseUp.bind(this);
25
+ this.enable();
26
+ }
27
+ on(event, callback) {
28
+ super.on(event, callback);
29
+ }
30
+ off(event) {
31
+ super.off(event);
32
+ }
33
+ enable() {
34
+ if (this.disabled === false)
35
+ return;
36
+ super.enable();
37
+ this.dragEl.addEventListener('mousedown', this._mouseDown);
38
+ if (dd_touch_1.isTouch) {
39
+ this.dragEl.addEventListener('touchstart', dd_touch_1.touchstart);
40
+ this.dragEl.addEventListener('pointerdown', dd_touch_1.pointerdown);
41
+ // this.dragEl.style.touchAction = 'none'; // not needed unlike pointerdown doc comment
42
+ }
43
+ this.el.classList.remove('ui-draggable-disabled');
44
+ this.el.classList.add('ui-draggable');
45
+ }
46
+ disable(forDestroy = false) {
47
+ if (this.disabled === true)
48
+ return;
49
+ super.disable();
50
+ this.dragEl.removeEventListener('mousedown', this._mouseDown);
51
+ if (dd_touch_1.isTouch) {
52
+ this.dragEl.removeEventListener('touchstart', dd_touch_1.touchstart);
53
+ this.dragEl.removeEventListener('pointerdown', dd_touch_1.pointerdown);
54
+ }
55
+ this.el.classList.remove('ui-draggable');
56
+ if (!forDestroy)
57
+ this.el.classList.add('ui-draggable-disabled');
58
+ }
59
+ destroy() {
60
+ if (this.dragging)
61
+ this._mouseUp(this.mouseDownEvent);
62
+ this.disable(true);
63
+ delete this.el;
64
+ delete this.helper;
65
+ delete this.option;
66
+ super.destroy();
67
+ }
68
+ updateOption(opts) {
69
+ Object.keys(opts).forEach(key => this.option[key] = opts[key]);
70
+ return this;
71
+ }
72
+ /** @internal call when mouse goes down before a dragstart happens */
73
+ _mouseDown(e) {
74
+ // don't let more than one widget handle mouseStart
75
+ if (dd_manager_1.DDManager.mouseHandled)
76
+ return;
77
+ if (e.button !== 0)
78
+ return true; // only left click
79
+ // make sure we are clicking on a drag handle or child of it...
80
+ // Note: we don't need to check that's handle is an immediate child, as mouseHandled will prevent parents from also handling it (lowest wins)
81
+ let className = this.option.handle.substring(1);
82
+ let el = e.target;
83
+ while (el && !el.classList.contains(className)) {
84
+ el = el.parentElement;
85
+ }
86
+ if (!el)
87
+ return;
88
+ this.mouseDownEvent = e;
89
+ delete this.dragging;
90
+ delete dd_manager_1.DDManager.dragElement;
91
+ delete dd_manager_1.DDManager.dropElement;
92
+ // document handler so we can continue receiving moves as the item is 'fixed' position, and capture=true so WE get a first crack
93
+ document.addEventListener('mousemove', this._mouseMove, true); // true=capture, not bubble
94
+ document.addEventListener('mouseup', this._mouseUp, true);
95
+ if (dd_touch_1.isTouch) {
96
+ this.dragEl.addEventListener('touchmove', dd_touch_1.touchmove);
97
+ this.dragEl.addEventListener('touchend', dd_touch_1.touchend);
98
+ }
99
+ e.preventDefault();
100
+ dd_manager_1.DDManager.mouseHandled = true;
101
+ return true;
102
+ }
103
+ /** @internal called when the main page (after successful mousedown) receives a move event to drag the item around the screen */
104
+ _mouseMove(e) {
105
+ var _a;
106
+ // console.log(`${count++} move ${e.x},${e.y}`)
107
+ let s = this.mouseDownEvent;
108
+ if (this.dragging) {
109
+ this._dragFollow(e);
110
+ const ev = utils_1.Utils.initEvent(e, { target: this.el, type: 'drag' });
111
+ if (this.option.drag) {
112
+ this.option.drag(ev, this.ui());
113
+ }
114
+ this.triggerEvent('drag', ev);
115
+ }
116
+ else if (Math.abs(e.x - s.x) + Math.abs(e.y - s.y) > 3) {
117
+ /**
118
+ * don't start unless we've moved at least 3 pixels
119
+ */
120
+ this.dragging = true;
121
+ dd_manager_1.DDManager.dragElement = this;
122
+ // if we're dragging an actual grid item, set the current drop as the grid (to detect enter/leave)
123
+ let grid = (_a = this.el.gridstackNode) === null || _a === void 0 ? void 0 : _a.grid;
124
+ if (grid) {
125
+ dd_manager_1.DDManager.dropElement = grid.el.ddElement.ddDroppable;
126
+ }
127
+ else {
128
+ delete dd_manager_1.DDManager.dropElement;
129
+ }
130
+ this.helper = this._createHelper(e);
131
+ this._setupHelperContainmentStyle();
132
+ this.dragOffset = this._getDragOffset(e, this.el, this.helperContainment);
133
+ const ev = utils_1.Utils.initEvent(e, { target: this.el, type: 'dragstart' });
134
+ this._setupHelperStyle(e);
135
+ if (this.option.start) {
136
+ this.option.start(ev, this.ui());
137
+ }
138
+ this.triggerEvent('dragstart', ev);
139
+ }
140
+ e.preventDefault();
141
+ return true;
142
+ }
143
+ /** @internal call when the mouse gets released to drop the item at current location */
144
+ _mouseUp(e) {
145
+ var _a;
146
+ document.removeEventListener('mousemove', this._mouseMove, true);
147
+ document.removeEventListener('mouseup', this._mouseUp, true);
148
+ if (dd_touch_1.isTouch) {
149
+ this.dragEl.removeEventListener('touchmove', dd_touch_1.touchmove, true);
150
+ this.dragEl.removeEventListener('touchend', dd_touch_1.touchend, true);
151
+ }
152
+ if (this.dragging) {
153
+ delete this.dragging;
154
+ // reset the drop target if dragging over ourself (already parented, just moving during stop callback below)
155
+ if (((_a = dd_manager_1.DDManager.dropElement) === null || _a === void 0 ? void 0 : _a.el) === this.el.parentElement) {
156
+ delete dd_manager_1.DDManager.dropElement;
157
+ }
158
+ this.helperContainment.style.position = this.parentOriginStylePosition || null;
159
+ if (this.helper === this.el) {
160
+ this._removeHelperStyle();
161
+ }
162
+ else {
163
+ this.helper.remove();
164
+ }
165
+ const ev = utils_1.Utils.initEvent(e, { target: this.el, type: 'dragstop' });
166
+ if (this.option.stop) {
167
+ this.option.stop(ev); // NOTE: destroy() will be called when removing item, so expect NULL ptr after!
168
+ }
169
+ this.triggerEvent('dragstop', ev);
170
+ // call the droppable method to receive the item
171
+ if (dd_manager_1.DDManager.dropElement) {
172
+ dd_manager_1.DDManager.dropElement.drop(e);
173
+ }
174
+ }
175
+ delete this.helper;
176
+ delete this.mouseDownEvent;
177
+ delete dd_manager_1.DDManager.dragElement;
178
+ delete dd_manager_1.DDManager.dropElement;
179
+ delete dd_manager_1.DDManager.mouseHandled;
180
+ e.preventDefault();
181
+ }
182
+ /** @internal create a clone copy (or user defined method) of the original drag item if set */
183
+ _createHelper(event) {
184
+ let helper = this.el;
185
+ if (typeof this.option.helper === 'function') {
186
+ helper = this.option.helper(event);
187
+ }
188
+ else if (this.option.helper === 'clone') {
189
+ helper = utils_1.Utils.cloneNode(this.el);
190
+ }
191
+ if (!document.body.contains(helper)) {
192
+ utils_1.Utils.appendTo(helper, this.option.appendTo === 'parent' ? this.el.parentNode : this.option.appendTo);
193
+ }
194
+ if (helper === this.el) {
195
+ this.dragElementOriginStyle = DDDraggable.originStyleProp.map(prop => this.el.style[prop]);
196
+ }
197
+ return helper;
198
+ }
199
+ /** @internal set the fix position of the dragged item */
200
+ _setupHelperStyle(e) {
201
+ this.helper.classList.add('ui-draggable-dragging');
202
+ // TODO: set all at once with style.cssText += ... ? https://stackoverflow.com/questions/3968593
203
+ const style = this.helper.style;
204
+ style.pointerEvents = 'none'; // needed for over items to get enter/leave
205
+ // style.cursor = 'move'; // TODO: can't set with pointerEvents=none ! (done in CSS as well)
206
+ style['min-width'] = 0; // since we no longer relative to our parent and we don't resize anyway (normally 100/#column %)
207
+ style.width = this.dragOffset.width + 'px';
208
+ style.height = this.dragOffset.height + 'px';
209
+ style.willChange = 'left, top';
210
+ style.position = 'fixed'; // let us drag between grids by not clipping as parent .grid-stack is position: 'relative'
211
+ this._dragFollow(e); // now position it
212
+ style.transition = 'none'; // show up instantly
213
+ setTimeout(() => {
214
+ if (this.helper) {
215
+ style.transition = null; // recover animation
216
+ }
217
+ }, 0);
218
+ return this;
219
+ }
220
+ /** @internal restore back the original style before dragging */
221
+ _removeHelperStyle() {
222
+ var _a;
223
+ this.helper.classList.remove('ui-draggable-dragging');
224
+ let node = (_a = this.helper) === null || _a === void 0 ? void 0 : _a.gridstackNode;
225
+ // don't bother restoring styles if we're gonna remove anyway...
226
+ if (this.dragElementOriginStyle && (!node || !node._isAboutToRemove)) {
227
+ let helper = this.helper;
228
+ // don't animate, otherwise we animate offseted when switching back to 'absolute' from 'fixed'
229
+ let transition = this.dragElementOriginStyle['transition'] || null;
230
+ helper.style.transition = this.dragElementOriginStyle['transition'] = 'none';
231
+ DDDraggable.originStyleProp.forEach(prop => helper.style[prop] = this.dragElementOriginStyle[prop] || null);
232
+ setTimeout(() => helper.style.transition = transition, 50); // recover animation from saved vars after a pause (0 isn't enough #1973)
233
+ }
234
+ delete this.dragElementOriginStyle;
235
+ return this;
236
+ }
237
+ /** @internal updates the top/left position to follow the mouse */
238
+ _dragFollow(e) {
239
+ let containmentRect = { left: 0, top: 0 };
240
+ // if (this.helper.style.position === 'absolute') { // we use 'fixed'
241
+ // const { left, top } = this.helperContainment.getBoundingClientRect();
242
+ // containmentRect = { left, top };
243
+ // }
244
+ const style = this.helper.style;
245
+ const offset = this.dragOffset;
246
+ style.left = e.clientX + offset.offsetLeft - containmentRect.left + 'px';
247
+ style.top = e.clientY + offset.offsetTop - containmentRect.top + 'px';
248
+ }
249
+ /** @internal */
250
+ _setupHelperContainmentStyle() {
251
+ this.helperContainment = this.helper.parentElement;
252
+ if (this.helper.style.position !== 'fixed') {
253
+ this.parentOriginStylePosition = this.helperContainment.style.position;
254
+ if (window.getComputedStyle(this.helperContainment).position.match(/static/)) {
255
+ this.helperContainment.style.position = 'relative';
256
+ }
257
+ }
258
+ return this;
259
+ }
260
+ /** @internal */
261
+ _getDragOffset(event, el, parent) {
262
+ // in case ancestor has transform/perspective css properties that change the viewpoint
263
+ let xformOffsetX = 0;
264
+ let xformOffsetY = 0;
265
+ if (parent) {
266
+ const testEl = document.createElement('div');
267
+ utils_1.Utils.addElStyles(testEl, {
268
+ opacity: '0',
269
+ position: 'fixed',
270
+ top: 0 + 'px',
271
+ left: 0 + 'px',
272
+ width: '1px',
273
+ height: '1px',
274
+ zIndex: '-999999',
275
+ });
276
+ parent.appendChild(testEl);
277
+ const testElPosition = testEl.getBoundingClientRect();
278
+ parent.removeChild(testEl);
279
+ xformOffsetX = testElPosition.left;
280
+ xformOffsetY = testElPosition.top;
281
+ // TODO: scale ?
282
+ }
283
+ const targetOffset = el.getBoundingClientRect();
284
+ return {
285
+ left: targetOffset.left,
286
+ top: targetOffset.top,
287
+ offsetLeft: -event.clientX + targetOffset.left - xformOffsetX,
288
+ offsetTop: -event.clientY + targetOffset.top - xformOffsetY,
289
+ width: targetOffset.width,
290
+ height: targetOffset.height
291
+ };
292
+ }
293
+ /** @internal TODO: set to public as called by DDDroppable! */
294
+ ui() {
295
+ const containmentEl = this.el.parentElement;
296
+ const containmentRect = containmentEl.getBoundingClientRect();
297
+ const offset = this.helper.getBoundingClientRect();
298
+ return {
299
+ position: {
300
+ top: offset.top - containmentRect.top,
301
+ left: offset.left - containmentRect.left
302
+ }
303
+ /* not used by GridStack for now...
304
+ helper: [this.helper], //The object arr representing the helper that's being dragged.
305
+ offset: { top: offset.top, left: offset.left } // Current offset position of the helper as { top, left } object.
306
+ */
307
+ };
308
+ }
309
+ }
310
+ exports.DDDraggable = DDDraggable;
311
+ /** @internal properties we change during dragging, and restore back */
312
+ DDDraggable.originStyleProp = ['transition', 'pointerEvents', 'position', 'left', 'top'];
313
+ //# sourceMappingURL=dd-draggable.js.map