gridstack 7.3.0 → 8.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (196) hide show
  1. package/README.md +8 -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 +389 -376
  64. package/dist/es5/gridstack.js +2252 -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 +591 -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 +3 -97
  81. package/dist/gridstack.d.ts +389 -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 +6 -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 +539 -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 +12 -0
  194. package/doc/README.md +15 -1
  195. package/package.json +25 -24
  196. /package/{dist → dist_save}/angular/README.md +0 -0
package/dist/es5/utils.js CHANGED
@@ -1,570 +1,592 @@
1
- "use strict";
2
- /**
3
- * utils.ts 7.3.0
4
- * Copyright (c) 2021 Alain Dumesny - see GridStack root license
5
- */
6
- var __assign = (this && this.__assign) || function () {
7
- __assign = Object.assign || function(t) {
8
- for (var s, i = 1, n = arguments.length; i < n; i++) {
9
- s = arguments[i];
10
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
11
- t[p] = s[p];
12
- }
13
- return t;
14
- };
15
- return __assign.apply(this, arguments);
16
- };
17
- var __spreadArrays = (this && this.__spreadArrays) || function () {
18
- for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
19
- for (var r = Array(s), k = 0, i = 0; i < il; i++)
20
- for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
21
- r[k] = a[j];
22
- return r;
23
- };
24
- Object.defineProperty(exports, "__esModule", { value: true });
25
- exports.Utils = exports.obsoleteAttr = exports.obsoleteOptsDel = exports.obsoleteOpts = exports.obsolete = void 0;
26
- /** checks for obsolete method names */
27
- // eslint-disable-next-line
28
- function obsolete(self, f, oldName, newName, rev) {
29
- var wrapper = function () {
30
- var args = [];
31
- for (var _i = 0; _i < arguments.length; _i++) {
32
- args[_i] = arguments[_i];
33
- }
34
- console.warn('gridstack.js: Function `' + oldName + '` is deprecated in ' + rev + ' and has been replaced ' +
35
- 'with `' + newName + '`. It will be **removed** in a future release');
36
- return f.apply(self, args);
37
- };
38
- wrapper.prototype = f.prototype;
39
- return wrapper;
40
- }
41
- exports.obsolete = obsolete;
42
- /** checks for obsolete grid options (can be used for any fields, but msg is about options) */
43
- function obsoleteOpts(opts, oldName, newName, rev) {
44
- if (opts[oldName] !== undefined) {
45
- opts[newName] = opts[oldName];
46
- console.warn('gridstack.js: Option `' + oldName + '` is deprecated in ' + rev + ' and has been replaced with `' +
47
- newName + '`. It will be **removed** in a future release');
48
- }
49
- }
50
- exports.obsoleteOpts = obsoleteOpts;
51
- /** checks for obsolete grid options which are gone */
52
- function obsoleteOptsDel(opts, oldName, rev, info) {
53
- if (opts[oldName] !== undefined) {
54
- console.warn('gridstack.js: Option `' + oldName + '` is deprecated in ' + rev + info);
55
- }
56
- }
57
- exports.obsoleteOptsDel = obsoleteOptsDel;
58
- /** checks for obsolete Jquery element attributes */
59
- function obsoleteAttr(el, oldName, newName, rev) {
60
- var oldAttr = el.getAttribute(oldName);
61
- if (oldAttr !== null) {
62
- el.setAttribute(newName, oldAttr);
63
- console.warn('gridstack.js: attribute `' + oldName + '`=' + oldAttr + ' is deprecated on this object in ' + rev + ' and has been replaced with `' +
64
- newName + '`. It will be **removed** in a future release');
65
- }
66
- }
67
- exports.obsoleteAttr = obsoleteAttr;
68
- /**
69
- * Utility methods
70
- */
71
- var Utils = /** @class */ (function () {
72
- function Utils() {
73
- }
74
- /** convert a potential selector into actual list of html elements */
75
- Utils.getElements = function (els) {
76
- if (typeof els === 'string') {
77
- var list = document.querySelectorAll(els);
78
- if (!list.length && els[0] !== '.' && els[0] !== '#') {
79
- list = document.querySelectorAll('.' + els);
80
- if (!list.length) {
81
- list = document.querySelectorAll('#' + els);
82
- }
83
- }
84
- return Array.from(list);
85
- }
86
- return [els];
87
- };
88
- /** convert a potential selector into actual single element */
89
- Utils.getElement = function (els) {
90
- if (typeof els === 'string') {
91
- if (!els.length)
92
- return null;
93
- if (els[0] === '#') {
94
- return document.getElementById(els.substring(1));
95
- }
96
- if (els[0] === '.' || els[0] === '[') {
97
- return document.querySelector(els);
98
- }
99
- // if we start with a digit, assume it's an id (error calling querySelector('#1')) as class are not valid CSS
100
- if (!isNaN(+els[0])) { // start with digit
101
- return document.getElementById(els);
102
- }
103
- // finally try string, then id then class
104
- var el = document.querySelector(els);
105
- if (!el) {
106
- el = document.getElementById(els);
107
- }
108
- if (!el) {
109
- el = document.querySelector('.' + els);
110
- }
111
- return el;
112
- }
113
- return els;
114
- };
115
- /** returns true if a and b overlap */
116
- Utils.isIntercepted = function (a, b) {
117
- return !(a.y >= b.y + b.h || a.y + a.h <= b.y || a.x + a.w <= b.x || a.x >= b.x + b.w);
118
- };
119
- /** returns true if a and b touch edges or corners */
120
- Utils.isTouching = function (a, b) {
121
- return Utils.isIntercepted(a, { x: b.x - 0.5, y: b.y - 0.5, w: b.w + 1, h: b.h + 1 });
122
- };
123
- /** returns the area a and b overlap */
124
- Utils.areaIntercept = function (a, b) {
125
- var x0 = (a.x > b.x) ? a.x : b.x;
126
- var x1 = (a.x + a.w < b.x + b.w) ? a.x + a.w : b.x + b.w;
127
- if (x1 <= x0)
128
- return 0; // no overlap
129
- var y0 = (a.y > b.y) ? a.y : b.y;
130
- var y1 = (a.y + a.h < b.y + b.h) ? a.y + a.h : b.y + b.h;
131
- if (y1 <= y0)
132
- return 0; // no overlap
133
- return (x1 - x0) * (y1 - y0);
134
- };
135
- /** returns the area */
136
- Utils.area = function (a) {
137
- return a.w * a.h;
138
- };
139
- /**
140
- * Sorts array of nodes
141
- * @param nodes array to sort
142
- * @param dir 1 for asc, -1 for desc (optional)
143
- * @param width width of the grid. If undefined the width will be calculated automatically (optional).
144
- **/
145
- Utils.sort = function (nodes, dir, column) {
146
- column = column || nodes.reduce(function (col, n) { return Math.max(n.x + n.w, col); }, 0) || 12;
147
- if (dir === -1)
148
- return nodes.sort(function (a, b) { return (b.x + b.y * column) - (a.x + a.y * column); });
149
- else
150
- return nodes.sort(function (b, a) { return (b.x + b.y * column) - (a.x + a.y * column); });
151
- };
152
- /**
153
- * creates a style sheet with style id under given parent
154
- * @param id will set the 'gs-style-id' attribute to that id
155
- * @param parent to insert the stylesheet as first child,
156
- * if none supplied it will be appended to the document head instead.
157
- */
158
- Utils.createStylesheet = function (id, parent, options) {
159
- var style = document.createElement('style');
160
- var nonce = options === null || options === void 0 ? void 0 : options.nonce;
161
- if (nonce)
162
- style.nonce = nonce;
163
- style.setAttribute('type', 'text/css');
164
- style.setAttribute('gs-style-id', id);
165
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
166
- if (style.styleSheet) { // TODO: only CSSImportRule have that and different beast ??
167
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
168
- style.styleSheet.cssText = '';
169
- }
170
- else {
171
- style.appendChild(document.createTextNode('')); // WebKit hack
172
- }
173
- if (!parent) {
174
- // default to head
175
- parent = document.getElementsByTagName('head')[0];
176
- parent.appendChild(style);
177
- }
178
- else {
179
- parent.insertBefore(style, parent.firstChild);
180
- }
181
- return style.sheet;
182
- };
183
- /** removed the given stylesheet id */
184
- Utils.removeStylesheet = function (id) {
185
- var el = document.querySelector('STYLE[gs-style-id=' + id + ']');
186
- if (el && el.parentNode)
187
- el.remove();
188
- };
189
- /** inserts a CSS rule */
190
- Utils.addCSSRule = function (sheet, selector, rules) {
191
- if (typeof sheet.addRule === 'function') {
192
- sheet.addRule(selector, rules);
193
- }
194
- else if (typeof sheet.insertRule === 'function') {
195
- sheet.insertRule(selector + "{" + rules + "}");
196
- }
197
- };
198
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
199
- Utils.toBool = function (v) {
200
- if (typeof v === 'boolean') {
201
- return v;
202
- }
203
- if (typeof v === 'string') {
204
- v = v.toLowerCase();
205
- return !(v === '' || v === 'no' || v === 'false' || v === '0');
206
- }
207
- return Boolean(v);
208
- };
209
- Utils.toNumber = function (value) {
210
- return (value === null || value.length === 0) ? undefined : Number(value);
211
- };
212
- Utils.parseHeight = function (val) {
213
- var h;
214
- var unit = 'px';
215
- if (typeof val === 'string') {
216
- var match = val.match(/^(-[0-9]+\.[0-9]+|[0-9]*\.[0-9]+|-[0-9]+|[0-9]+)(px|em|rem|vh|vw|%)?$/);
217
- if (!match) {
218
- throw new Error('Invalid height');
219
- }
220
- unit = match[2] || 'px';
221
- h = parseFloat(match[1]);
222
- }
223
- else {
224
- h = val;
225
- }
226
- return { h: h, unit: unit };
227
- };
228
- /** copies unset fields in target to use the given default sources values */
229
- // eslint-disable-next-line
230
- Utils.defaults = function (target) {
231
- var _this = this;
232
- var sources = [];
233
- for (var _i = 1; _i < arguments.length; _i++) {
234
- sources[_i - 1] = arguments[_i];
235
- }
236
- sources.forEach(function (source) {
237
- for (var key in source) {
238
- if (!source.hasOwnProperty(key))
239
- return;
240
- if (target[key] === null || target[key] === undefined) {
241
- target[key] = source[key];
242
- }
243
- else if (typeof source[key] === 'object' && typeof target[key] === 'object') {
244
- // property is an object, recursively add it's field over... #1373
245
- _this.defaults(target[key], source[key]);
246
- }
247
- }
248
- });
249
- return target;
250
- };
251
- /** given 2 objects return true if they have the same values. Checks for Object {} having same fields and values (just 1 level down) */
252
- Utils.same = function (a, b) {
253
- if (typeof a !== 'object')
254
- return a == b;
255
- if (typeof a !== typeof b)
256
- return false;
257
- // else we have object, check just 1 level deep for being same things...
258
- if (Object.keys(a).length !== Object.keys(b).length)
259
- return false;
260
- for (var key in a) {
261
- if (a[key] !== b[key])
262
- return false;
263
- }
264
- return true;
265
- };
266
- /** copies over b size & position (GridStackPosition), and optionally min/max as well */
267
- Utils.copyPos = function (a, b, doMinMax) {
268
- if (doMinMax === void 0) { doMinMax = false; }
269
- a.x = b.x;
270
- a.y = b.y;
271
- a.w = b.w;
272
- a.h = b.h;
273
- if (doMinMax) {
274
- if (b.minW)
275
- a.minW = b.minW;
276
- if (b.minH)
277
- a.minH = b.minH;
278
- if (b.maxW)
279
- a.maxW = b.maxW;
280
- if (b.maxH)
281
- a.maxH = b.maxH;
282
- }
283
- return a;
284
- };
285
- /** true if a and b has same size & position */
286
- Utils.samePos = function (a, b) {
287
- return a && b && a.x === b.x && a.y === b.y && a.w === b.w && a.h === b.h;
288
- };
289
- /** removes field from the first object if same as the second objects (like diffing) and internal '_' for saving */
290
- Utils.removeInternalAndSame = function (a, b) {
291
- if (typeof a !== 'object' || typeof b !== 'object')
292
- return;
293
- for (var key in a) {
294
- var val = a[key];
295
- if (key[0] === '_' || val === b[key]) {
296
- delete a[key];
297
- }
298
- else if (val && typeof val === 'object' && b[key] !== undefined) {
299
- for (var i in val) {
300
- if (val[i] === b[key][i] || i[0] === '_') {
301
- delete val[i];
302
- }
303
- }
304
- if (!Object.keys(val).length) {
305
- delete a[key];
306
- }
307
- }
308
- }
309
- };
310
- /** removes internal fields '_' and default values for saving */
311
- Utils.removeInternalForSave = function (n, removeEl) {
312
- if (removeEl === void 0) { removeEl = true; }
313
- for (var key in n) {
314
- if (key[0] === '_' || n[key] === null || n[key] === undefined)
315
- delete n[key];
316
- }
317
- delete n.grid;
318
- if (removeEl)
319
- delete n.el;
320
- // delete default values (will be re-created on read)
321
- if (!n.autoPosition)
322
- delete n.autoPosition;
323
- if (!n.noResize)
324
- delete n.noResize;
325
- if (!n.noMove)
326
- delete n.noMove;
327
- if (!n.locked)
328
- delete n.locked;
329
- if (n.w === 1 || n.w === n.minW)
330
- delete n.w;
331
- if (n.h === 1 || n.h === n.minH)
332
- delete n.h;
333
- };
334
- /** return the closest parent (or itself) matching the given class */
335
- Utils.closestUpByClass = function (el, name) {
336
- while (el) {
337
- if (el.classList.contains(name))
338
- return el;
339
- el = el.parentElement;
340
- }
341
- return null;
342
- };
343
- /** delay calling the given function for given delay, preventing new calls from happening while waiting */
344
- Utils.throttle = function (func, delay) {
345
- var isWaiting = false;
346
- return function () {
347
- var args = [];
348
- for (var _i = 0; _i < arguments.length; _i++) {
349
- args[_i] = arguments[_i];
350
- }
351
- if (!isWaiting) {
352
- isWaiting = true;
353
- setTimeout(function () { func.apply(void 0, args); isWaiting = false; }, delay);
354
- }
355
- };
356
- };
357
- Utils.removePositioningStyles = function (el) {
358
- var style = el.style;
359
- if (style.position) {
360
- style.removeProperty('position');
361
- }
362
- if (style.left) {
363
- style.removeProperty('left');
364
- }
365
- if (style.top) {
366
- style.removeProperty('top');
367
- }
368
- if (style.width) {
369
- style.removeProperty('width');
370
- }
371
- if (style.height) {
372
- style.removeProperty('height');
373
- }
374
- };
375
- /** @internal returns the passed element if scrollable, else the closest parent that will, up to the entire document scrolling element */
376
- Utils.getScrollElement = function (el) {
377
- if (!el)
378
- return document.scrollingElement || document.documentElement; // IE support
379
- var style = getComputedStyle(el);
380
- var overflowRegex = /(auto|scroll)/;
381
- if (overflowRegex.test(style.overflow + style.overflowY)) {
382
- return el;
383
- }
384
- else {
385
- return this.getScrollElement(el.parentElement);
386
- }
387
- };
388
- /** @internal */
389
- Utils.updateScrollPosition = function (el, position, distance) {
390
- // is widget in view?
391
- var rect = el.getBoundingClientRect();
392
- var innerHeightOrClientHeight = (window.innerHeight || document.documentElement.clientHeight);
393
- if (rect.top < 0 ||
394
- rect.bottom > innerHeightOrClientHeight) {
395
- // set scrollTop of first parent that scrolls
396
- // if parent is larger than el, set as low as possible
397
- // to get entire widget on screen
398
- var offsetDiffDown = rect.bottom - innerHeightOrClientHeight;
399
- var offsetDiffUp = rect.top;
400
- var scrollEl = this.getScrollElement(el);
401
- if (scrollEl !== null) {
402
- var prevScroll = scrollEl.scrollTop;
403
- if (rect.top < 0 && distance < 0) {
404
- // moving up
405
- if (el.offsetHeight > innerHeightOrClientHeight) {
406
- scrollEl.scrollTop += distance;
407
- }
408
- else {
409
- scrollEl.scrollTop += Math.abs(offsetDiffUp) > Math.abs(distance) ? distance : offsetDiffUp;
410
- }
411
- }
412
- else if (distance > 0) {
413
- // moving down
414
- if (el.offsetHeight > innerHeightOrClientHeight) {
415
- scrollEl.scrollTop += distance;
416
- }
417
- else {
418
- scrollEl.scrollTop += offsetDiffDown > distance ? distance : offsetDiffDown;
419
- }
420
- }
421
- // move widget y by amount scrolled
422
- position.top += scrollEl.scrollTop - prevScroll;
423
- }
424
- }
425
- };
426
- /**
427
- * @internal Function used to scroll the page.
428
- *
429
- * @param event `MouseEvent` that triggers the resize
430
- * @param el `HTMLElement` that's being resized
431
- * @param distance Distance from the V edges to start scrolling
432
- */
433
- Utils.updateScrollResize = function (event, el, distance) {
434
- var scrollEl = this.getScrollElement(el);
435
- var height = scrollEl.clientHeight;
436
- // #1727 event.clientY is relative to viewport, so must compare this against position of scrollEl getBoundingClientRect().top
437
- // #1745 Special situation if scrollEl is document 'html': here browser spec states that
438
- // clientHeight is height of viewport, but getBoundingClientRect() is rectangle of html element;
439
- // this discrepancy arises because in reality scrollbar is attached to viewport, not html element itself.
440
- var offsetTop = (scrollEl === this.getScrollElement()) ? 0 : scrollEl.getBoundingClientRect().top;
441
- var pointerPosY = event.clientY - offsetTop;
442
- var top = pointerPosY < distance;
443
- var bottom = pointerPosY > height - distance;
444
- if (top) {
445
- // This also can be done with a timeout to keep scrolling while the mouse is
446
- // in the scrolling zone. (will have smoother behavior)
447
- scrollEl.scrollBy({ behavior: 'smooth', top: pointerPosY - distance });
448
- }
449
- else if (bottom) {
450
- scrollEl.scrollBy({ behavior: 'smooth', top: distance - (height - pointerPosY) });
451
- }
452
- };
453
- /** single level clone, returning a new object with same top fields. This will share sub objects and arrays */
454
- Utils.clone = function (obj) {
455
- if (obj === null || obj === undefined || typeof (obj) !== 'object') {
456
- return obj;
457
- }
458
- // return Object.assign({}, obj);
459
- if (obj instanceof Array) {
460
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
461
- return __spreadArrays(obj);
462
- }
463
- return __assign({}, obj);
464
- };
465
- /**
466
- * Recursive clone version that returns a full copy, checking for nested objects and arrays ONLY.
467
- * Note: this will use as-is any key starting with double __ (and not copy inside) some lib have circular dependencies.
468
- */
469
- Utils.cloneDeep = function (obj) {
470
- // list of fields we will skip during cloneDeep (nested objects, other internal)
471
- var skipFields = ['parentGrid', 'el', 'grid', 'subGrid', 'engine'];
472
- // return JSON.parse(JSON.stringify(obj)); // doesn't work with date format ?
473
- var ret = Utils.clone(obj);
474
- var _loop_1 = function (key) {
475
- // NOTE: we don't support function/circular dependencies so skip those properties for now...
476
- if (ret.hasOwnProperty(key) && typeof (ret[key]) === 'object' && key.substring(0, 2) !== '__' && !skipFields.find(function (k) { return k === key; })) {
477
- ret[key] = Utils.cloneDeep(obj[key]);
478
- }
479
- };
480
- for (var key in ret) {
481
- _loop_1(key);
482
- }
483
- return ret;
484
- };
485
- /** deep clone the given HTML node, removing teh unique id field */
486
- Utils.cloneNode = function (el) {
487
- var node = el.cloneNode(true);
488
- node.removeAttribute('id');
489
- return node;
490
- };
491
- Utils.appendTo = function (el, parent) {
492
- var parentNode;
493
- if (typeof parent === 'string') {
494
- parentNode = document.querySelector(parent);
495
- }
496
- else {
497
- parentNode = parent;
498
- }
499
- if (parentNode) {
500
- parentNode.appendChild(el);
501
- }
502
- };
503
- // public static setPositionRelative(el: HTMLElement): void {
504
- // if (!(/^(?:r|a|f)/).test(window.getComputedStyle(el).position)) {
505
- // el.style.position = "relative";
506
- // }
507
- // }
508
- Utils.addElStyles = function (el, styles) {
509
- if (styles instanceof Object) {
510
- var _loop_2 = function (s) {
511
- if (styles.hasOwnProperty(s)) {
512
- if (Array.isArray(styles[s])) {
513
- // support fallback value
514
- styles[s].forEach(function (val) {
515
- el.style[s] = val;
516
- });
517
- }
518
- else {
519
- el.style[s] = styles[s];
520
- }
521
- }
522
- };
523
- for (var s in styles) {
524
- _loop_2(s);
525
- }
526
- }
527
- };
528
- Utils.initEvent = function (e, info) {
529
- var evt = { type: info.type };
530
- var obj = {
531
- button: 0,
532
- which: 0,
533
- buttons: 1,
534
- bubbles: true,
535
- cancelable: true,
536
- target: info.target ? info.target : e.target
537
- };
538
- // don't check for `instanceof DragEvent` as Safari use MouseEvent #1540
539
- if (e.dataTransfer) {
540
- evt['dataTransfer'] = e.dataTransfer; // workaround 'readonly' field.
541
- }
542
- ['altKey', 'ctrlKey', 'metaKey', 'shiftKey'].forEach(function (p) { return evt[p] = e[p]; }); // keys
543
- ['pageX', 'pageY', 'clientX', 'clientY', 'screenX', 'screenY'].forEach(function (p) { return evt[p] = e[p]; }); // point info
544
- return __assign(__assign({}, evt), obj);
545
- };
546
- /** copies the MouseEvent properties and sends it as another event to the given target */
547
- Utils.simulateMouseEvent = function (e, simulatedType, target) {
548
- var simulatedEvent = document.createEvent('MouseEvents');
549
- simulatedEvent.initMouseEvent(simulatedType, // type
550
- true, // bubbles
551
- true, // cancelable
552
- window, // view
553
- 1, // detail
554
- e.screenX, // screenX
555
- e.screenY, // screenY
556
- e.clientX, // clientX
557
- e.clientY, // clientY
558
- e.ctrlKey, // ctrlKey
559
- e.altKey, // altKey
560
- e.shiftKey, // shiftKey
561
- e.metaKey, // metaKey
562
- 0, // button
563
- e.target // relatedTarget
564
- );
565
- (target || e.target).dispatchEvent(simulatedEvent);
566
- };
567
- return Utils;
568
- }());
569
- exports.Utils = Utils;
1
+ "use strict";
2
+ /**
3
+ * utils.ts 8.0.0
4
+ * Copyright (c) 2021 Alain Dumesny - see GridStack root license
5
+ */
6
+ var __assign = (this && this.__assign) || function () {
7
+ __assign = Object.assign || function(t) {
8
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
9
+ s = arguments[i];
10
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
11
+ t[p] = s[p];
12
+ }
13
+ return t;
14
+ };
15
+ return __assign.apply(this, arguments);
16
+ };
17
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
18
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
19
+ if (ar || !(i in from)) {
20
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
21
+ ar[i] = from[i];
22
+ }
23
+ }
24
+ return to.concat(ar || Array.prototype.slice.call(from));
25
+ };
26
+ Object.defineProperty(exports, "__esModule", { value: true });
27
+ exports.Utils = exports.obsoleteAttr = exports.obsoleteOptsDel = exports.obsoleteOpts = exports.obsolete = void 0;
28
+ /** checks for obsolete method names */
29
+ // eslint-disable-next-line
30
+ function obsolete(self, f, oldName, newName, rev) {
31
+ var wrapper = function () {
32
+ var args = [];
33
+ for (var _i = 0; _i < arguments.length; _i++) {
34
+ args[_i] = arguments[_i];
35
+ }
36
+ console.warn('gridstack.js: Function `' + oldName + '` is deprecated in ' + rev + ' and has been replaced ' +
37
+ 'with `' + newName + '`. It will be **removed** in a future release');
38
+ return f.apply(self, args);
39
+ };
40
+ wrapper.prototype = f.prototype;
41
+ return wrapper;
42
+ }
43
+ exports.obsolete = obsolete;
44
+ /** checks for obsolete grid options (can be used for any fields, but msg is about options) */
45
+ function obsoleteOpts(opts, oldName, newName, rev) {
46
+ if (opts[oldName] !== undefined) {
47
+ opts[newName] = opts[oldName];
48
+ console.warn('gridstack.js: Option `' + oldName + '` is deprecated in ' + rev + ' and has been replaced with `' +
49
+ newName + '`. It will be **removed** in a future release');
50
+ }
51
+ }
52
+ exports.obsoleteOpts = obsoleteOpts;
53
+ /** checks for obsolete grid options which are gone */
54
+ function obsoleteOptsDel(opts, oldName, rev, info) {
55
+ if (opts[oldName] !== undefined) {
56
+ console.warn('gridstack.js: Option `' + oldName + '` is deprecated in ' + rev + info);
57
+ }
58
+ }
59
+ exports.obsoleteOptsDel = obsoleteOptsDel;
60
+ /** checks for obsolete Jquery element attributes */
61
+ function obsoleteAttr(el, oldName, newName, rev) {
62
+ var oldAttr = el.getAttribute(oldName);
63
+ if (oldAttr !== null) {
64
+ el.setAttribute(newName, oldAttr);
65
+ console.warn('gridstack.js: attribute `' + oldName + '`=' + oldAttr + ' is deprecated on this object in ' + rev + ' and has been replaced with `' +
66
+ newName + '`. It will be **removed** in a future release');
67
+ }
68
+ }
69
+ exports.obsoleteAttr = obsoleteAttr;
70
+ /**
71
+ * Utility methods
72
+ */
73
+ var Utils = /** @class */ (function () {
74
+ function Utils() {
75
+ }
76
+ /** convert a potential selector into actual list of html elements */
77
+ Utils.getElements = function (els) {
78
+ if (typeof els === 'string') {
79
+ var list = document.querySelectorAll(els);
80
+ if (!list.length && els[0] !== '.' && els[0] !== '#') {
81
+ list = document.querySelectorAll('.' + els);
82
+ if (!list.length) {
83
+ list = document.querySelectorAll('#' + els);
84
+ }
85
+ }
86
+ return Array.from(list);
87
+ }
88
+ return [els];
89
+ };
90
+ /** convert a potential selector into actual single element */
91
+ Utils.getElement = function (els) {
92
+ if (typeof els === 'string') {
93
+ if (!els.length)
94
+ return null;
95
+ if (els[0] === '#') {
96
+ return document.getElementById(els.substring(1));
97
+ }
98
+ if (els[0] === '.' || els[0] === '[') {
99
+ return document.querySelector(els);
100
+ }
101
+ // if we start with a digit, assume it's an id (error calling querySelector('#1')) as class are not valid CSS
102
+ if (!isNaN(+els[0])) { // start with digit
103
+ return document.getElementById(els);
104
+ }
105
+ // finally try string, then id then class
106
+ var el = document.querySelector(els);
107
+ if (!el) {
108
+ el = document.getElementById(els);
109
+ }
110
+ if (!el) {
111
+ el = document.querySelector('.' + els);
112
+ }
113
+ return el;
114
+ }
115
+ return els;
116
+ };
117
+ /** returns true if a and b overlap */
118
+ Utils.isIntercepted = function (a, b) {
119
+ return !(a.y >= b.y + b.h || a.y + a.h <= b.y || a.x + a.w <= b.x || a.x >= b.x + b.w);
120
+ };
121
+ /** returns true if a and b touch edges or corners */
122
+ Utils.isTouching = function (a, b) {
123
+ return Utils.isIntercepted(a, { x: b.x - 0.5, y: b.y - 0.5, w: b.w + 1, h: b.h + 1 });
124
+ };
125
+ /** returns the area a and b overlap */
126
+ Utils.areaIntercept = function (a, b) {
127
+ var x0 = (a.x > b.x) ? a.x : b.x;
128
+ var x1 = (a.x + a.w < b.x + b.w) ? a.x + a.w : b.x + b.w;
129
+ if (x1 <= x0)
130
+ return 0; // no overlap
131
+ var y0 = (a.y > b.y) ? a.y : b.y;
132
+ var y1 = (a.y + a.h < b.y + b.h) ? a.y + a.h : b.y + b.h;
133
+ if (y1 <= y0)
134
+ return 0; // no overlap
135
+ return (x1 - x0) * (y1 - y0);
136
+ };
137
+ /** returns the area */
138
+ Utils.area = function (a) {
139
+ return a.w * a.h;
140
+ };
141
+ /**
142
+ * Sorts array of nodes
143
+ * @param nodes array to sort
144
+ * @param dir 1 for asc, -1 for desc (optional)
145
+ * @param width width of the grid. If undefined the width will be calculated automatically (optional).
146
+ **/
147
+ Utils.sort = function (nodes, dir, column) {
148
+ column = column || nodes.reduce(function (col, n) { return Math.max(n.x + n.w, col); }, 0) || 12;
149
+ if (dir === -1)
150
+ return nodes.sort(function (a, b) { return (b.x + b.y * column) - (a.x + a.y * column); });
151
+ else
152
+ return nodes.sort(function (b, a) { return (b.x + b.y * column) - (a.x + a.y * column); });
153
+ };
154
+ /**
155
+ * creates a style sheet with style id under given parent
156
+ * @param id will set the 'gs-style-id' attribute to that id
157
+ * @param parent to insert the stylesheet as first child,
158
+ * if none supplied it will be appended to the document head instead.
159
+ */
160
+ Utils.createStylesheet = function (id, parent, options) {
161
+ var style = document.createElement('style');
162
+ var nonce = options === null || options === void 0 ? void 0 : options.nonce;
163
+ if (nonce)
164
+ style.nonce = nonce;
165
+ style.setAttribute('type', 'text/css');
166
+ style.setAttribute('gs-style-id', id);
167
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
168
+ if (style.styleSheet) { // TODO: only CSSImportRule have that and different beast ??
169
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
170
+ style.styleSheet.cssText = '';
171
+ }
172
+ else {
173
+ style.appendChild(document.createTextNode('')); // WebKit hack
174
+ }
175
+ if (!parent) {
176
+ // default to head
177
+ parent = document.getElementsByTagName('head')[0];
178
+ parent.appendChild(style);
179
+ }
180
+ else {
181
+ parent.insertBefore(style, parent.firstChild);
182
+ }
183
+ return style.sheet;
184
+ };
185
+ /** removed the given stylesheet id */
186
+ Utils.removeStylesheet = function (id) {
187
+ var el = document.querySelector('STYLE[gs-style-id=' + id + ']');
188
+ if (el && el.parentNode)
189
+ el.remove();
190
+ };
191
+ /** inserts a CSS rule */
192
+ Utils.addCSSRule = function (sheet, selector, rules) {
193
+ if (typeof sheet.addRule === 'function') {
194
+ sheet.addRule(selector, rules);
195
+ }
196
+ else if (typeof sheet.insertRule === 'function') {
197
+ sheet.insertRule("".concat(selector, "{").concat(rules, "}"));
198
+ }
199
+ };
200
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
201
+ Utils.toBool = function (v) {
202
+ if (typeof v === 'boolean') {
203
+ return v;
204
+ }
205
+ if (typeof v === 'string') {
206
+ v = v.toLowerCase();
207
+ return !(v === '' || v === 'no' || v === 'false' || v === '0');
208
+ }
209
+ return Boolean(v);
210
+ };
211
+ Utils.toNumber = function (value) {
212
+ return (value === null || value.length === 0) ? undefined : Number(value);
213
+ };
214
+ Utils.parseHeight = function (val) {
215
+ var h;
216
+ var unit = 'px';
217
+ if (typeof val === 'string') {
218
+ var match = val.match(/^(-[0-9]+\.[0-9]+|[0-9]*\.[0-9]+|-[0-9]+|[0-9]+)(px|em|rem|vh|vw|%)?$/);
219
+ if (!match) {
220
+ throw new Error('Invalid height');
221
+ }
222
+ unit = match[2] || 'px';
223
+ h = parseFloat(match[1]);
224
+ }
225
+ else {
226
+ h = val;
227
+ }
228
+ return { h: h, unit: unit };
229
+ };
230
+ /** copies unset fields in target to use the given default sources values */
231
+ // eslint-disable-next-line
232
+ Utils.defaults = function (target) {
233
+ var _this = this;
234
+ var sources = [];
235
+ for (var _i = 1; _i < arguments.length; _i++) {
236
+ sources[_i - 1] = arguments[_i];
237
+ }
238
+ sources.forEach(function (source) {
239
+ for (var key in source) {
240
+ if (!source.hasOwnProperty(key))
241
+ return;
242
+ if (target[key] === null || target[key] === undefined) {
243
+ target[key] = source[key];
244
+ }
245
+ else if (typeof source[key] === 'object' && typeof target[key] === 'object') {
246
+ // property is an object, recursively add it's field over... #1373
247
+ _this.defaults(target[key], source[key]);
248
+ }
249
+ }
250
+ });
251
+ return target;
252
+ };
253
+ /** given 2 objects return true if they have the same values. Checks for Object {} having same fields and values (just 1 level down) */
254
+ Utils.same = function (a, b) {
255
+ if (typeof a !== 'object')
256
+ return a == b;
257
+ if (typeof a !== typeof b)
258
+ return false;
259
+ // else we have object, check just 1 level deep for being same things...
260
+ if (Object.keys(a).length !== Object.keys(b).length)
261
+ return false;
262
+ for (var key in a) {
263
+ if (a[key] !== b[key])
264
+ return false;
265
+ }
266
+ return true;
267
+ };
268
+ /** copies over b size & position (GridStackPosition), and optionally min/max as well */
269
+ Utils.copyPos = function (a, b, doMinMax) {
270
+ if (doMinMax === void 0) { doMinMax = false; }
271
+ if (b.x !== undefined)
272
+ a.x = b.x;
273
+ if (b.y !== undefined)
274
+ a.y = b.y;
275
+ if (b.w !== undefined)
276
+ a.w = b.w;
277
+ if (b.h !== undefined)
278
+ a.h = b.h;
279
+ if (doMinMax) {
280
+ if (b.minW)
281
+ a.minW = b.minW;
282
+ if (b.minH)
283
+ a.minH = b.minH;
284
+ if (b.maxW)
285
+ a.maxW = b.maxW;
286
+ if (b.maxH)
287
+ a.maxH = b.maxH;
288
+ }
289
+ return a;
290
+ };
291
+ /** true if a and b has same size & position */
292
+ Utils.samePos = function (a, b) {
293
+ return a && b && a.x === b.x && a.y === b.y && a.w === b.w && a.h === b.h;
294
+ };
295
+ /** given a node, makes sure it's min/max are valid */
296
+ Utils.sanitizeMinMax = function (node) {
297
+ // remove 0, undefine, null
298
+ if (!node.minW) {
299
+ delete node.minW;
300
+ }
301
+ if (!node.minH) {
302
+ delete node.minH;
303
+ }
304
+ if (!node.maxW) {
305
+ delete node.maxW;
306
+ }
307
+ if (!node.maxH) {
308
+ delete node.maxH;
309
+ }
310
+ };
311
+ /** removes field from the first object if same as the second objects (like diffing) and internal '_' for saving */
312
+ Utils.removeInternalAndSame = function (a, b) {
313
+ if (typeof a !== 'object' || typeof b !== 'object')
314
+ return;
315
+ for (var key in a) {
316
+ var val = a[key];
317
+ if (key[0] === '_' || val === b[key]) {
318
+ delete a[key];
319
+ }
320
+ else if (val && typeof val === 'object' && b[key] !== undefined) {
321
+ for (var i in val) {
322
+ if (val[i] === b[key][i] || i[0] === '_') {
323
+ delete val[i];
324
+ }
325
+ }
326
+ if (!Object.keys(val).length) {
327
+ delete a[key];
328
+ }
329
+ }
330
+ }
331
+ };
332
+ /** removes internal fields '_' and default values for saving */
333
+ Utils.removeInternalForSave = function (n, removeEl) {
334
+ if (removeEl === void 0) { removeEl = true; }
335
+ for (var key in n) {
336
+ if (key[0] === '_' || n[key] === null || n[key] === undefined)
337
+ delete n[key];
338
+ }
339
+ delete n.grid;
340
+ if (removeEl)
341
+ delete n.el;
342
+ // delete default values (will be re-created on read)
343
+ if (!n.autoPosition)
344
+ delete n.autoPosition;
345
+ if (!n.noResize)
346
+ delete n.noResize;
347
+ if (!n.noMove)
348
+ delete n.noMove;
349
+ if (!n.locked)
350
+ delete n.locked;
351
+ if (n.w === 1 || n.w === n.minW)
352
+ delete n.w;
353
+ if (n.h === 1 || n.h === n.minH)
354
+ delete n.h;
355
+ };
356
+ /** return the closest parent (or itself) matching the given class */
357
+ Utils.closestUpByClass = function (el, name) {
358
+ while (el) {
359
+ if (el.classList.contains(name))
360
+ return el;
361
+ el = el.parentElement;
362
+ }
363
+ return null;
364
+ };
365
+ /** delay calling the given function for given delay, preventing new calls from happening while waiting */
366
+ Utils.throttle = function (func, delay) {
367
+ var isWaiting = false;
368
+ return function () {
369
+ var args = [];
370
+ for (var _i = 0; _i < arguments.length; _i++) {
371
+ args[_i] = arguments[_i];
372
+ }
373
+ if (!isWaiting) {
374
+ isWaiting = true;
375
+ setTimeout(function () { func.apply(void 0, args); isWaiting = false; }, delay);
376
+ }
377
+ };
378
+ };
379
+ Utils.removePositioningStyles = function (el) {
380
+ var style = el.style;
381
+ if (style.position) {
382
+ style.removeProperty('position');
383
+ }
384
+ if (style.left) {
385
+ style.removeProperty('left');
386
+ }
387
+ if (style.top) {
388
+ style.removeProperty('top');
389
+ }
390
+ if (style.width) {
391
+ style.removeProperty('width');
392
+ }
393
+ if (style.height) {
394
+ style.removeProperty('height');
395
+ }
396
+ };
397
+ /** @internal returns the passed element if scrollable, else the closest parent that will, up to the entire document scrolling element */
398
+ Utils.getScrollElement = function (el) {
399
+ if (!el)
400
+ return document.scrollingElement || document.documentElement; // IE support
401
+ var style = getComputedStyle(el);
402
+ var overflowRegex = /(auto|scroll)/;
403
+ if (overflowRegex.test(style.overflow + style.overflowY)) {
404
+ return el;
405
+ }
406
+ else {
407
+ return this.getScrollElement(el.parentElement);
408
+ }
409
+ };
410
+ /** @internal */
411
+ Utils.updateScrollPosition = function (el, position, distance) {
412
+ // is widget in view?
413
+ var rect = el.getBoundingClientRect();
414
+ var innerHeightOrClientHeight = (window.innerHeight || document.documentElement.clientHeight);
415
+ if (rect.top < 0 ||
416
+ rect.bottom > innerHeightOrClientHeight) {
417
+ // set scrollTop of first parent that scrolls
418
+ // if parent is larger than el, set as low as possible
419
+ // to get entire widget on screen
420
+ var offsetDiffDown = rect.bottom - innerHeightOrClientHeight;
421
+ var offsetDiffUp = rect.top;
422
+ var scrollEl = this.getScrollElement(el);
423
+ if (scrollEl !== null) {
424
+ var prevScroll = scrollEl.scrollTop;
425
+ if (rect.top < 0 && distance < 0) {
426
+ // moving up
427
+ if (el.offsetHeight > innerHeightOrClientHeight) {
428
+ scrollEl.scrollTop += distance;
429
+ }
430
+ else {
431
+ scrollEl.scrollTop += Math.abs(offsetDiffUp) > Math.abs(distance) ? distance : offsetDiffUp;
432
+ }
433
+ }
434
+ else if (distance > 0) {
435
+ // moving down
436
+ if (el.offsetHeight > innerHeightOrClientHeight) {
437
+ scrollEl.scrollTop += distance;
438
+ }
439
+ else {
440
+ scrollEl.scrollTop += offsetDiffDown > distance ? distance : offsetDiffDown;
441
+ }
442
+ }
443
+ // move widget y by amount scrolled
444
+ position.top += scrollEl.scrollTop - prevScroll;
445
+ }
446
+ }
447
+ };
448
+ /**
449
+ * @internal Function used to scroll the page.
450
+ *
451
+ * @param event `MouseEvent` that triggers the resize
452
+ * @param el `HTMLElement` that's being resized
453
+ * @param distance Distance from the V edges to start scrolling
454
+ */
455
+ Utils.updateScrollResize = function (event, el, distance) {
456
+ var scrollEl = this.getScrollElement(el);
457
+ var height = scrollEl.clientHeight;
458
+ // #1727 event.clientY is relative to viewport, so must compare this against position of scrollEl getBoundingClientRect().top
459
+ // #1745 Special situation if scrollEl is document 'html': here browser spec states that
460
+ // clientHeight is height of viewport, but getBoundingClientRect() is rectangle of html element;
461
+ // this discrepancy arises because in reality scrollbar is attached to viewport, not html element itself.
462
+ var offsetTop = (scrollEl === this.getScrollElement()) ? 0 : scrollEl.getBoundingClientRect().top;
463
+ var pointerPosY = event.clientY - offsetTop;
464
+ var top = pointerPosY < distance;
465
+ var bottom = pointerPosY > height - distance;
466
+ if (top) {
467
+ // This also can be done with a timeout to keep scrolling while the mouse is
468
+ // in the scrolling zone. (will have smoother behavior)
469
+ scrollEl.scrollBy({ behavior: 'smooth', top: pointerPosY - distance });
470
+ }
471
+ else if (bottom) {
472
+ scrollEl.scrollBy({ behavior: 'smooth', top: distance - (height - pointerPosY) });
473
+ }
474
+ };
475
+ /** single level clone, returning a new object with same top fields. This will share sub objects and arrays */
476
+ Utils.clone = function (obj) {
477
+ if (obj === null || obj === undefined || typeof (obj) !== 'object') {
478
+ return obj;
479
+ }
480
+ // return Object.assign({}, obj);
481
+ if (obj instanceof Array) {
482
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
483
+ return __spreadArray([], obj, true);
484
+ }
485
+ return __assign({}, obj);
486
+ };
487
+ /**
488
+ * Recursive clone version that returns a full copy, checking for nested objects and arrays ONLY.
489
+ * Note: this will use as-is any key starting with double __ (and not copy inside) some lib have circular dependencies.
490
+ */
491
+ Utils.cloneDeep = function (obj) {
492
+ // list of fields we will skip during cloneDeep (nested objects, other internal)
493
+ var skipFields = ['parentGrid', 'el', 'grid', 'subGrid', 'engine'];
494
+ // return JSON.parse(JSON.stringify(obj)); // doesn't work with date format ?
495
+ var ret = Utils.clone(obj);
496
+ var _loop_1 = function (key) {
497
+ // NOTE: we don't support function/circular dependencies so skip those properties for now...
498
+ if (ret.hasOwnProperty(key) && typeof (ret[key]) === 'object' && key.substring(0, 2) !== '__' && !skipFields.find(function (k) { return k === key; })) {
499
+ ret[key] = Utils.cloneDeep(obj[key]);
500
+ }
501
+ };
502
+ for (var key in ret) {
503
+ _loop_1(key);
504
+ }
505
+ return ret;
506
+ };
507
+ /** deep clone the given HTML node, removing teh unique id field */
508
+ Utils.cloneNode = function (el) {
509
+ var node = el.cloneNode(true);
510
+ node.removeAttribute('id');
511
+ return node;
512
+ };
513
+ Utils.appendTo = function (el, parent) {
514
+ var parentNode;
515
+ if (typeof parent === 'string') {
516
+ parentNode = document.querySelector(parent);
517
+ }
518
+ else {
519
+ parentNode = parent;
520
+ }
521
+ if (parentNode) {
522
+ parentNode.appendChild(el);
523
+ }
524
+ };
525
+ // public static setPositionRelative(el: HTMLElement): void {
526
+ // if (!(/^(?:r|a|f)/).test(window.getComputedStyle(el).position)) {
527
+ // el.style.position = "relative";
528
+ // }
529
+ // }
530
+ Utils.addElStyles = function (el, styles) {
531
+ if (styles instanceof Object) {
532
+ var _loop_2 = function (s) {
533
+ if (styles.hasOwnProperty(s)) {
534
+ if (Array.isArray(styles[s])) {
535
+ // support fallback value
536
+ styles[s].forEach(function (val) {
537
+ el.style[s] = val;
538
+ });
539
+ }
540
+ else {
541
+ el.style[s] = styles[s];
542
+ }
543
+ }
544
+ };
545
+ for (var s in styles) {
546
+ _loop_2(s);
547
+ }
548
+ }
549
+ };
550
+ Utils.initEvent = function (e, info) {
551
+ var evt = { type: info.type };
552
+ var obj = {
553
+ button: 0,
554
+ which: 0,
555
+ buttons: 1,
556
+ bubbles: true,
557
+ cancelable: true,
558
+ target: info.target ? info.target : e.target
559
+ };
560
+ // don't check for `instanceof DragEvent` as Safari use MouseEvent #1540
561
+ if (e.dataTransfer) {
562
+ evt['dataTransfer'] = e.dataTransfer; // workaround 'readonly' field.
563
+ }
564
+ ['altKey', 'ctrlKey', 'metaKey', 'shiftKey'].forEach(function (p) { return evt[p] = e[p]; }); // keys
565
+ ['pageX', 'pageY', 'clientX', 'clientY', 'screenX', 'screenY'].forEach(function (p) { return evt[p] = e[p]; }); // point info
566
+ return __assign(__assign({}, evt), obj);
567
+ };
568
+ /** copies the MouseEvent properties and sends it as another event to the given target */
569
+ Utils.simulateMouseEvent = function (e, simulatedType, target) {
570
+ var simulatedEvent = document.createEvent('MouseEvents');
571
+ simulatedEvent.initMouseEvent(simulatedType, // type
572
+ true, // bubbles
573
+ true, // cancelable
574
+ window, // view
575
+ 1, // detail
576
+ e.screenX, // screenX
577
+ e.screenY, // screenY
578
+ e.clientX, // clientX
579
+ e.clientY, // clientY
580
+ e.ctrlKey, // ctrlKey
581
+ e.altKey, // altKey
582
+ e.shiftKey, // shiftKey
583
+ e.metaKey, // metaKey
584
+ 0, // button
585
+ e.target // relatedTarget
586
+ );
587
+ (target || e.target).dispatchEvent(simulatedEvent);
588
+ };
589
+ return Utils;
590
+ }());
591
+ exports.Utils = Utils;
570
592
  //# sourceMappingURL=utils.js.map