gridstack 7.3.0 → 8.0.1

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 (196) hide show
  1. package/README.md +9 -2
  2. package/dist/dd-base-impl.d.ts +20 -20
  3. package/dist/dd-base-impl.js +31 -35
  4. package/dist/dd-base-impl.js.map +1 -1
  5. package/dist/dd-draggable.d.ts +28 -28
  6. package/dist/dd-draggable.js +336 -344
  7. package/dist/dd-draggable.js.map +1 -1
  8. package/dist/dd-droppable.d.ts +26 -26
  9. package/dist/dd-droppable.js +146 -148
  10. package/dist/dd-droppable.js.map +1 -1
  11. package/dist/dd-element.d.ts +27 -27
  12. package/dist/dd-element.js +90 -94
  13. package/dist/dd-element.js.map +1 -1
  14. package/dist/dd-gridstack.d.ts +34 -34
  15. package/dist/dd-gridstack.js +127 -124
  16. package/dist/dd-gridstack.js.map +1 -1
  17. package/dist/dd-manager.d.ts +22 -22
  18. package/dist/dd-manager.js +9 -13
  19. package/dist/dd-manager.js.map +1 -1
  20. package/dist/dd-resizable-handle.d.ts +14 -14
  21. package/dist/dd-resizable-handle.js +102 -105
  22. package/dist/dd-resizable-handle.js.map +1 -1
  23. package/dist/dd-resizable.d.ts +28 -28
  24. package/dist/dd-resizable.js +290 -296
  25. package/dist/dd-resizable.js.map +1 -1
  26. package/dist/dd-touch.d.ts +33 -33
  27. package/dist/dd-touch.js +173 -182
  28. package/dist/dd-touch.js.map +1 -1
  29. package/dist/es5/dd-base-impl.d.ts +20 -20
  30. package/dist/es5/dd-base-impl.js +40 -40
  31. package/dist/es5/dd-base-impl.js.map +1 -1
  32. package/dist/es5/dd-draggable.d.ts +28 -28
  33. package/dist/es5/dd-draggable.js +366 -367
  34. package/dist/es5/dd-draggable.js.map +1 -1
  35. package/dist/es5/dd-droppable.d.ts +26 -26
  36. package/dist/es5/dd-droppable.js +181 -179
  37. package/dist/es5/dd-droppable.js.map +1 -1
  38. package/dist/es5/dd-element.d.ts +27 -27
  39. package/dist/es5/dd-element.js +95 -95
  40. package/dist/es5/dd-element.js.map +1 -1
  41. package/dist/es5/dd-gridstack.d.ts +34 -34
  42. package/dist/es5/dd-gridstack.js +144 -144
  43. package/dist/es5/dd-gridstack.js.map +1 -1
  44. package/dist/es5/dd-manager.d.ts +22 -22
  45. package/dist/es5/dd-manager.js +16 -16
  46. package/dist/es5/dd-manager.js.map +1 -1
  47. package/dist/es5/dd-resizable-handle.d.ts +14 -14
  48. package/dist/es5/dd-resizable-handle.js +105 -106
  49. package/dist/es5/dd-resizable-handle.js.map +1 -1
  50. package/dist/es5/dd-resizable.d.ts +28 -28
  51. package/dist/es5/dd-resizable.js +317 -318
  52. package/dist/es5/dd-resizable.js.map +1 -1
  53. package/dist/es5/dd-touch.d.ts +33 -33
  54. package/dist/es5/dd-touch.js +185 -185
  55. package/dist/es5/dd-touch.js.map +1 -1
  56. package/dist/es5/gridstack-all.js +1 -1
  57. package/dist/es5/gridstack-all.js.LICENSE.txt +1 -1
  58. package/dist/es5/gridstack-all.js.map +1 -1
  59. package/dist/es5/gridstack-engine.d.ts +102 -102
  60. package/dist/es5/gridstack-engine.js +1000 -995
  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 +392 -376
  64. package/dist/es5/gridstack.js +2254 -2233
  65. package/dist/es5/gridstack.js.map +1 -1
  66. package/dist/es5/types.d.ts +279 -284
  67. package/dist/es5/types.js +47 -35
  68. package/dist/es5/types.js.map +1 -1
  69. package/dist/es5/utils.d.ts +95 -93
  70. package/dist/es5/utils.js +600 -569
  71. package/dist/es5/utils.js.map +1 -1
  72. package/dist/gridstack-all.js +1 -1
  73. package/dist/gridstack-all.js.LICENSE.txt +1 -1
  74. package/dist/gridstack-all.js.map +1 -1
  75. package/dist/gridstack-engine.d.ts +102 -102
  76. package/dist/gridstack-engine.js +950 -954
  77. package/dist/gridstack-engine.js.map +1 -1
  78. package/dist/gridstack-extra.css +0 -390
  79. package/dist/gridstack-extra.min.css +1 -1
  80. package/dist/gridstack.css +19 -97
  81. package/dist/gridstack.d.ts +392 -376
  82. package/dist/gridstack.js +2155 -2157
  83. package/dist/gridstack.js.map +1 -1
  84. package/dist/gridstack.min.css +1 -1
  85. package/dist/ng/README.md +154 -0
  86. package/dist/ng/gridstack-item.component.d.ts +29 -0
  87. package/dist/ng/gridstack-item.component.js +65 -0
  88. package/dist/ng/gridstack-item.component.js.map +1 -0
  89. package/dist/ng/gridstack.component.d.ts +118 -0
  90. package/dist/ng/gridstack.component.js +245 -0
  91. package/dist/ng/gridstack.component.js.map +1 -0
  92. package/dist/src/gridstack-extra.scss +0 -2
  93. package/dist/src/gridstack.scss +14 -9
  94. package/dist/types.d.ts +279 -284
  95. package/dist/types.js +44 -35
  96. package/dist/types.js.map +1 -1
  97. package/dist/utils.d.ts +95 -93
  98. package/dist/utils.js +546 -527
  99. package/dist/utils.js.map +1 -1
  100. package/{dist → dist_save}/angular/gridstack-item.component.ts +5 -3
  101. package/{dist → dist_save}/angular/gridstack.component.ts +32 -18
  102. package/dist_save/dd-base-impl.d.ts +20 -0
  103. package/dist_save/dd-base-impl.js +36 -0
  104. package/dist_save/dd-base-impl.js.map +1 -0
  105. package/dist_save/dd-draggable.d.ts +28 -0
  106. package/dist_save/dd-draggable.js +343 -0
  107. package/dist_save/dd-draggable.js.map +1 -0
  108. package/dist_save/dd-droppable.d.ts +26 -0
  109. package/dist_save/dd-droppable.js +149 -0
  110. package/dist_save/dd-droppable.js.map +1 -0
  111. package/dist_save/dd-element.d.ts +27 -0
  112. package/dist_save/dd-element.js +95 -0
  113. package/dist_save/dd-element.js.map +1 -0
  114. package/dist_save/dd-gridstack.d.ts +34 -0
  115. package/dist_save/dd-gridstack.js +125 -0
  116. package/dist_save/dd-gridstack.js.map +1 -0
  117. package/dist_save/dd-manager.d.ts +22 -0
  118. package/dist_save/dd-manager.js +14 -0
  119. package/dist_save/dd-manager.js.map +1 -0
  120. package/dist_save/dd-resizable-handle.d.ts +14 -0
  121. package/dist_save/dd-resizable-handle.js +106 -0
  122. package/dist_save/dd-resizable-handle.js.map +1 -0
  123. package/dist_save/dd-resizable.d.ts +28 -0
  124. package/dist_save/dd-resizable.js +294 -0
  125. package/dist_save/dd-resizable.js.map +1 -0
  126. package/dist_save/dd-touch.d.ts +33 -0
  127. package/dist_save/dd-touch.js +183 -0
  128. package/dist_save/dd-touch.js.map +1 -0
  129. package/dist_save/es5/dd-base-impl.d.ts +20 -0
  130. package/dist_save/es5/dd-base-impl.js +41 -0
  131. package/dist_save/es5/dd-base-impl.js.map +1 -0
  132. package/dist_save/es5/dd-draggable.d.ts +28 -0
  133. package/dist_save/es5/dd-draggable.js +366 -0
  134. package/dist_save/es5/dd-draggable.js.map +1 -0
  135. package/dist_save/es5/dd-droppable.d.ts +26 -0
  136. package/dist_save/es5/dd-droppable.js +180 -0
  137. package/dist_save/es5/dd-droppable.js.map +1 -0
  138. package/dist_save/es5/dd-element.d.ts +27 -0
  139. package/dist_save/es5/dd-element.js +96 -0
  140. package/dist_save/es5/dd-element.js.map +1 -0
  141. package/dist_save/es5/dd-gridstack.d.ts +34 -0
  142. package/dist_save/es5/dd-gridstack.js +145 -0
  143. package/dist_save/es5/dd-gridstack.js.map +1 -0
  144. package/dist_save/es5/dd-manager.d.ts +22 -0
  145. package/dist_save/es5/dd-manager.js +17 -0
  146. package/dist_save/es5/dd-manager.js.map +1 -0
  147. package/dist_save/es5/dd-resizable-handle.d.ts +14 -0
  148. package/dist_save/es5/dd-resizable-handle.js +107 -0
  149. package/dist_save/es5/dd-resizable-handle.js.map +1 -0
  150. package/dist_save/es5/dd-resizable.d.ts +28 -0
  151. package/dist_save/es5/dd-resizable.js +316 -0
  152. package/dist_save/es5/dd-resizable.js.map +1 -0
  153. package/dist_save/es5/dd-touch.d.ts +33 -0
  154. package/dist_save/es5/dd-touch.js +186 -0
  155. package/dist_save/es5/dd-touch.js.map +1 -0
  156. package/dist_save/es5/gridstack-all.js +3 -0
  157. package/dist_save/es5/gridstack-all.js.LICENSE.txt +7 -0
  158. package/dist_save/es5/gridstack-all.js.map +1 -0
  159. package/dist_save/es5/gridstack-engine.d.ts +102 -0
  160. package/dist_save/es5/gridstack-engine.js +997 -0
  161. package/dist_save/es5/gridstack-engine.js.map +1 -0
  162. package/dist_save/es5/gridstack-poly.js +356 -0
  163. package/dist_save/es5/gridstack.d.ts +376 -0
  164. package/dist_save/es5/gridstack.js +2238 -0
  165. package/dist_save/es5/gridstack.js.map +1 -0
  166. package/dist_save/es5/types.d.ts +284 -0
  167. package/dist_save/es5/types.js +36 -0
  168. package/dist_save/es5/types.js.map +1 -0
  169. package/dist_save/es5/utils.d.ts +95 -0
  170. package/dist_save/es5/utils.js +590 -0
  171. package/dist_save/es5/utils.js.map +1 -0
  172. package/dist_save/gridstack-all.js +3 -0
  173. package/dist_save/gridstack-all.js.LICENSE.txt +7 -0
  174. package/dist_save/gridstack-all.js.map +1 -0
  175. package/dist_save/gridstack-engine.d.ts +102 -0
  176. package/dist_save/gridstack-engine.js +956 -0
  177. package/dist_save/gridstack-engine.js.map +1 -0
  178. package/dist_save/gridstack-extra.css +433 -0
  179. package/dist_save/gridstack-extra.min.css +1 -0
  180. package/dist_save/gridstack.css +226 -0
  181. package/dist_save/gridstack.d.ts +376 -0
  182. package/dist_save/gridstack.js +2162 -0
  183. package/dist_save/gridstack.js.map +1 -0
  184. package/dist_save/gridstack.min.css +1 -0
  185. package/dist_save/src/gridstack-extra.scss +27 -0
  186. package/dist_save/src/gridstack.scss +131 -0
  187. package/dist_save/types.d.ts +284 -0
  188. package/dist_save/types.js +36 -0
  189. package/dist_save/types.js.map +1 -0
  190. package/dist_save/utils.d.ts +95 -0
  191. package/dist_save/utils.js +548 -0
  192. package/dist_save/utils.js.map +1 -0
  193. package/doc/CHANGES.md +20 -0
  194. package/doc/README.md +21 -14
  195. package/package.json +25 -24
  196. /package/{dist → dist_save}/angular/README.md +0 -0
