@domql/utils 2.5.187 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/array.js +26 -13
- package/cache.js +4 -0
- package/component.js +10 -227
- package/cookie.js +27 -24
- package/dist/cjs/array.js +30 -16
- package/dist/cjs/cache.js +26 -0
- package/dist/cjs/component.js +16 -226
- package/dist/cjs/cookie.js +19 -24
- package/dist/cjs/element.js +137 -0
- package/dist/cjs/events.js +37 -0
- package/dist/cjs/extends.js +351 -0
- package/dist/cjs/function.js +2 -4
- package/dist/cjs/if.js +30 -0
- package/dist/cjs/index.js +25 -15
- package/dist/cjs/key.js +6 -1
- package/dist/cjs/keys.js +178 -0
- package/dist/cjs/log.js +1 -2
- package/dist/cjs/methods.js +305 -0
- package/dist/cjs/object.js +89 -237
- package/dist/cjs/props.js +220 -0
- package/dist/cjs/scope.js +28 -0
- package/dist/cjs/state.js +175 -0
- package/dist/cjs/string.js +27 -16
- package/dist/cjs/types.js +2 -4
- package/dist/cjs/update.js +42 -0
- package/dist/esm/array.js +30 -16
- package/dist/esm/cache.js +6 -0
- package/dist/esm/component.js +17 -245
- package/dist/esm/cookie.js +19 -24
- package/dist/esm/element.js +135 -0
- package/dist/esm/events.js +17 -0
- package/dist/esm/extends.js +349 -0
- package/dist/esm/function.js +2 -4
- package/dist/esm/if.js +10 -0
- package/dist/esm/index.js +10 -0
- package/dist/esm/key.js +6 -1
- package/dist/esm/keys.js +158 -0
- package/dist/esm/log.js +1 -2
- package/dist/esm/methods.js +285 -0
- package/dist/esm/object.js +90 -239
- package/dist/esm/props.js +216 -0
- package/dist/esm/scope.js +8 -0
- package/dist/esm/state.js +185 -0
- package/dist/esm/string.js +27 -16
- package/dist/esm/types.js +2 -4
- package/dist/esm/update.js +22 -0
- package/element.js +149 -0
- package/env.js +5 -2
- package/events.js +17 -0
- package/extends.js +425 -0
- package/if.js +14 -0
- package/index.js +10 -0
- package/key.js +6 -0
- package/keys.js +157 -0
- package/log.js +4 -1
- package/methods.js +315 -0
- package/node.js +21 -13
- package/object.js +121 -235
- package/package.json +3 -3
- package/props.js +249 -0
- package/scope.js +8 -0
- package/state.js +208 -0
- package/string.js +66 -30
- package/update.js +27 -0
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var methods_exports = {};
|
|
20
|
+
__export(methods_exports, {
|
|
21
|
+
call: () => call,
|
|
22
|
+
defineSetter: () => defineSetter,
|
|
23
|
+
error: () => error,
|
|
24
|
+
get: () => get,
|
|
25
|
+
getPath: () => getPath,
|
|
26
|
+
getRef: () => getRef,
|
|
27
|
+
isMethod: () => isMethod,
|
|
28
|
+
keys: () => keys,
|
|
29
|
+
log: () => log,
|
|
30
|
+
lookdown: () => lookdown,
|
|
31
|
+
lookdownAll: () => lookdownAll,
|
|
32
|
+
lookup: () => lookup,
|
|
33
|
+
nextElement: () => nextElement,
|
|
34
|
+
parse: () => parse,
|
|
35
|
+
parseDeep: () => parseDeep,
|
|
36
|
+
previousElement: () => previousElement,
|
|
37
|
+
remove: () => remove,
|
|
38
|
+
setNodeStyles: () => setNodeStyles,
|
|
39
|
+
setProps: () => setProps,
|
|
40
|
+
spotByPath: () => spotByPath,
|
|
41
|
+
variables: () => variables,
|
|
42
|
+
verbose: () => verbose,
|
|
43
|
+
warn: () => warn
|
|
44
|
+
});
|
|
45
|
+
module.exports = __toCommonJS(methods_exports);
|
|
46
|
+
var import_event = require("@domql/event");
|
|
47
|
+
var import_keys = require("./keys.js");
|
|
48
|
+
var import_types = require("./types.js");
|
|
49
|
+
var import_object = require("./object.js");
|
|
50
|
+
var import_env = require("./env.js");
|
|
51
|
+
var import_array = require("./array.js");
|
|
52
|
+
const ENV = "development";
|
|
53
|
+
function spotByPath(path) {
|
|
54
|
+
const element = this;
|
|
55
|
+
const { __ref: ref } = element;
|
|
56
|
+
const arr = [].concat(path);
|
|
57
|
+
let foundelement = ref.root[arr[0]];
|
|
58
|
+
if (!arr || !arr.length) {
|
|
59
|
+
return console.log(arr, "on", element.key, "is undefined");
|
|
60
|
+
}
|
|
61
|
+
while (foundelement.key === arr[0]) {
|
|
62
|
+
arr.shift();
|
|
63
|
+
if (!arr.length) break;
|
|
64
|
+
foundelement = foundelement[arr[0]];
|
|
65
|
+
if (!foundelement) return;
|
|
66
|
+
}
|
|
67
|
+
return foundelement;
|
|
68
|
+
}
|
|
69
|
+
function lookup(param) {
|
|
70
|
+
const el = this;
|
|
71
|
+
let { parent } = el;
|
|
72
|
+
if ((0, import_types.isFunction)(param)) {
|
|
73
|
+
if (parent.state && param(parent, parent.state, parent.context)) {
|
|
74
|
+
return parent;
|
|
75
|
+
} else if (parent.parent) return parent.lookup(param);
|
|
76
|
+
else return;
|
|
77
|
+
}
|
|
78
|
+
if (el[param]) return el[param];
|
|
79
|
+
while (parent.param !== param) {
|
|
80
|
+
if (parent[param]) return parent[param];
|
|
81
|
+
parent = parent.parent;
|
|
82
|
+
if (!parent) return;
|
|
83
|
+
}
|
|
84
|
+
return parent;
|
|
85
|
+
}
|
|
86
|
+
function lookdown(param) {
|
|
87
|
+
var _a;
|
|
88
|
+
const el = this;
|
|
89
|
+
const { __ref: ref } = el;
|
|
90
|
+
const children = ref.__children;
|
|
91
|
+
for (let i = 0; i < children.length; i++) {
|
|
92
|
+
const v = children[i];
|
|
93
|
+
const childElem = el[v];
|
|
94
|
+
if (v === param) return childElem;
|
|
95
|
+
else if ((0, import_types.isFunction)(param)) {
|
|
96
|
+
const exec = param(childElem, childElem.state, childElem.context);
|
|
97
|
+
if (childElem.state && exec) {
|
|
98
|
+
return childElem;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
const lookdown2 = (_a = childElem == null ? void 0 : childElem.lookdown) == null ? void 0 : _a.call(childElem, param);
|
|
102
|
+
if (lookdown2) return lookdown2;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
function lookdownAll(param, results = []) {
|
|
106
|
+
var _a;
|
|
107
|
+
const el = this;
|
|
108
|
+
const { __ref: ref } = el;
|
|
109
|
+
const children = ref.__children;
|
|
110
|
+
for (let i = 0; i < children.length; i++) {
|
|
111
|
+
const v = children[i];
|
|
112
|
+
const childElem = el[v];
|
|
113
|
+
if (v === param) results.push(childElem);
|
|
114
|
+
else if ((0, import_types.isFunction)(param)) {
|
|
115
|
+
const exec = param(childElem, childElem.state, childElem.context);
|
|
116
|
+
if (childElem.state && exec) results.push(childElem);
|
|
117
|
+
}
|
|
118
|
+
(_a = childElem == null ? void 0 : childElem.lookdownAll) == null ? void 0 : _a.call(childElem, param, results);
|
|
119
|
+
}
|
|
120
|
+
return results.length ? results : void 0;
|
|
121
|
+
}
|
|
122
|
+
function setNodeStyles(params = {}) {
|
|
123
|
+
var _a;
|
|
124
|
+
const el = this;
|
|
125
|
+
if (!((_a = el.node) == null ? void 0 : _a.style)) return;
|
|
126
|
+
for (const param in params) {
|
|
127
|
+
const value = params[param];
|
|
128
|
+
const childElem = el[param];
|
|
129
|
+
if ((0, import_types.isObject)(value) && childElem) setNodeStyles.call(childElem, value);
|
|
130
|
+
else el.node.style[param] = value;
|
|
131
|
+
}
|
|
132
|
+
return el;
|
|
133
|
+
}
|
|
134
|
+
function remove(opts) {
|
|
135
|
+
const element = this;
|
|
136
|
+
const beforeRemoveReturns = (0, import_event.triggerEventOn)("beforeRemove", element, opts);
|
|
137
|
+
if (beforeRemoveReturns === false) return element;
|
|
138
|
+
if ((0, import_types.isFunction)(element.node.remove)) element.node.remove();
|
|
139
|
+
else if (!(0, import_env.isProduction)()) {
|
|
140
|
+
console.warn("This item cant be removed");
|
|
141
|
+
element.log();
|
|
142
|
+
}
|
|
143
|
+
delete element.parent[element.key];
|
|
144
|
+
if (element.parent.__ref) {
|
|
145
|
+
element.parent.__ref.__children = (0, import_array.removeValueFromArray)(
|
|
146
|
+
element.parent.__ref.__children,
|
|
147
|
+
element.key
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
(0, import_event.triggerEventOn)("remove", element, opts);
|
|
151
|
+
}
|
|
152
|
+
function get(param) {
|
|
153
|
+
const element = this;
|
|
154
|
+
return element[param];
|
|
155
|
+
}
|
|
156
|
+
function setProps(param, options) {
|
|
157
|
+
const element = this;
|
|
158
|
+
if (!param || !element.props) return;
|
|
159
|
+
element.update({ props: param }, options);
|
|
160
|
+
return element;
|
|
161
|
+
}
|
|
162
|
+
function getRef() {
|
|
163
|
+
return this.__ref;
|
|
164
|
+
}
|
|
165
|
+
function getPath() {
|
|
166
|
+
return this.getRef().path;
|
|
167
|
+
}
|
|
168
|
+
const defineSetter = (element, key, get2, set) => Object.defineProperty(element, key, { get: get2, set });
|
|
169
|
+
function keys() {
|
|
170
|
+
const element = this;
|
|
171
|
+
const keys2 = [];
|
|
172
|
+
for (const param in element) {
|
|
173
|
+
if (
|
|
174
|
+
// (REGISTRY[param] && !DOMQ_PROPERTIES.includes(param)) ||
|
|
175
|
+
!Object.hasOwnProperty.call(element, param) || import_keys.DOMQ_PROPERTIES.includes(param) && !import_keys.PARSED_DOMQ_PROPERTIES.includes(param)
|
|
176
|
+
) {
|
|
177
|
+
continue;
|
|
178
|
+
}
|
|
179
|
+
keys2.push(param);
|
|
180
|
+
}
|
|
181
|
+
return keys2;
|
|
182
|
+
}
|
|
183
|
+
function parse(excl = []) {
|
|
184
|
+
const element = this;
|
|
185
|
+
const { __ref: ref } = element;
|
|
186
|
+
const obj = {};
|
|
187
|
+
const keyList = keys.call(element);
|
|
188
|
+
keyList.forEach((v) => {
|
|
189
|
+
if (excl.includes(v)) return;
|
|
190
|
+
const val = element[v];
|
|
191
|
+
if (v === "state") {
|
|
192
|
+
if (!(ref == null ? void 0 : ref.__hasRootState)) return;
|
|
193
|
+
const parsedVal = (0, import_types.isFunction)(val && val.parse) ? val.parse() : val;
|
|
194
|
+
obj[v] = (0, import_types.isFunction)(parsedVal) ? parsedVal : JSON.parse(JSON.stringify(parsedVal || {}));
|
|
195
|
+
} else if (v === "scope") {
|
|
196
|
+
if (!(ref == null ? void 0 : ref.__hasRootScope)) return;
|
|
197
|
+
obj[v] = JSON.parse(JSON.stringify(val || {}));
|
|
198
|
+
} else if ((0, import_types.isDefined)(val) && Object.hasOwnProperty.call(element, v)) {
|
|
199
|
+
obj[v] = val;
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
return obj;
|
|
203
|
+
}
|
|
204
|
+
function parseDeep(excl = []) {
|
|
205
|
+
const element = this;
|
|
206
|
+
const obj = parse.call(element, excl);
|
|
207
|
+
for (const v in obj) {
|
|
208
|
+
if (excl.includes(v)) return;
|
|
209
|
+
if ((0, import_types.isObjectLike)(obj[v])) {
|
|
210
|
+
obj[v] = parseDeep.call(obj[v], excl);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
return obj;
|
|
214
|
+
}
|
|
215
|
+
function verbose(...args) {
|
|
216
|
+
if (ENV !== "test" && ENV !== "development") return;
|
|
217
|
+
const element = this;
|
|
218
|
+
const { __ref: ref } = element;
|
|
219
|
+
console.groupCollapsed(element.key);
|
|
220
|
+
if (args.length) {
|
|
221
|
+
args.forEach((v) => console.log(`%c${v}:
|
|
222
|
+
`, "font-weight: bold", element[v]));
|
|
223
|
+
} else {
|
|
224
|
+
console.log(ref.path);
|
|
225
|
+
const keys2 = element.keys();
|
|
226
|
+
keys2.forEach((v) => console.log(`%c${v}:`, "font-weight: bold", element[v]));
|
|
227
|
+
}
|
|
228
|
+
console.log(element);
|
|
229
|
+
console.groupEnd(element.key);
|
|
230
|
+
return element;
|
|
231
|
+
}
|
|
232
|
+
function log(...params) {
|
|
233
|
+
if (ENV === "test" || ENV === "development") {
|
|
234
|
+
console.log(...params);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
function warn(...params) {
|
|
238
|
+
if (ENV === "test" || ENV === "development") {
|
|
239
|
+
console.warn(...params);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
function error(...params) {
|
|
243
|
+
var _a, _b;
|
|
244
|
+
if (ENV === "test" || ENV === "development") {
|
|
245
|
+
if ((_a = params[params.length - 1]) == null ? void 0 : _a.debugger) debugger;
|
|
246
|
+
if ((_b = params[params.length - 1]) == null ? void 0 : _b.verbose) verbose.call(this);
|
|
247
|
+
throw new Error(...params);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
function nextElement() {
|
|
251
|
+
const element = this;
|
|
252
|
+
const { key, parent } = element;
|
|
253
|
+
const { __children } = parent.__ref;
|
|
254
|
+
const currentIndex = __children.indexOf(key);
|
|
255
|
+
const nextChild = __children[currentIndex + 1];
|
|
256
|
+
return parent[nextChild];
|
|
257
|
+
}
|
|
258
|
+
function previousElement(el) {
|
|
259
|
+
const element = el || this;
|
|
260
|
+
const { key, parent } = element;
|
|
261
|
+
const { __children } = parent.__ref;
|
|
262
|
+
if (!__children) return;
|
|
263
|
+
const currentIndex = __children.indexOf(key);
|
|
264
|
+
return parent[__children[currentIndex - 1]];
|
|
265
|
+
}
|
|
266
|
+
function variables(obj = {}) {
|
|
267
|
+
const element = this;
|
|
268
|
+
if (!element.data) element.data = {};
|
|
269
|
+
if (!element.data.varCaches) element.data.varCaches = {};
|
|
270
|
+
const varCaches = element.data.varCaches;
|
|
271
|
+
const changes = {};
|
|
272
|
+
let changed;
|
|
273
|
+
for (const key in obj) {
|
|
274
|
+
if (obj[key] !== varCaches[key]) {
|
|
275
|
+
changed = true;
|
|
276
|
+
changes[key] = obj[key];
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
return {
|
|
280
|
+
changed: (cb) => {
|
|
281
|
+
if (!changed) return;
|
|
282
|
+
const returns = cb(changes, (0, import_object.deepClone)(varCaches));
|
|
283
|
+
for (const key in changes) {
|
|
284
|
+
varCaches[key] = changes[key];
|
|
285
|
+
}
|
|
286
|
+
return returns;
|
|
287
|
+
},
|
|
288
|
+
timeout: (cb, timeout) => {
|
|
289
|
+
if (!changed) return;
|
|
290
|
+
const t = setTimeout(() => {
|
|
291
|
+
cb(changes);
|
|
292
|
+
clearTimeout(t);
|
|
293
|
+
}, timeout);
|
|
294
|
+
}
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
function call(fnKey, ...args) {
|
|
298
|
+
var _a, _b, _c, _d, _e;
|
|
299
|
+
const context = this.context;
|
|
300
|
+
return (_e = ((_a = context.utils) == null ? void 0 : _a[fnKey]) || ((_b = context.functions) == null ? void 0 : _b[fnKey]) || ((_c = context.methods) == null ? void 0 : _c[fnKey]) || ((_d = context.snippets) == null ? void 0 : _d[fnKey])) == null ? void 0 : _e.call(this, ...args);
|
|
301
|
+
}
|
|
302
|
+
function isMethod(param, element) {
|
|
303
|
+
var _a, _b;
|
|
304
|
+
return Boolean(import_keys.METHODS.includes(param) || ((_b = (_a = element == null ? void 0 : element.context) == null ? void 0 : _a.methods) == null ? void 0 : _b[param]));
|
|
305
|
+
}
|