@domql/utils 3.2.3 → 3.2.10
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 +11 -5
- package/cache.js +3 -0
- package/component.js +3 -4
- package/dist/cjs/array.js +11 -5
- package/dist/cjs/component.js +4 -6
- package/dist/cjs/element.js +5 -5
- package/dist/cjs/extends.js +43 -27
- package/dist/cjs/function.js +3 -3
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/key.js +2 -2
- package/dist/cjs/keys.js +30 -16
- package/dist/cjs/methods.js +64 -28
- package/dist/cjs/object.js +141 -125
- package/dist/cjs/props.js +41 -32
- package/dist/cjs/scope.js +1 -2
- package/dist/cjs/state.js +9 -8
- package/dist/cjs/string.js +15 -20
- package/dist/cjs/tags.js +69 -4
- package/dist/cjs/triggerEvent.js +90 -0
- package/dist/cjs/types.js +4 -12
- package/dist/esm/array.js +11 -5
- package/dist/esm/component.js +4 -6
- package/dist/esm/element.js +8 -26
- package/dist/esm/extends.js +47 -49
- package/dist/esm/function.js +3 -3
- package/dist/esm/index.js +1 -0
- package/dist/esm/key.js +2 -2
- package/dist/esm/keys.js +30 -16
- package/dist/esm/methods.js +63 -42
- package/dist/esm/object.js +145 -149
- package/dist/esm/props.js +41 -48
- package/dist/esm/scope.js +1 -2
- package/dist/esm/state.js +17 -34
- package/dist/esm/string.js +15 -20
- package/dist/esm/tags.js +69 -4
- package/dist/esm/triggerEvent.js +70 -0
- package/dist/esm/types.js +4 -12
- package/dist/iife/index.js +2779 -0
- package/element.js +2 -2
- package/extends.js +28 -17
- package/function.js +4 -6
- package/index.js +1 -0
- package/keys.js +26 -16
- package/methods.js +63 -18
- package/object.js +142 -200
- package/package.json +33 -12
- package/props.js +42 -25
- package/state.js +7 -7
- package/string.js +20 -38
- package/tags.js +43 -4
- package/triggerEvent.js +76 -0
- package/types.js +4 -23
- package/dist/cjs/package.json +0 -4
package/dist/cjs/object.js
CHANGED
|
@@ -56,8 +56,10 @@ var import_string = require("./string.js");
|
|
|
56
56
|
var import_node = require("./node.js");
|
|
57
57
|
var import_keys = require("./keys.js");
|
|
58
58
|
const ENV = process.env.NODE_ENV;
|
|
59
|
+
const _startsWithDunder = (e) => e.charCodeAt(0) === 95 && e.charCodeAt(1) === 95;
|
|
59
60
|
const exec = (param, element, state, context) => {
|
|
60
61
|
if ((0, import_types.isFunction)(param)) {
|
|
62
|
+
if (!element) return;
|
|
61
63
|
const result = param.call(
|
|
62
64
|
element,
|
|
63
65
|
element,
|
|
@@ -81,25 +83,23 @@ const map = (obj, extention, element) => {
|
|
|
81
83
|
}
|
|
82
84
|
};
|
|
83
85
|
const merge = (element, obj, excludeFrom = []) => {
|
|
86
|
+
const useSet = excludeFrom instanceof Set;
|
|
84
87
|
for (const e in obj) {
|
|
85
|
-
|
|
86
|
-
if (
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
const objProp = obj[e];
|
|
91
|
-
if (elementProp === void 0) {
|
|
92
|
-
element[e] = objProp;
|
|
88
|
+
if (!Object.prototype.hasOwnProperty.call(obj, e)) continue;
|
|
89
|
+
if (_startsWithDunder(e)) continue;
|
|
90
|
+
if (useSet ? excludeFrom.has(e) : excludeFrom.includes(e)) continue;
|
|
91
|
+
if (element[e] === void 0) {
|
|
92
|
+
element[e] = obj[e];
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
95
|
return element;
|
|
96
96
|
};
|
|
97
97
|
const deepMerge = (element, extend, excludeFrom = import_keys.METHODS_EXL) => {
|
|
98
|
+
const useSet = excludeFrom instanceof Set;
|
|
98
99
|
for (const e in extend) {
|
|
99
|
-
|
|
100
|
-
if (
|
|
101
|
-
|
|
102
|
-
}
|
|
100
|
+
if (!Object.prototype.hasOwnProperty.call(extend, e)) continue;
|
|
101
|
+
if (_startsWithDunder(e)) continue;
|
|
102
|
+
if (useSet ? excludeFrom.has(e) : excludeFrom.includes(e)) continue;
|
|
103
103
|
const elementProp = element[e];
|
|
104
104
|
const extendProp = extend[e];
|
|
105
105
|
if ((0, import_types.isObjectLike)(elementProp) && (0, import_types.isObjectLike)(extendProp)) {
|
|
@@ -111,12 +111,12 @@ const deepMerge = (element, extend, excludeFrom = import_keys.METHODS_EXL) => {
|
|
|
111
111
|
return element;
|
|
112
112
|
};
|
|
113
113
|
const clone = (obj, excludeFrom = []) => {
|
|
114
|
+
const useSet = excludeFrom instanceof Set;
|
|
114
115
|
const o = {};
|
|
115
116
|
for (const prop in obj) {
|
|
116
|
-
|
|
117
|
-
if (
|
|
118
|
-
|
|
119
|
-
}
|
|
117
|
+
if (!Object.prototype.hasOwnProperty.call(obj, prop)) continue;
|
|
118
|
+
if (_startsWithDunder(prop)) continue;
|
|
119
|
+
if (useSet ? excludeFrom.has(prop) : excludeFrom.includes(prop)) continue;
|
|
120
120
|
o[prop] = obj[prop];
|
|
121
121
|
}
|
|
122
122
|
return o;
|
|
@@ -137,17 +137,17 @@ const deepClone = (obj, options = {}) => {
|
|
|
137
137
|
if (visited.has(obj)) {
|
|
138
138
|
return visited.get(obj);
|
|
139
139
|
}
|
|
140
|
-
const
|
|
140
|
+
const isArr = (0, import_types.isArray)(obj);
|
|
141
|
+
const clone2 = isArr ? [] : {};
|
|
141
142
|
visited.set(obj, clone2);
|
|
143
|
+
const excludeSet = exclude instanceof Set ? exclude : exclude.length > 3 ? new Set(exclude) : null;
|
|
142
144
|
for (const key in obj) {
|
|
143
145
|
if (!Object.prototype.hasOwnProperty.call(obj, key)) continue;
|
|
144
|
-
if (
|
|
145
|
-
|
|
146
|
-
}
|
|
146
|
+
if (_startsWithDunder(key) || key === "__proto__") continue;
|
|
147
|
+
if (excludeSet ? excludeSet.has(key) : exclude.includes(key)) continue;
|
|
147
148
|
const value = obj[key];
|
|
148
|
-
if (cleanUndefined &&
|
|
149
|
-
|
|
150
|
-
}
|
|
149
|
+
if (cleanUndefined && value === void 0) continue;
|
|
150
|
+
if (cleanNull && value === null) continue;
|
|
151
151
|
if ((0, import_node.isDOMNode)(value)) {
|
|
152
152
|
clone2[key] = value;
|
|
153
153
|
continue;
|
|
@@ -172,14 +172,13 @@ const deepClone = (obj, options = {}) => {
|
|
|
172
172
|
return clone2;
|
|
173
173
|
};
|
|
174
174
|
const deepStringify = (obj, stringified = {}) => {
|
|
175
|
-
var _a, _b;
|
|
176
175
|
if (obj.node || obj.__ref || obj.parent || obj.__element || obj.parse) {
|
|
177
176
|
;
|
|
178
|
-
(obj.__element ||
|
|
177
|
+
(obj.__element || obj.parent?.__element).warn(
|
|
179
178
|
"Trying to clone element or state at",
|
|
180
179
|
obj
|
|
181
180
|
);
|
|
182
|
-
obj =
|
|
181
|
+
obj = obj.parse?.();
|
|
183
182
|
}
|
|
184
183
|
for (const prop in obj) {
|
|
185
184
|
const objProp = obj[prop];
|
|
@@ -189,50 +188,63 @@ const deepStringify = (obj, stringified = {}) => {
|
|
|
189
188
|
stringified[prop] = {};
|
|
190
189
|
deepStringify(objProp, stringified[prop]);
|
|
191
190
|
} else if ((0, import_types.isArray)(objProp)) {
|
|
192
|
-
stringified[prop] = [];
|
|
193
|
-
objProp.
|
|
191
|
+
const arr = stringified[prop] = [];
|
|
192
|
+
for (let i = 0; i < objProp.length; i++) {
|
|
193
|
+
const v = objProp[i];
|
|
194
194
|
if ((0, import_types.isObject)(v)) {
|
|
195
|
-
|
|
196
|
-
deepStringify(v,
|
|
195
|
+
arr[i] = {};
|
|
196
|
+
deepStringify(v, arr[i]);
|
|
197
197
|
} else if ((0, import_types.isFunction)(v)) {
|
|
198
|
-
|
|
198
|
+
arr[i] = v.toString();
|
|
199
199
|
} else {
|
|
200
|
-
|
|
200
|
+
arr[i] = v;
|
|
201
201
|
}
|
|
202
|
-
}
|
|
202
|
+
}
|
|
203
203
|
} else {
|
|
204
204
|
stringified[prop] = objProp;
|
|
205
205
|
}
|
|
206
206
|
}
|
|
207
207
|
return stringified;
|
|
208
208
|
};
|
|
209
|
+
const OBJ_TO_STR_SPECIAL_CHARS = /* @__PURE__ */ new Set([
|
|
210
|
+
"&",
|
|
211
|
+
"*",
|
|
212
|
+
"-",
|
|
213
|
+
":",
|
|
214
|
+
"%",
|
|
215
|
+
"{",
|
|
216
|
+
"}",
|
|
217
|
+
">",
|
|
218
|
+
"<",
|
|
219
|
+
"@",
|
|
220
|
+
".",
|
|
221
|
+
"/",
|
|
222
|
+
"!",
|
|
223
|
+
" "
|
|
224
|
+
]);
|
|
209
225
|
const objectToString = (obj = {}, indent = 0) => {
|
|
210
226
|
if (obj === null || typeof obj !== "object") {
|
|
211
227
|
return String(obj);
|
|
212
228
|
}
|
|
213
|
-
|
|
214
|
-
|
|
229
|
+
let hasKeys = false;
|
|
230
|
+
for (const _k in obj) {
|
|
231
|
+
hasKeys = true;
|
|
232
|
+
break;
|
|
215
233
|
}
|
|
234
|
+
if (!hasKeys) return "{}";
|
|
216
235
|
const spaces = " ".repeat(indent);
|
|
217
236
|
let str = "{\n";
|
|
218
|
-
for (const
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
"@",
|
|
230
|
-
".",
|
|
231
|
-
"/",
|
|
232
|
-
"!",
|
|
233
|
-
" "
|
|
234
|
-
]);
|
|
235
|
-
const stringedKey = keyNotAllowdChars ? `'${key}'` : key;
|
|
237
|
+
for (const key in obj) {
|
|
238
|
+
if (!Object.prototype.hasOwnProperty.call(obj, key)) continue;
|
|
239
|
+
const value = obj[key];
|
|
240
|
+
let keyNeedsQuotes = false;
|
|
241
|
+
for (let i = 0; i < key.length; i++) {
|
|
242
|
+
if (OBJ_TO_STR_SPECIAL_CHARS.has(key[i])) {
|
|
243
|
+
keyNeedsQuotes = true;
|
|
244
|
+
break;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
const stringedKey = keyNeedsQuotes ? `'${key}'` : key;
|
|
236
248
|
str += `${spaces} ${stringedKey}: `;
|
|
237
249
|
if ((0, import_types.isArray)(value)) {
|
|
238
250
|
str += "[\n";
|
|
@@ -261,36 +273,36 @@ const objectToString = (obj = {}, indent = 0) => {
|
|
|
261
273
|
str += `${spaces}}`;
|
|
262
274
|
return str;
|
|
263
275
|
};
|
|
276
|
+
const FN_PATTERNS = [
|
|
277
|
+
/^\(\s*\{[^}]*\}\s*\)\s*=>/,
|
|
278
|
+
/^(\([^)]*\)|[^=]*)\s*=>/,
|
|
279
|
+
/^function[\s(]/,
|
|
280
|
+
/^async\s+/,
|
|
281
|
+
/^\(\s*function/,
|
|
282
|
+
/^[a-zA-Z_$][a-zA-Z0-9_$]*\s*=>/
|
|
283
|
+
];
|
|
284
|
+
const RE_JSON_LIKE = /^["[{]/;
|
|
264
285
|
const hasFunction = (str) => {
|
|
265
286
|
if (!str) return false;
|
|
266
287
|
const trimmed = str.trim().replace(/\n\s*/g, " ").trim();
|
|
267
|
-
if (trimmed === "") return false;
|
|
268
|
-
|
|
269
|
-
if (
|
|
270
|
-
const
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
/^[a-zA-Z_$][a-zA-Z0-9_$]*\s*=>/
|
|
277
|
-
];
|
|
278
|
-
const isFunction2 = patterns.some((pattern) => pattern.test(trimmed));
|
|
279
|
-
const isObjectLiteral = trimmed.startsWith("{") && !trimmed.includes("=>");
|
|
280
|
-
const isArrayLiteral = trimmed.startsWith("[");
|
|
281
|
-
const isJSONLike = /^["[{]/.test(trimmed) && !trimmed.includes("=>");
|
|
282
|
-
return isFunction2 && !isObjectLiteral && !isArrayLiteral && !isJSONLike;
|
|
288
|
+
if (trimmed === "" || trimmed === "{}" || trimmed === "[]") return false;
|
|
289
|
+
const isFn = FN_PATTERNS.some((pattern) => pattern.test(trimmed));
|
|
290
|
+
if (!isFn) return false;
|
|
291
|
+
const firstChar = trimmed.charCodeAt(0);
|
|
292
|
+
const hasArrow = trimmed.includes("=>");
|
|
293
|
+
if (firstChar === 123 && !hasArrow) return false;
|
|
294
|
+
if (firstChar === 91) return false;
|
|
295
|
+
if (RE_JSON_LIKE.test(trimmed) && !hasArrow) return false;
|
|
296
|
+
return true;
|
|
283
297
|
};
|
|
284
298
|
const deepDestringify = (obj, destringified = {}) => {
|
|
285
299
|
for (const prop in obj) {
|
|
286
|
-
|
|
287
|
-
if (!hasOwnProperty2) continue;
|
|
300
|
+
if (!Object.prototype.hasOwnProperty.call(obj, prop)) continue;
|
|
288
301
|
const objProp = obj[prop];
|
|
289
302
|
if ((0, import_types.isString)(objProp)) {
|
|
290
303
|
if (hasFunction(objProp)) {
|
|
291
304
|
try {
|
|
292
|
-
|
|
293
|
-
destringified[prop] = evalProp;
|
|
305
|
+
destringified[prop] = import_globals.window.eval(`(${objProp})`);
|
|
294
306
|
} catch (e) {
|
|
295
307
|
if (e) destringified[prop] = objProp;
|
|
296
308
|
}
|
|
@@ -298,25 +310,25 @@ const deepDestringify = (obj, destringified = {}) => {
|
|
|
298
310
|
destringified[prop] = objProp;
|
|
299
311
|
}
|
|
300
312
|
} else if ((0, import_types.isArray)(objProp)) {
|
|
301
|
-
destringified[prop] = [];
|
|
302
|
-
objProp.
|
|
313
|
+
const arr = destringified[prop] = [];
|
|
314
|
+
for (let i = 0; i < objProp.length; i++) {
|
|
315
|
+
const arrProp = objProp[i];
|
|
303
316
|
if ((0, import_types.isString)(arrProp)) {
|
|
304
317
|
if (hasFunction(arrProp)) {
|
|
305
318
|
try {
|
|
306
|
-
|
|
307
|
-
destringified[prop].push(evalProp);
|
|
319
|
+
arr.push(import_globals.window.eval(`(${arrProp})`));
|
|
308
320
|
} catch (e) {
|
|
309
|
-
if (e)
|
|
321
|
+
if (e) arr.push(arrProp);
|
|
310
322
|
}
|
|
311
323
|
} else {
|
|
312
|
-
|
|
324
|
+
arr.push(arrProp);
|
|
313
325
|
}
|
|
314
326
|
} else if ((0, import_types.isObject)(arrProp)) {
|
|
315
|
-
|
|
327
|
+
arr.push(deepDestringify(arrProp));
|
|
316
328
|
} else {
|
|
317
|
-
|
|
329
|
+
arr.push(arrProp);
|
|
318
330
|
}
|
|
319
|
-
}
|
|
331
|
+
}
|
|
320
332
|
} else if ((0, import_types.isObject)(objProp)) {
|
|
321
333
|
destringified[prop] = deepDestringify(objProp, destringified[prop]);
|
|
322
334
|
} else {
|
|
@@ -333,39 +345,44 @@ const stringToObject = (str, opts = { verbose: true }) => {
|
|
|
333
345
|
}
|
|
334
346
|
};
|
|
335
347
|
const hasOwnProperty = (o, ...args) => Object.prototype.hasOwnProperty.call(o, ...args);
|
|
336
|
-
const isEmpty = (o) =>
|
|
348
|
+
const isEmpty = (o) => {
|
|
349
|
+
for (const _ in o) return false;
|
|
350
|
+
return true;
|
|
351
|
+
};
|
|
337
352
|
const isEmptyObject = (o) => (0, import_types.isObject)(o) && isEmpty(o);
|
|
338
353
|
const makeObjectWithoutPrototype = () => /* @__PURE__ */ Object.create(null);
|
|
339
354
|
const overwrite = (element, params, opts = {}) => {
|
|
340
355
|
const excl = opts.exclude || [];
|
|
341
356
|
const allowUnderscore = opts.preventUnderscore;
|
|
342
357
|
for (const e in params) {
|
|
343
|
-
if (excl.includes(e) || !allowUnderscore && e
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
element[e] = paramsProp;
|
|
358
|
+
if (excl.includes(e) || !allowUnderscore && _startsWithDunder(e)) continue;
|
|
359
|
+
if (params[e] !== void 0) {
|
|
360
|
+
element[e] = params[e];
|
|
347
361
|
}
|
|
348
362
|
}
|
|
349
363
|
return element;
|
|
350
364
|
};
|
|
351
365
|
const overwriteShallow = (obj, params, excludeFrom = []) => {
|
|
366
|
+
const useSet = excludeFrom instanceof Set;
|
|
352
367
|
for (const e in params) {
|
|
353
|
-
if (
|
|
368
|
+
if (_startsWithDunder(e)) continue;
|
|
369
|
+
if (useSet ? excludeFrom.has(e) : excludeFrom.includes(e)) continue;
|
|
354
370
|
obj[e] = params[e];
|
|
355
371
|
}
|
|
356
372
|
return obj;
|
|
357
373
|
};
|
|
358
374
|
const overwriteDeep = (obj, params, opts = {}, visited = /* @__PURE__ */ new WeakMap()) => {
|
|
359
|
-
const excl = opts.exclude || [];
|
|
360
|
-
const forcedExclude = opts.preventForce ? [] : ["node", "window"];
|
|
361
375
|
if (!(0, import_types.isObjectLike)(obj) || !(0, import_types.isObjectLike)(params) || (0, import_node.isDOMNode)(obj) || (0, import_node.isDOMNode)(params)) {
|
|
362
376
|
return params;
|
|
363
377
|
}
|
|
364
378
|
if (visited.has(obj)) return visited.get(obj);
|
|
365
379
|
visited.set(obj, obj);
|
|
380
|
+
const excl = opts.exclude;
|
|
381
|
+
const exclSet = excl ? excl instanceof Set ? excl : new Set(excl) : null;
|
|
382
|
+
const forcedExclude = !opts.preventForce;
|
|
366
383
|
for (const e in params) {
|
|
367
|
-
if (!Object.hasOwnProperty.call(params, e)) continue;
|
|
368
|
-
if (
|
|
384
|
+
if (!Object.prototype.hasOwnProperty.call(params, e)) continue;
|
|
385
|
+
if (exclSet && exclSet.has(e) || forcedExclude && _startsWithDunder(e)) continue;
|
|
369
386
|
const objProp = obj[e];
|
|
370
387
|
const paramsProp = params[e];
|
|
371
388
|
if ((0, import_node.isDOMNode)(paramsProp)) {
|
|
@@ -392,29 +409,30 @@ const isEqualDeep = (param, element, visited = /* @__PURE__ */ new Set()) => {
|
|
|
392
409
|
if (keysParam.length !== keysElement.length) {
|
|
393
410
|
return false;
|
|
394
411
|
}
|
|
395
|
-
for (
|
|
396
|
-
|
|
412
|
+
for (let i = 0; i < keysParam.length; i++) {
|
|
413
|
+
const key = keysParam[i];
|
|
414
|
+
if (!Object.prototype.hasOwnProperty.call(element, key)) {
|
|
397
415
|
return false;
|
|
398
416
|
}
|
|
399
|
-
|
|
400
|
-
const elementProp = element[key];
|
|
401
|
-
if (!isEqualDeep(paramProp, elementProp, visited)) {
|
|
417
|
+
if (!isEqualDeep(param[key], element[key], visited)) {
|
|
402
418
|
return false;
|
|
403
419
|
}
|
|
404
420
|
}
|
|
405
421
|
return true;
|
|
406
422
|
};
|
|
407
|
-
const
|
|
423
|
+
const DEEP_CONTAINS_IGNORED = /* @__PURE__ */ new Set(["node", "__ref"]);
|
|
424
|
+
const deepContains = (obj1, obj2, ignoredKeys = DEEP_CONTAINS_IGNORED) => {
|
|
408
425
|
if (obj1 === obj2) return true;
|
|
409
426
|
if (!(0, import_types.isObjectLike)(obj1) || !(0, import_types.isObjectLike)(obj2)) return obj1 === obj2;
|
|
410
427
|
if ((0, import_node.isDOMNode)(obj1) || (0, import_node.isDOMNode)(obj2)) return obj1 === obj2;
|
|
428
|
+
const ignored = ignoredKeys instanceof Set ? ignoredKeys : new Set(ignoredKeys);
|
|
411
429
|
const visited = /* @__PURE__ */ new WeakSet();
|
|
412
430
|
function checkContains(target, source) {
|
|
413
431
|
if (visited.has(source)) return true;
|
|
414
432
|
visited.add(source);
|
|
415
433
|
for (const key in source) {
|
|
416
434
|
if (!Object.prototype.hasOwnProperty.call(source, key)) continue;
|
|
417
|
-
if (
|
|
435
|
+
if (ignored.has(key)) continue;
|
|
418
436
|
if (!Object.prototype.hasOwnProperty.call(target, key)) return false;
|
|
419
437
|
const sourceValue = source[key];
|
|
420
438
|
const targetValue = target[key];
|
|
@@ -435,7 +453,7 @@ const removeFromObject = (obj, props) => {
|
|
|
435
453
|
if ((0, import_types.is)(props)("string", "number")) {
|
|
436
454
|
delete obj[props];
|
|
437
455
|
} else if ((0, import_types.isArray)(props)) {
|
|
438
|
-
props.
|
|
456
|
+
for (let i = 0; i < props.length; i++) delete obj[props[i]];
|
|
439
457
|
} else {
|
|
440
458
|
throw new Error(
|
|
441
459
|
"Invalid input: props must be a string or an array of strings"
|
|
@@ -456,19 +474,17 @@ const createObjectWithoutPrototype = (obj) => {
|
|
|
456
474
|
return newObj;
|
|
457
475
|
};
|
|
458
476
|
const createNestedObject = (arr, lastValue) => {
|
|
477
|
+
if (arr.length === 0) return lastValue;
|
|
459
478
|
const nestedObject = {};
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
if (index === arr.length - 1 && lastValue) {
|
|
468
|
-
obj[value] = lastValue;
|
|
479
|
+
let current = nestedObject;
|
|
480
|
+
for (let i = 0; i < arr.length; i++) {
|
|
481
|
+
if (i === arr.length - 1 && lastValue) {
|
|
482
|
+
current[arr[i]] = lastValue;
|
|
483
|
+
} else {
|
|
484
|
+
current[arr[i]] = {};
|
|
485
|
+
current = current[arr[i]];
|
|
469
486
|
}
|
|
470
|
-
|
|
471
|
-
}, nestedObject);
|
|
487
|
+
}
|
|
472
488
|
return nestedObject;
|
|
473
489
|
};
|
|
474
490
|
const removeNestedKeyByPath = (obj, path) => {
|
|
@@ -477,13 +493,11 @@ const removeNestedKeyByPath = (obj, path) => {
|
|
|
477
493
|
}
|
|
478
494
|
let current = obj;
|
|
479
495
|
for (let i = 0; i < path.length - 1; i++) {
|
|
480
|
-
if (current[path[i]] === void 0)
|
|
481
|
-
return;
|
|
482
|
-
}
|
|
496
|
+
if (current[path[i]] === void 0) return;
|
|
483
497
|
current = current[path[i]];
|
|
484
498
|
}
|
|
485
499
|
const lastKey = path[path.length - 1];
|
|
486
|
-
if (current && Object.hasOwnProperty.call(current, lastKey)) {
|
|
500
|
+
if (current && Object.prototype.hasOwnProperty.call(current, lastKey)) {
|
|
487
501
|
delete current[lastKey];
|
|
488
502
|
}
|
|
489
503
|
};
|
|
@@ -498,8 +512,7 @@ const setInObjectByPath = (obj, path, value) => {
|
|
|
498
512
|
}
|
|
499
513
|
current = current[path[i]];
|
|
500
514
|
}
|
|
501
|
-
|
|
502
|
-
current[lastKey] = value;
|
|
515
|
+
current[path[path.length - 1]] = value;
|
|
503
516
|
return obj;
|
|
504
517
|
};
|
|
505
518
|
const getInObjectByPath = (obj, path) => {
|
|
@@ -542,15 +555,13 @@ const detectInfiniteLoop = (arr) => {
|
|
|
542
555
|
}
|
|
543
556
|
};
|
|
544
557
|
const isCyclic = (obj) => {
|
|
545
|
-
const
|
|
558
|
+
const seen = /* @__PURE__ */ new WeakSet();
|
|
546
559
|
function detect(obj2) {
|
|
547
560
|
if (obj2 && typeof obj2 === "object") {
|
|
548
|
-
if (
|
|
549
|
-
|
|
550
|
-
}
|
|
551
|
-
seenObjects.push(obj2);
|
|
561
|
+
if (seen.has(obj2)) return true;
|
|
562
|
+
seen.add(obj2);
|
|
552
563
|
for (const key in obj2) {
|
|
553
|
-
if (Object.hasOwnProperty.call(obj2, key) && detect(obj2[key])) {
|
|
564
|
+
if (Object.prototype.hasOwnProperty.call(obj2, key) && detect(obj2[key])) {
|
|
554
565
|
console.log(obj2, "cycle at " + key);
|
|
555
566
|
return true;
|
|
556
567
|
}
|
|
@@ -561,7 +572,12 @@ const isCyclic = (obj) => {
|
|
|
561
572
|
return detect(obj);
|
|
562
573
|
};
|
|
563
574
|
const excludeKeysFromObject = (obj, excludedKeys) => {
|
|
564
|
-
const
|
|
565
|
-
|
|
575
|
+
const excluded = excludedKeys instanceof Set ? excludedKeys : new Set(excludedKeys);
|
|
576
|
+
const result = {};
|
|
577
|
+
for (const key in obj) {
|
|
578
|
+
if (Object.prototype.hasOwnProperty.call(obj, key) && !excluded.has(key)) {
|
|
579
|
+
result[key] = obj[key];
|
|
580
|
+
}
|
|
581
|
+
}
|
|
566
582
|
return result;
|
|
567
583
|
};
|
package/dist/cjs/props.js
CHANGED
|
@@ -40,6 +40,9 @@ var import_keys = require("./keys.js");
|
|
|
40
40
|
var import_events = require("./events.js");
|
|
41
41
|
var import_object = require("./object.js");
|
|
42
42
|
var import_types = require("./types.js");
|
|
43
|
+
var import_string = require("./string.js");
|
|
44
|
+
const RE_UPPER = /^[A-Z]/;
|
|
45
|
+
const RE_DIGITS = /^\d+$/;
|
|
43
46
|
const createProps = (element, parent, key) => {
|
|
44
47
|
const { props, __ref: ref } = element;
|
|
45
48
|
ref.__propsStack = [];
|
|
@@ -52,14 +55,20 @@ const createProps = (element, parent, key) => {
|
|
|
52
55
|
return { ...props };
|
|
53
56
|
};
|
|
54
57
|
function pickupPropsFromElement(obj, opts = {}) {
|
|
55
|
-
var _a, _b, _c;
|
|
56
58
|
const cachedKeys = opts.cachedKeys || [];
|
|
57
59
|
for (const key in obj) {
|
|
58
60
|
const value = obj[key];
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
61
|
+
const isEventHandler = key.length > 2 && key.charCodeAt(0) === 111 && key.charCodeAt(1) === 110 && key[2] === key[2].toUpperCase() && (0, import_types.isFunction)(value);
|
|
62
|
+
if (isEventHandler) {
|
|
63
|
+
const eventName = (0, import_string.lowercaseFirstLetter)(key.slice(2));
|
|
64
|
+
if (obj.on) obj.on[eventName] = value;
|
|
65
|
+
delete obj[key];
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
const hasDefine = (0, import_types.isObject)(this.define?.[key]);
|
|
69
|
+
const hasGlobalDefine = (0, import_types.isObject)(this.context?.define?.[key]);
|
|
70
|
+
const isElement = RE_UPPER.test(key) || RE_DIGITS.test(key);
|
|
71
|
+
const isBuiltin = import_keys.DOMQ_PROPERTIES.has(key);
|
|
63
72
|
if (!isElement && !isBuiltin && !hasDefine && !hasGlobalDefine) {
|
|
64
73
|
obj.props[key] = value;
|
|
65
74
|
delete obj[key];
|
|
@@ -69,11 +78,10 @@ function pickupPropsFromElement(obj, opts = {}) {
|
|
|
69
78
|
return obj;
|
|
70
79
|
}
|
|
71
80
|
function pickupElementFromProps(obj = this, opts) {
|
|
72
|
-
var _a, _b, _c;
|
|
73
81
|
const cachedKeys = opts.cachedKeys || [];
|
|
74
82
|
for (const key in obj.props) {
|
|
75
83
|
const value = obj.props[key];
|
|
76
|
-
const isEvent = key.
|
|
84
|
+
const isEvent = key.length > 2 && key.charCodeAt(0) === 111 && key.charCodeAt(1) === 110;
|
|
77
85
|
const isFn = (0, import_types.isFunction)(value);
|
|
78
86
|
if (isEvent && isFn) {
|
|
79
87
|
(0, import_events.addEventFromProps)(key, obj);
|
|
@@ -81,13 +89,15 @@ function pickupElementFromProps(obj = this, opts) {
|
|
|
81
89
|
continue;
|
|
82
90
|
}
|
|
83
91
|
if (cachedKeys.includes(key)) continue;
|
|
84
|
-
const hasDefine = (0, import_types.isObject)(
|
|
85
|
-
const hasGlobalDefine = (0, import_types.isObject)(
|
|
86
|
-
const isElement =
|
|
87
|
-
const isBuiltin = import_keys.DOMQ_PROPERTIES.
|
|
92
|
+
const hasDefine = (0, import_types.isObject)(this.define?.[key]);
|
|
93
|
+
const hasGlobalDefine = (0, import_types.isObject)(this.context?.define?.[key]);
|
|
94
|
+
const isElement = RE_UPPER.test(key) || RE_DIGITS.test(key);
|
|
95
|
+
const isBuiltin = import_keys.DOMQ_PROPERTIES.has(key);
|
|
88
96
|
if (isElement || isBuiltin || hasDefine || hasGlobalDefine) {
|
|
89
|
-
obj[key]
|
|
90
|
-
|
|
97
|
+
if (obj[key] === void 0 || value === null) {
|
|
98
|
+
obj[key] = value;
|
|
99
|
+
if (obj.props) delete obj.props[key];
|
|
100
|
+
}
|
|
91
101
|
}
|
|
92
102
|
}
|
|
93
103
|
return obj;
|
|
@@ -99,8 +109,9 @@ function propertizeElement(element = this) {
|
|
|
99
109
|
return element;
|
|
100
110
|
}
|
|
101
111
|
function propertizeUpdate(params = {}) {
|
|
102
|
-
|
|
103
|
-
|
|
112
|
+
if (!params.on) params.on = {};
|
|
113
|
+
if (!params.props) params.props = {};
|
|
114
|
+
return propertizeElement.call(this, params);
|
|
104
115
|
}
|
|
105
116
|
const objectizeStringProperty = (propValue) => {
|
|
106
117
|
if ((0, import_types.is)(propValue)("string", "number")) {
|
|
@@ -110,21 +121,16 @@ const objectizeStringProperty = (propValue) => {
|
|
|
110
121
|
};
|
|
111
122
|
const propExists = (prop, stack) => {
|
|
112
123
|
if (!prop || !stack.length) return false;
|
|
113
|
-
|
|
114
|
-
return stack.some((existing) => {
|
|
115
|
-
const existingKey = (0, import_types.isObject)(existing) ? JSON.stringify(existing) : existing;
|
|
116
|
-
return existingKey === key;
|
|
117
|
-
});
|
|
124
|
+
return stack.includes(prop);
|
|
118
125
|
};
|
|
119
126
|
const inheritParentProps = (element, parent) => {
|
|
120
|
-
var _a;
|
|
121
127
|
const { __ref: ref } = element;
|
|
122
128
|
const propsStack = ref.__propsStack || [];
|
|
123
129
|
const parentProps = parent.props;
|
|
124
130
|
if (!parentProps) return propsStack;
|
|
125
131
|
const matchParentKeyProps = parentProps[element.key];
|
|
126
132
|
const matchParentChildProps = parentProps.childProps;
|
|
127
|
-
const ignoreChildProps =
|
|
133
|
+
const ignoreChildProps = element.props?.ignoreChildProps;
|
|
128
134
|
if (matchParentChildProps && !ignoreChildProps) {
|
|
129
135
|
const childProps = objectizeStringProperty(matchParentChildProps);
|
|
130
136
|
propsStack.unshift(childProps);
|
|
@@ -146,16 +152,15 @@ function setPropsPrototype(element) {
|
|
|
146
152
|
const removeDuplicateProps = (propsStack) => {
|
|
147
153
|
const seen = /* @__PURE__ */ new Set();
|
|
148
154
|
return propsStack.filter((prop) => {
|
|
149
|
-
if (!prop || import_keys.PROPS_METHODS.
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
seen.add(key);
|
|
155
|
+
if (!prop || import_keys.PROPS_METHODS.has(prop)) return false;
|
|
156
|
+
if (seen.has(prop)) return false;
|
|
157
|
+
seen.add(prop);
|
|
153
158
|
return true;
|
|
154
159
|
});
|
|
155
160
|
};
|
|
156
161
|
const syncProps = (propsStack, element, opts) => {
|
|
157
162
|
element.props = propsStack.reduce((mergedProps, v) => {
|
|
158
|
-
if (import_keys.PROPS_METHODS.
|
|
163
|
+
if (import_keys.PROPS_METHODS.has(v)) return mergedProps;
|
|
159
164
|
while ((0, import_types.isFunction)(v)) v = (0, import_object.exec)(v, element);
|
|
160
165
|
return (0, import_object.deepMerge)(mergedProps, (0, import_object.deepClone)(v, { exclude: import_keys.PROPS_METHODS }));
|
|
161
166
|
}, {});
|
|
@@ -165,19 +170,20 @@ const syncProps = (propsStack, element, opts) => {
|
|
|
165
170
|
const createPropsStack = (element, parent) => {
|
|
166
171
|
const { props, __ref: ref } = element;
|
|
167
172
|
let propsStack = ref.__propsStack || [];
|
|
168
|
-
if (parent
|
|
173
|
+
if (parent?.props) {
|
|
169
174
|
const parentStack = inheritParentProps(element, parent);
|
|
170
175
|
propsStack = [...parentStack];
|
|
171
176
|
}
|
|
172
177
|
if ((0, import_types.isObject)(props)) propsStack.push(props);
|
|
173
|
-
else if (props === "inherit" &&
|
|
178
|
+
else if (props === "inherit" && parent?.props) propsStack.push(parent.props);
|
|
174
179
|
else if (props) propsStack.push(props);
|
|
175
180
|
if ((0, import_types.isArray)(ref.__extendsStack)) {
|
|
176
|
-
ref.__extendsStack.
|
|
181
|
+
for (let i = 0; i < ref.__extendsStack.length; i++) {
|
|
182
|
+
const _extends = ref.__extendsStack[i];
|
|
177
183
|
if (_extends.props && _extends.props !== props) {
|
|
178
184
|
propsStack.push(_extends.props);
|
|
179
185
|
}
|
|
180
|
-
}
|
|
186
|
+
}
|
|
181
187
|
}
|
|
182
188
|
ref.__propsStack = removeDuplicateProps(propsStack);
|
|
183
189
|
return ref.__propsStack;
|
|
@@ -198,7 +204,10 @@ const initProps = function(element, parent, options) {
|
|
|
198
204
|
else {
|
|
199
205
|
try {
|
|
200
206
|
applyProps(element, parent);
|
|
201
|
-
} catch {
|
|
207
|
+
} catch (e) {
|
|
208
|
+
if (element.context?.designSystem?.verbose) {
|
|
209
|
+
console.warn("initProps error at", ref.path?.join("."), e);
|
|
210
|
+
}
|
|
202
211
|
element.props = {};
|
|
203
212
|
ref.__propsStack = [];
|
|
204
213
|
}
|
package/dist/cjs/scope.js
CHANGED
|
@@ -22,7 +22,6 @@ __export(scope_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(scope_exports);
|
|
24
24
|
const createScope = (element, parent) => {
|
|
25
|
-
var _a;
|
|
26
25
|
const { __ref: ref } = element;
|
|
27
|
-
if (!element.scope) element.scope = parent.scope ||
|
|
26
|
+
if (!element.scope) element.scope = parent.scope || ref.root?.scope || {};
|
|
28
27
|
};
|