@@ -1,368 +1,367 @@
1
- "use strict";
2
- /**
3
- * dd-draggable.ts 7.3.0
4
- * Copyright (c) 2021-2022 Alain Dumesny - see GridStack root license
5
- */
6
- var __extends = (this && this.__extends) || (function () {
7
- var extendStatics = function (d, b) {
8
- extendStatics = Object.setPrototypeOf ||
9
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
10
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
11
- return extendStatics(d, b);
12
- };
13
- return function (d, b) {
14
- extendStatics(d, b);
15
- function __() { this.constructor = d; }
16
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
17
- };
18
- })();
19
- Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.DDDraggable = void 0;
21
- var dd_manager_1 = require("./dd-manager");
22
- var utils_1 = require("./utils");
23
- var dd_base_impl_1 = require("./dd-base-impl");
24
- var dd_touch_1 = require("./dd-touch");
25
- // let count = 0; // TEST
26
- var DDDraggable = /** @class */ (function (_super) {
27
- __extends(DDDraggable, _super);
28
- function DDDraggable(el, option) {
29
- if (option === void 0) { option = {}; }
30
- var _this = _super.call(this) || this;
31
- _this.el = el;
32
- _this.option = option;
33
- // get the element that is actually supposed to be dragged by
34
- var handleName = option.handle.substring(1);
35
- _this.dragEl = el.classList.contains(handleName) ? el : el.querySelector(option.handle) || el;
36
- // create var event binding so we can easily remove and still look like TS methods (unlike anonymous functions)
37
- _this._mouseDown = _this._mouseDown.bind(_this);
38
- _this._mouseMove = _this._mouseMove.bind(_this);
39
- _this._mouseUp = _this._mouseUp.bind(_this);
40
- _this.enable();
41
- return _this;
42
- }
43
- DDDraggable.prototype.on = function (event, callback) {
44
- _super.prototype.on.call(this, event, callback);
45
- };
46
- DDDraggable.prototype.off = function (event) {
47
- _super.prototype.off.call(this, event);
48
- };
49
- DDDraggable.prototype.enable = function () {
50
- if (this.disabled === false)
51
- return;
52
- _super.prototype.enable.call(this);
53
- this.dragEl.addEventListener('mousedown', this._mouseDown);
54
- if (dd_touch_1.isTouch) {
55
- this.dragEl.addEventListener('touchstart', dd_touch_1.touchstart);
56
- this.dragEl.addEventListener('pointerdown', dd_touch_1.pointerdown);
57
- // this.dragEl.style.touchAction = 'none'; // not needed unlike pointerdown doc comment
58
- }
59
- this.el.classList.remove('ui-draggable-disabled');
60
- this.el.classList.add('ui-draggable');
61
- };
62
- DDDraggable.prototype.disable = function (forDestroy) {
63
- if (forDestroy === void 0) { forDestroy = false; }
64
- if (this.disabled === true)
65
- return;
66
- _super.prototype.disable.call(this);
67
- this.dragEl.removeEventListener('mousedown', this._mouseDown);
68
- if (dd_touch_1.isTouch) {
69
- this.dragEl.removeEventListener('touchstart', dd_touch_1.touchstart);
70
- this.dragEl.removeEventListener('pointerdown', dd_touch_1.pointerdown);
71
- }
72
- this.el.classList.remove('ui-draggable');
73
- if (!forDestroy)
74
- this.el.classList.add('ui-draggable-disabled');
75
- };
76
- DDDraggable.prototype.destroy = function () {
77
- if (this.dragTimeout)
78
- window.clearTimeout(this.dragTimeout);
79
- delete this.dragTimeout;
80
- if (this.dragging)
81
- this._mouseUp(this.mouseDownEvent);
82
- this.disable(true);
83
- delete this.el;
84
- delete this.helper;
85
- delete this.option;
86
- _super.prototype.destroy.call(this);
87
- };
88
- DDDraggable.prototype.updateOption = function (opts) {
89
- var _this = this;
90
- Object.keys(opts).forEach(function (key) { return _this.option[key] = opts[key]; });
91
- return this;
92
- };
93
- /** @internal call when mouse goes down before a dragstart happens */
94
- DDDraggable.prototype._mouseDown = function (e) {
95
- // don't let more than one widget handle mouseStart
96
- if (dd_manager_1.DDManager.mouseHandled)
97
- return;
98
- if (e.button !== 0)
99
- return true; // only left click
100
- // make sure we are not clicking on known object that handles mouseDown (TODO: make this extensible ?) #2054
101
- var skipMouseDown = ['input', 'textarea', 'button', 'select', 'option'];
102
- var name = e.target.nodeName.toLowerCase();
103
- if (skipMouseDown.find(function (skip) { return skip === name; }))
104
- return true;
105
- // also check for content editable
106
- if (e.target.closest('[contenteditable="true"]'))
107
- return true;
108
- // REMOVE: why would we get the event if it wasn't for us or child ?
109
- // make sure we are clicking on a drag handle or child of it...
110
- // 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)
111
- // let className = this.option.handle.substring(1);
112
- // let el = e.target as HTMLElement;
113
- // while (el && !el.classList.contains(className)) { el = el.parentElement; }
114
- // if (!el) return;
115
- this.mouseDownEvent = e;
116
- delete this.dragging;
117
- delete dd_manager_1.DDManager.dragElement;
118
- delete dd_manager_1.DDManager.dropElement;
119
- // document handler so we can continue receiving moves as the item is 'fixed' position, and capture=true so WE get a first crack
120
- document.addEventListener('mousemove', this._mouseMove, true); // true=capture, not bubble
121
- document.addEventListener('mouseup', this._mouseUp, true);
122
- if (dd_touch_1.isTouch) {
123
- this.dragEl.addEventListener('touchmove', dd_touch_1.touchmove);
124
- this.dragEl.addEventListener('touchend', dd_touch_1.touchend);
125
- }
126
- e.preventDefault();
127
- // preventDefault() prevents blur event which occurs just after mousedown event.
128
- // if an editable content has focus, then blur must be call
129
- if (document.activeElement)
130
- document.activeElement.blur();
131
- dd_manager_1.DDManager.mouseHandled = true;
132
- return true;
133
- };
134
- /** @internal method to call actual drag event */
135
- DDDraggable.prototype._callDrag = function (e) {
136
- if (!this.dragging)
137
- return;
138
- var ev = utils_1.Utils.initEvent(e, { target: this.el, type: 'drag' });
139
- if (this.option.drag) {
140
- this.option.drag(ev, this.ui());
141
- }
142
- this.triggerEvent('drag', ev);
143
- };
144
- /** @internal called when the main page (after successful mousedown) receives a move event to drag the item around the screen */
145
- DDDraggable.prototype._mouseMove = function (e) {
146
- var _this = this;
147
- var _a;
148
- // console.log(`${count++} move ${e.x},${e.y}`)
149
- var s = this.mouseDownEvent;
150
- if (this.dragging) {
151
- this._dragFollow(e);
152
- // delay actual grid handling drag until we pause for a while if set
153
- if (dd_manager_1.DDManager.pauseDrag) {
154
- var pause = Number.isInteger(dd_manager_1.DDManager.pauseDrag) ? dd_manager_1.DDManager.pauseDrag : 100;
155
- if (this.dragTimeout)
156
- window.clearTimeout(this.dragTimeout);
157
- this.dragTimeout = window.setTimeout(function () { return _this._callDrag(e); }, pause);
158
- }
159
- else {
160
- this._callDrag(e);
161
- }
162
- }
163
- else if (Math.abs(e.x - s.x) + Math.abs(e.y - s.y) > 3) {
164
- /**
165
- * don't start unless we've moved at least 3 pixels
166
- */
167
- this.dragging = true;
168
- dd_manager_1.DDManager.dragElement = this;
169
- // if we're dragging an actual grid item, set the current drop as the grid (to detect enter/leave)
170
- var grid = (_a = this.el.gridstackNode) === null || _a === void 0 ? void 0 : _a.grid;
171
- if (grid) {
172
- dd_manager_1.DDManager.dropElement = grid.el.ddElement.ddDroppable;
173
- }
174
- else {
175
- delete dd_manager_1.DDManager.dropElement;
176
- }
177
- this.helper = this._createHelper(e);
178
- this._setupHelperContainmentStyle();
179
- this.dragOffset = this._getDragOffset(e, this.el, this.helperContainment);
180
- var ev = utils_1.Utils.initEvent(e, { target: this.el, type: 'dragstart' });
181
- this._setupHelperStyle(e);
182
- if (this.option.start) {
183
- this.option.start(ev, this.ui());
184
- }
185
- this.triggerEvent('dragstart', ev);
186
- }
187
- e.preventDefault(); // needed otherwise we get text sweep text selection as we drag around
188
- return true;
189
- };
190
- /** @internal call when the mouse gets released to drop the item at current location */
191
- DDDraggable.prototype._mouseUp = function (e) {
192
- var _a;
193
- document.removeEventListener('mousemove', this._mouseMove, true);
194
- document.removeEventListener('mouseup', this._mouseUp, true);
195
- if (dd_touch_1.isTouch) {
196
- this.dragEl.removeEventListener('touchmove', dd_touch_1.touchmove, true);
197
- this.dragEl.removeEventListener('touchend', dd_touch_1.touchend, true);
198
- }
199
- if (this.dragging) {
200
- delete this.dragging;
201
- // reset the drop target if dragging over ourself (already parented, just moving during stop callback below)
202
- if (((_a = dd_manager_1.DDManager.dropElement) === null || _a === void 0 ? void 0 : _a.el) === this.el.parentElement) {
203
- delete dd_manager_1.DDManager.dropElement;
204
- }
205
- this.helperContainment.style.position = this.parentOriginStylePosition || null;
206
- if (this.helper === this.el) {
207
- this._removeHelperStyle();
208
- }
209
- else {
210
- this.helper.remove();
211
- }
212
- var ev = utils_1.Utils.initEvent(e, { target: this.el, type: 'dragstop' });
213
- if (this.option.stop) {
214
- this.option.stop(ev); // NOTE: destroy() will be called when removing item, so expect NULL ptr after!
215
- }
216
- this.triggerEvent('dragstop', ev);
217
- // call the droppable method to receive the item
218
- if (dd_manager_1.DDManager.dropElement) {
219
- dd_manager_1.DDManager.dropElement.drop(e);
220
- }
221
- }
222
- delete this.helper;
223
- delete this.mouseDownEvent;
224
- delete dd_manager_1.DDManager.dragElement;
225
- delete dd_manager_1.DDManager.dropElement;
226
- delete dd_manager_1.DDManager.mouseHandled;
227
- e.preventDefault();
228
- };
229
- /** @internal create a clone copy (or user defined method) of the original drag item if set */
230
- DDDraggable.prototype._createHelper = function (event) {
231
- var _this = this;
232
- var helper = this.el;
233
- if (typeof this.option.helper === 'function') {
234
- helper = this.option.helper(event);
235
- }
236
- else if (this.option.helper === 'clone') {
237
- helper = utils_1.Utils.cloneNode(this.el);
238
- }
239
- if (!document.body.contains(helper)) {
240
- utils_1.Utils.appendTo(helper, this.option.appendTo === 'parent' ? this.el.parentNode : this.option.appendTo);
241
- }
242
- if (helper === this.el) {
243
- this.dragElementOriginStyle = DDDraggable.originStyleProp.map(function (prop) { return _this.el.style[prop]; });
244
- }
245
- return helper;
246
- };
247
- /** @internal set the fix position of the dragged item */
248
- DDDraggable.prototype._setupHelperStyle = function (e) {
249
- var _this = this;
250
- this.helper.classList.add('ui-draggable-dragging');
251
- // TODO: set all at once with style.cssText += ... ? https://stackoverflow.com/questions/3968593
252
- var style = this.helper.style;
253
- style.pointerEvents = 'none'; // needed for over items to get enter/leave
254
- // style.cursor = 'move'; // TODO: can't set with pointerEvents=none ! (done in CSS as well)
255
- style['min-width'] = 0; // since we no longer relative to our parent and we don't resize anyway (normally 100/#column %)
256
- style.width = this.dragOffset.width + 'px';
257
- style.height = this.dragOffset.height + 'px';
258
- style.willChange = 'left, top';
259
- style.position = 'fixed'; // let us drag between grids by not clipping as parent .grid-stack is position: 'relative'
260
- this._dragFollow(e); // now position it
261
- style.transition = 'none'; // show up instantly
262
- setTimeout(function () {
263
- if (_this.helper) {
264
- style.transition = null; // recover animation
265
- }
266
- }, 0);
267
- return this;
268
- };
269
- /** @internal restore back the original style before dragging */
270
- DDDraggable.prototype._removeHelperStyle = function () {
271
- var _this = this;
272
- var _a;
273
- this.helper.classList.remove('ui-draggable-dragging');
274
- var node = (_a = this.helper) === null || _a === void 0 ? void 0 : _a.gridstackNode;
275
- // don't bother restoring styles if we're gonna remove anyway...
276
- if (!(node === null || node === void 0 ? void 0 : node._isAboutToRemove) && this.dragElementOriginStyle) {
277
- var helper_1 = this.helper;
278
- // don't animate, otherwise we animate offseted when switching back to 'absolute' from 'fixed'.
279
- // TODO: this also removes resizing animation which doesn't have this issue, but others.
280
- // Ideally both would animate ('move' would immediately restore 'absolute' and adjust coordinate to match,
281
- // then trigger a delay (repaint) to restore to final dest with animate) but then we need to make sure 'resizestop'
282
- // is called AFTER 'transitionend' event is received (see https://github.com/gridstack/gridstack.js/issues/2033)
283
- var transition_1 = this.dragElementOriginStyle['transition'] || null;
284
- helper_1.style.transition = this.dragElementOriginStyle['transition'] = 'none'; // can't be NULL #1973
285
- DDDraggable.originStyleProp.forEach(function (prop) { return helper_1.style[prop] = _this.dragElementOriginStyle[prop] || null; });
286
- setTimeout(function () { return helper_1.style.transition = transition_1; }, 50); // recover animation from saved vars after a pause (0 isn't enough #1973)
287
- }
288
- delete this.dragElementOriginStyle;
289
- return this;
290
- };
291
- /** @internal updates the top/left position to follow the mouse */
292
- DDDraggable.prototype._dragFollow = function (e) {
293
- var containmentRect = { left: 0, top: 0 };
294
- // if (this.helper.style.position === 'absolute') { // we use 'fixed'
295
- // const { left, top } = this.helperContainment.getBoundingClientRect();
296
- // containmentRect = { left, top };
297
- // }
298
- var style = this.helper.style;
299
- var offset = this.dragOffset;
300
- style.left = e.clientX + offset.offsetLeft - containmentRect.left + 'px';
301
- style.top = e.clientY + offset.offsetTop - containmentRect.top + 'px';
302
- };
303
- /** @internal */
304
- DDDraggable.prototype._setupHelperContainmentStyle = function () {
305
- this.helperContainment = this.helper.parentElement;
306
- if (this.helper.style.position !== 'fixed') {
307
- this.parentOriginStylePosition = this.helperContainment.style.position;
308
- if (window.getComputedStyle(this.helperContainment).position.match(/static/)) {
309
- this.helperContainment.style.position = 'relative';
310
- }
311
- }
312
- return this;
313
- };
314
- /** @internal */
315
- DDDraggable.prototype._getDragOffset = function (event, el, parent) {
316
- // in case ancestor has transform/perspective css properties that change the viewpoint
317
- var xformOffsetX = 0;
318
- var xformOffsetY = 0;
319
- if (parent) {
320
- var testEl = document.createElement('div');
321
- utils_1.Utils.addElStyles(testEl, {
322
- opacity: '0',
323
- position: 'fixed',
324
- top: 0 + 'px',
325
- left: 0 + 'px',
326
- width: '1px',
327
- height: '1px',
328
- zIndex: '-999999',
329
- });
330
- parent.appendChild(testEl);
331
- var testElPosition = testEl.getBoundingClientRect();
332
- parent.removeChild(testEl);
333
- xformOffsetX = testElPosition.left;
334
- xformOffsetY = testElPosition.top;
335
- // TODO: scale ?
336
- }
337
- var targetOffset = el.getBoundingClientRect();
338
- return {
339
- left: targetOffset.left,
340
- top: targetOffset.top,
341
- offsetLeft: -event.clientX + targetOffset.left - xformOffsetX,
342
- offsetTop: -event.clientY + targetOffset.top - xformOffsetY,
343
- width: targetOffset.width,
344
- height: targetOffset.height
345
- };
346
- };
347
- /** @internal TODO: set to public as called by DDDroppable! */
348
- DDDraggable.prototype.ui = function () {
349
- var containmentEl = this.el.parentElement;
350
- var containmentRect = containmentEl.getBoundingClientRect();
351
- var offset = this.helper.getBoundingClientRect();
352
- return {
353
- position: {
354
- top: offset.top - containmentRect.top,
355
- left: offset.left - containmentRect.left
356
- }
357
- /* not used by GridStack for now...
358
- helper: [this.helper], //The object arr representing the helper that's being dragged.
359
- offset: { top: offset.top, left: offset.left } // Current offset position of the helper as { top, left } object.
360
- */
361
- };
362
- };
363
- /** @internal properties we change during dragging, and restore back */
364
- DDDraggable.originStyleProp = ['transition', 'pointerEvents', 'position', 'left', 'top', 'minWidth', 'willChange'];
365
- return DDDraggable;
366
- }(dd_base_impl_1.DDBaseImplement));
367
- exports.DDDraggable = DDDraggable;
1
+ "use strict";
2
+ /**
3
+ * dd-draggable.ts 8.0.1
4
+ * Copyright (c) 2021-2022 Alain Dumesny - see GridStack root license
5
+ */
6
+ var __extends = (this && this.__extends) || (function () {
7
+ var extendStatics = function (d, b) {
8
+ extendStatics = Object.setPrototypeOf ||
9
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
10
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
11
+ return extendStatics(d, b);
12
+ };
13
+ return function (d, b) {
14
+ if (typeof b !== "function" && b !== null)
15
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
16
+ extendStatics(d, b);
17
+ function __() { this.constructor = d; }
18
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
19
+ };
20
+ })();
21
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ exports.DDDraggable = void 0;
23
+ var dd_manager_1 = require("./dd-manager");
24
+ var utils_1 = require("./utils");
25
+ var dd_base_impl_1 = require("./dd-base-impl");
26
+ var dd_touch_1 = require("./dd-touch");
27
+ // let count = 0; // TEST
28
+ var DDDraggable = exports.DDDraggable = /** @class */ (function (_super) {
29
+ __extends(DDDraggable, _super);
30
+ function DDDraggable(el, option) {
31
+ if (option === void 0) { option = {}; }
32
+ var _this = _super.call(this) || this;
33
+ _this.el = el;
34
+ _this.option = option;
35
+ // get the element that is actually supposed to be dragged by
36
+ var handleName = option.handle.substring(1);
37
+ _this.dragEl = el.classList.contains(handleName) ? el : el.querySelector(option.handle) || el;
38
+ // create var event binding so we can easily remove and still look like TS methods (unlike anonymous functions)
39
+ _this._mouseDown = _this._mouseDown.bind(_this);
40
+ _this._mouseMove = _this._mouseMove.bind(_this);
41
+ _this._mouseUp = _this._mouseUp.bind(_this);
42
+ _this.enable();
43
+ return _this;
44
+ }
45
+ DDDraggable.prototype.on = function (event, callback) {
46
+ _super.prototype.on.call(this, event, callback);
47
+ };
48
+ DDDraggable.prototype.off = function (event) {
49
+ _super.prototype.off.call(this, event);
50
+ };
51
+ DDDraggable.prototype.enable = function () {
52
+ if (this.disabled === false)
53
+ return;
54
+ _super.prototype.enable.call(this);
55
+ this.dragEl.addEventListener('mousedown', this._mouseDown);
56
+ if (dd_touch_1.isTouch) {
57
+ this.dragEl.addEventListener('touchstart', dd_touch_1.touchstart);
58
+ this.dragEl.addEventListener('pointerdown', dd_touch_1.pointerdown);
59
+ // this.dragEl.style.touchAction = 'none'; // not needed unlike pointerdown doc comment
60
+ }
61
+ this.el.classList.remove('ui-draggable-disabled');
62
+ };
63
+ DDDraggable.prototype.disable = function (forDestroy) {
64
+ if (forDestroy === void 0) { forDestroy = false; }
65
+ if (this.disabled === true)
66
+ return;
67
+ _super.prototype.disable.call(this);
68
+ this.dragEl.removeEventListener('mousedown', this._mouseDown);
69
+ if (dd_touch_1.isTouch) {
70
+ this.dragEl.removeEventListener('touchstart', dd_touch_1.touchstart);
71
+ this.dragEl.removeEventListener('pointerdown', dd_touch_1.pointerdown);
72
+ }
73
+ if (!forDestroy)
74
+ this.el.classList.add('ui-draggable-disabled');
75
+ };
76
+ DDDraggable.prototype.destroy = function () {
77
+ if (this.dragTimeout)
78
+ window.clearTimeout(this.dragTimeout);
79
+ delete this.dragTimeout;
80
+ if (this.dragging)
81
+ this._mouseUp(this.mouseDownEvent);
82
+ this.disable(true);
83
+ delete this.el;
84
+ delete this.helper;
85
+ delete this.option;
86
+ _super.prototype.destroy.call(this);
87
+ };
88
+ DDDraggable.prototype.updateOption = function (opts) {
89
+ var _this = this;
90
+ Object.keys(opts).forEach(function (key) { return _this.option[key] = opts[key]; });
91
+ return this;
92
+ };
93
+ /** @internal call when mouse goes down before a dragstart happens */
94
+ DDDraggable.prototype._mouseDown = function (e) {
95
+ // don't let more than one widget handle mouseStart
96
+ if (dd_manager_1.DDManager.mouseHandled)
97
+ return;
98
+ if (e.button !== 0)
99
+ return true; // only left click
100
+ // make sure we are not clicking on known object that handles mouseDown (TODO: make this extensible ?) #2054
101
+ var skipMouseDown = ['input', 'textarea', 'button', 'select', 'option'];
102
+ var name = e.target.nodeName.toLowerCase();
103
+ if (skipMouseDown.find(function (skip) { return skip === name; }))
104
+ return true;
105
+ // also check for content editable
106
+ if (e.target.closest('[contenteditable="true"]'))
107
+ return true;
108
+ // REMOVE: why would we get the event if it wasn't for us or child ?
109
+ // make sure we are clicking on a drag handle or child of it...
110
+ // 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)
111
+ // let className = this.option.handle.substring(1);
112
+ // let el = e.target as HTMLElement;
113
+ // while (el && !el.classList.contains(className)) { el = el.parentElement; }
114
+ // if (!el) return;
115
+ this.mouseDownEvent = e;
116
+ delete this.dragging;
117
+ delete dd_manager_1.DDManager.dragElement;
118
+ delete dd_manager_1.DDManager.dropElement;
119
+ // document handler so we can continue receiving moves as the item is 'fixed' position, and capture=true so WE get a first crack
120
+ document.addEventListener('mousemove', this._mouseMove, true); // true=capture, not bubble
121
+ document.addEventListener('mouseup', this._mouseUp, true);
122
+ if (dd_touch_1.isTouch) {
123
+ this.dragEl.addEventListener('touchmove', dd_touch_1.touchmove);
124
+ this.dragEl.addEventListener('touchend', dd_touch_1.touchend);
125
+ }
126
+ e.preventDefault();
127
+ // preventDefault() prevents blur event which occurs just after mousedown event.
128
+ // if an editable content has focus, then blur must be call
129
+ if (document.activeElement)
130
+ document.activeElement.blur();
131
+ dd_manager_1.DDManager.mouseHandled = true;
132
+ return true;
133
+ };
134
+ /** @internal method to call actual drag event */
135
+ DDDraggable.prototype._callDrag = function (e) {
136
+ if (!this.dragging)
137
+ return;
138
+ var ev = utils_1.Utils.initEvent(e, { target: this.el, type: 'drag' });
139
+ if (this.option.drag) {
140
+ this.option.drag(ev, this.ui());
141
+ }
142
+ this.triggerEvent('drag', ev);
143
+ };
144
+ /** @internal called when the main page (after successful mousedown) receives a move event to drag the item around the screen */
145
+ DDDraggable.prototype._mouseMove = function (e) {
146
+ var _this = this;
147
+ var _a;
148
+ // console.log(`${count++} move ${e.x},${e.y}`)
149
+ var s = this.mouseDownEvent;
150
+ if (this.dragging) {
151
+ this._dragFollow(e);
152
+ // delay actual grid handling drag until we pause for a while if set
153
+ if (dd_manager_1.DDManager.pauseDrag) {
154
+ var pause = Number.isInteger(dd_manager_1.DDManager.pauseDrag) ? dd_manager_1.DDManager.pauseDrag : 100;
155
+ if (this.dragTimeout)
156
+ window.clearTimeout(this.dragTimeout);
157
+ this.dragTimeout = window.setTimeout(function () { return _this._callDrag(e); }, pause);
158
+ }
159
+ else {
160
+ this._callDrag(e);
161
+ }
162
+ }
163
+ else if (Math.abs(e.x - s.x) + Math.abs(e.y - s.y) > 3) {
164
+ /**
165
+ * don't start unless we've moved at least 3 pixels
166
+ */
167
+ this.dragging = true;
168
+ dd_manager_1.DDManager.dragElement = this;
169
+ // if we're dragging an actual grid item, set the current drop as the grid (to detect enter/leave)
170
+ var grid = (_a = this.el.gridstackNode) === null || _a === void 0 ? void 0 : _a.grid;
171
+ if (grid) {
172
+ dd_manager_1.DDManager.dropElement = grid.el.ddElement.ddDroppable;
173
+ }
174
+ else {
175
+ delete dd_manager_1.DDManager.dropElement;
176
+ }
177
+ this.helper = this._createHelper(e);
178
+ this._setupHelperContainmentStyle();
179
+ this.dragOffset = this._getDragOffset(e, this.el, this.helperContainment);
180
+ var ev = utils_1.Utils.initEvent(e, { target: this.el, type: 'dragstart' });
181
+ this._setupHelperStyle(e);
182
+ if (this.option.start) {
183
+ this.option.start(ev, this.ui());
184
+ }
185
+ this.triggerEvent('dragstart', ev);
186
+ }
187
+ e.preventDefault(); // needed otherwise we get text sweep text selection as we drag around
188
+ return true;
189
+ };
190
+ /** @internal call when the mouse gets released to drop the item at current location */
191
+ DDDraggable.prototype._mouseUp = function (e) {
192
+ var _a;
193
+ document.removeEventListener('mousemove', this._mouseMove, true);
194
+ document.removeEventListener('mouseup', this._mouseUp, true);
195
+ if (dd_touch_1.isTouch) {
196
+ this.dragEl.removeEventListener('touchmove', dd_touch_1.touchmove, true);
197
+ this.dragEl.removeEventListener('touchend', dd_touch_1.touchend, true);
198
+ }
199
+ if (this.dragging) {
200
+ delete this.dragging;
201
+ // reset the drop target if dragging over ourself (already parented, just moving during stop callback below)
202
+ if (((_a = dd_manager_1.DDManager.dropElement) === null || _a === void 0 ? void 0 : _a.el) === this.el.parentElement) {
203
+ delete dd_manager_1.DDManager.dropElement;
204
+ }
205
+ this.helperContainment.style.position = this.parentOriginStylePosition || null;
206
+ if (this.helper === this.el) {
207
+ this._removeHelperStyle();
208
+ }
209
+ else {
210
+ this.helper.remove();
211
+ }
212
+ var ev = utils_1.Utils.initEvent(e, { target: this.el, type: 'dragstop' });
213
+ if (this.option.stop) {
214
+ this.option.stop(ev); // NOTE: destroy() will be called when removing item, so expect NULL ptr after!
215
+ }
216
+ this.triggerEvent('dragstop', ev);
217
+ // call the droppable method to receive the item
218
+ if (dd_manager_1.DDManager.dropElement) {
219
+ dd_manager_1.DDManager.dropElement.drop(e);
220
+ }
221
+ }
222
+ delete this.helper;
223
+ delete this.mouseDownEvent;
224
+ delete dd_manager_1.DDManager.dragElement;
225
+ delete dd_manager_1.DDManager.dropElement;
226
+ delete dd_manager_1.DDManager.mouseHandled;
227
+ e.preventDefault();
228
+ };
229
+ /** @internal create a clone copy (or user defined method) of the original drag item if set */
230
+ DDDraggable.prototype._createHelper = function (event) {
231
+ var _this = this;
232
+ var helper = this.el;
233
+ if (typeof this.option.helper === 'function') {
234
+ helper = this.option.helper(event);
235
+ }
236
+ else if (this.option.helper === 'clone') {
237
+ helper = utils_1.Utils.cloneNode(this.el);
238
+ }
239
+ if (!document.body.contains(helper)) {
240
+ utils_1.Utils.appendTo(helper, this.option.appendTo === 'parent' ? this.el.parentElement : this.option.appendTo);
241
+ }
242
+ if (helper === this.el) {
243
+ this.dragElementOriginStyle = DDDraggable.originStyleProp.map(function (prop) { return _this.el.style[prop]; });
244
+ }
245
+ return helper;
246
+ };
247
+ /** @internal set the fix position of the dragged item */
248
+ DDDraggable.prototype._setupHelperStyle = function (e) {
249
+ var _this = this;
250
+ this.helper.classList.add('ui-draggable-dragging');
251
+ // TODO: set all at once with style.cssText += ... ? https://stackoverflow.com/questions/3968593
252
+ var style = this.helper.style;
253
+ style.pointerEvents = 'none'; // needed for over items to get enter/leave
254
+ // style.cursor = 'move'; // TODO: can't set with pointerEvents=none ! (done in CSS as well)
255
+ style['min-width'] = 0; // since we no longer relative to our parent and we don't resize anyway (normally 100/#column %)
256
+ style.width = this.dragOffset.width + 'px';
257
+ style.height = this.dragOffset.height + 'px';
258
+ style.willChange = 'left, top';
259
+ style.position = 'fixed'; // let us drag between grids by not clipping as parent .grid-stack is position: 'relative'
260
+ this._dragFollow(e); // now position it
261
+ style.transition = 'none'; // show up instantly
262
+ setTimeout(function () {
263
+ if (_this.helper) {
264
+ style.transition = null; // recover animation
265
+ }
266
+ }, 0);
267
+ return this;
268
+ };
269
+ /** @internal restore back the original style before dragging */
270
+ DDDraggable.prototype._removeHelperStyle = function () {
271
+ var _this = this;
272
+ var _a;
273
+ this.helper.classList.remove('ui-draggable-dragging');
274
+ var node = (_a = this.helper) === null || _a === void 0 ? void 0 : _a.gridstackNode;
275
+ // don't bother restoring styles if we're gonna remove anyway...
276
+ if (!(node === null || node === void 0 ? void 0 : node._isAboutToRemove) && this.dragElementOriginStyle) {
277
+ var helper_1 = this.helper;
278
+ // don't animate, otherwise we animate offseted when switching back to 'absolute' from 'fixed'.
279
+ // TODO: this also removes resizing animation which doesn't have this issue, but others.
280
+ // Ideally both would animate ('move' would immediately restore 'absolute' and adjust coordinate to match,
281
+ // then trigger a delay (repaint) to restore to final dest with animate) but then we need to make sure 'resizestop'
282
+ // is called AFTER 'transitionend' event is received (see https://github.com/gridstack/gridstack.js/issues/2033)
283
+ var transition_1 = this.dragElementOriginStyle['transition'] || null;
284
+ helper_1.style.transition = this.dragElementOriginStyle['transition'] = 'none'; // can't be NULL #1973
285
+ DDDraggable.originStyleProp.forEach(function (prop) { return helper_1.style[prop] = _this.dragElementOriginStyle[prop] || null; });
286
+ setTimeout(function () { return helper_1.style.transition = transition_1; }, 50); // recover animation from saved vars after a pause (0 isn't enough #1973)
287
+ }
288
+ delete this.dragElementOriginStyle;
289
+ return this;
290
+ };
291
+ /** @internal updates the top/left position to follow the mouse */
292
+ DDDraggable.prototype._dragFollow = function (e) {
293
+ var containmentRect = { left: 0, top: 0 };
294
+ // if (this.helper.style.position === 'absolute') { // we use 'fixed'
295
+ // const { left, top } = this.helperContainment.getBoundingClientRect();
296
+ // containmentRect = { left, top };
297
+ // }
298
+ var style = this.helper.style;
299
+ var offset = this.dragOffset;
300
+ style.left = e.clientX + offset.offsetLeft - containmentRect.left + 'px';
301
+ style.top = e.clientY + offset.offsetTop - containmentRect.top + 'px';
302
+ };
303
+ /** @internal */
304
+ DDDraggable.prototype._setupHelperContainmentStyle = function () {
305
+ this.helperContainment = this.helper.parentElement;
306
+ if (this.helper.style.position !== 'fixed') {
307
+ this.parentOriginStylePosition = this.helperContainment.style.position;
308
+ if (window.getComputedStyle(this.helperContainment).position.match(/static/)) {
309
+ this.helperContainment.style.position = 'relative';
310
+ }
311
+ }
312
+ return this;
313
+ };
314
+ /** @internal */
315
+ DDDraggable.prototype._getDragOffset = function (event, el, parent) {
316
+ // in case ancestor has transform/perspective css properties that change the viewpoint
317
+ var xformOffsetX = 0;
318
+ var xformOffsetY = 0;
319
+ if (parent) {
320
+ var testEl = document.createElement('div');
321
+ utils_1.Utils.addElStyles(testEl, {
322
+ opacity: '0',
323
+ position: 'fixed',
324
+ top: 0 + 'px',
325
+ left: 0 + 'px',
326
+ width: '1px',
327
+ height: '1px',
328
+ zIndex: '-999999',
329
+ });
330
+ parent.appendChild(testEl);
331
+ var testElPosition = testEl.getBoundingClientRect();
332
+ parent.removeChild(testEl);
333
+ xformOffsetX = testElPosition.left;
334
+ xformOffsetY = testElPosition.top;
335
+ // TODO: scale ?
336
+ }
337
+ var targetOffset = el.getBoundingClientRect();
338
+ return {
339
+ left: targetOffset.left,
340
+ top: targetOffset.top,
341
+ offsetLeft: -event.clientX + targetOffset.left - xformOffsetX,
342
+ offsetTop: -event.clientY + targetOffset.top - xformOffsetY,
343
+ width: targetOffset.width,
344
+ height: targetOffset.height
345
+ };
346
+ };
347
+ /** @internal TODO: set to public as called by DDDroppable! */
348
+ DDDraggable.prototype.ui = function () {
349
+ var containmentEl = this.el.parentElement;
350
+ var containmentRect = containmentEl.getBoundingClientRect();
351
+ var offset = this.helper.getBoundingClientRect();
352
+ return {
353
+ position: {
354
+ top: offset.top - containmentRect.top,
355
+ left: offset.left - containmentRect.left
356
+ }
357
+ /* not used by GridStack for now...
358
+ helper: [this.helper], //The object arr representing the helper that's being dragged.
359
+ offset: { top: offset.top, left: offset.left } // Current offset position of the helper as { top, left } object.
360
+ */
361
+ };
362
+ };
363
+ /** @internal properties we change during dragging, and restore back */
364
+ DDDraggable.originStyleProp = ['transition', 'pointerEvents', 'position', 'left', 'top', 'minWidth', 'willChange'];
365
+ return DDDraggable;
366
+ }(dd_base_impl_1.DDBaseImplement));
368
367
  //# sourceMappingURL=dd-draggable.js.map