gridstack 11.5.1 → 12.1.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 (113) hide show
  1. package/README.md +16 -3
  2. package/dist/angular/README.md +0 -1
  3. package/dist/angular/esm2020/lib/base-widget.mjs +2 -2
  4. package/dist/angular/esm2020/lib/gridstack-item.component.mjs +2 -2
  5. package/dist/angular/esm2020/lib/gridstack.component.mjs +2 -2
  6. package/dist/angular/esm2020/lib/gridstack.module.mjs +2 -2
  7. package/dist/angular/esm2020/lib/types.mjs +2 -2
  8. package/dist/angular/fesm2015/gridstack-angular.mjs +4 -4
  9. package/dist/angular/fesm2015/gridstack-angular.mjs.map +1 -1
  10. package/dist/angular/fesm2020/gridstack-angular.mjs +5 -5
  11. package/dist/angular/fesm2020/gridstack-angular.mjs.map +1 -1
  12. package/dist/angular/lib/gridstack-item.component.d.ts +1 -1
  13. package/dist/angular/lib/gridstack.component.d.ts +1 -1
  14. package/dist/angular/lib/types.d.ts +1 -1
  15. package/dist/angular/src/base-widget.ts +1 -1
  16. package/dist/angular/src/gridstack-item.component.ts +1 -1
  17. package/dist/angular/src/gridstack.component.ts +1 -1
  18. package/dist/angular/src/gridstack.module.ts +1 -1
  19. package/dist/dd-base-impl.d.ts +1 -1
  20. package/dist/dd-base-impl.js +1 -1
  21. package/dist/dd-base-impl.js.map +1 -1
  22. package/dist/dd-draggable.d.ts +1 -1
  23. package/dist/dd-draggable.js +1 -1
  24. package/dist/dd-draggable.js.map +1 -1
  25. package/dist/dd-droppable.d.ts +1 -1
  26. package/dist/dd-droppable.js +1 -1
  27. package/dist/dd-droppable.js.map +1 -1
  28. package/dist/dd-element.d.ts +1 -1
  29. package/dist/dd-element.js +1 -1
  30. package/dist/dd-element.js.map +1 -1
  31. package/dist/dd-gridstack.d.ts +1 -1
  32. package/dist/dd-gridstack.js +1 -1
  33. package/dist/dd-gridstack.js.map +1 -1
  34. package/dist/dd-manager.d.ts +1 -1
  35. package/dist/dd-manager.js +1 -1
  36. package/dist/dd-manager.js.map +1 -1
  37. package/dist/dd-resizable-handle.d.ts +1 -1
  38. package/dist/dd-resizable-handle.js +1 -1
  39. package/dist/dd-resizable-handle.js.map +1 -1
  40. package/dist/dd-resizable.d.ts +1 -1
  41. package/dist/dd-resizable.js +3 -2
  42. package/dist/dd-resizable.js.map +1 -1
  43. package/dist/dd-touch.d.ts +1 -1
  44. package/dist/dd-touch.js +1 -1
  45. package/dist/dd-touch.js.map +1 -1
  46. package/dist/gridstack-all.js +1 -1
  47. package/dist/gridstack-all.js.LICENSE.txt +1 -1
  48. package/dist/gridstack-all.js.map +1 -1
  49. package/dist/gridstack-engine.d.ts +1 -1
  50. package/dist/gridstack-engine.js +1 -1
  51. package/dist/gridstack-engine.js.map +1 -1
  52. package/dist/gridstack.css +25 -79
  53. package/dist/gridstack.d.ts +6 -5
  54. package/dist/gridstack.js +132 -203
  55. package/dist/gridstack.js.map +1 -1
  56. package/dist/gridstack.min.css +1 -1
  57. package/dist/src/gridstack.scss +22 -21
  58. package/dist/types.d.ts +4 -2
  59. package/dist/types.js +1 -2
  60. package/dist/types.js.map +1 -1
  61. package/dist/utils.d.ts +1 -14
  62. package/dist/utils.js +1 -45
  63. package/dist/utils.js.map +1 -1
  64. package/doc/CHANGES.md +17 -0
  65. package/doc/README.md +0 -3
  66. package/package.json +2 -4
  67. package/dist/angular/node_modules/tslib/README.md +0 -164
  68. package/dist/es5/dd-base-impl.d.ts +0 -20
  69. package/dist/es5/dd-base-impl.js +0 -41
  70. package/dist/es5/dd-base-impl.js.map +0 -1
  71. package/dist/es5/dd-draggable.d.ts +0 -20
  72. package/dist/es5/dd-draggable.js +0 -408
  73. package/dist/es5/dd-draggable.js.map +0 -1
  74. package/dist/es5/dd-droppable.d.ts +0 -26
  75. package/dist/es5/dd-droppable.js +0 -185
  76. package/dist/es5/dd-droppable.js.map +0 -1
  77. package/dist/es5/dd-element.d.ts +0 -27
  78. package/dist/es5/dd-element.js +0 -96
  79. package/dist/es5/dd-element.js.map +0 -1
  80. package/dist/es5/dd-gridstack.d.ts +0 -34
  81. package/dist/es5/dd-gridstack.js +0 -154
  82. package/dist/es5/dd-gridstack.js.map +0 -1
  83. package/dist/es5/dd-manager.d.ts +0 -22
  84. package/dist/es5/dd-manager.js +0 -17
  85. package/dist/es5/dd-manager.js.map +0 -1
  86. package/dist/es5/dd-resizable-handle.d.ts +0 -18
  87. package/dist/es5/dd-resizable-handle.js +0 -117
  88. package/dist/es5/dd-resizable-handle.js.map +0 -1
  89. package/dist/es5/dd-resizable.d.ts +0 -30
  90. package/dist/es5/dd-resizable.js +0 -330
  91. package/dist/es5/dd-resizable.js.map +0 -1
  92. package/dist/es5/dd-touch.d.ts +0 -33
  93. package/dist/es5/dd-touch.js +0 -157
  94. package/dist/es5/dd-touch.js.map +0 -1
  95. package/dist/es5/gridstack-all.js +0 -3
  96. package/dist/es5/gridstack-all.js.LICENSE.txt +0 -7
  97. package/dist/es5/gridstack-all.js.map +0 -1
  98. package/dist/es5/gridstack-engine.d.ts +0 -107
  99. package/dist/es5/gridstack-engine.js +0 -1070
  100. package/dist/es5/gridstack-engine.js.map +0 -1
  101. package/dist/es5/gridstack-poly.js +0 -356
  102. package/dist/es5/gridstack.d.ts +0 -453
  103. package/dist/es5/gridstack.js +0 -2717
  104. package/dist/es5/gridstack.js.map +0 -1
  105. package/dist/es5/types.d.ts +0 -324
  106. package/dist/es5/types.js +0 -39
  107. package/dist/es5/types.js.map +0 -1
  108. package/dist/es5/utils.d.ts +0 -117
  109. package/dist/es5/utils.js +0 -677
  110. package/dist/es5/utils.js.map +0 -1
  111. package/dist/gridstack-extra.css +0 -373
  112. package/dist/gridstack-extra.min.css +0 -1
  113. package/dist/src/gridstack-extra.scss +0 -25
