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,319 +1,318 @@
1
- "use strict";
2
- /**
3
- * dd-resizable.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.DDResizable = void 0;
21
- var dd_resizable_handle_1 = require("./dd-resizable-handle");
22
- var dd_base_impl_1 = require("./dd-base-impl");
23
- var utils_1 = require("./utils");
24
- var dd_manager_1 = require("./dd-manager");
25
- var DDResizable = /** @class */ (function (_super) {
26
- __extends(DDResizable, _super);
27
- function DDResizable(el, opts) {
28
- if (opts === void 0) { opts = {}; }
29
- var _this = _super.call(this) || this;
30
- /** @internal */
31
- _this._ui = function () {
32
- var containmentEl = _this.el.parentElement;
33
- var containmentRect = containmentEl.getBoundingClientRect();
34
- var newRect = {
35
- width: _this.originalRect.width,
36
- height: _this.originalRect.height + _this.scrolled,
37
- left: _this.originalRect.left,
38
- top: _this.originalRect.top - _this.scrolled
39
- };
40
- var rect = _this.temporalRect || newRect;
41
- return {
42
- position: {
43
- left: rect.left - containmentRect.left,
44
- top: rect.top - containmentRect.top
45
- },
46
- size: {
47
- width: rect.width,
48
- height: rect.height
49
- }
50
- /* Gridstack ONLY needs position set above... keep around in case.
51
- element: [this.el], // The object representing the element to be resized
52
- helper: [], // TODO: not support yet - The object representing the helper that's being resized
53
- originalElement: [this.el],// we don't wrap here, so simplify as this.el //The object representing the original element before it is wrapped
54
- originalPosition: { // The position represented as { left, top } before the resizable is resized
55
- left: this.originalRect.left - containmentRect.left,
56
- top: this.originalRect.top - containmentRect.top
57
- },
58
- originalSize: { // The size represented as { width, height } before the resizable is resized
59
- width: this.originalRect.width,
60
- height: this.originalRect.height
61
- }
62
- */
63
- };
64
- };
65
- _this.el = el;
66
- _this.option = opts;
67
- // create var event binding so we can easily remove and still look like TS methods (unlike anonymous functions)
68
- _this._mouseOver = _this._mouseOver.bind(_this);
69
- _this._mouseOut = _this._mouseOut.bind(_this);
70
- _this.enable();
71
- _this._setupAutoHide(_this.option.autoHide);
72
- _this._setupHandlers();
73
- return _this;
74
- }
75
- DDResizable.prototype.on = function (event, callback) {
76
- _super.prototype.on.call(this, event, callback);
77
- };
78
- DDResizable.prototype.off = function (event) {
79
- _super.prototype.off.call(this, event);
80
- };
81
- DDResizable.prototype.enable = function () {
82
- _super.prototype.enable.call(this);
83
- this.el.classList.add('ui-resizable');
84
- this.el.classList.remove('ui-resizable-disabled');
85
- this._setupAutoHide(this.option.autoHide);
86
- };
87
- DDResizable.prototype.disable = function () {
88
- _super.prototype.disable.call(this);
89
- this.el.classList.add('ui-resizable-disabled');
90
- this.el.classList.remove('ui-resizable');
91
- this._setupAutoHide(false);
92
- };
93
- DDResizable.prototype.destroy = function () {
94
- this._removeHandlers();
95
- this._setupAutoHide(false);
96
- this.el.classList.remove('ui-resizable');
97
- delete this.el;
98
- _super.prototype.destroy.call(this);
99
- };
100
- DDResizable.prototype.updateOption = function (opts) {
101
- var _this = this;
102
- var updateHandles = (opts.handles && opts.handles !== this.option.handles);
103
- var updateAutoHide = (opts.autoHide && opts.autoHide !== this.option.autoHide);
104
- Object.keys(opts).forEach(function (key) { return _this.option[key] = opts[key]; });
105
- if (updateHandles) {
106
- this._removeHandlers();
107
- this._setupHandlers();
108
- }
109
- if (updateAutoHide) {
110
- this._setupAutoHide(this.option.autoHide);
111
- }
112
- return this;
113
- };
114
- /** @internal turns auto hide on/off */
115
- DDResizable.prototype._setupAutoHide = function (auto) {
116
- if (auto) {
117
- this.el.classList.add('ui-resizable-autohide');
118
- // use mouseover and not mouseenter to get better performance and track for nested cases
119
- this.el.addEventListener('mouseover', this._mouseOver);
120
- this.el.addEventListener('mouseout', this._mouseOut);
121
- }
122
- else {
123
- this.el.classList.remove('ui-resizable-autohide');
124
- this.el.removeEventListener('mouseover', this._mouseOver);
125
- this.el.removeEventListener('mouseout', this._mouseOut);
126
- if (dd_manager_1.DDManager.overResizeElement === this) {
127
- delete dd_manager_1.DDManager.overResizeElement;
128
- }
129
- }
130
- return this;
131
- };
132
- /** @internal */
133
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
134
- DDResizable.prototype._mouseOver = function (e) {
135
- // console.log(`${count++} pre-enter ${(this.el as GridItemHTMLElement).gridstackNode._id}`)
136
- // already over a child, ignore. Ideally we just call e.stopPropagation() but see https://github.com/gridstack/gridstack.js/issues/2018
137
- if (dd_manager_1.DDManager.overResizeElement || dd_manager_1.DDManager.dragElement)
138
- return;
139
- dd_manager_1.DDManager.overResizeElement = this;
140
- // console.log(`${count++} enter ${(this.el as GridItemHTMLElement).gridstackNode._id}`)
141
- this.el.classList.remove('ui-resizable-autohide');
142
- };
143
- /** @internal */
144
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
145
- DDResizable.prototype._mouseOut = function (e) {
146
- // console.log(`${count++} pre-leave ${(this.el as GridItemHTMLElement).gridstackNode._id}`)
147
- if (dd_manager_1.DDManager.overResizeElement !== this)
148
- return;
149
- delete dd_manager_1.DDManager.overResizeElement;
150
- // console.log(`${count++} leave ${(this.el as GridItemHTMLElement).gridstackNode._id}`)
151
- this.el.classList.add('ui-resizable-autohide');
152
- };
153
- /** @internal */
154
- DDResizable.prototype._setupHandlers = function () {
155
- var _this = this;
156
- var handlerDirection = this.option.handles || 'e,s,se';
157
- if (handlerDirection === 'all') {
158
- handlerDirection = 'n,e,s,w,se,sw,ne,nw';
159
- }
160
- this.handlers = handlerDirection.split(',')
161
- .map(function (dir) { return dir.trim(); })
162
- .map(function (dir) { return new dd_resizable_handle_1.DDResizableHandle(_this.el, dir, {
163
- start: function (event) {
164
- _this._resizeStart(event);
165
- },
166
- stop: function (event) {
167
- _this._resizeStop(event);
168
- },
169
- move: function (event) {
170
- _this._resizing(event, dir);
171
- }
172
- }); });
173
- return this;
174
- };
175
- /** @internal */
176
- DDResizable.prototype._resizeStart = function (event) {
177
- this.originalRect = this.el.getBoundingClientRect();
178
- this.scrollEl = utils_1.Utils.getScrollElement(this.el);
179
- this.scrollY = this.scrollEl.scrollTop;
180
- this.scrolled = 0;
181
- this.startEvent = event;
182
- this._setupHelper();
183
- this._applyChange();
184
- var ev = utils_1.Utils.initEvent(event, { type: 'resizestart', target: this.el });
185
- if (this.option.start) {
186
- this.option.start(ev, this._ui());
187
- }
188
- this.el.classList.add('ui-resizable-resizing');
189
- this.triggerEvent('resizestart', ev);
190
- return this;
191
- };
192
- /** @internal */
193
- DDResizable.prototype._resizing = function (event, dir) {
194
- this.scrolled = this.scrollEl.scrollTop - this.scrollY;
195
- this.temporalRect = this._getChange(event, dir);
196
- this._applyChange();
197
- var ev = utils_1.Utils.initEvent(event, { type: 'resize', target: this.el });
198
- if (this.option.resize) {
199
- this.option.resize(ev, this._ui());
200
- }
201
- this.triggerEvent('resize', ev);
202
- return this;
203
- };
204
- /** @internal */
205
- DDResizable.prototype._resizeStop = function (event) {
206
- var ev = utils_1.Utils.initEvent(event, { type: 'resizestop', target: this.el });
207
- if (this.option.stop) {
208
- this.option.stop(ev); // Note: ui() not used by gridstack so don't pass
209
- }
210
- this.el.classList.remove('ui-resizable-resizing');
211
- this.triggerEvent('resizestop', ev);
212
- this._cleanHelper();
213
- delete this.startEvent;
214
- delete this.originalRect;
215
- delete this.temporalRect;
216
- delete this.scrollY;
217
- delete this.scrolled;
218
- return this;
219
- };
220
- /** @internal */
221
- DDResizable.prototype._setupHelper = function () {
222
- var _this = this;
223
- this.elOriginStyleVal = DDResizable._originStyleProp.map(function (prop) { return _this.el.style[prop]; });
224
- this.parentOriginStylePosition = this.el.parentElement.style.position;
225
- if (window.getComputedStyle(this.el.parentElement).position.match(/static/)) {
226
- this.el.parentElement.style.position = 'relative';
227
- }
228
- this.el.style.position = 'absolute';
229
- this.el.style.opacity = '0.8';
230
- return this;
231
- };
232
- /** @internal */
233
- DDResizable.prototype._cleanHelper = function () {
234
- var _this = this;
235
- DDResizable._originStyleProp.forEach(function (prop, i) {
236
- _this.el.style[prop] = _this.elOriginStyleVal[i] || null;
237
- });
238
- this.el.parentElement.style.position = this.parentOriginStylePosition || null;
239
- return this;
240
- };
241
- /** @internal */
242
- DDResizable.prototype._getChange = function (event, dir) {
243
- var oEvent = this.startEvent;
244
- var newRect = {
245
- width: this.originalRect.width,
246
- height: this.originalRect.height + this.scrolled,
247
- left: this.originalRect.left,
248
- top: this.originalRect.top - this.scrolled
249
- };
250
- var offsetX = event.clientX - oEvent.clientX;
251
- var offsetY = event.clientY - oEvent.clientY;
252
- if (dir.indexOf('e') > -1) {
253
- newRect.width += offsetX;
254
- }
255
- else if (dir.indexOf('w') > -1) {
256
- newRect.width -= offsetX;
257
- newRect.left += offsetX;
258
- }
259
- if (dir.indexOf('s') > -1) {
260
- newRect.height += offsetY;
261
- }
262
- else if (dir.indexOf('n') > -1) {
263
- newRect.height -= offsetY;
264
- newRect.top += offsetY;
265
- }
266
- var constrain = this._constrainSize(newRect.width, newRect.height);
267
- if (Math.round(newRect.width) !== Math.round(constrain.width)) { // round to ignore slight round-off errors
268
- if (dir.indexOf('w') > -1) {
269
- newRect.left += newRect.width - constrain.width;
270
- }
271
- newRect.width = constrain.width;
272
- }
273
- if (Math.round(newRect.height) !== Math.round(constrain.height)) {
274
- if (dir.indexOf('n') > -1) {
275
- newRect.top += newRect.height - constrain.height;
276
- }
277
- newRect.height = constrain.height;
278
- }
279
- return newRect;
280
- };
281
- /** @internal constrain the size to the set min/max values */
282
- DDResizable.prototype._constrainSize = function (oWidth, oHeight) {
283
- var maxWidth = this.option.maxWidth || Number.MAX_SAFE_INTEGER;
284
- var minWidth = this.option.minWidth || oWidth;
285
- var maxHeight = this.option.maxHeight || Number.MAX_SAFE_INTEGER;
286
- var minHeight = this.option.minHeight || oHeight;
287
- var width = Math.min(maxWidth, Math.max(minWidth, oWidth));
288
- var height = Math.min(maxHeight, Math.max(minHeight, oHeight));
289
- return { width: width, height: height };
290
- };
291
- /** @internal */
292
- DDResizable.prototype._applyChange = function () {
293
- var _this = this;
294
- var containmentRect = { left: 0, top: 0, width: 0, height: 0 };
295
- if (this.el.style.position === 'absolute') {
296
- var containmentEl = this.el.parentElement;
297
- var _a = containmentEl.getBoundingClientRect(), left = _a.left, top_1 = _a.top;
298
- containmentRect = { left: left, top: top_1, width: 0, height: 0 };
299
- }
300
- if (!this.temporalRect)
301
- return this;
302
- Object.keys(this.temporalRect).forEach(function (key) {
303
- var value = _this.temporalRect[key];
304
- _this.el.style[key] = value - containmentRect[key] + 'px';
305
- });
306
- return this;
307
- };
308
- /** @internal */
309
- DDResizable.prototype._removeHandlers = function () {
310
- this.handlers.forEach(function (handle) { return handle.destroy(); });
311
- delete this.handlers;
312
- return this;
313
- };
314
- /** @internal */
315
- DDResizable._originStyleProp = ['width', 'height', 'position', 'left', 'top', 'opacity', 'zIndex'];
316
- return DDResizable;
317
- }(dd_base_impl_1.DDBaseImplement));
318
- exports.DDResizable = DDResizable;
1
+ "use strict";
2
+ /**
3
+ * dd-resizable.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.DDResizable = void 0;
23
+ var dd_resizable_handle_1 = require("./dd-resizable-handle");
24
+ var dd_base_impl_1 = require("./dd-base-impl");
25
+ var utils_1 = require("./utils");
26
+ var dd_manager_1 = require("./dd-manager");
27
+ var DDResizable = exports.DDResizable = /** @class */ (function (_super) {
28
+ __extends(DDResizable, _super);
29
+ function DDResizable(el, opts) {
30
+ if (opts === void 0) { opts = {}; }
31
+ var _this = _super.call(this) || this;
32
+ /** @internal */
33
+ _this._ui = function () {
34
+ var containmentEl = _this.el.parentElement;
35
+ var containmentRect = containmentEl.getBoundingClientRect();
36
+ var newRect = {
37
+ width: _this.originalRect.width,
38
+ height: _this.originalRect.height + _this.scrolled,
39
+ left: _this.originalRect.left,
40
+ top: _this.originalRect.top - _this.scrolled
41
+ };
42
+ var rect = _this.temporalRect || newRect;
43
+ return {
44
+ position: {
45
+ left: rect.left - containmentRect.left,
46
+ top: rect.top - containmentRect.top
47
+ },
48
+ size: {
49
+ width: rect.width,
50
+ height: rect.height
51
+ }
52
+ /* Gridstack ONLY needs position set above... keep around in case.
53
+ element: [this.el], // The object representing the element to be resized
54
+ helper: [], // TODO: not support yet - The object representing the helper that's being resized
55
+ originalElement: [this.el],// we don't wrap here, so simplify as this.el //The object representing the original element before it is wrapped
56
+ originalPosition: { // The position represented as { left, top } before the resizable is resized
57
+ left: this.originalRect.left - containmentRect.left,
58
+ top: this.originalRect.top - containmentRect.top
59
+ },
60
+ originalSize: { // The size represented as { width, height } before the resizable is resized
61
+ width: this.originalRect.width,
62
+ height: this.originalRect.height
63
+ }
64
+ */
65
+ };
66
+ };
67
+ _this.el = el;
68
+ _this.option = opts;
69
+ // create var event binding so we can easily remove and still look like TS methods (unlike anonymous functions)
70
+ _this._mouseOver = _this._mouseOver.bind(_this);
71
+ _this._mouseOut = _this._mouseOut.bind(_this);
72
+ _this.enable();
73
+ _this._setupAutoHide(_this.option.autoHide);
74
+ _this._setupHandlers();
75
+ return _this;
76
+ }
77
+ DDResizable.prototype.on = function (event, callback) {
78
+ _super.prototype.on.call(this, event, callback);
79
+ };
80
+ DDResizable.prototype.off = function (event) {
81
+ _super.prototype.off.call(this, event);
82
+ };
83
+ DDResizable.prototype.enable = function () {
84
+ _super.prototype.enable.call(this);
85
+ this.el.classList.remove('ui-resizable-disabled');
86
+ this._setupAutoHide(this.option.autoHide);
87
+ };
88
+ DDResizable.prototype.disable = function () {
89
+ _super.prototype.disable.call(this);
90
+ this.el.classList.add('ui-resizable-disabled');
91
+ this._setupAutoHide(false);
92
+ };
93
+ DDResizable.prototype.destroy = function () {
94
+ this._removeHandlers();
95
+ this._setupAutoHide(false);
96
+ delete this.el;
97
+ _super.prototype.destroy.call(this);
98
+ };
99
+ DDResizable.prototype.updateOption = function (opts) {
100
+ var _this = this;
101
+ var updateHandles = (opts.handles && opts.handles !== this.option.handles);
102
+ var updateAutoHide = (opts.autoHide && opts.autoHide !== this.option.autoHide);
103
+ Object.keys(opts).forEach(function (key) { return _this.option[key] = opts[key]; });
104
+ if (updateHandles) {
105
+ this._removeHandlers();
106
+ this._setupHandlers();
107
+ }
108
+ if (updateAutoHide) {
109
+ this._setupAutoHide(this.option.autoHide);
110
+ }
111
+ return this;
112
+ };
113
+ /** @internal turns auto hide on/off */
114
+ DDResizable.prototype._setupAutoHide = function (auto) {
115
+ if (auto) {
116
+ this.el.classList.add('ui-resizable-autohide');
117
+ // use mouseover and not mouseenter to get better performance and track for nested cases
118
+ this.el.addEventListener('mouseover', this._mouseOver);
119
+ this.el.addEventListener('mouseout', this._mouseOut);
120
+ }
121
+ else {
122
+ this.el.classList.remove('ui-resizable-autohide');
123
+ this.el.removeEventListener('mouseover', this._mouseOver);
124
+ this.el.removeEventListener('mouseout', this._mouseOut);
125
+ if (dd_manager_1.DDManager.overResizeElement === this) {
126
+ delete dd_manager_1.DDManager.overResizeElement;
127
+ }
128
+ }
129
+ return this;
130
+ };
131
+ /** @internal */
132
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
133
+ DDResizable.prototype._mouseOver = function (e) {
134
+ // console.log(`${count++} pre-enter ${(this.el as GridItemHTMLElement).gridstackNode._id}`)
135
+ // already over a child, ignore. Ideally we just call e.stopPropagation() but see https://github.com/gridstack/gridstack.js/issues/2018
136
+ if (dd_manager_1.DDManager.overResizeElement || dd_manager_1.DDManager.dragElement)
137
+ return;
138
+ dd_manager_1.DDManager.overResizeElement = this;
139
+ // console.log(`${count++} enter ${(this.el as GridItemHTMLElement).gridstackNode._id}`)
140
+ this.el.classList.remove('ui-resizable-autohide');
141
+ };
142
+ /** @internal */
143
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
144
+ DDResizable.prototype._mouseOut = function (e) {
145
+ // console.log(`${count++} pre-leave ${(this.el as GridItemHTMLElement).gridstackNode._id}`)
146
+ if (dd_manager_1.DDManager.overResizeElement !== this)
147
+ return;
148
+ delete dd_manager_1.DDManager.overResizeElement;
149
+ // console.log(`${count++} leave ${(this.el as GridItemHTMLElement).gridstackNode._id}`)
150
+ this.el.classList.add('ui-resizable-autohide');
151
+ };
152
+ /** @internal */
153
+ DDResizable.prototype._setupHandlers = function () {
154
+ var _this = this;
155
+ var handlerDirection = this.option.handles || 'e,s,se';
156
+ if (handlerDirection === 'all') {
157
+ handlerDirection = 'n,e,s,w,se,sw,ne,nw';
158
+ }
159
+ this.handlers = handlerDirection.split(',')
160
+ .map(function (dir) { return dir.trim(); })
161
+ .map(function (dir) { return new dd_resizable_handle_1.DDResizableHandle(_this.el, dir, {
162
+ start: function (event) {
163
+ _this._resizeStart(event);
164
+ },
165
+ stop: function (event) {
166
+ _this._resizeStop(event);
167
+ },
168
+ move: function (event) {
169
+ _this._resizing(event, dir);
170
+ }
171
+ }); });
172
+ return this;
173
+ };
174
+ /** @internal */
175
+ DDResizable.prototype._resizeStart = function (event) {
176
+ this.originalRect = this.el.getBoundingClientRect();
177
+ this.scrollEl = utils_1.Utils.getScrollElement(this.el);
178
+ this.scrollY = this.scrollEl.scrollTop;
179
+ this.scrolled = 0;
180
+ this.startEvent = event;
181
+ this._setupHelper();
182
+ this._applyChange();
183
+ var ev = utils_1.Utils.initEvent(event, { type: 'resizestart', target: this.el });
184
+ if (this.option.start) {
185
+ this.option.start(ev, this._ui());
186
+ }
187
+ this.el.classList.add('ui-resizable-resizing');
188
+ this.triggerEvent('resizestart', ev);
189
+ return this;
190
+ };
191
+ /** @internal */
192
+ DDResizable.prototype._resizing = function (event, dir) {
193
+ this.scrolled = this.scrollEl.scrollTop - this.scrollY;
194
+ this.temporalRect = this._getChange(event, dir);
195
+ this._applyChange();
196
+ var ev = utils_1.Utils.initEvent(event, { type: 'resize', target: this.el });
197
+ if (this.option.resize) {
198
+ this.option.resize(ev, this._ui());
199
+ }
200
+ this.triggerEvent('resize', ev);
201
+ return this;
202
+ };
203
+ /** @internal */
204
+ DDResizable.prototype._resizeStop = function (event) {
205
+ var ev = utils_1.Utils.initEvent(event, { type: 'resizestop', target: this.el });
206
+ if (this.option.stop) {
207
+ this.option.stop(ev); // Note: ui() not used by gridstack so don't pass
208
+ }
209
+ this.el.classList.remove('ui-resizable-resizing');
210
+ this.triggerEvent('resizestop', ev);
211
+ this._cleanHelper();
212
+ delete this.startEvent;
213
+ delete this.originalRect;
214
+ delete this.temporalRect;
215
+ delete this.scrollY;
216
+ delete this.scrolled;
217
+ return this;
218
+ };
219
+ /** @internal */
220
+ DDResizable.prototype._setupHelper = function () {
221
+ var _this = this;
222
+ this.elOriginStyleVal = DDResizable._originStyleProp.map(function (prop) { return _this.el.style[prop]; });
223
+ this.parentOriginStylePosition = this.el.parentElement.style.position;
224
+ if (window.getComputedStyle(this.el.parentElement).position.match(/static/)) {
225
+ this.el.parentElement.style.position = 'relative';
226
+ }
227
+ this.el.style.position = 'absolute';
228
+ this.el.style.opacity = '0.8';
229
+ return this;
230
+ };
231
+ /** @internal */
232
+ DDResizable.prototype._cleanHelper = function () {
233
+ var _this = this;
234
+ DDResizable._originStyleProp.forEach(function (prop, i) {
235
+ _this.el.style[prop] = _this.elOriginStyleVal[i] || null;
236
+ });
237
+ this.el.parentElement.style.position = this.parentOriginStylePosition || null;
238
+ return this;
239
+ };
240
+ /** @internal */
241
+ DDResizable.prototype._getChange = function (event, dir) {
242
+ var oEvent = this.startEvent;
243
+ var newRect = {
244
+ width: this.originalRect.width,
245
+ height: this.originalRect.height + this.scrolled,
246
+ left: this.originalRect.left,
247
+ top: this.originalRect.top - this.scrolled
248
+ };
249
+ var offsetX = event.clientX - oEvent.clientX;
250
+ var offsetY = event.clientY - oEvent.clientY;
251
+ if (dir.indexOf('e') > -1) {
252
+ newRect.width += offsetX;
253
+ }
254
+ else if (dir.indexOf('w') > -1) {
255
+ newRect.width -= offsetX;
256
+ newRect.left += offsetX;
257
+ }
258
+ if (dir.indexOf('s') > -1) {
259
+ newRect.height += offsetY;
260
+ }
261
+ else if (dir.indexOf('n') > -1) {
262
+ newRect.height -= offsetY;
263
+ newRect.top += offsetY;
264
+ }
265
+ var constrain = this._constrainSize(newRect.width, newRect.height);
266
+ if (Math.round(newRect.width) !== Math.round(constrain.width)) { // round to ignore slight round-off errors
267
+ if (dir.indexOf('w') > -1) {
268
+ newRect.left += newRect.width - constrain.width;
269
+ }
270
+ newRect.width = constrain.width;
271
+ }
272
+ if (Math.round(newRect.height) !== Math.round(constrain.height)) {
273
+ if (dir.indexOf('n') > -1) {
274
+ newRect.top += newRect.height - constrain.height;
275
+ }
276
+ newRect.height = constrain.height;
277
+ }
278
+ return newRect;
279
+ };
280
+ /** @internal constrain the size to the set min/max values */
281
+ DDResizable.prototype._constrainSize = function (oWidth, oHeight) {
282
+ var maxWidth = this.option.maxWidth || Number.MAX_SAFE_INTEGER;
283
+ var minWidth = this.option.minWidth || oWidth;
284
+ var maxHeight = this.option.maxHeight || Number.MAX_SAFE_INTEGER;
285
+ var minHeight = this.option.minHeight || oHeight;
286
+ var width = Math.min(maxWidth, Math.max(minWidth, oWidth));
287
+ var height = Math.min(maxHeight, Math.max(minHeight, oHeight));
288
+ return { width: width, height: height };
289
+ };
290
+ /** @internal */
291
+ DDResizable.prototype._applyChange = function () {
292
+ var _a;
293
+ var _this = this;
294
+ var containmentRect = { left: 0, top: 0, width: 0, height: 0 };
295
+ if (this.el.style.position === 'absolute') {
296
+ var containmentEl = this.el.parentElement;
297
+ var left = (_a = containmentEl.getBoundingClientRect(), _a.left), top_1 = _a.top;
298
+ containmentRect = { left: left, top: top_1, width: 0, height: 0 };
299
+ }
300
+ if (!this.temporalRect)
301
+ return this;
302
+ Object.keys(this.temporalRect).forEach(function (key) {
303
+ var value = _this.temporalRect[key];
304
+ _this.el.style[key] = value - containmentRect[key] + 'px';
305
+ });
306
+ return this;
307
+ };
308
+ /** @internal */
309
+ DDResizable.prototype._removeHandlers = function () {
310
+ this.handlers.forEach(function (handle) { return handle.destroy(); });
311
+ delete this.handlers;
312
+ return this;
313
+ };
314
+ /** @internal */
315
+ DDResizable._originStyleProp = ['width', 'height', 'position', 'left', 'top', 'opacity', 'zIndex'];
316
+ return DDResizable;
317
+ }(dd_base_impl_1.DDBaseImplement));
319
318
  //# sourceMappingURL=dd-resizable.js.map