tsgrid-ui 2.7.1 → 2.10.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/CHANGELOG.md +217 -0
- package/dist/base.d.ts +148 -0
- package/dist/base.es6.js +11 -0
- package/dist/base.es6.js.map +1 -0
- package/dist/chunks/chunk-3NYH6545.js +2423 -0
- package/dist/chunks/chunk-3NYH6545.js.map +1 -0
- package/dist/chunks/chunk-6MOFFUV2.js +2305 -0
- package/dist/chunks/chunk-6MOFFUV2.js.map +1 -0
- package/dist/chunks/chunk-6UCGFWIQ.js +865 -0
- package/dist/chunks/chunk-6UCGFWIQ.js.map +1 -0
- package/dist/chunks/chunk-DXZJHS4M.js +1283 -0
- package/dist/chunks/chunk-DXZJHS4M.js.map +1 -0
- package/dist/chunks/chunk-DZSFZLV6.js +1638 -0
- package/dist/chunks/chunk-DZSFZLV6.js.map +1 -0
- package/dist/chunks/chunk-EQK6JAHT.js +33 -0
- package/dist/chunks/chunk-EQK6JAHT.js.map +1 -0
- package/dist/chunks/chunk-FAIRNXQR.js +3020 -0
- package/dist/chunks/chunk-FAIRNXQR.js.map +1 -0
- package/dist/chunks/chunk-GZFWK4LZ.js +677 -0
- package/dist/chunks/chunk-GZFWK4LZ.js.map +1 -0
- package/dist/chunks/chunk-IYF3Q7GX.js +127 -0
- package/dist/chunks/chunk-IYF3Q7GX.js.map +1 -0
- package/dist/chunks/chunk-KLJ35UAH.js +1795 -0
- package/dist/chunks/chunk-KLJ35UAH.js.map +1 -0
- package/dist/chunks/chunk-LUSNRF73.js +1212 -0
- package/dist/chunks/chunk-LUSNRF73.js.map +1 -0
- package/dist/chunks/chunk-N3GASHTI.js +1127 -0
- package/dist/chunks/chunk-N3GASHTI.js.map +1 -0
- package/dist/field.d.ts +329 -0
- package/dist/field.es6.js +12 -0
- package/dist/field.es6.js.map +1 -0
- package/dist/form.d.ts +162 -0
- package/dist/form.es6.js +15 -0
- package/dist/form.es6.js.map +1 -0
- package/dist/layout.d.ts +108 -0
- package/dist/layout.es6.js +14 -0
- package/dist/layout.es6.js.map +1 -0
- package/dist/locale.d.ts +30 -0
- package/dist/locale.es6.js +7 -0
- package/dist/locale.es6.js.map +1 -0
- package/dist/popup.d.ts +97 -0
- package/dist/popup.es6.js +21 -0
- package/dist/popup.es6.js.map +1 -0
- package/dist/query-CKGg5Ugv.d.ts +81 -0
- package/dist/sidebar.d.ts +138 -0
- package/dist/sidebar.es6.js +12 -0
- package/dist/sidebar.es6.js.map +1 -0
- package/dist/tabs.d.ts +63 -0
- package/dist/tabs.es6.js +12 -0
- package/dist/tabs.es6.js.map +1 -0
- package/dist/toolbar.d.ts +97 -0
- package/dist/toolbar.es6.js +12 -0
- package/dist/toolbar.es6.js.map +1 -0
- package/dist/tooltip.d.ts +330 -0
- package/dist/tooltip.es6.js +21 -0
- package/dist/tooltip.es6.js.map +1 -0
- package/dist/tsgrid-ui.css +2 -2
- package/dist/tsgrid-ui.d.ts +16 -2004
- package/dist/tsgrid-ui.es6.js +7751 -23830
- package/dist/tsgrid-ui.es6.js.map +1 -1
- package/dist/tsgrid-ui.es6.min.js +37 -37
- package/dist/tsgrid-ui.js +150 -22
- package/dist/tsgrid-ui.min.css +2 -2
- package/dist/tsgrid-ui.min.js +39 -39
- package/dist/tsutils-message-CogFtVtO.d.ts +82 -0
- package/dist/utils.d.ts +418 -0
- package/dist/utils.es6.js +14 -0
- package/dist/utils.es6.js.map +1 -0
- package/package.json +25 -5
|
@@ -0,0 +1,1283 @@
|
|
|
1
|
+
// src/tsutils-type-guards.ts
|
|
2
|
+
function isBin(val) {
|
|
3
|
+
const re = /^[0-1]+$/;
|
|
4
|
+
return re.test(String(val));
|
|
5
|
+
}
|
|
6
|
+
function isInt(val) {
|
|
7
|
+
const re = /^[-+]?[0-9]+$/;
|
|
8
|
+
return re.test(String(val));
|
|
9
|
+
}
|
|
10
|
+
function isFloat(val, settings) {
|
|
11
|
+
if (typeof val === "string") {
|
|
12
|
+
val = val.replace(new RegExp(settings.groupSymbol, "g"), "").replace(settings.decimalSymbol, ".");
|
|
13
|
+
}
|
|
14
|
+
return (typeof val === "number" || typeof val === "string" && val !== "") && !isNaN(Number(val));
|
|
15
|
+
}
|
|
16
|
+
function isMoney(val, settings) {
|
|
17
|
+
if (typeof val === "object" || val === "") return false;
|
|
18
|
+
if (isFloat(val, settings)) return true;
|
|
19
|
+
const se = settings;
|
|
20
|
+
const re = new RegExp("^" + (se.currencyPrefix ? "\\" + se.currencyPrefix + "?" : "") + "[-+]?" + (se.currencyPrefix ? "\\" + se.currencyPrefix + "?" : "") + "[0-9]*[\\" + se.decimalSymbol + "]?[0-9]+" + (se.currencySuffix ? "\\" + se.currencySuffix + "?" : "") + "$", "i");
|
|
21
|
+
if (typeof val === "string") {
|
|
22
|
+
val = val.replace(new RegExp(se.groupSymbol, "g"), "");
|
|
23
|
+
}
|
|
24
|
+
return re.test(String(val));
|
|
25
|
+
}
|
|
26
|
+
function isHex(val) {
|
|
27
|
+
const re = /^(0x)?[0-9a-fA-F]+$/;
|
|
28
|
+
return re.test(String(val));
|
|
29
|
+
}
|
|
30
|
+
function isAlphaNumeric(val) {
|
|
31
|
+
const re = /^[a-zA-Z0-9_-]+$/;
|
|
32
|
+
return re.test(String(val));
|
|
33
|
+
}
|
|
34
|
+
function isEmail(val) {
|
|
35
|
+
const email = /^[a-zA-Z0-9._%\-+]+@[а-яА-Яa-zA-Z0-9.-]+\.[а-яА-Яa-zA-Z]+$/;
|
|
36
|
+
return email.test(String(val));
|
|
37
|
+
}
|
|
38
|
+
function isIpAddress(val) {
|
|
39
|
+
const re = new RegExp("^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$");
|
|
40
|
+
return re.test(String(val));
|
|
41
|
+
}
|
|
42
|
+
function isPlainObject(value) {
|
|
43
|
+
if (value == null) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
if (Object.prototype.toString.call(value) !== "[object Object]") {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
if (value.constructor === void 0) {
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
const proto = Object.getPrototypeOf(value);
|
|
53
|
+
return proto === null || proto === Object.prototype;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// src/tsutils-data.ts
|
|
57
|
+
function clone(obj, options) {
|
|
58
|
+
const opts = Object.assign(
|
|
59
|
+
{ functions: true, elements: true, events: true, exclude: [], parent: "" },
|
|
60
|
+
options ?? {}
|
|
61
|
+
);
|
|
62
|
+
if (Array.isArray(obj)) {
|
|
63
|
+
const arr = Array.from(obj);
|
|
64
|
+
arr.forEach((value, ind) => {
|
|
65
|
+
arr[ind] = clone(value, { functions: opts.functions, elements: opts.elements, events: opts.events, exclude: opts.exclude, parent: opts.parent + "[]" });
|
|
66
|
+
});
|
|
67
|
+
return arr;
|
|
68
|
+
} else if (isPlainObject(obj)) {
|
|
69
|
+
const ret = {};
|
|
70
|
+
Object.assign(ret, obj);
|
|
71
|
+
if (Array.isArray(opts.exclude)) {
|
|
72
|
+
opts.exclude.forEach((key) => {
|
|
73
|
+
delete ret[key];
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
Object.keys(ret).forEach((key) => {
|
|
77
|
+
if (typeof opts.exclude == "function" && opts.exclude(key, { obj, parent: opts.parent })) {
|
|
78
|
+
ret[key] = void 0;
|
|
79
|
+
} else {
|
|
80
|
+
ret[key] = clone(ret[key], { functions: opts.functions, elements: opts.elements, events: opts.events, exclude: opts.exclude, parent: opts.parent + (opts.parent ? "." : "") + key });
|
|
81
|
+
}
|
|
82
|
+
if (ret[key] === void 0) delete ret[key];
|
|
83
|
+
});
|
|
84
|
+
return ret;
|
|
85
|
+
} else {
|
|
86
|
+
if (obj instanceof Function && !opts.functions || obj instanceof Node && !opts.elements || obj instanceof Event && !opts.events) {
|
|
87
|
+
return void 0;
|
|
88
|
+
} else {
|
|
89
|
+
return obj;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
function extend(target, source, ...rest) {
|
|
94
|
+
if (Array.isArray(target)) {
|
|
95
|
+
if (Array.isArray(source)) {
|
|
96
|
+
target.splice(0, target.length);
|
|
97
|
+
source.forEach((s) => {
|
|
98
|
+
target.push(clone(s));
|
|
99
|
+
});
|
|
100
|
+
} else {
|
|
101
|
+
throw new Error("Arrays can be extended with arrays only");
|
|
102
|
+
}
|
|
103
|
+
} else if (target instanceof Node || target instanceof Event) {
|
|
104
|
+
throw new Error("HTML elmenents and events cannot be extended");
|
|
105
|
+
} else if (target && typeof target == "object" && source != null) {
|
|
106
|
+
if (typeof source != "object") {
|
|
107
|
+
throw new Error("Object can be extended with other objects only.");
|
|
108
|
+
}
|
|
109
|
+
Object.keys(source).forEach((key) => {
|
|
110
|
+
if (target[key] != null && typeof target[key] == "object" && source[key] != null && typeof source[key] == "object") {
|
|
111
|
+
const src = clone(source[key]);
|
|
112
|
+
if (target[key] instanceof Node || target[key] instanceof Event) {
|
|
113
|
+
target[key] = src;
|
|
114
|
+
} else {
|
|
115
|
+
if (Array.isArray(target[key]) && isPlainObject(src)) {
|
|
116
|
+
target[key] = {};
|
|
117
|
+
}
|
|
118
|
+
extend(target[key], src);
|
|
119
|
+
}
|
|
120
|
+
} else {
|
|
121
|
+
target[key] = clone(source[key]);
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
} else if (source != null) {
|
|
125
|
+
throw new Error("Object is not extendable, only {} or [] can be extended.");
|
|
126
|
+
}
|
|
127
|
+
if (rest.length > 0) {
|
|
128
|
+
for (let i = 0; i < rest.length; i++) {
|
|
129
|
+
extend(target, rest[i]);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return target;
|
|
133
|
+
}
|
|
134
|
+
function naturalCompare(a, b) {
|
|
135
|
+
let i = 0, codeA = 0, codeB = 1, posA = 0, posB = 0;
|
|
136
|
+
const alphabet = String["alphabet"];
|
|
137
|
+
function getCode(str, pos, code) {
|
|
138
|
+
if (code) {
|
|
139
|
+
for (i = pos; code = getCode(str, i), code < 76 && code > 65; ) ++i;
|
|
140
|
+
return +str.slice(pos - 1, i);
|
|
141
|
+
}
|
|
142
|
+
let c = alphabet ? alphabet.indexOf(str.charAt(pos)) : -1;
|
|
143
|
+
return c > -1 ? c + 76 : (c = str.charCodeAt(pos) || 0, c < 45 || c > 127) ? c : c < 46 ? 65 : c < 48 ? c - 1 : c < 58 ? c + 18 : c < 65 ? c - 11 : c < 91 ? c + 11 : c < 97 ? c - 37 : c < 123 ? c + 5 : c - 63;
|
|
144
|
+
}
|
|
145
|
+
const aStr = "" + a, bStr = "" + b;
|
|
146
|
+
if (aStr != bStr) for (; codeB; ) {
|
|
147
|
+
codeA = getCode(aStr, posA++);
|
|
148
|
+
codeB = getCode(bStr, posB++);
|
|
149
|
+
if (codeA < 76 && codeB < 76 && codeA > 66 && codeB > 66) {
|
|
150
|
+
codeA = getCode(aStr, posA, posA);
|
|
151
|
+
codeB = getCode(bStr, posB, posA = i);
|
|
152
|
+
posB = i;
|
|
153
|
+
}
|
|
154
|
+
if (codeA != codeB) return codeA < codeB ? -1 : 1;
|
|
155
|
+
}
|
|
156
|
+
return 0;
|
|
157
|
+
}
|
|
158
|
+
function getNested(obj, prop) {
|
|
159
|
+
let val;
|
|
160
|
+
try {
|
|
161
|
+
val = obj;
|
|
162
|
+
const tmp = String(prop).split(".");
|
|
163
|
+
for (let i = 0; i < tmp.length; i++) {
|
|
164
|
+
val = val[tmp[i] ?? ""];
|
|
165
|
+
}
|
|
166
|
+
} catch (event) {
|
|
167
|
+
val = void 0;
|
|
168
|
+
}
|
|
169
|
+
return val;
|
|
170
|
+
}
|
|
171
|
+
function normMenu(menu, options = {}) {
|
|
172
|
+
if (Array.isArray(menu)) {
|
|
173
|
+
menu.forEach((it, m) => {
|
|
174
|
+
if (typeof it === "string" || typeof it === "number") {
|
|
175
|
+
menu[m] = { id: it, text: String(it) };
|
|
176
|
+
} else if (it != null) {
|
|
177
|
+
if (options.itemMap != null) {
|
|
178
|
+
let val = getNested(it, options.itemMap.id);
|
|
179
|
+
if (options.itemMap.id != null && val != null) {
|
|
180
|
+
it.id = val;
|
|
181
|
+
}
|
|
182
|
+
val = getNested(it, options.itemMap.text);
|
|
183
|
+
if (options.itemMap.text != null && val) {
|
|
184
|
+
it.text = val;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
if (it.caption != null && it.text == null) it.text = it.caption;
|
|
188
|
+
if (it.text != null && it.id == null) it.id = it.text;
|
|
189
|
+
if (it.text == null && it.id != null) it.text = it.id;
|
|
190
|
+
} else {
|
|
191
|
+
menu[m] = { id: null, text: "null" };
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
return menu;
|
|
195
|
+
} else if (typeof menu === "function") {
|
|
196
|
+
const newMenu = menu(menu, options);
|
|
197
|
+
return normMenu(newMenu, options);
|
|
198
|
+
} else if (typeof menu === "object" && menu !== null) {
|
|
199
|
+
const menuObj = menu;
|
|
200
|
+
return Object.keys(menuObj).map((key) => {
|
|
201
|
+
return { id: key, text: String(menuObj[key] ?? "") };
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
function encodeParams(obj, prefix = "") {
|
|
206
|
+
let str = "";
|
|
207
|
+
Object.keys(obj).forEach((key) => {
|
|
208
|
+
if (str != "") str += "&";
|
|
209
|
+
if (typeof obj[key] == "object") {
|
|
210
|
+
str += encodeParams(obj[key], prefix + key + (prefix ? "]" : "") + "[");
|
|
211
|
+
} else {
|
|
212
|
+
str += `${prefix}${key}${prefix ? "]" : ""}=${obj[key]}`;
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
return str;
|
|
216
|
+
}
|
|
217
|
+
function prepareParams(url, fetchOptions, options, defaultDataType) {
|
|
218
|
+
const dataType = options?.["dataType"] ?? defaultDataType;
|
|
219
|
+
let postParams = fetchOptions["body"];
|
|
220
|
+
fetchOptions["method"] = String(fetchOptions["method"]).toUpperCase();
|
|
221
|
+
switch (dataType) {
|
|
222
|
+
/**
|
|
223
|
+
* Will submit GET, POST, PUT, DELETE
|
|
224
|
+
* - if GET - it will be in URL
|
|
225
|
+
* - if POST, PUT, DELETE it will be JSON encoded
|
|
226
|
+
*/
|
|
227
|
+
case "RESTFULL":
|
|
228
|
+
case "RESTFULJSON": {
|
|
229
|
+
if (["POST", "PUT", "DELETE"].includes(String(fetchOptions["method"]))) {
|
|
230
|
+
;
|
|
231
|
+
fetchOptions["headers"]["Content-Type"] = "application/json";
|
|
232
|
+
}
|
|
233
|
+
if (String(fetchOptions["method"]) == "GET") {
|
|
234
|
+
if (dataType == "RESTFULLJSON") {
|
|
235
|
+
postParams = { request: postParams };
|
|
236
|
+
}
|
|
237
|
+
body2params();
|
|
238
|
+
}
|
|
239
|
+
break;
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Will submit either GET or POST and
|
|
243
|
+
* - if POST it will be JSON encoded
|
|
244
|
+
* - if GET it will be in URL
|
|
245
|
+
* - if HTTPJSON and GET then it will be JSON encoded
|
|
246
|
+
*/
|
|
247
|
+
case "HTTP":
|
|
248
|
+
case "HTTPJSON":
|
|
249
|
+
case "JSON": {
|
|
250
|
+
if (String(fetchOptions["method"]) == "GET") {
|
|
251
|
+
if (dataType == "JSON" || dataType === "HTTPJSON") {
|
|
252
|
+
postParams = { request: postParams };
|
|
253
|
+
}
|
|
254
|
+
body2params();
|
|
255
|
+
} else {
|
|
256
|
+
;
|
|
257
|
+
fetchOptions["headers"]["Content-Type"] = "application/json";
|
|
258
|
+
fetchOptions["method"] = "POST";
|
|
259
|
+
}
|
|
260
|
+
break;
|
|
261
|
+
}
|
|
262
|
+
default: {
|
|
263
|
+
if (typeof dataType == "function") {
|
|
264
|
+
fetchOptions = dataType(url, fetchOptions, options);
|
|
265
|
+
} else {
|
|
266
|
+
console.log(`ERROR: Unsupported dataType "${dataType}". Supported types are JSON (default), HTTP, RESTFULL. For backward compatibility HTTPJSON is same as JSON. RESTULFLJSON will encode GET request as JSON.`);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
if (fetchOptions["body"] != null) {
|
|
271
|
+
fetchOptions["body"] = typeof fetchOptions["body"] == "string" ? fetchOptions["body"] : JSON.stringify(fetchOptions["body"]);
|
|
272
|
+
}
|
|
273
|
+
return fetchOptions;
|
|
274
|
+
function body2params() {
|
|
275
|
+
const pp = postParams;
|
|
276
|
+
Object.keys(pp).forEach((key) => {
|
|
277
|
+
let param = pp[key];
|
|
278
|
+
if (typeof param == "object") param = JSON.stringify(param);
|
|
279
|
+
url.searchParams.append(key, String(param ?? ""));
|
|
280
|
+
});
|
|
281
|
+
delete fetchOptions["body"];
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
function parseRoute(route) {
|
|
285
|
+
const keys = [];
|
|
286
|
+
const path = route.replace(/\/\(/g, "(?:/").replace(/\+/g, "__plus__").replace(/(\/)?(\.)?:(\w+)(?:(\(.*?\)))?(\?)?/g, (_, slash, format, key, capture, optional) => {
|
|
287
|
+
keys.push({ name: key, optional: !!optional });
|
|
288
|
+
slash = slash || "";
|
|
289
|
+
return "" + (optional ? "" : slash) + "(?:" + (optional ? slash : "") + (format || "") + (capture || (format && "([^/.]+?)" || "([^/]+?)")) + ")" + (optional || "");
|
|
290
|
+
}).replace(/([\/.])/g, "\\$1").replace(/__plus__/g, "(.+)").replace(/\*/g, "(.*)");
|
|
291
|
+
return {
|
|
292
|
+
path: new RegExp("^" + path + "$", "i"),
|
|
293
|
+
keys
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
function debounce(func, wait2 = 250) {
|
|
297
|
+
let timeout;
|
|
298
|
+
return (...args) => {
|
|
299
|
+
clearTimeout(timeout);
|
|
300
|
+
timeout = setTimeout(() => {
|
|
301
|
+
func(...args);
|
|
302
|
+
}, wait2);
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
async function wait(time = 0) {
|
|
306
|
+
return new Promise((resolve) => {
|
|
307
|
+
setTimeout(() => resolve(), time);
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
// src/tsutils-registry.ts
|
|
312
|
+
var TsUi = {};
|
|
313
|
+
function checkName(name) {
|
|
314
|
+
if (name == null) {
|
|
315
|
+
console.log('ERROR: Property "name" is required but not supplied.');
|
|
316
|
+
return false;
|
|
317
|
+
}
|
|
318
|
+
if (TsUi[name] != null) {
|
|
319
|
+
console.log(`ERROR: Object named "${name}" is already registered as TsUi.${name}.`);
|
|
320
|
+
return false;
|
|
321
|
+
}
|
|
322
|
+
if (!isAlphaNumeric(name)) {
|
|
323
|
+
console.log('ERROR: Property "name" has to be alpha-numeric (a-z, 0-9, dash and underscore).');
|
|
324
|
+
return false;
|
|
325
|
+
}
|
|
326
|
+
return true;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
// src/query.ts
|
|
330
|
+
var Query = class _Query {
|
|
331
|
+
static version = 0.8;
|
|
332
|
+
context;
|
|
333
|
+
nodes;
|
|
334
|
+
length;
|
|
335
|
+
constructor(selector, context) {
|
|
336
|
+
this.context = context ?? document;
|
|
337
|
+
let nodes = [];
|
|
338
|
+
if (Array.isArray(selector)) {
|
|
339
|
+
nodes = selector;
|
|
340
|
+
} else if (selector instanceof Node || selector instanceof Window) {
|
|
341
|
+
nodes = [selector];
|
|
342
|
+
} else if (selector instanceof _Query) {
|
|
343
|
+
nodes = selector.nodes;
|
|
344
|
+
} else if (typeof selector == "string") {
|
|
345
|
+
if (typeof this.context.querySelector != "function") {
|
|
346
|
+
throw new Error("Invalid context");
|
|
347
|
+
}
|
|
348
|
+
nodes = Array.from(this.context.querySelectorAll(selector));
|
|
349
|
+
} else if (selector == null) {
|
|
350
|
+
nodes = [];
|
|
351
|
+
} else {
|
|
352
|
+
const arr = Array.from(selector ?? []);
|
|
353
|
+
if (typeof selector == "object" && Array.isArray(arr)) {
|
|
354
|
+
nodes = arr;
|
|
355
|
+
} else {
|
|
356
|
+
throw new Error(`Invalid selector "${selector}"`);
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
this.nodes = nodes;
|
|
360
|
+
this.length = nodes.length;
|
|
361
|
+
this.each((node, ind) => {
|
|
362
|
+
this[ind] = node;
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
static _fragment(html) {
|
|
366
|
+
const tmpl = document.createElement("template");
|
|
367
|
+
tmpl.innerHTML = html;
|
|
368
|
+
tmpl.content.childNodes.forEach((node) => {
|
|
369
|
+
const newNode = _Query._scriptConvert(node);
|
|
370
|
+
if (newNode != node) {
|
|
371
|
+
tmpl.content.replaceChild(newNode, node);
|
|
372
|
+
}
|
|
373
|
+
});
|
|
374
|
+
return tmpl.content;
|
|
375
|
+
}
|
|
376
|
+
// innerHTML, append, etc. script tags will not be executed unless they are proper script tags
|
|
377
|
+
static _scriptConvert(node) {
|
|
378
|
+
const convert = (txtNode) => {
|
|
379
|
+
const doc = txtNode.ownerDocument;
|
|
380
|
+
const scNode = doc.createElement("script");
|
|
381
|
+
scNode.text = txtNode.text;
|
|
382
|
+
const attrs = txtNode.attributes;
|
|
383
|
+
for (let i = 0; i < attrs.length; i++) {
|
|
384
|
+
const attr = attrs[i];
|
|
385
|
+
if (attr) scNode.setAttribute(attr.name, attr.value);
|
|
386
|
+
}
|
|
387
|
+
return scNode;
|
|
388
|
+
};
|
|
389
|
+
if (node.tagName == "SCRIPT") {
|
|
390
|
+
node = convert(node);
|
|
391
|
+
}
|
|
392
|
+
if (node.querySelectorAll) {
|
|
393
|
+
node.querySelectorAll("script").forEach((textNode) => {
|
|
394
|
+
textNode.parentNode.replaceChild(convert(textNode), textNode);
|
|
395
|
+
});
|
|
396
|
+
}
|
|
397
|
+
return node;
|
|
398
|
+
}
|
|
399
|
+
static _fixProp(name) {
|
|
400
|
+
const fixes = {
|
|
401
|
+
cellpadding: "cellPadding",
|
|
402
|
+
cellspacing: "cellSpacing",
|
|
403
|
+
class: "className",
|
|
404
|
+
colspan: "colSpan",
|
|
405
|
+
contenteditable: "contentEditable",
|
|
406
|
+
for: "htmlFor",
|
|
407
|
+
frameborder: "frameBorder",
|
|
408
|
+
maxlength: "maxLength",
|
|
409
|
+
readonly: "readOnly",
|
|
410
|
+
rowspan: "rowSpan",
|
|
411
|
+
tabindex: "tabIndex",
|
|
412
|
+
usemap: "useMap"
|
|
413
|
+
};
|
|
414
|
+
return fixes[name] ? fixes[name] : name;
|
|
415
|
+
}
|
|
416
|
+
_insert(method, html) {
|
|
417
|
+
const nodes = [];
|
|
418
|
+
const len = this.length;
|
|
419
|
+
if (len < 1) return this;
|
|
420
|
+
if (typeof html == "string") {
|
|
421
|
+
this.each((node) => {
|
|
422
|
+
const clone2 = _Query._fragment(html);
|
|
423
|
+
nodes.push(...clone2.childNodes);
|
|
424
|
+
node[method]?.(clone2);
|
|
425
|
+
});
|
|
426
|
+
} else if (html instanceof _Query) {
|
|
427
|
+
const single = len == 1;
|
|
428
|
+
html.each((el) => {
|
|
429
|
+
this.each((node) => {
|
|
430
|
+
const clone2 = single ? el : el.cloneNode(true);
|
|
431
|
+
nodes.push(clone2);
|
|
432
|
+
node[method]?.(clone2);
|
|
433
|
+
_Query._scriptConvert(clone2);
|
|
434
|
+
});
|
|
435
|
+
});
|
|
436
|
+
if (!single) html.remove();
|
|
437
|
+
} else if (html instanceof Node) {
|
|
438
|
+
this.each((node) => {
|
|
439
|
+
const clone2 = len === 1 ? html : _Query._fragment(html.outerHTML);
|
|
440
|
+
nodes.push(...len === 1 ? [html] : clone2.childNodes);
|
|
441
|
+
node[method]?.(clone2);
|
|
442
|
+
});
|
|
443
|
+
if (len > 1) html.remove();
|
|
444
|
+
} else {
|
|
445
|
+
throw new Error(`Incorrect argument for "${method}(html)". It expects one string argument.`);
|
|
446
|
+
}
|
|
447
|
+
if (method == "replaceWith") {
|
|
448
|
+
return new _Query(nodes, this.context);
|
|
449
|
+
}
|
|
450
|
+
return this;
|
|
451
|
+
}
|
|
452
|
+
_save(node, name, value) {
|
|
453
|
+
node._mQuery = node._mQuery ?? {};
|
|
454
|
+
if (Array.isArray(value)) {
|
|
455
|
+
node._mQuery[name] = node._mQuery[name] ?? [];
|
|
456
|
+
node._mQuery[name].push(...value);
|
|
457
|
+
} else if (value != null) {
|
|
458
|
+
node._mQuery[name] = value;
|
|
459
|
+
} else {
|
|
460
|
+
delete node._mQuery[name];
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
get(index) {
|
|
464
|
+
if (index === void 0 || index === null) return this.nodes;
|
|
465
|
+
if (index < 0) index = this.length + index;
|
|
466
|
+
const node = this[index];
|
|
467
|
+
if (node) {
|
|
468
|
+
return node;
|
|
469
|
+
}
|
|
470
|
+
return null;
|
|
471
|
+
}
|
|
472
|
+
eq(index) {
|
|
473
|
+
if (index < 0) index = this.length + index;
|
|
474
|
+
const item = this[index];
|
|
475
|
+
const nodes = item != null ? [item] : [];
|
|
476
|
+
return new _Query(nodes, this.context);
|
|
477
|
+
}
|
|
478
|
+
then(fun) {
|
|
479
|
+
const ret = fun(this);
|
|
480
|
+
return ret != null ? ret : this;
|
|
481
|
+
}
|
|
482
|
+
find(selector) {
|
|
483
|
+
const nodes = [];
|
|
484
|
+
this.each((node) => {
|
|
485
|
+
const nn = Array.from(node.querySelectorAll(selector));
|
|
486
|
+
if (nn.length > 0) {
|
|
487
|
+
nodes.push(...nn);
|
|
488
|
+
}
|
|
489
|
+
});
|
|
490
|
+
return new _Query(nodes, this.context);
|
|
491
|
+
}
|
|
492
|
+
filter(selector) {
|
|
493
|
+
const nodes = [];
|
|
494
|
+
this.each((node) => {
|
|
495
|
+
if (node === selector || typeof selector == "string" && node.matches && node.matches(selector) || typeof selector == "function" && selector(node)) {
|
|
496
|
+
nodes.push(node);
|
|
497
|
+
}
|
|
498
|
+
});
|
|
499
|
+
return new _Query(nodes, this.context);
|
|
500
|
+
}
|
|
501
|
+
next() {
|
|
502
|
+
const nodes = [];
|
|
503
|
+
this.each((node) => {
|
|
504
|
+
const nn = node.nextElementSibling;
|
|
505
|
+
if (nn) {
|
|
506
|
+
nodes.push(nn);
|
|
507
|
+
}
|
|
508
|
+
});
|
|
509
|
+
return new _Query(nodes, this.context);
|
|
510
|
+
}
|
|
511
|
+
prev() {
|
|
512
|
+
const nodes = [];
|
|
513
|
+
this.each((node) => {
|
|
514
|
+
const nn = node.previousElementSibling;
|
|
515
|
+
if (nn) {
|
|
516
|
+
nodes.push(nn);
|
|
517
|
+
}
|
|
518
|
+
});
|
|
519
|
+
return new _Query(nodes, this.context);
|
|
520
|
+
}
|
|
521
|
+
shadow(selector) {
|
|
522
|
+
const nodes = [];
|
|
523
|
+
this.each((node) => {
|
|
524
|
+
if (node.shadowRoot) nodes.push(node.shadowRoot);
|
|
525
|
+
});
|
|
526
|
+
const col = new _Query(nodes, this.context);
|
|
527
|
+
return selector ? col.find(selector) : col;
|
|
528
|
+
}
|
|
529
|
+
closest(selector) {
|
|
530
|
+
const nodes = [];
|
|
531
|
+
this.each((node) => {
|
|
532
|
+
const nn = node.closest(selector);
|
|
533
|
+
if (nn) {
|
|
534
|
+
nodes.push(nn);
|
|
535
|
+
}
|
|
536
|
+
});
|
|
537
|
+
return new _Query(nodes, this.context);
|
|
538
|
+
}
|
|
539
|
+
host(all) {
|
|
540
|
+
const nodes = [];
|
|
541
|
+
const top = (node) => {
|
|
542
|
+
if (node.parentNode) {
|
|
543
|
+
return top(node.parentNode);
|
|
544
|
+
} else {
|
|
545
|
+
return node;
|
|
546
|
+
}
|
|
547
|
+
};
|
|
548
|
+
const fun = (node) => {
|
|
549
|
+
const nn = top(node);
|
|
550
|
+
nodes.push(nn.host ? nn.host : nn);
|
|
551
|
+
if (nn.host && all) fun(nn.host);
|
|
552
|
+
};
|
|
553
|
+
this.each((node) => {
|
|
554
|
+
fun(node);
|
|
555
|
+
});
|
|
556
|
+
return new _Query(nodes, this.context);
|
|
557
|
+
}
|
|
558
|
+
parent(selector) {
|
|
559
|
+
return this.parents(selector, true);
|
|
560
|
+
}
|
|
561
|
+
parents(selector, firstOnly) {
|
|
562
|
+
const nodes = [];
|
|
563
|
+
const add = (node) => {
|
|
564
|
+
if (nodes.indexOf(node) == -1) {
|
|
565
|
+
nodes.push(node);
|
|
566
|
+
}
|
|
567
|
+
if (!firstOnly && node.parentNode) {
|
|
568
|
+
return add(node.parentNode);
|
|
569
|
+
}
|
|
570
|
+
};
|
|
571
|
+
this.each((node) => {
|
|
572
|
+
if (node.parentNode) add(node.parentNode);
|
|
573
|
+
});
|
|
574
|
+
const col = new _Query(nodes, this.context);
|
|
575
|
+
return selector ? col.filter(selector) : col;
|
|
576
|
+
}
|
|
577
|
+
add(more) {
|
|
578
|
+
const nodes = more instanceof _Query ? more.nodes : Array.isArray(more) ? more : [more];
|
|
579
|
+
return new _Query(this.nodes.concat(nodes), this.context);
|
|
580
|
+
}
|
|
581
|
+
each(func) {
|
|
582
|
+
this.nodes.forEach((node, ind) => {
|
|
583
|
+
func(node, ind, this);
|
|
584
|
+
});
|
|
585
|
+
return this;
|
|
586
|
+
}
|
|
587
|
+
append(html) {
|
|
588
|
+
return this._insert("append", html);
|
|
589
|
+
}
|
|
590
|
+
prepend(html) {
|
|
591
|
+
return this._insert("prepend", html);
|
|
592
|
+
}
|
|
593
|
+
after(html) {
|
|
594
|
+
return this._insert("after", html);
|
|
595
|
+
}
|
|
596
|
+
before(html) {
|
|
597
|
+
return this._insert("before", html);
|
|
598
|
+
}
|
|
599
|
+
replace(html) {
|
|
600
|
+
return this._insert("replaceWith", html);
|
|
601
|
+
}
|
|
602
|
+
remove() {
|
|
603
|
+
this.each((node) => {
|
|
604
|
+
node.remove();
|
|
605
|
+
});
|
|
606
|
+
return this;
|
|
607
|
+
}
|
|
608
|
+
css(key, value) {
|
|
609
|
+
let css = typeof key === "object" ? key : {};
|
|
610
|
+
const len = arguments.length;
|
|
611
|
+
if (len === 0 || len === 1 && typeof key == "string") {
|
|
612
|
+
if (this[0]) {
|
|
613
|
+
const st = this[0].style;
|
|
614
|
+
if (typeof key == "string") {
|
|
615
|
+
const pri = st.getPropertyPriority(key);
|
|
616
|
+
return st.getPropertyValue(key) + (pri ? "!" + pri : "");
|
|
617
|
+
} else {
|
|
618
|
+
return Object.fromEntries(
|
|
619
|
+
this[0].style.cssText.split(";").filter((a) => !!a).map((a) => {
|
|
620
|
+
return a.split(":").map((a2) => a2.trim());
|
|
621
|
+
})
|
|
622
|
+
);
|
|
623
|
+
}
|
|
624
|
+
} else {
|
|
625
|
+
return void 0;
|
|
626
|
+
}
|
|
627
|
+
} else {
|
|
628
|
+
if (typeof key != "object") {
|
|
629
|
+
css = {};
|
|
630
|
+
css[key] = value;
|
|
631
|
+
}
|
|
632
|
+
this.each((el) => {
|
|
633
|
+
Object.keys(css).forEach((key2) => {
|
|
634
|
+
const imp = String(css[key2]).toLowerCase().includes("!important") ? "important" : "";
|
|
635
|
+
el.style.setProperty(key2, String(css[key2]).replace(/\!important/i, ""), imp);
|
|
636
|
+
});
|
|
637
|
+
});
|
|
638
|
+
return this;
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
addClass(classes) {
|
|
642
|
+
this.toggleClass(classes, true);
|
|
643
|
+
return this;
|
|
644
|
+
}
|
|
645
|
+
removeClass(classes) {
|
|
646
|
+
this.toggleClass(classes, false);
|
|
647
|
+
return this;
|
|
648
|
+
}
|
|
649
|
+
toggleClass(classes, force) {
|
|
650
|
+
if (typeof classes == "string") classes = classes.split(/[,\s]+/);
|
|
651
|
+
this.each((node) => {
|
|
652
|
+
let classes2 = classes;
|
|
653
|
+
if (classes2 == null && force === false) classes2 = Array.from(node.classList);
|
|
654
|
+
if (classes2) {
|
|
655
|
+
classes2.forEach((className) => {
|
|
656
|
+
if (className !== "") {
|
|
657
|
+
let act = "toggle";
|
|
658
|
+
if (force != null) act = force ? "add" : "remove";
|
|
659
|
+
node.classList[act](className);
|
|
660
|
+
}
|
|
661
|
+
});
|
|
662
|
+
}
|
|
663
|
+
});
|
|
664
|
+
return this;
|
|
665
|
+
}
|
|
666
|
+
hasClass(classes) {
|
|
667
|
+
if (typeof classes == "string") classes = classes.split(/[,\s]+/);
|
|
668
|
+
if (classes == null && this.length > 0) {
|
|
669
|
+
return Array.from(this[0].classList);
|
|
670
|
+
}
|
|
671
|
+
let ret = false;
|
|
672
|
+
this.each((node) => {
|
|
673
|
+
ret = ret || classes.every((className) => {
|
|
674
|
+
return Array.from(node.classList ?? []).includes(className);
|
|
675
|
+
});
|
|
676
|
+
});
|
|
677
|
+
return ret;
|
|
678
|
+
}
|
|
679
|
+
on(events, optionsOrCallback, callback) {
|
|
680
|
+
let options = void 0;
|
|
681
|
+
if (typeof optionsOrCallback == "function") {
|
|
682
|
+
callback = optionsOrCallback;
|
|
683
|
+
options = void 0;
|
|
684
|
+
} else {
|
|
685
|
+
options = optionsOrCallback;
|
|
686
|
+
}
|
|
687
|
+
let delegate;
|
|
688
|
+
if (options?.delegate) {
|
|
689
|
+
delegate = options.delegate;
|
|
690
|
+
delete options.delegate;
|
|
691
|
+
}
|
|
692
|
+
const eventsStr = events.split(/[,\s]+/);
|
|
693
|
+
eventsStr.forEach((eventName) => {
|
|
694
|
+
const parts = String(eventName).toLowerCase().split(".");
|
|
695
|
+
const event = parts[0] ?? "";
|
|
696
|
+
const scope = parts[1];
|
|
697
|
+
let cb = callback;
|
|
698
|
+
if (delegate) {
|
|
699
|
+
const fun = cb;
|
|
700
|
+
cb = (evt) => {
|
|
701
|
+
const parent = query(evt.target).parents(delegate);
|
|
702
|
+
if (parent.length > 0) {
|
|
703
|
+
evt["delegate"] = parent[0];
|
|
704
|
+
} else {
|
|
705
|
+
evt["delegate"] = evt.target;
|
|
706
|
+
}
|
|
707
|
+
if (evt.target.matches(delegate) || parent.length > 0) {
|
|
708
|
+
fun(evt);
|
|
709
|
+
}
|
|
710
|
+
};
|
|
711
|
+
}
|
|
712
|
+
this.each((node) => {
|
|
713
|
+
this._save(node, "events", [{ event, scope, callback: cb, options }]);
|
|
714
|
+
node.addEventListener(event, cb, options);
|
|
715
|
+
});
|
|
716
|
+
});
|
|
717
|
+
return this;
|
|
718
|
+
}
|
|
719
|
+
off(events, options, callback) {
|
|
720
|
+
if (typeof options == "function") {
|
|
721
|
+
callback = options;
|
|
722
|
+
options = void 0;
|
|
723
|
+
}
|
|
724
|
+
const eventsStr = (events ?? "").split(/[,\s]+/);
|
|
725
|
+
eventsStr.forEach((eventName) => {
|
|
726
|
+
const offParts = String(eventName).toLowerCase().split(".");
|
|
727
|
+
const event = offParts[0] ?? "";
|
|
728
|
+
const scope = offParts[1];
|
|
729
|
+
this.each((node) => {
|
|
730
|
+
if (Array.isArray(node._mQuery?.events)) {
|
|
731
|
+
for (let i = node._mQuery.events.length - 1; i >= 0; i--) {
|
|
732
|
+
const evt = node._mQuery.events[i];
|
|
733
|
+
if (!evt) continue;
|
|
734
|
+
if (scope == null || scope === "") {
|
|
735
|
+
if ((evt.event == event || event === "") && (evt.callback == callback || callback == null)) {
|
|
736
|
+
node.removeEventListener(evt.event, evt.callback, evt.options);
|
|
737
|
+
node._mQuery.events.splice(i, 1);
|
|
738
|
+
}
|
|
739
|
+
} else {
|
|
740
|
+
if ((evt.event == event || event === "") && evt.scope == scope) {
|
|
741
|
+
node.removeEventListener(evt.event, evt.callback, evt.options);
|
|
742
|
+
node._mQuery.events.splice(i, 1);
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
});
|
|
748
|
+
});
|
|
749
|
+
return this;
|
|
750
|
+
}
|
|
751
|
+
trigger(name, options) {
|
|
752
|
+
let event;
|
|
753
|
+
const mevent = ["click", "dblclick", "mousedown", "mouseup", "mousemove"];
|
|
754
|
+
const kevent = ["keydown", "keyup", "keypress"];
|
|
755
|
+
if (name instanceof Event) {
|
|
756
|
+
event = name;
|
|
757
|
+
} else if (mevent.includes(name)) {
|
|
758
|
+
event = new MouseEvent(name, options);
|
|
759
|
+
} else if (kevent.includes(name)) {
|
|
760
|
+
event = new KeyboardEvent(name, options);
|
|
761
|
+
} else {
|
|
762
|
+
event = new Event(name, options);
|
|
763
|
+
}
|
|
764
|
+
this.each((node) => {
|
|
765
|
+
node.dispatchEvent(event);
|
|
766
|
+
});
|
|
767
|
+
return this;
|
|
768
|
+
}
|
|
769
|
+
attr(name, value) {
|
|
770
|
+
if (value === void 0 && typeof name == "string") {
|
|
771
|
+
return this[0] ? this[0].getAttribute(name) ?? void 0 : void 0;
|
|
772
|
+
} else {
|
|
773
|
+
let obj = {};
|
|
774
|
+
if (typeof name == "object") obj = name;
|
|
775
|
+
else obj[name] = value;
|
|
776
|
+
this.each((node) => {
|
|
777
|
+
Object.entries(obj).forEach(([nm, val]) => {
|
|
778
|
+
node.setAttribute(nm, val);
|
|
779
|
+
});
|
|
780
|
+
});
|
|
781
|
+
return this;
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
removeAttr(...attrs) {
|
|
785
|
+
this.each((node) => {
|
|
786
|
+
attrs.forEach((attr) => {
|
|
787
|
+
node.removeAttribute(attr);
|
|
788
|
+
});
|
|
789
|
+
});
|
|
790
|
+
return this;
|
|
791
|
+
}
|
|
792
|
+
prop(name, value) {
|
|
793
|
+
if (value === void 0 && typeof name == "string") {
|
|
794
|
+
return this[0] ? this[0][name] : void 0;
|
|
795
|
+
} else {
|
|
796
|
+
let obj = {};
|
|
797
|
+
if (typeof name == "object") obj = name;
|
|
798
|
+
else obj[name] = value;
|
|
799
|
+
this.each((node) => {
|
|
800
|
+
Object.entries(obj).forEach(([nm, val]) => {
|
|
801
|
+
const prop = _Query._fixProp(nm);
|
|
802
|
+
node[prop] = val;
|
|
803
|
+
if (prop == "innerHTML") {
|
|
804
|
+
_Query._scriptConvert(node);
|
|
805
|
+
}
|
|
806
|
+
});
|
|
807
|
+
});
|
|
808
|
+
return this;
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
removeProp(...props) {
|
|
812
|
+
this.each((node) => {
|
|
813
|
+
props.forEach((prop) => {
|
|
814
|
+
delete node[_Query._fixProp(prop)];
|
|
815
|
+
});
|
|
816
|
+
});
|
|
817
|
+
return this;
|
|
818
|
+
}
|
|
819
|
+
data(key, value) {
|
|
820
|
+
if (key instanceof Object && !(typeof key === "string")) {
|
|
821
|
+
Object.entries(key).forEach((item) => {
|
|
822
|
+
this.data(item[0], item[1]);
|
|
823
|
+
});
|
|
824
|
+
return;
|
|
825
|
+
}
|
|
826
|
+
if (key && typeof key === "string" && key.indexOf("-") != -1) {
|
|
827
|
+
console.error(`Key "${key}" contains "-" (dash). Dashes are not allowed in property names. Use camelCase instead.`);
|
|
828
|
+
}
|
|
829
|
+
if (arguments.length < 2) {
|
|
830
|
+
if (this[0]) {
|
|
831
|
+
const data = Object.assign({}, this[0].dataset);
|
|
832
|
+
Object.keys(data).forEach((k) => {
|
|
833
|
+
const v = data[k];
|
|
834
|
+
if (v.startsWith("[") || v.startsWith("{")) {
|
|
835
|
+
try {
|
|
836
|
+
data[k] = JSON.parse(v);
|
|
837
|
+
} catch (e) {
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
});
|
|
841
|
+
return key ? data[key] : data;
|
|
842
|
+
} else {
|
|
843
|
+
return void 0;
|
|
844
|
+
}
|
|
845
|
+
} else {
|
|
846
|
+
this.each((node) => {
|
|
847
|
+
if (value != null) {
|
|
848
|
+
node.dataset[key] = value instanceof Object ? JSON.stringify(value) : value;
|
|
849
|
+
} else {
|
|
850
|
+
delete node.dataset[key];
|
|
851
|
+
}
|
|
852
|
+
});
|
|
853
|
+
return this;
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
removeData(key) {
|
|
857
|
+
if (typeof key == "string") key = key.split(/[,\s]+/);
|
|
858
|
+
this.each((node) => {
|
|
859
|
+
key.forEach((k) => {
|
|
860
|
+
delete node.dataset[k];
|
|
861
|
+
});
|
|
862
|
+
});
|
|
863
|
+
return this;
|
|
864
|
+
}
|
|
865
|
+
show() {
|
|
866
|
+
return this.toggle(true);
|
|
867
|
+
}
|
|
868
|
+
hide() {
|
|
869
|
+
return this.toggle(false);
|
|
870
|
+
}
|
|
871
|
+
toggle(force) {
|
|
872
|
+
return this.each((node) => {
|
|
873
|
+
const prev = node.style.display;
|
|
874
|
+
const dsp = getComputedStyle(node).display;
|
|
875
|
+
const isHidden = prev == "none" || dsp == "none";
|
|
876
|
+
if (isHidden && (force == null || force === true)) {
|
|
877
|
+
const def = node instanceof HTMLTableRowElement ? "table-row" : node instanceof HTMLTableCellElement ? "table-cell" : "block";
|
|
878
|
+
node.style.display = node._mQuery?.prevDisplay ?? (prev == dsp && dsp != "none" ? "" : def);
|
|
879
|
+
this._save(node, "prevDisplay", null);
|
|
880
|
+
}
|
|
881
|
+
if (!isHidden && (force == null || force === false)) {
|
|
882
|
+
if (dsp != "none") this._save(node, "prevDisplay", dsp);
|
|
883
|
+
node.style.setProperty("display", "none");
|
|
884
|
+
}
|
|
885
|
+
});
|
|
886
|
+
}
|
|
887
|
+
empty() {
|
|
888
|
+
return this.html("");
|
|
889
|
+
}
|
|
890
|
+
html(html) {
|
|
891
|
+
if (html instanceof HTMLElement) {
|
|
892
|
+
return this.empty().append(html);
|
|
893
|
+
} else {
|
|
894
|
+
return this.prop("innerHTML", html);
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
text(text) {
|
|
898
|
+
return this.prop("textContent", text);
|
|
899
|
+
}
|
|
900
|
+
val(value) {
|
|
901
|
+
return this.prop("value", value);
|
|
902
|
+
}
|
|
903
|
+
change() {
|
|
904
|
+
return this.trigger("change");
|
|
905
|
+
}
|
|
906
|
+
click() {
|
|
907
|
+
return this.trigger("click");
|
|
908
|
+
}
|
|
909
|
+
};
|
|
910
|
+
var query = function(selector, context) {
|
|
911
|
+
if (typeof selector == "function") {
|
|
912
|
+
const fn = selector;
|
|
913
|
+
if (document.readyState == "complete") {
|
|
914
|
+
fn();
|
|
915
|
+
} else {
|
|
916
|
+
window.addEventListener("load", fn);
|
|
917
|
+
}
|
|
918
|
+
} else {
|
|
919
|
+
return new Query(selector, context);
|
|
920
|
+
}
|
|
921
|
+
};
|
|
922
|
+
query.html = (str) => {
|
|
923
|
+
const frag = Query._fragment(str);
|
|
924
|
+
return query(frag.children, frag);
|
|
925
|
+
};
|
|
926
|
+
query.version = Query.version;
|
|
927
|
+
|
|
928
|
+
// src/tsbase.ts
|
|
929
|
+
var query2 = query;
|
|
930
|
+
var TsEvent = class {
|
|
931
|
+
type;
|
|
932
|
+
// assigned via Object.assign in constructor
|
|
933
|
+
detail;
|
|
934
|
+
// assigned via Object.assign in constructor
|
|
935
|
+
owner;
|
|
936
|
+
// assigned via Object.assign in constructor
|
|
937
|
+
target;
|
|
938
|
+
phase;
|
|
939
|
+
// assigned via Object.assign in constructor
|
|
940
|
+
object;
|
|
941
|
+
execute;
|
|
942
|
+
// assigned via Object.assign in constructor
|
|
943
|
+
isStopped;
|
|
944
|
+
// assigned via Object.assign in constructor
|
|
945
|
+
isCancelled;
|
|
946
|
+
// assigned via Object.assign in constructor
|
|
947
|
+
onComplete;
|
|
948
|
+
// assigned via Object.assign in constructor
|
|
949
|
+
listeners;
|
|
950
|
+
// assigned via Object.assign in constructor
|
|
951
|
+
complete;
|
|
952
|
+
_resolve;
|
|
953
|
+
_reject;
|
|
954
|
+
constructor(owner, edata) {
|
|
955
|
+
Object.assign(this, {
|
|
956
|
+
type: edata.type ?? null,
|
|
957
|
+
detail: edata,
|
|
958
|
+
owner,
|
|
959
|
+
target: edata.target ?? null,
|
|
960
|
+
phase: edata.phase ?? "before",
|
|
961
|
+
object: edata.object ?? null,
|
|
962
|
+
execute: null,
|
|
963
|
+
isStopped: false,
|
|
964
|
+
isCancelled: false,
|
|
965
|
+
onComplete: null,
|
|
966
|
+
listeners: []
|
|
967
|
+
});
|
|
968
|
+
delete edata.type;
|
|
969
|
+
delete edata.target;
|
|
970
|
+
delete edata.object;
|
|
971
|
+
this.complete = new Promise((resolve, reject) => {
|
|
972
|
+
this._resolve = resolve;
|
|
973
|
+
this._reject = reject;
|
|
974
|
+
});
|
|
975
|
+
this.complete.catch(() => {
|
|
976
|
+
});
|
|
977
|
+
}
|
|
978
|
+
finish(detail) {
|
|
979
|
+
if (detail) {
|
|
980
|
+
extend(this.detail, detail);
|
|
981
|
+
}
|
|
982
|
+
this.phase = "after";
|
|
983
|
+
this.owner.trigger.call(this.owner, this);
|
|
984
|
+
}
|
|
985
|
+
done(func) {
|
|
986
|
+
this.listeners.push(func);
|
|
987
|
+
}
|
|
988
|
+
preventDefault() {
|
|
989
|
+
this._reject();
|
|
990
|
+
this.isCancelled = true;
|
|
991
|
+
}
|
|
992
|
+
stopPropagation() {
|
|
993
|
+
this.isStopped = true;
|
|
994
|
+
}
|
|
995
|
+
};
|
|
996
|
+
function toSafeEvent(event) {
|
|
997
|
+
if (typeof event !== "object" || event === null) {
|
|
998
|
+
return { type: null, phase: "before", detail: {}, isStopped: false, isCancelled: false };
|
|
999
|
+
}
|
|
1000
|
+
const ev = event;
|
|
1001
|
+
return {
|
|
1002
|
+
type: typeof ev["type"] === "string" ? ev["type"] : null,
|
|
1003
|
+
phase: typeof ev["phase"] === "string" ? ev["phase"] : "before",
|
|
1004
|
+
detail: ev["detail"] ?? {},
|
|
1005
|
+
isStopped: ev["isStopped"] === true,
|
|
1006
|
+
isCancelled: ev["isCancelled"] === true
|
|
1007
|
+
};
|
|
1008
|
+
}
|
|
1009
|
+
var TsBase = class {
|
|
1010
|
+
activeEvents = [];
|
|
1011
|
+
listeners = [];
|
|
1012
|
+
debug = false;
|
|
1013
|
+
name;
|
|
1014
|
+
box;
|
|
1015
|
+
/**
|
|
1016
|
+
* Initializes base object for TsUi, registers it with TsUi object
|
|
1017
|
+
*
|
|
1018
|
+
* @param {string} name - name of the object
|
|
1019
|
+
* @returns
|
|
1020
|
+
*/
|
|
1021
|
+
constructor(name) {
|
|
1022
|
+
this.activeEvents = [];
|
|
1023
|
+
this.listeners = [];
|
|
1024
|
+
if (typeof name !== "undefined") {
|
|
1025
|
+
if (!checkName(name)) return;
|
|
1026
|
+
TsUi[name] = this;
|
|
1027
|
+
}
|
|
1028
|
+
this.debug = false;
|
|
1029
|
+
}
|
|
1030
|
+
/**
|
|
1031
|
+
* Adds event listener, supports event phase and event scoping
|
|
1032
|
+
*
|
|
1033
|
+
* @param {*} edata - an object or string, if string "eventName:phase.scope"
|
|
1034
|
+
* @param {*} handler
|
|
1035
|
+
* @returns itself
|
|
1036
|
+
*/
|
|
1037
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
1038
|
+
on(events, handler) {
|
|
1039
|
+
if (typeof events == "string") {
|
|
1040
|
+
events = events.split(/[,\s]+/);
|
|
1041
|
+
} else {
|
|
1042
|
+
events = [events];
|
|
1043
|
+
}
|
|
1044
|
+
events.forEach((edata) => {
|
|
1045
|
+
const name = typeof edata == "string" ? edata : edata.type + ":" + edata.execute + "." + edata.scope;
|
|
1046
|
+
if (typeof edata == "string") {
|
|
1047
|
+
const [eventName, scope] = edata.split(".");
|
|
1048
|
+
const [type, execute] = (eventName ?? "").replace(":complete", ":after").replace(":done", ":after").split(":");
|
|
1049
|
+
edata = { type, execute: execute ?? "before", scope };
|
|
1050
|
+
}
|
|
1051
|
+
edata = extend({ type: null, execute: "before", onComplete: null }, edata);
|
|
1052
|
+
if (!edata.type) {
|
|
1053
|
+
console.log("ERROR: You must specify event type when calling .on() method of " + this.name);
|
|
1054
|
+
return;
|
|
1055
|
+
}
|
|
1056
|
+
if (!handler) {
|
|
1057
|
+
console.log("ERROR: You must specify event handler function when calling .on() method of " + this.name);
|
|
1058
|
+
return;
|
|
1059
|
+
}
|
|
1060
|
+
if (!Array.isArray(this.listeners)) this.listeners = [];
|
|
1061
|
+
this.listeners.push({ name, edata, handler });
|
|
1062
|
+
if (this.debug) {
|
|
1063
|
+
console.log("TsBase: add event", { name, edata, handler });
|
|
1064
|
+
}
|
|
1065
|
+
});
|
|
1066
|
+
return this;
|
|
1067
|
+
}
|
|
1068
|
+
/**
|
|
1069
|
+
* Removes event listener, supports event phase and event scoping
|
|
1070
|
+
*
|
|
1071
|
+
* @param {*} edata - an object or string, if string "eventName:phase.scope"
|
|
1072
|
+
* @param {*} handler
|
|
1073
|
+
* @returns itself
|
|
1074
|
+
*/
|
|
1075
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
1076
|
+
off(events, handler) {
|
|
1077
|
+
if (typeof events == "string") {
|
|
1078
|
+
events = events.split(/[,\s]+/);
|
|
1079
|
+
} else {
|
|
1080
|
+
events = [events];
|
|
1081
|
+
}
|
|
1082
|
+
events.forEach((edata) => {
|
|
1083
|
+
const name = typeof edata == "string" ? edata : edata.type + ":" + edata.execute + "." + edata.scope;
|
|
1084
|
+
if (typeof edata == "string") {
|
|
1085
|
+
const [eventName, scope] = edata.split(".");
|
|
1086
|
+
const [type, execute] = (eventName ?? "").replace(":complete", ":after").replace(":done", ":after").split(":");
|
|
1087
|
+
edata = { type: type || "*", execute: execute || "", scope: scope || "" };
|
|
1088
|
+
}
|
|
1089
|
+
edata = extend({ type: null, execute: null, onComplete: null }, edata);
|
|
1090
|
+
if (!edata.type && !edata.scope) {
|
|
1091
|
+
console.log("ERROR: You must specify event type when calling .off() method of " + this.name);
|
|
1092
|
+
return;
|
|
1093
|
+
}
|
|
1094
|
+
if (!handler) {
|
|
1095
|
+
handler = void 0;
|
|
1096
|
+
}
|
|
1097
|
+
let count = 0;
|
|
1098
|
+
this.listeners = this.listeners.filter((curr) => {
|
|
1099
|
+
if ((edata.type === "*" || edata.type === curr.edata.type) && (edata.execute === "" || edata.execute === curr.edata.execute) && (edata.scope === "" || edata.scope === curr.edata.scope) && (edata.handler == null || edata.handler === curr.edata.handler)) {
|
|
1100
|
+
count++;
|
|
1101
|
+
return false;
|
|
1102
|
+
} else {
|
|
1103
|
+
return true;
|
|
1104
|
+
}
|
|
1105
|
+
});
|
|
1106
|
+
if (this.debug) {
|
|
1107
|
+
console.log(`TsBase: remove event (${count})`, { name, edata, handler });
|
|
1108
|
+
}
|
|
1109
|
+
});
|
|
1110
|
+
return this;
|
|
1111
|
+
}
|
|
1112
|
+
/**
|
|
1113
|
+
* Triggers even listeners for a specific event, loops through this.listeners
|
|
1114
|
+
*
|
|
1115
|
+
* @param {Object} edata - Object
|
|
1116
|
+
* @returns modified edata
|
|
1117
|
+
*
|
|
1118
|
+
* NOTE: `edata` is typed as `any` here intentionally. The method mutates the argument
|
|
1119
|
+
* from TsEventData into a TsEvent mid-execution. Runtime type mutation is inherent
|
|
1120
|
+
* to the event dispatch pattern. Phase 6 strict tighten will revisit this.
|
|
1121
|
+
*/
|
|
1122
|
+
// any: targeted-any per typing_policy; TsBase event payload is widget-defined at runtime
|
|
1123
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1124
|
+
trigger(eventName, edataIn) {
|
|
1125
|
+
let edata;
|
|
1126
|
+
if (arguments.length == 1) {
|
|
1127
|
+
if (typeof eventName == "string") {
|
|
1128
|
+
edata = { type: eventName, target: this };
|
|
1129
|
+
} else {
|
|
1130
|
+
edata = eventName;
|
|
1131
|
+
}
|
|
1132
|
+
} else {
|
|
1133
|
+
edata = edataIn;
|
|
1134
|
+
edata.type = eventName;
|
|
1135
|
+
edata.target = edata.target ?? this;
|
|
1136
|
+
}
|
|
1137
|
+
if (isPlainObject(edata) && edata.phase == "after") {
|
|
1138
|
+
edata = this.activeEvents.find((event) => {
|
|
1139
|
+
if (event.type == edata.type && event.target == edata.target) {
|
|
1140
|
+
return true;
|
|
1141
|
+
}
|
|
1142
|
+
return false;
|
|
1143
|
+
});
|
|
1144
|
+
if (!edata) {
|
|
1145
|
+
console.log(`ERROR: Cannot find even handler for "${edata?.type}" on "${edata?.target}".`);
|
|
1146
|
+
return edata;
|
|
1147
|
+
}
|
|
1148
|
+
console.log(`NOTICE: This syntax "edata.trigger({ phase: 'after' })" is outdated. Use edata.finish() instead.`);
|
|
1149
|
+
} else if (!(edata instanceof TsEvent)) {
|
|
1150
|
+
edata = new TsEvent(this, edata);
|
|
1151
|
+
this.activeEvents.push(edata);
|
|
1152
|
+
}
|
|
1153
|
+
let args, fun, tmp;
|
|
1154
|
+
if (!Array.isArray(this.listeners)) this.listeners = [];
|
|
1155
|
+
if (this.debug) {
|
|
1156
|
+
console.log(`TsBase: trigger "${edata.type}:${edata.phase}"`, edata);
|
|
1157
|
+
}
|
|
1158
|
+
for (let h = this.listeners.length - 1; h >= 0; h--) {
|
|
1159
|
+
const item = this.listeners[h];
|
|
1160
|
+
if (item != null && (item.edata.type === edata.type || item.edata.type === "*") && (item.edata["target"] === edata.target || item.edata["target"] == null) && (item.edata.execute === edata.phase || item.edata.execute === "*" || item.edata["phase"] === "*")) {
|
|
1161
|
+
Object.keys(item.edata).forEach((key) => {
|
|
1162
|
+
if (edata[key] == null && item.edata[key] != null) {
|
|
1163
|
+
edata[key] = item.edata[key];
|
|
1164
|
+
}
|
|
1165
|
+
});
|
|
1166
|
+
args = [];
|
|
1167
|
+
tmp = new RegExp(/\((.*?)\)/).exec(String(item.handler).split("=>")[0] ?? "");
|
|
1168
|
+
if (tmp) args = (tmp[1] ?? "").split(/\s*,\s*/);
|
|
1169
|
+
if (args.length === 2) {
|
|
1170
|
+
item.handler.call(this, edata.target, edata);
|
|
1171
|
+
if (this.debug) console.log(" - call (old)", item.handler);
|
|
1172
|
+
} else {
|
|
1173
|
+
item.handler.call(this, edata);
|
|
1174
|
+
if (this.debug) console.log(" - call", item.handler);
|
|
1175
|
+
}
|
|
1176
|
+
if (edata.isStopped === true || edata.stop === true) return edata;
|
|
1177
|
+
}
|
|
1178
|
+
}
|
|
1179
|
+
const funName = "on" + edata.type.substr(0, 1).toUpperCase() + edata.type.substr(1);
|
|
1180
|
+
if (edata.phase === "before" && typeof this[funName] === "function") {
|
|
1181
|
+
fun = this[funName];
|
|
1182
|
+
args = [];
|
|
1183
|
+
tmp = new RegExp(/\((.*?)\)/).exec(String(fun).split("=>")[0] ?? "");
|
|
1184
|
+
if (tmp) args = (tmp[1] ?? "").split(/\s*,\s*/);
|
|
1185
|
+
if (args.length === 2) {
|
|
1186
|
+
fun.call(this, edata.target, edata);
|
|
1187
|
+
if (this.debug) console.log(" - call: on[Event] (old)", fun);
|
|
1188
|
+
} else {
|
|
1189
|
+
fun.call(this, edata);
|
|
1190
|
+
if (this.debug) console.log(" - call: on[Event]", fun);
|
|
1191
|
+
}
|
|
1192
|
+
if (edata.isStopped === true || edata.stop === true) return edata;
|
|
1193
|
+
}
|
|
1194
|
+
if (edata.object != null && edata.phase === "before" && typeof edata.object[funName] === "function") {
|
|
1195
|
+
fun = edata.object[funName];
|
|
1196
|
+
args = [];
|
|
1197
|
+
tmp = new RegExp(/\((.*?)\)/).exec(String(fun).split("=>")[0] ?? "");
|
|
1198
|
+
if (tmp) args = (tmp[1] ?? "").split(/\s*,\s*/);
|
|
1199
|
+
if (args.length === 2) {
|
|
1200
|
+
fun.call(this, edata.target, edata);
|
|
1201
|
+
if (this.debug) console.log(" - call: edata.object (old)", fun);
|
|
1202
|
+
} else {
|
|
1203
|
+
fun.call(this, edata);
|
|
1204
|
+
if (this.debug) console.log(" - call: edata.object", fun);
|
|
1205
|
+
}
|
|
1206
|
+
if (edata.isStopped === true || edata.stop === true) return edata;
|
|
1207
|
+
}
|
|
1208
|
+
if (edata.phase === "after") {
|
|
1209
|
+
if (typeof edata.onComplete === "function") edata.onComplete.call(this, edata);
|
|
1210
|
+
for (let i = 0; i < edata.listeners.length; i++) {
|
|
1211
|
+
if (typeof edata.listeners[i] === "function") {
|
|
1212
|
+
edata.listeners[i].call(this, edata);
|
|
1213
|
+
if (this.debug) console.log(" - call: done", fun);
|
|
1214
|
+
}
|
|
1215
|
+
}
|
|
1216
|
+
edata._resolve(edata);
|
|
1217
|
+
if (this.debug) {
|
|
1218
|
+
console.log(`TsBase: trigger "${edata.type}:${edata.phase}"`, edata);
|
|
1219
|
+
}
|
|
1220
|
+
const ind = this.activeEvents.indexOf(edata);
|
|
1221
|
+
if (ind !== -1) this.activeEvents.splice(ind, 1);
|
|
1222
|
+
}
|
|
1223
|
+
return edata;
|
|
1224
|
+
}
|
|
1225
|
+
/**
|
|
1226
|
+
* This method renders component into the box. It is overwritten in descendents and in this base
|
|
1227
|
+
* component it is empty.
|
|
1228
|
+
*/
|
|
1229
|
+
render(_box) {
|
|
1230
|
+
}
|
|
1231
|
+
/**
|
|
1232
|
+
* Removes all classes that start with tsg-* and sets box to null. It is needed so that control will
|
|
1233
|
+
* release the box to be used for other widgets
|
|
1234
|
+
*/
|
|
1235
|
+
unmount() {
|
|
1236
|
+
const edata = this.trigger("unmount", { target: this.name });
|
|
1237
|
+
if (edata.isCancelled) {
|
|
1238
|
+
return;
|
|
1239
|
+
}
|
|
1240
|
+
const remove = [];
|
|
1241
|
+
if (this.box instanceof HTMLElement) {
|
|
1242
|
+
this.box.classList.forEach((cl) => {
|
|
1243
|
+
if (cl.startsWith("tsg-")) remove.push(cl);
|
|
1244
|
+
});
|
|
1245
|
+
}
|
|
1246
|
+
query2(this.box).off().removeClass(remove).removeAttr("name").html("");
|
|
1247
|
+
this.box = null;
|
|
1248
|
+
edata.finish();
|
|
1249
|
+
}
|
|
1250
|
+
};
|
|
1251
|
+
|
|
1252
|
+
export {
|
|
1253
|
+
query,
|
|
1254
|
+
isBin,
|
|
1255
|
+
isInt,
|
|
1256
|
+
isFloat,
|
|
1257
|
+
isMoney,
|
|
1258
|
+
isHex,
|
|
1259
|
+
isAlphaNumeric,
|
|
1260
|
+
isEmail,
|
|
1261
|
+
isIpAddress,
|
|
1262
|
+
isPlainObject,
|
|
1263
|
+
clone,
|
|
1264
|
+
extend,
|
|
1265
|
+
naturalCompare,
|
|
1266
|
+
getNested,
|
|
1267
|
+
normMenu,
|
|
1268
|
+
encodeParams,
|
|
1269
|
+
prepareParams,
|
|
1270
|
+
parseRoute,
|
|
1271
|
+
debounce,
|
|
1272
|
+
wait,
|
|
1273
|
+
TsUi,
|
|
1274
|
+
checkName,
|
|
1275
|
+
TsEvent,
|
|
1276
|
+
toSafeEvent,
|
|
1277
|
+
TsBase
|
|
1278
|
+
};
|
|
1279
|
+
/*
|
|
1280
|
+
* @author Lauri Rooden (https://github.com/litejs/natural-compare-lite)
|
|
1281
|
+
* @license MIT License
|
|
1282
|
+
*/
|
|
1283
|
+
//# sourceMappingURL=chunk-DXZJHS4M.js.map
|