gridstack 12.0.0 → 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.
- package/README.md +1 -1
- package/dist/angular/esm2020/lib/base-widget.mjs +2 -2
- package/dist/angular/esm2020/lib/gridstack-item.component.mjs +2 -2
- package/dist/angular/esm2020/lib/gridstack.component.mjs +2 -2
- package/dist/angular/esm2020/lib/gridstack.module.mjs +2 -2
- package/dist/angular/esm2020/lib/types.mjs +2 -2
- package/dist/angular/fesm2015/gridstack-angular.mjs +4 -4
- package/dist/angular/fesm2015/gridstack-angular.mjs.map +1 -1
- package/dist/angular/fesm2020/gridstack-angular.mjs +5 -5
- package/dist/angular/fesm2020/gridstack-angular.mjs.map +1 -1
- package/dist/angular/lib/gridstack-item.component.d.ts +1 -1
- package/dist/angular/lib/gridstack.component.d.ts +1 -1
- package/dist/angular/lib/types.d.ts +1 -1
- package/dist/angular/src/base-widget.ts +1 -1
- package/dist/angular/src/gridstack-item.component.ts +1 -1
- package/dist/angular/src/gridstack.component.ts +1 -1
- package/dist/angular/src/gridstack.module.ts +1 -1
- package/dist/dd-base-impl.d.ts +1 -1
- package/dist/dd-base-impl.js +1 -1
- package/dist/dd-base-impl.js.map +1 -1
- package/dist/dd-draggable.d.ts +1 -1
- package/dist/dd-draggable.js +1 -1
- package/dist/dd-draggable.js.map +1 -1
- package/dist/dd-droppable.d.ts +1 -1
- package/dist/dd-droppable.js +1 -1
- package/dist/dd-droppable.js.map +1 -1
- package/dist/dd-element.d.ts +1 -1
- package/dist/dd-element.js +1 -1
- package/dist/dd-element.js.map +1 -1
- package/dist/dd-gridstack.d.ts +1 -1
- package/dist/dd-gridstack.js +1 -1
- package/dist/dd-gridstack.js.map +1 -1
- package/dist/dd-manager.d.ts +1 -1
- package/dist/dd-manager.js +1 -1
- package/dist/dd-manager.js.map +1 -1
- package/dist/dd-resizable-handle.d.ts +1 -1
- package/dist/dd-resizable-handle.js +1 -1
- package/dist/dd-resizable-handle.js.map +1 -1
- package/dist/dd-resizable.d.ts +1 -1
- package/dist/dd-resizable.js +1 -1
- package/dist/dd-resizable.js.map +1 -1
- package/dist/dd-touch.d.ts +1 -1
- package/dist/dd-touch.js +1 -1
- package/dist/dd-touch.js.map +1 -1
- package/dist/gridstack-all.js +1 -1
- package/dist/gridstack-all.js.LICENSE.txt +1 -1
- package/dist/gridstack-all.js.map +1 -1
- package/dist/gridstack-engine.d.ts +1 -1
- package/dist/gridstack-engine.js +1 -1
- package/dist/gridstack-engine.js.map +1 -1
- package/dist/gridstack.css +1 -1
- package/dist/gridstack.d.ts +3 -1
- package/dist/gridstack.js +57 -55
- package/dist/gridstack.js.map +1 -1
- package/dist/src/gridstack.scss +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/types.js +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utils.d.ts +1 -1
- package/dist/utils.js +1 -1
- package/dist/utils.js.map +1 -1
- package/doc/CHANGES.md +10 -0
- package/package.json +2 -4
- package/dist/es5/dd-base-impl.d.ts +0 -20
- package/dist/es5/dd-base-impl.js +0 -41
- package/dist/es5/dd-base-impl.js.map +0 -1
- package/dist/es5/dd-draggable.d.ts +0 -20
- package/dist/es5/dd-draggable.js +0 -408
- package/dist/es5/dd-draggable.js.map +0 -1
- package/dist/es5/dd-droppable.d.ts +0 -26
- package/dist/es5/dd-droppable.js +0 -185
- package/dist/es5/dd-droppable.js.map +0 -1
- package/dist/es5/dd-element.d.ts +0 -27
- package/dist/es5/dd-element.js +0 -96
- package/dist/es5/dd-element.js.map +0 -1
- package/dist/es5/dd-gridstack.d.ts +0 -34
- package/dist/es5/dd-gridstack.js +0 -154
- package/dist/es5/dd-gridstack.js.map +0 -1
- package/dist/es5/dd-manager.d.ts +0 -22
- package/dist/es5/dd-manager.js +0 -17
- package/dist/es5/dd-manager.js.map +0 -1
- package/dist/es5/dd-resizable-handle.d.ts +0 -18
- package/dist/es5/dd-resizable-handle.js +0 -117
- package/dist/es5/dd-resizable-handle.js.map +0 -1
- package/dist/es5/dd-resizable.d.ts +0 -30
- package/dist/es5/dd-resizable.js +0 -331
- package/dist/es5/dd-resizable.js.map +0 -1
- package/dist/es5/dd-touch.d.ts +0 -33
- package/dist/es5/dd-touch.js +0 -157
- package/dist/es5/dd-touch.js.map +0 -1
- package/dist/es5/gridstack-all.js +0 -3
- package/dist/es5/gridstack-all.js.LICENSE.txt +0 -7
- package/dist/es5/gridstack-all.js.map +0 -1
- package/dist/es5/gridstack-engine.d.ts +0 -107
- package/dist/es5/gridstack-engine.js +0 -1070
- package/dist/es5/gridstack-engine.js.map +0 -1
- package/dist/es5/gridstack-poly.js +0 -356
- package/dist/es5/gridstack.d.ts +0 -452
- package/dist/es5/gridstack.js +0 -2644
- package/dist/es5/gridstack.js.map +0 -1
- package/dist/es5/types.d.ts +0 -326
- package/dist/es5/types.js +0 -38
- package/dist/es5/types.js.map +0 -1
- package/dist/es5/utils.d.ts +0 -104
- package/dist/es5/utils.js +0 -633
- package/dist/es5/utils.js.map +0 -1
package/dist/es5/utils.js
DELETED
|
@@ -1,633 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* utils.ts 12.0.0
|
|
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
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
193
|
-
Utils.toBool = function (v) {
|
|
194
|
-
if (typeof v === 'boolean') {
|
|
195
|
-
return v;
|
|
196
|
-
}
|
|
197
|
-
if (typeof v === 'string') {
|
|
198
|
-
v = v.toLowerCase();
|
|
199
|
-
return !(v === '' || v === 'no' || v === 'false' || v === '0');
|
|
200
|
-
}
|
|
201
|
-
return Boolean(v);
|
|
202
|
-
};
|
|
203
|
-
Utils.toNumber = function (value) {
|
|
204
|
-
return (value === null || value.length === 0) ? undefined : Number(value);
|
|
205
|
-
};
|
|
206
|
-
Utils.parseHeight = function (val) {
|
|
207
|
-
var h;
|
|
208
|
-
var unit = 'px';
|
|
209
|
-
if (typeof val === 'string') {
|
|
210
|
-
if (val === 'auto' || val === '')
|
|
211
|
-
h = 0;
|
|
212
|
-
else {
|
|
213
|
-
var match = val.match(/^(-[0-9]+\.[0-9]+|[0-9]*\.[0-9]+|-[0-9]+|[0-9]+)(px|em|rem|vh|vw|%|cm|mm)?$/);
|
|
214
|
-
if (!match) {
|
|
215
|
-
throw new Error("Invalid height val = ".concat(val));
|
|
216
|
-
}
|
|
217
|
-
unit = match[2] || 'px';
|
|
218
|
-
h = parseFloat(match[1]);
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
else {
|
|
222
|
-
h = val;
|
|
223
|
-
}
|
|
224
|
-
return { h: h, unit: unit };
|
|
225
|
-
};
|
|
226
|
-
/** copies unset fields in target to use the given default sources values */
|
|
227
|
-
// eslint-disable-next-line
|
|
228
|
-
Utils.defaults = function (target) {
|
|
229
|
-
var _this = this;
|
|
230
|
-
var sources = [];
|
|
231
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
232
|
-
sources[_i - 1] = arguments[_i];
|
|
233
|
-
}
|
|
234
|
-
sources.forEach(function (source) {
|
|
235
|
-
for (var key in source) {
|
|
236
|
-
if (!source.hasOwnProperty(key))
|
|
237
|
-
return;
|
|
238
|
-
if (target[key] === null || target[key] === undefined) {
|
|
239
|
-
target[key] = source[key];
|
|
240
|
-
}
|
|
241
|
-
else if (typeof source[key] === 'object' && typeof target[key] === 'object') {
|
|
242
|
-
// property is an object, recursively add it's field over... #1373
|
|
243
|
-
_this.defaults(target[key], source[key]);
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
});
|
|
247
|
-
return target;
|
|
248
|
-
};
|
|
249
|
-
/** given 2 objects return true if they have the same values. Checks for Object {} having same fields and values (just 1 level down) */
|
|
250
|
-
Utils.same = function (a, b) {
|
|
251
|
-
if (typeof a !== 'object')
|
|
252
|
-
return a == b;
|
|
253
|
-
if (typeof a !== typeof b)
|
|
254
|
-
return false;
|
|
255
|
-
// else we have object, check just 1 level deep for being same things...
|
|
256
|
-
if (Object.keys(a).length !== Object.keys(b).length)
|
|
257
|
-
return false;
|
|
258
|
-
for (var key in a) {
|
|
259
|
-
if (a[key] !== b[key])
|
|
260
|
-
return false;
|
|
261
|
-
}
|
|
262
|
-
return true;
|
|
263
|
-
};
|
|
264
|
-
/** copies over b size & position (GridStackPosition), and optionally min/max as well */
|
|
265
|
-
Utils.copyPos = function (a, b, doMinMax) {
|
|
266
|
-
if (doMinMax === void 0) { doMinMax = false; }
|
|
267
|
-
if (b.x !== undefined)
|
|
268
|
-
a.x = b.x;
|
|
269
|
-
if (b.y !== undefined)
|
|
270
|
-
a.y = b.y;
|
|
271
|
-
if (b.w !== undefined)
|
|
272
|
-
a.w = b.w;
|
|
273
|
-
if (b.h !== undefined)
|
|
274
|
-
a.h = b.h;
|
|
275
|
-
if (doMinMax) {
|
|
276
|
-
if (b.minW)
|
|
277
|
-
a.minW = b.minW;
|
|
278
|
-
if (b.minH)
|
|
279
|
-
a.minH = b.minH;
|
|
280
|
-
if (b.maxW)
|
|
281
|
-
a.maxW = b.maxW;
|
|
282
|
-
if (b.maxH)
|
|
283
|
-
a.maxH = b.maxH;
|
|
284
|
-
}
|
|
285
|
-
return a;
|
|
286
|
-
};
|
|
287
|
-
/** true if a and b has same size & position */
|
|
288
|
-
Utils.samePos = function (a, b) {
|
|
289
|
-
return a && b && a.x === b.x && a.y === b.y && (a.w || 1) === (b.w || 1) && (a.h || 1) === (b.h || 1);
|
|
290
|
-
};
|
|
291
|
-
/** given a node, makes sure it's min/max are valid */
|
|
292
|
-
Utils.sanitizeMinMax = function (node) {
|
|
293
|
-
// remove 0, undefine, null
|
|
294
|
-
if (!node.minW) {
|
|
295
|
-
delete node.minW;
|
|
296
|
-
}
|
|
297
|
-
if (!node.minH) {
|
|
298
|
-
delete node.minH;
|
|
299
|
-
}
|
|
300
|
-
if (!node.maxW) {
|
|
301
|
-
delete node.maxW;
|
|
302
|
-
}
|
|
303
|
-
if (!node.maxH) {
|
|
304
|
-
delete node.maxH;
|
|
305
|
-
}
|
|
306
|
-
};
|
|
307
|
-
/** removes field from the first object if same as the second objects (like diffing) and internal '_' for saving */
|
|
308
|
-
Utils.removeInternalAndSame = function (a, b) {
|
|
309
|
-
if (typeof a !== 'object' || typeof b !== 'object')
|
|
310
|
-
return;
|
|
311
|
-
for (var key in a) {
|
|
312
|
-
var aVal = a[key];
|
|
313
|
-
var bVal = b[key];
|
|
314
|
-
if (key[0] === '_' || aVal === bVal) {
|
|
315
|
-
delete a[key];
|
|
316
|
-
}
|
|
317
|
-
else if (aVal && typeof aVal === 'object' && bVal !== undefined) {
|
|
318
|
-
Utils.removeInternalAndSame(aVal, bVal);
|
|
319
|
-
if (!Object.keys(aVal).length) {
|
|
320
|
-
delete a[key];
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
};
|
|
325
|
-
/** removes internal fields '_' and default values for saving */
|
|
326
|
-
Utils.removeInternalForSave = function (n, removeEl) {
|
|
327
|
-
if (removeEl === void 0) { removeEl = true; }
|
|
328
|
-
for (var key in n) {
|
|
329
|
-
if (key[0] === '_' || n[key] === null || n[key] === undefined)
|
|
330
|
-
delete n[key];
|
|
331
|
-
}
|
|
332
|
-
delete n.grid;
|
|
333
|
-
if (removeEl)
|
|
334
|
-
delete n.el;
|
|
335
|
-
// delete default values (will be re-created on read)
|
|
336
|
-
if (!n.autoPosition)
|
|
337
|
-
delete n.autoPosition;
|
|
338
|
-
if (!n.noResize)
|
|
339
|
-
delete n.noResize;
|
|
340
|
-
if (!n.noMove)
|
|
341
|
-
delete n.noMove;
|
|
342
|
-
if (!n.locked)
|
|
343
|
-
delete n.locked;
|
|
344
|
-
if (n.w === 1 || n.w === n.minW)
|
|
345
|
-
delete n.w;
|
|
346
|
-
if (n.h === 1 || n.h === n.minH)
|
|
347
|
-
delete n.h;
|
|
348
|
-
};
|
|
349
|
-
/** return the closest parent (or itself) matching the given class */
|
|
350
|
-
// static closestUpByClass(el: HTMLElement, name: string): HTMLElement {
|
|
351
|
-
// while (el) {
|
|
352
|
-
// if (el.classList.contains(name)) return el;
|
|
353
|
-
// el = el.parentElement
|
|
354
|
-
// }
|
|
355
|
-
// return null;
|
|
356
|
-
// }
|
|
357
|
-
/** delay calling the given function for given delay, preventing new calls from happening while waiting */
|
|
358
|
-
Utils.throttle = function (func, delay) {
|
|
359
|
-
var isWaiting = false;
|
|
360
|
-
return function () {
|
|
361
|
-
var args = [];
|
|
362
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
363
|
-
args[_i] = arguments[_i];
|
|
364
|
-
}
|
|
365
|
-
if (!isWaiting) {
|
|
366
|
-
isWaiting = true;
|
|
367
|
-
setTimeout(function () { func.apply(void 0, args); isWaiting = false; }, delay);
|
|
368
|
-
}
|
|
369
|
-
};
|
|
370
|
-
};
|
|
371
|
-
Utils.removePositioningStyles = function (el) {
|
|
372
|
-
var style = el.style;
|
|
373
|
-
if (style.position) {
|
|
374
|
-
style.removeProperty('position');
|
|
375
|
-
}
|
|
376
|
-
if (style.left) {
|
|
377
|
-
style.removeProperty('left');
|
|
378
|
-
}
|
|
379
|
-
if (style.top) {
|
|
380
|
-
style.removeProperty('top');
|
|
381
|
-
}
|
|
382
|
-
if (style.width) {
|
|
383
|
-
style.removeProperty('width');
|
|
384
|
-
}
|
|
385
|
-
if (style.height) {
|
|
386
|
-
style.removeProperty('height');
|
|
387
|
-
}
|
|
388
|
-
};
|
|
389
|
-
/** @internal returns the passed element if scrollable, else the closest parent that will, up to the entire document scrolling element */
|
|
390
|
-
Utils.getScrollElement = function (el) {
|
|
391
|
-
if (!el)
|
|
392
|
-
return document.scrollingElement || document.documentElement; // IE support
|
|
393
|
-
var style = getComputedStyle(el);
|
|
394
|
-
var overflowRegex = /(auto|scroll)/;
|
|
395
|
-
if (overflowRegex.test(style.overflow + style.overflowY)) {
|
|
396
|
-
return el;
|
|
397
|
-
}
|
|
398
|
-
else {
|
|
399
|
-
return this.getScrollElement(el.parentElement);
|
|
400
|
-
}
|
|
401
|
-
};
|
|
402
|
-
/** @internal */
|
|
403
|
-
Utils.updateScrollPosition = function (el, position, distance) {
|
|
404
|
-
// is widget in view?
|
|
405
|
-
var rect = el.getBoundingClientRect();
|
|
406
|
-
var innerHeightOrClientHeight = (window.innerHeight || document.documentElement.clientHeight);
|
|
407
|
-
if (rect.top < 0 ||
|
|
408
|
-
rect.bottom > innerHeightOrClientHeight) {
|
|
409
|
-
// set scrollTop of first parent that scrolls
|
|
410
|
-
// if parent is larger than el, set as low as possible
|
|
411
|
-
// to get entire widget on screen
|
|
412
|
-
var offsetDiffDown = rect.bottom - innerHeightOrClientHeight;
|
|
413
|
-
var offsetDiffUp = rect.top;
|
|
414
|
-
var scrollEl = this.getScrollElement(el);
|
|
415
|
-
if (scrollEl !== null) {
|
|
416
|
-
var prevScroll = scrollEl.scrollTop;
|
|
417
|
-
if (rect.top < 0 && distance < 0) {
|
|
418
|
-
// moving up
|
|
419
|
-
if (el.offsetHeight > innerHeightOrClientHeight) {
|
|
420
|
-
scrollEl.scrollTop += distance;
|
|
421
|
-
}
|
|
422
|
-
else {
|
|
423
|
-
scrollEl.scrollTop += Math.abs(offsetDiffUp) > Math.abs(distance) ? distance : offsetDiffUp;
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
else if (distance > 0) {
|
|
427
|
-
// moving down
|
|
428
|
-
if (el.offsetHeight > innerHeightOrClientHeight) {
|
|
429
|
-
scrollEl.scrollTop += distance;
|
|
430
|
-
}
|
|
431
|
-
else {
|
|
432
|
-
scrollEl.scrollTop += offsetDiffDown > distance ? distance : offsetDiffDown;
|
|
433
|
-
}
|
|
434
|
-
}
|
|
435
|
-
// move widget y by amount scrolled
|
|
436
|
-
position.top += scrollEl.scrollTop - prevScroll;
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
|
-
};
|
|
440
|
-
/**
|
|
441
|
-
* @internal Function used to scroll the page.
|
|
442
|
-
*
|
|
443
|
-
* @param event `MouseEvent` that triggers the resize
|
|
444
|
-
* @param el `HTMLElement` that's being resized
|
|
445
|
-
* @param distance Distance from the V edges to start scrolling
|
|
446
|
-
*/
|
|
447
|
-
Utils.updateScrollResize = function (event, el, distance) {
|
|
448
|
-
var scrollEl = this.getScrollElement(el);
|
|
449
|
-
var height = scrollEl.clientHeight;
|
|
450
|
-
// #1727 event.clientY is relative to viewport, so must compare this against position of scrollEl getBoundingClientRect().top
|
|
451
|
-
// #1745 Special situation if scrollEl is document 'html': here browser spec states that
|
|
452
|
-
// clientHeight is height of viewport, but getBoundingClientRect() is rectangle of html element;
|
|
453
|
-
// this discrepancy arises because in reality scrollbar is attached to viewport, not html element itself.
|
|
454
|
-
var offsetTop = (scrollEl === this.getScrollElement()) ? 0 : scrollEl.getBoundingClientRect().top;
|
|
455
|
-
var pointerPosY = event.clientY - offsetTop;
|
|
456
|
-
var top = pointerPosY < distance;
|
|
457
|
-
var bottom = pointerPosY > height - distance;
|
|
458
|
-
if (top) {
|
|
459
|
-
// This also can be done with a timeout to keep scrolling while the mouse is
|
|
460
|
-
// in the scrolling zone. (will have smoother behavior)
|
|
461
|
-
scrollEl.scrollBy({ behavior: 'smooth', top: pointerPosY - distance });
|
|
462
|
-
}
|
|
463
|
-
else if (bottom) {
|
|
464
|
-
scrollEl.scrollBy({ behavior: 'smooth', top: distance - (height - pointerPosY) });
|
|
465
|
-
}
|
|
466
|
-
};
|
|
467
|
-
/** single level clone, returning a new object with same top fields. This will share sub objects and arrays */
|
|
468
|
-
Utils.clone = function (obj) {
|
|
469
|
-
if (obj === null || obj === undefined || typeof (obj) !== 'object') {
|
|
470
|
-
return obj;
|
|
471
|
-
}
|
|
472
|
-
// return Object.assign({}, obj);
|
|
473
|
-
if (obj instanceof Array) {
|
|
474
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
475
|
-
return __spreadArray([], obj, true);
|
|
476
|
-
}
|
|
477
|
-
return __assign({}, obj);
|
|
478
|
-
};
|
|
479
|
-
/**
|
|
480
|
-
* Recursive clone version that returns a full copy, checking for nested objects and arrays ONLY.
|
|
481
|
-
* Note: this will use as-is any key starting with double __ (and not copy inside) some lib have circular dependencies.
|
|
482
|
-
*/
|
|
483
|
-
Utils.cloneDeep = function (obj) {
|
|
484
|
-
// list of fields we will skip during cloneDeep (nested objects, other internal)
|
|
485
|
-
var skipFields = ['parentGrid', 'el', 'grid', 'subGrid', 'engine'];
|
|
486
|
-
// return JSON.parse(JSON.stringify(obj)); // doesn't work with date format ?
|
|
487
|
-
var ret = Utils.clone(obj);
|
|
488
|
-
var _loop_1 = function (key) {
|
|
489
|
-
// NOTE: we don't support function/circular dependencies so skip those properties for now...
|
|
490
|
-
if (ret.hasOwnProperty(key) && typeof (ret[key]) === 'object' && key.substring(0, 2) !== '__' && !skipFields.find(function (k) { return k === key; })) {
|
|
491
|
-
ret[key] = Utils.cloneDeep(obj[key]);
|
|
492
|
-
}
|
|
493
|
-
};
|
|
494
|
-
for (var key in ret) {
|
|
495
|
-
_loop_1(key);
|
|
496
|
-
}
|
|
497
|
-
return ret;
|
|
498
|
-
};
|
|
499
|
-
/** deep clone the given HTML node, removing teh unique id field */
|
|
500
|
-
Utils.cloneNode = function (el) {
|
|
501
|
-
var node = el.cloneNode(true);
|
|
502
|
-
node.removeAttribute('id');
|
|
503
|
-
return node;
|
|
504
|
-
};
|
|
505
|
-
Utils.appendTo = function (el, parent) {
|
|
506
|
-
var parentNode;
|
|
507
|
-
if (typeof parent === 'string') {
|
|
508
|
-
parentNode = Utils.getElement(parent);
|
|
509
|
-
}
|
|
510
|
-
else {
|
|
511
|
-
parentNode = parent;
|
|
512
|
-
}
|
|
513
|
-
if (parentNode) {
|
|
514
|
-
parentNode.appendChild(el);
|
|
515
|
-
}
|
|
516
|
-
};
|
|
517
|
-
// public static setPositionRelative(el: HTMLElement): void {
|
|
518
|
-
// if (!(/^(?:r|a|f)/).test(getComputedStyle(el).position)) {
|
|
519
|
-
// el.style.position = "relative";
|
|
520
|
-
// }
|
|
521
|
-
// }
|
|
522
|
-
Utils.addElStyles = function (el, styles) {
|
|
523
|
-
if (styles instanceof Object) {
|
|
524
|
-
var _loop_2 = function (s) {
|
|
525
|
-
if (styles.hasOwnProperty(s)) {
|
|
526
|
-
if (Array.isArray(styles[s])) {
|
|
527
|
-
// support fallback value
|
|
528
|
-
styles[s].forEach(function (val) {
|
|
529
|
-
el.style[s] = val;
|
|
530
|
-
});
|
|
531
|
-
}
|
|
532
|
-
else {
|
|
533
|
-
el.style[s] = styles[s];
|
|
534
|
-
}
|
|
535
|
-
}
|
|
536
|
-
};
|
|
537
|
-
for (var s in styles) {
|
|
538
|
-
_loop_2(s);
|
|
539
|
-
}
|
|
540
|
-
}
|
|
541
|
-
};
|
|
542
|
-
Utils.initEvent = function (e, info) {
|
|
543
|
-
var evt = { type: info.type };
|
|
544
|
-
var obj = {
|
|
545
|
-
button: 0,
|
|
546
|
-
which: 0,
|
|
547
|
-
buttons: 1,
|
|
548
|
-
bubbles: true,
|
|
549
|
-
cancelable: true,
|
|
550
|
-
target: info.target ? info.target : e.target
|
|
551
|
-
};
|
|
552
|
-
['altKey', 'ctrlKey', 'metaKey', 'shiftKey'].forEach(function (p) { return evt[p] = e[p]; }); // keys
|
|
553
|
-
['pageX', 'pageY', 'clientX', 'clientY', 'screenX', 'screenY'].forEach(function (p) { return evt[p] = e[p]; }); // point info
|
|
554
|
-
return __assign(__assign({}, evt), obj);
|
|
555
|
-
};
|
|
556
|
-
/** copies the MouseEvent (or convert Touch) properties and sends it as another event to the given target */
|
|
557
|
-
Utils.simulateMouseEvent = function (e, simulatedType, target) {
|
|
558
|
-
var _a, _b, _c, _d;
|
|
559
|
-
var me = e;
|
|
560
|
-
var simulatedEvent = new MouseEvent(simulatedType, {
|
|
561
|
-
bubbles: true,
|
|
562
|
-
composed: true,
|
|
563
|
-
cancelable: true,
|
|
564
|
-
view: window,
|
|
565
|
-
detail: 1,
|
|
566
|
-
screenX: e.screenX,
|
|
567
|
-
screenY: e.screenY,
|
|
568
|
-
clientX: e.clientX,
|
|
569
|
-
clientY: e.clientY,
|
|
570
|
-
ctrlKey: (_a = me.ctrlKey) !== null && _a !== void 0 ? _a : false,
|
|
571
|
-
altKey: (_b = me.altKey) !== null && _b !== void 0 ? _b : false,
|
|
572
|
-
shiftKey: (_c = me.shiftKey) !== null && _c !== void 0 ? _c : false,
|
|
573
|
-
metaKey: (_d = me.metaKey) !== null && _d !== void 0 ? _d : false,
|
|
574
|
-
button: 0,
|
|
575
|
-
relatedTarget: e.target
|
|
576
|
-
});
|
|
577
|
-
(target || e.target).dispatchEvent(simulatedEvent);
|
|
578
|
-
};
|
|
579
|
-
/**
|
|
580
|
-
* defines an element that is used to get the offset and scale from grid transforms
|
|
581
|
-
* returns the scale and offsets from said element
|
|
582
|
-
*/
|
|
583
|
-
Utils.getValuesFromTransformedElement = function (parent) {
|
|
584
|
-
var transformReference = document.createElement('div');
|
|
585
|
-
Utils.addElStyles(transformReference, {
|
|
586
|
-
opacity: '0',
|
|
587
|
-
position: 'fixed',
|
|
588
|
-
top: 0 + 'px',
|
|
589
|
-
left: 0 + 'px',
|
|
590
|
-
width: '1px',
|
|
591
|
-
height: '1px',
|
|
592
|
-
zIndex: '-999999',
|
|
593
|
-
});
|
|
594
|
-
parent.appendChild(transformReference);
|
|
595
|
-
var transformValues = transformReference.getBoundingClientRect();
|
|
596
|
-
parent.removeChild(transformReference);
|
|
597
|
-
transformReference.remove();
|
|
598
|
-
return {
|
|
599
|
-
xScale: 1 / transformValues.width,
|
|
600
|
-
yScale: 1 / transformValues.height,
|
|
601
|
-
xOffset: transformValues.left,
|
|
602
|
-
yOffset: transformValues.top,
|
|
603
|
-
};
|
|
604
|
-
};
|
|
605
|
-
/** swap the given object 2 field values */
|
|
606
|
-
Utils.swap = function (o, a, b) {
|
|
607
|
-
if (!o)
|
|
608
|
-
return;
|
|
609
|
-
var tmp = o[a];
|
|
610
|
-
o[a] = o[b];
|
|
611
|
-
o[b] = tmp;
|
|
612
|
-
};
|
|
613
|
-
/** returns true if event is inside the given element rectangle */
|
|
614
|
-
// Note: Safari Mac has null event.relatedTarget which causes #1684 so check if DragEvent is inside the coordinates instead
|
|
615
|
-
// this.el.contains(event.relatedTarget as HTMLElement)
|
|
616
|
-
// public static inside(e: MouseEvent, el: HTMLElement): boolean {
|
|
617
|
-
// // srcElement, toElement, target: all set to placeholder when leaving simple grid, so we can't use that (Chrome)
|
|
618
|
-
// const target: HTMLElement = e.relatedTarget || (e as any).fromElement;
|
|
619
|
-
// if (!target) {
|
|
620
|
-
// const { bottom, left, right, top } = el.getBoundingClientRect();
|
|
621
|
-
// return (e.x < right && e.x > left && e.y < bottom && e.y > top);
|
|
622
|
-
// }
|
|
623
|
-
// return el.contains(target);
|
|
624
|
-
// }
|
|
625
|
-
/** true if the item can be rotated (checking for prop, not space available) */
|
|
626
|
-
Utils.canBeRotated = function (n) {
|
|
627
|
-
var _a;
|
|
628
|
-
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));
|
|
629
|
-
};
|
|
630
|
-
return Utils;
|
|
631
|
-
}());
|
|
632
|
-
exports.Utils = Utils;
|
|
633
|
-
//# sourceMappingURL=utils.js.map
|