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