package/dist/es5/utils.js DELETED
@@ -1,677 +0,0 @@
1
- "use strict";
2
- /**
3
- * utils.ts 11.5.1
4
- * Copyright (c) 2021-2024 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. optional root which defaults to document (for shadow dom) */
77
- Utils.getElements = function (els, root) {
78
- if (root === void 0) { root = document; }
79
- if (typeof els === 'string') {
80
- var doc = ('getElementById' in root) ? root : undefined;
81
- // Note: very common for people use to id='1,2,3' which is only legal as HTML5 id, but not CSS selectors
82
- // so if we start with a number, assume it's an id and just return that one item...
83
- // see https://github.com/gridstack/gridstack.js/issues/2234#issuecomment-1523796562
84
- if (doc && !isNaN(+els[0])) { // start with digit
85
- var el = doc.getElementById(els);
86
- return el ? [el] : [];
87
- }
88
- var list = root.querySelectorAll(els);
89
- if (!list.length && els[0] !== '.' && els[0] !== '#') {
90
- list = root.querySelectorAll('.' + els);
91
- if (!list.length) {
92
- list = root.querySelectorAll('#' + els);
93
- }
94
- }
95
- return Array.from(list);
96
- }
97
- return [els];
98
- };
99
- /** convert a potential selector into actual single element. optional root which defaults to document (for shadow dom) */
100
- Utils.getElement = function (els, root) {
101
- if (root === void 0) { root = document; }
102
- if (typeof els === 'string') {
103
- var doc = ('getElementById' in root) ? root : undefined;
104
- if (!els.length)
105
- return null;
106
- if (doc && els[0] === '#') {
107
- return doc.getElementById(els.substring(1));
108
- }
109
- if (els[0] === '#' || els[0] === '.' || els[0] === '[') {
110
- return root.querySelector(els);
111
- }
112
- // if we start with a digit, assume it's an id (error calling querySelector('#1')) as class are not valid CSS
113
- if (doc && !isNaN(+els[0])) { // start with digit
114
- return doc.getElementById(els);
115
- }
116
- // finally try string, then id, then class
117
- var el = root.querySelector(els);
118
- if (doc && !el) {
119
- el = doc.getElementById(els);
120
- }
121
- if (!el) {
122
- el = root.querySelector('.' + els);
123
- }
124
- return el;
125
- }
126
- return els;
127
- };
128
- /** true if widget (or grid) makes this item lazyLoad */
129
- Utils.lazyLoad = function (n) {
130
- var _a, _b;
131
- return n.lazyLoad || ((_b = (_a = n.grid) === null || _a === void 0 ? void 0 : _a.opts) === null || _b === void 0 ? void 0 : _b.lazyLoad) && n.lazyLoad !== false;
132
- };
133
- /** create a div with the given classes */
134
- Utils.createDiv = function (classes, parent) {
135
- var el = document.createElement('div');
136
- classes.forEach(function (c) { if (c)
137
- el.classList.add(c); });
138
- parent === null || parent === void 0 ? void 0 : parent.appendChild(el);
139
- return el;
140
- };
141
- /** true if we should resize to content. strict=true when only 'sizeToContent:true' and not a number which lets user adjust */
142
- Utils.shouldSizeToContent = function (n, strict) {
143
- if (strict === void 0) { strict = false; }
144
- return (n === null || n === void 0 ? void 0 : n.grid) && (strict ?
145
- (n.sizeToContent === true || (n.grid.opts.sizeToContent === true && n.sizeToContent === undefined)) :
146
- (!!n.sizeToContent || (n.grid.opts.sizeToContent && n.sizeToContent !== false)));
147
- };
148
- /** returns true if a and b overlap */
149
- Utils.isIntercepted = function (a, b) {
150
- 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);
151
- };
152
- /** returns true if a and b touch edges or corners */
153
- Utils.isTouching = function (a, b) {
154
- return Utils.isIntercepted(a, { x: b.x - 0.5, y: b.y - 0.5, w: b.w + 1, h: b.h + 1 });
155
- };
156
- /** returns the area a and b overlap */
157
- Utils.areaIntercept = function (a, b) {
158
- var x0 = (a.x > b.x) ? a.x : b.x;
159
- var x1 = (a.x + a.w < b.x + b.w) ? a.x + a.w : b.x + b.w;
160
- if (x1 <= x0)
161
- return 0; // no overlap
162
- var y0 = (a.y > b.y) ? a.y : b.y;
163
- var y1 = (a.y + a.h < b.y + b.h) ? a.y + a.h : b.y + b.h;
164
- if (y1 <= y0)
165
- return 0; // no overlap
166
- return (x1 - x0) * (y1 - y0);
167
- };
168
- /** returns the area */
169
- Utils.area = function (a) {
170
- return a.w * a.h;
171
- };
172
- /**
173
- * Sorts array of nodes
174
- * @param nodes array to sort
175
- * @param dir 1 for ascending, -1 for descending (optional)
176
- **/
177
- Utils.sort = function (nodes, dir) {
178
- if (dir === void 0) { dir = 1; }
179
- var und = 10000;
180
- return nodes.sort(function (a, b) {
181
- var _a, _b, _c, _d;
182
- var diffY = dir * (((_a = a.y) !== null && _a !== void 0 ? _a : und) - ((_b = b.y) !== null && _b !== void 0 ? _b : und));
183
- if (diffY === 0)
184
- return dir * (((_c = a.x) !== null && _c !== void 0 ? _c : und) - ((_d = b.x) !== null && _d !== void 0 ? _d : und));
185
- return diffY;
186
- });
187
- };
188
- /** find an item by id */
189
- Utils.find = function (nodes, id) {
190
- return id ? nodes.find(function (n) { return n.id === id; }) : undefined;
191
- };
192
- /**
193
- * creates a style sheet with style id under given parent
194
- * @param id will set the 'gs-style-id' attribute to that id
195
- * @param parent to insert the stylesheet as first child,
196
- * if none supplied it will be appended to the document head instead.
197
- */
198
- Utils.createStylesheet = function (id, parent, options) {
199
- var style = document.createElement('style');
200
- var nonce = options === null || options === void 0 ? void 0 : options.nonce;
201
- if (nonce)
202
- style.nonce = nonce;
203
- style.setAttribute('type', 'text/css');
204
- style.setAttribute('gs-style-id', id);
205
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
206
- if (style.styleSheet) { // TODO: only CSSImportRule have that and different beast ??
207
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
208
- style.styleSheet.cssText = '';
209
- }
210
- else {
211
- style.appendChild(document.createTextNode('')); // WebKit hack
212
- }
213
- if (!parent) {
214
- // default to head
215
- parent = document.getElementsByTagName('head')[0];
216
- parent.appendChild(style);
217
- }
218
- else {
219
- parent.insertBefore(style, parent.firstChild);
220
- }
221
- return style;
222
- };
223
- /** removed the given stylesheet id */
224
- Utils.removeStylesheet = function (id, parent) {
225
- var target = parent || document;
226
- var el = target.querySelector('STYLE[gs-style-id=' + id + ']');
227
- if (el && el.parentNode)
228
- el.remove();
229
- };
230
- /** inserts a CSS rule */
231
- Utils.addCSSRule = function (sheet, selector, rules) {
232
- // Rather than using sheet.insertRule, use text since it supports
233
- // gridstack node reparenting around in the DOM
234
- sheet.textContent += "".concat(selector, " { ").concat(rules, " } ");
235
- };
236
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
237
- Utils.toBool = function (v) {
238
- if (typeof v === 'boolean') {
239
- return v;
240
- }
241
- if (typeof v === 'string') {
242
- v = v.toLowerCase();
243
- return !(v === '' || v === 'no' || v === 'false' || v === '0');
244
- }
245
- return Boolean(v);
246
- };
247
- Utils.toNumber = function (value) {
248
- return (value === null || value.length === 0) ? undefined : Number(value);
249
- };
250
- Utils.parseHeight = function (val) {
251
- var h;
252
- var unit = 'px';
253
- if (typeof val === 'string') {
254
- if (val === 'auto' || val === '')
255
- h = 0;
256
- else {
257
- var match = val.match(/^(-[0-9]+\.[0-9]+|[0-9]*\.[0-9]+|-[0-9]+|[0-9]+)(px|em|rem|vh|vw|%|cm|mm)?$/);
258
- if (!match) {
259
- throw new Error("Invalid height val = ".concat(val));
260
- }
261
- unit = match[2] || 'px';
262
- h = parseFloat(match[1]);
263
- }
264
- }
265
- else {
266
- h = val;
267
- }
268
- return { h: h, unit: unit };
269
- };
270
- /** copies unset fields in target to use the given default sources values */
271
- // eslint-disable-next-line
272
- Utils.defaults = function (target) {
273
- var _this = this;
274
- var sources = [];
275
- for (var _i = 1; _i < arguments.length; _i++) {
276
- sources[_i - 1] = arguments[_i];
277
- }
278
- sources.forEach(function (source) {
279
- for (var key in source) {
280
- if (!source.hasOwnProperty(key))
281
- return;
282
- if (target[key] === null || target[key] === undefined) {
283
- target[key] = source[key];
284
- }
285
- else if (typeof source[key] === 'object' && typeof target[key] === 'object') {
286
- // property is an object, recursively add it's field over... #1373
287
- _this.defaults(target[key], source[key]);
288
- }
289
- }
290
- });
291
- return target;
292
- };
293
- /** given 2 objects return true if they have the same values. Checks for Object {} having same fields and values (just 1 level down) */
294
- Utils.same = function (a, b) {
295
- if (typeof a !== 'object')
296
- return a == b;
297
- if (typeof a !== typeof b)
298
- return false;
299
- // else we have object, check just 1 level deep for being same things...
300
- if (Object.keys(a).length !== Object.keys(b).length)
301
- return false;
302
- for (var key in a) {
303
- if (a[key] !== b[key])
304
- return false;
305
- }
306
- return true;
307
- };
308
- /** copies over b size & position (GridStackPosition), and optionally min/max as well */
309
- Utils.copyPos = function (a, b, doMinMax) {
310
- if (doMinMax === void 0) { doMinMax = false; }
311
- if (b.x !== undefined)
312
- a.x = b.x;
313
- if (b.y !== undefined)
314
- a.y = b.y;
315
- if (b.w !== undefined)
316
- a.w = b.w;
317
- if (b.h !== undefined)
318
- a.h = b.h;
319
- if (doMinMax) {
320
- if (b.minW)
321
- a.minW = b.minW;
322
- if (b.minH)
323
- a.minH = b.minH;
324
- if (b.maxW)
325
- a.maxW = b.maxW;
326
- if (b.maxH)
327
- a.maxH = b.maxH;
328
- }
329
- return a;
330
- };
331
- /** true if a and b has same size & position */
332
- Utils.samePos = function (a, b) {
333
- return a && b && a.x === b.x && a.y === b.y && (a.w || 1) === (b.w || 1) && (a.h || 1) === (b.h || 1);
334
- };
335
- /** given a node, makes sure it's min/max are valid */
336
- Utils.sanitizeMinMax = function (node) {
337
- // remove 0, undefine, null
338
- if (!node.minW) {
339
- delete node.minW;
340
- }
341
- if (!node.minH) {
342
- delete node.minH;
343
- }
344
- if (!node.maxW) {
345
- delete node.maxW;
346
- }
347
- if (!node.maxH) {
348
- delete node.maxH;
349
- }
350
- };
351
- /** removes field from the first object if same as the second objects (like diffing) and internal '_' for saving */
352
- Utils.removeInternalAndSame = function (a, b) {
353
- if (typeof a !== 'object' || typeof b !== 'object')
354
- return;
355
- for (var key in a) {
356
- var aVal = a[key];
357
- var bVal = b[key];
358
- if (key[0] === '_' || aVal === bVal) {
359
- delete a[key];
360
- }
361
- else if (aVal && typeof aVal === 'object' && bVal !== undefined) {
362
- Utils.removeInternalAndSame(aVal, bVal);
363
- if (!Object.keys(aVal).length) {
364
- delete a[key];
365
- }
366
- }
367
- }
368
- };
369
- /** removes internal fields '_' and default values for saving */
370
- Utils.removeInternalForSave = function (n, removeEl) {
371
- if (removeEl === void 0) { removeEl = true; }
372
- for (var key in n) {
373
- if (key[0] === '_' || n[key] === null || n[key] === undefined)
374
- delete n[key];
375
- }
376
- delete n.grid;
377
- if (removeEl)
378
- delete n.el;
379
- // delete default values (will be re-created on read)
380
- if (!n.autoPosition)
381
- delete n.autoPosition;
382
- if (!n.noResize)
383
- delete n.noResize;
384
- if (!n.noMove)
385
- delete n.noMove;
386
- if (!n.locked)
387
- delete n.locked;
388
- if (n.w === 1 || n.w === n.minW)
389
- delete n.w;
390
- if (n.h === 1 || n.h === n.minH)
391
- delete n.h;
392
- };
393
- /** return the closest parent (or itself) matching the given class */
394
- // static closestUpByClass(el: HTMLElement, name: string): HTMLElement {
395
- // while (el) {
396
- // if (el.classList.contains(name)) return el;
397
- // el = el.parentElement
398
- // }
399
- // return null;
400
- // }
401
- /** delay calling the given function for given delay, preventing new calls from happening while waiting */
402
- Utils.throttle = function (func, delay) {
403
- var isWaiting = false;
404
- return function () {
405
- var args = [];
406
- for (var _i = 0; _i < arguments.length; _i++) {
407
- args[_i] = arguments[_i];
408
- }
409
- if (!isWaiting) {
410
- isWaiting = true;
411
- setTimeout(function () { func.apply(void 0, args); isWaiting = false; }, delay);
412
- }
413
- };
414
- };
415
- Utils.removePositioningStyles = function (el) {
416
- var style = el.style;
417
- if (style.position) {
418
- style.removeProperty('position');
419
- }
420
- if (style.left) {
421
- style.removeProperty('left');
422
- }
423
- if (style.top) {
424
- style.removeProperty('top');
425
- }
426
- if (style.width) {
427
- style.removeProperty('width');
428
- }
429
- if (style.height) {
430
- style.removeProperty('height');
431
- }
432
- };
433
- /** @internal returns the passed element if scrollable, else the closest parent that will, up to the entire document scrolling element */
434
- Utils.getScrollElement = function (el) {
435
- if (!el)
436
- return document.scrollingElement || document.documentElement; // IE support
437
- var style = getComputedStyle(el);
438
- var overflowRegex = /(auto|scroll)/;
439
- if (overflowRegex.test(style.overflow + style.overflowY)) {
440
- return el;
441
- }
442
- else {
443
- return this.getScrollElement(el.parentElement);
444
- }
445
- };
446
- /** @internal */
447
- Utils.updateScrollPosition = function (el, position, distance) {
448
- // is widget in view?
449
- var rect = el.getBoundingClientRect();
450
- var innerHeightOrClientHeight = (window.innerHeight || document.documentElement.clientHeight);
451
- if (rect.top < 0 ||
452
- rect.bottom > innerHeightOrClientHeight) {
453
- // set scrollTop of first parent that scrolls
454
- // if parent is larger than el, set as low as possible
455
- // to get entire widget on screen
456
- var offsetDiffDown = rect.bottom - innerHeightOrClientHeight;
457
- var offsetDiffUp = rect.top;
458
- var scrollEl = this.getScrollElement(el);
459
- if (scrollEl !== null) {
460
- var prevScroll = scrollEl.scrollTop;
461
- if (rect.top < 0 && distance < 0) {
462
- // moving up
463
- if (el.offsetHeight > innerHeightOrClientHeight) {
464
- scrollEl.scrollTop += distance;
465
- }
466
- else {
467
- scrollEl.scrollTop += Math.abs(offsetDiffUp) > Math.abs(distance) ? distance : offsetDiffUp;
468
- }
469
- }
470
- else if (distance > 0) {
471
- // moving down
472
- if (el.offsetHeight > innerHeightOrClientHeight) {
473
- scrollEl.scrollTop += distance;
474
- }
475
- else {
476
- scrollEl.scrollTop += offsetDiffDown > distance ? distance : offsetDiffDown;
477
- }
478
- }
479
- // move widget y by amount scrolled
480
- position.top += scrollEl.scrollTop - prevScroll;
481
- }
482
- }
483
- };
484
- /**
485
- * @internal Function used to scroll the page.
486
- *
487
- * @param event `MouseEvent` that triggers the resize
488
- * @param el `HTMLElement` that's being resized
489
- * @param distance Distance from the V edges to start scrolling
490
- */
491
- Utils.updateScrollResize = function (event, el, distance) {
492
- var scrollEl = this.getScrollElement(el);
493
- var height = scrollEl.clientHeight;
494
- // #1727 event.clientY is relative to viewport, so must compare this against position of scrollEl getBoundingClientRect().top
495
- // #1745 Special situation if scrollEl is document 'html': here browser spec states that
496
- // clientHeight is height of viewport, but getBoundingClientRect() is rectangle of html element;
497
- // this discrepancy arises because in reality scrollbar is attached to viewport, not html element itself.
498
- var offsetTop = (scrollEl === this.getScrollElement()) ? 0 : scrollEl.getBoundingClientRect().top;
499
- var pointerPosY = event.clientY - offsetTop;
500
- var top = pointerPosY < distance;
501
- var bottom = pointerPosY > height - distance;
502
- if (top) {
503
- // This also can be done with a timeout to keep scrolling while the mouse is
504
- // in the scrolling zone. (will have smoother behavior)
505
- scrollEl.scrollBy({ behavior: 'smooth', top: pointerPosY - distance });
506
- }
507
- else if (bottom) {
508
- scrollEl.scrollBy({ behavior: 'smooth', top: distance - (height - pointerPosY) });
509
- }
510
- };
511
- /** single level clone, returning a new object with same top fields. This will share sub objects and arrays */
512
- Utils.clone = function (obj) {
513
- if (obj === null || obj === undefined || typeof (obj) !== 'object') {
514
- return obj;
515
- }
516
- // return Object.assign({}, obj);
517
- if (obj instanceof Array) {
518
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
519
- return __spreadArray([], obj, true);
520
- }
521
- return __assign({}, obj);
522
- };
523
- /**
524
- * Recursive clone version that returns a full copy, checking for nested objects and arrays ONLY.
525
- * Note: this will use as-is any key starting with double __ (and not copy inside) some lib have circular dependencies.
526
- */
527
- Utils.cloneDeep = function (obj) {
528
- // list of fields we will skip during cloneDeep (nested objects, other internal)
529
- var skipFields = ['parentGrid', 'el', 'grid', 'subGrid', 'engine'];
530
- // return JSON.parse(JSON.stringify(obj)); // doesn't work with date format ?
531
- var ret = Utils.clone(obj);
532
- var _loop_1 = function (key) {
533
- // NOTE: we don't support function/circular dependencies so skip those properties for now...
534
- if (ret.hasOwnProperty(key) && typeof (ret[key]) === 'object' && key.substring(0, 2) !== '__' && !skipFields.find(function (k) { return k === key; })) {
535
- ret[key] = Utils.cloneDeep(obj[key]);
536
- }
537
- };
538
- for (var key in ret) {
539
- _loop_1(key);
540
- }
541
- return ret;
542
- };
543
- /** deep clone the given HTML node, removing teh unique id field */
544
- Utils.cloneNode = function (el) {
545
- var node = el.cloneNode(true);
546
- node.removeAttribute('id');
547
- return node;
548
- };
549
- Utils.appendTo = function (el, parent) {
550
- var parentNode;
551
- if (typeof parent === 'string') {
552
- parentNode = Utils.getElement(parent);
553
- }
554
- else {
555
- parentNode = parent;
556
- }
557
- if (parentNode) {
558
- parentNode.appendChild(el);
559
- }
560
- };
561
- // public static setPositionRelative(el: HTMLElement): void {
562
- // if (!(/^(?:r|a|f)/).test(getComputedStyle(el).position)) {
563
- // el.style.position = "relative";
564
- // }
565
- // }
566
- Utils.addElStyles = function (el, styles) {
567
- if (styles instanceof Object) {
568
- var _loop_2 = function (s) {
569
- if (styles.hasOwnProperty(s)) {
570
- if (Array.isArray(styles[s])) {
571
- // support fallback value
572
- styles[s].forEach(function (val) {
573
- el.style[s] = val;
574
- });
575
- }
576
- else {
577
- el.style[s] = styles[s];
578
- }
579
- }
580
- };
581
- for (var s in styles) {
582
- _loop_2(s);
583
- }
584
- }
585
- };
586
- Utils.initEvent = function (e, info) {
587
- var evt = { type: info.type };
588
- var obj = {
589
- button: 0,
590
- which: 0,
591
- buttons: 1,
592
- bubbles: true,
593
- cancelable: true,
594
- target: info.target ? info.target : e.target
595
- };
596
- ['altKey', 'ctrlKey', 'metaKey', 'shiftKey'].forEach(function (p) { return evt[p] = e[p]; }); // keys
597
- ['pageX', 'pageY', 'clientX', 'clientY', 'screenX', 'screenY'].forEach(function (p) { return evt[p] = e[p]; }); // point info
598
- return __assign(__assign({}, evt), obj);
599
- };
600
- /** copies the MouseEvent (or convert Touch) properties and sends it as another event to the given target */
601
- Utils.simulateMouseEvent = function (e, simulatedType, target) {
602
- var _a, _b, _c, _d;
603
- var me = e;
604
- var simulatedEvent = new MouseEvent(simulatedType, {
605
- bubbles: true,
606
- composed: true,
607
- cancelable: true,
608
- view: window,
609
- detail: 1,
610
- screenX: e.screenX,
611
- screenY: e.screenY,
612
- clientX: e.clientX,
613
- clientY: e.clientY,
614
- ctrlKey: (_a = me.ctrlKey) !== null && _a !== void 0 ? _a : false,
615
- altKey: (_b = me.altKey) !== null && _b !== void 0 ? _b : false,
616
- shiftKey: (_c = me.shiftKey) !== null && _c !== void 0 ? _c : false,
617
- metaKey: (_d = me.metaKey) !== null && _d !== void 0 ? _d : false,
618
- button: 0,
619
- relatedTarget: e.target
620
- });
621
- (target || e.target).dispatchEvent(simulatedEvent);
622
- };
623
- /**
624
- * defines an element that is used to get the offset and scale from grid transforms
625
- * returns the scale and offsets from said element
626
- */
627
- Utils.getValuesFromTransformedElement = function (parent) {
628
- var transformReference = document.createElement('div');
629
- Utils.addElStyles(transformReference, {
630
- opacity: '0',
631
- position: 'fixed',
632
- top: 0 + 'px',
633
- left: 0 + 'px',
634
- width: '1px',
635
- height: '1px',
636
- zIndex: '-999999',
637
- });
638
- parent.appendChild(transformReference);
639
- var transformValues = transformReference.getBoundingClientRect();
640
- parent.removeChild(transformReference);
641
- transformReference.remove();
642
- return {
643
- xScale: 1 / transformValues.width,
644
- yScale: 1 / transformValues.height,
645
- xOffset: transformValues.left,
646
- yOffset: transformValues.top,
647
- };
648
- };
649
- /** swap the given object 2 field values */
650
- Utils.swap = function (o, a, b) {
651
- if (!o)
652
- return;
653
- var tmp = o[a];
654
- o[a] = o[b];
655
- o[b] = tmp;
656
- };
657
- /** returns true if event is inside the given element rectangle */
658
- // Note: Safari Mac has null event.relatedTarget which causes #1684 so check if DragEvent is inside the coordinates instead
659
- // this.el.contains(event.relatedTarget as HTMLElement)
660
- // public static inside(e: MouseEvent, el: HTMLElement): boolean {
661
- // // srcElement, toElement, target: all set to placeholder when leaving simple grid, so we can't use that (Chrome)
662
- // const target: HTMLElement = e.relatedTarget || (e as any).fromElement;
663
- // if (!target) {
664
- // const { bottom, left, right, top } = el.getBoundingClientRect();
665
- // return (e.x < right && e.x > left && e.y < bottom && e.y > top);
666
- // }
667
- // return el.contains(target);
668
- // }
669
- /** true if the item can be rotated (checking for prop, not space available) */
670
- Utils.canBeRotated = function (n) {
671
- var _a;
672
- return !(!n || n.w === n.h || n.locked || n.noResize || ((_a = n.grid) === null || _a === void 0 ? void 0 : _a.opts.disableResize) || (n.minW && n.minW === n.maxW) || (n.minH && n.minH === n.maxH));
673
- };
674
- return Utils;
675
- }());
676
- exports.Utils = Utils;
677
- //# sourceMappingURL=utils.js.map