@domql/utils 3.5.0 → 3.6.1
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/dist/cjs/extends.js +81 -20
- package/dist/cjs/methods.js +14 -1
- package/dist/cjs/node.js +1 -1
- package/dist/cjs/props.js +25 -1
- package/dist/cjs/triggerEvent.js +39 -23
- package/dist/esm/extends.js +81 -20
- package/dist/esm/methods.js +14 -1
- package/dist/esm/node.js +1 -1
- package/dist/esm/props.js +25 -1
- package/dist/esm/triggerEvent.js +39 -23
- package/dist/iife/index.js +160 -46
- package/extends.js +95 -20
- package/methods.js +15 -2
- package/node.js +2 -2
- package/package.json +9 -11
- package/props.js +15 -1
- package/triggerEvent.js +39 -21
package/dist/cjs/extends.js
CHANGED
|
@@ -52,6 +52,7 @@ var import_component = require("./component.js");
|
|
|
52
52
|
var import_object = require("./object.js");
|
|
53
53
|
var import_types = require("./types.js");
|
|
54
54
|
const ENV = process.env.NODE_ENV;
|
|
55
|
+
const isSourcemapEnabled = (options) => options.sourcemap !== false && ENV !== "production";
|
|
55
56
|
const createExtendsFromKeys = (key) => {
|
|
56
57
|
if (key.includes("+")) {
|
|
57
58
|
return key.split("+").filter(import_component.matchesComponentNaming);
|
|
@@ -126,17 +127,17 @@ const getExtendsStackRegistry = (extend, stack) => {
|
|
|
126
127
|
}
|
|
127
128
|
return setHashedExtend(extend, stack);
|
|
128
129
|
};
|
|
129
|
-
const extractArrayExtend = (extend, stack, context, processed = /* @__PURE__ */ new Set()) => {
|
|
130
|
+
const extractArrayExtend = (extend, stack, context, processed = /* @__PURE__ */ new Set(), nameStack, componentNameMap) => {
|
|
130
131
|
for (const each of extend) {
|
|
131
132
|
if ((0, import_types.isArray)(each)) {
|
|
132
|
-
extractArrayExtend(each, stack, context, processed);
|
|
133
|
+
extractArrayExtend(each, stack, context, processed, nameStack, componentNameMap);
|
|
133
134
|
} else {
|
|
134
|
-
flattenExtend(each, stack, context, processed);
|
|
135
|
+
flattenExtend(each, stack, context, processed, nameStack, void 0, componentNameMap);
|
|
135
136
|
}
|
|
136
137
|
}
|
|
137
138
|
return stack;
|
|
138
139
|
};
|
|
139
|
-
const deepExtend = (extend, stack, context, processed = /* @__PURE__ */ new Set()) => {
|
|
140
|
+
const deepExtend = (extend, stack, context, processed = /* @__PURE__ */ new Set(), nameStack, currentName, componentNameMap) => {
|
|
140
141
|
const extendOflattenExtend = extend.extends || extend.extend;
|
|
141
142
|
const cleanExtend = { ...extend };
|
|
142
143
|
delete cleanExtend.extends;
|
|
@@ -148,26 +149,32 @@ const deepExtend = (extend, stack, context, processed = /* @__PURE__ */ new Set(
|
|
|
148
149
|
}
|
|
149
150
|
if (hasKeys) {
|
|
150
151
|
stack.push(cleanExtend);
|
|
152
|
+
if (nameStack) nameStack.push(currentName);
|
|
151
153
|
}
|
|
152
154
|
if (extendOflattenExtend) {
|
|
153
|
-
flattenExtend(extendOflattenExtend, stack, context, processed);
|
|
155
|
+
flattenExtend(extendOflattenExtend, stack, context, processed, nameStack, currentName, componentNameMap);
|
|
154
156
|
}
|
|
155
157
|
return stack;
|
|
156
158
|
};
|
|
157
|
-
const flattenExtend = (extend, stack, context, processed = /* @__PURE__ */ new Set()) => {
|
|
159
|
+
const flattenExtend = (extend, stack, context, processed = /* @__PURE__ */ new Set(), nameStack, parentName, componentNameMap) => {
|
|
158
160
|
if (!extend) return stack;
|
|
159
161
|
if (processed.has(extend)) return stack;
|
|
160
162
|
if ((0, import_types.isArray)(extend)) {
|
|
161
|
-
return extractArrayExtend(extend, stack, context, processed);
|
|
163
|
+
return extractArrayExtend(extend, stack, context, processed, nameStack, componentNameMap);
|
|
162
164
|
}
|
|
165
|
+
let currentName = parentName;
|
|
163
166
|
if ((0, import_types.isString)(extend)) {
|
|
167
|
+
currentName = extend;
|
|
164
168
|
extend = mapStringsWithContextComponents(extend, context);
|
|
169
|
+
} else if (componentNameMap && (0, import_types.isObject)(extend) && componentNameMap.has(extend)) {
|
|
170
|
+
currentName = componentNameMap.get(extend);
|
|
165
171
|
}
|
|
166
172
|
processed.add(extend);
|
|
167
173
|
if (extend?.extends || extend?.extend) {
|
|
168
|
-
deepExtend(extend, stack, context, processed);
|
|
174
|
+
deepExtend(extend, stack, context, processed, nameStack, currentName, componentNameMap);
|
|
169
175
|
} else if (extend) {
|
|
170
176
|
stack.push(extend);
|
|
177
|
+
if (nameStack) nameStack.push(currentName);
|
|
171
178
|
}
|
|
172
179
|
return stack;
|
|
173
180
|
};
|
|
@@ -180,7 +187,7 @@ const MERGE_EXTENDS_SKIP = /* @__PURE__ */ new Set([
|
|
|
180
187
|
"childExtend",
|
|
181
188
|
"childExtendRecursive"
|
|
182
189
|
]);
|
|
183
|
-
const deepMergeExtends = (element, extend) => {
|
|
190
|
+
const deepMergeExtends = (element, extend, sourcemap, sourceName, preBuiltSourcemap) => {
|
|
184
191
|
extend = (0, import_object.deepClone)(extend);
|
|
185
192
|
for (const e in extend) {
|
|
186
193
|
if (MERGE_EXTENDS_SKIP.has(e)) continue;
|
|
@@ -190,11 +197,23 @@ const deepMergeExtends = (element, extend) => {
|
|
|
190
197
|
if (Object.prototype.hasOwnProperty.call(extend, e) && e !== "__proto__" && e !== "constructor" && e !== "prototype") {
|
|
191
198
|
if (elementProp === void 0) {
|
|
192
199
|
element[e] = extendProp;
|
|
200
|
+
if (sourcemap && sourceName) {
|
|
201
|
+
if ((0, import_types.isObject)(extendProp) && !(0, import_types.isArray)(extendProp)) {
|
|
202
|
+
sourcemap[e] = sourcemap[e] || {};
|
|
203
|
+
trackSourcemapDeep(sourcemap[e], extendProp, sourceName);
|
|
204
|
+
} else {
|
|
205
|
+
sourcemap[e] = sourceName;
|
|
206
|
+
}
|
|
207
|
+
} else if (sourcemap && preBuiltSourcemap?.[e]) {
|
|
208
|
+
sourcemap[e] = preBuiltSourcemap[e];
|
|
209
|
+
}
|
|
193
210
|
} else if ((0, import_types.isObject)(elementProp) && (0, import_types.isObject)(extendProp)) {
|
|
211
|
+
const nestedSourcemap = sourcemap ? sourcemap[e] = sourcemap[e] || {} : void 0;
|
|
212
|
+
const nestedPreBuilt = preBuiltSourcemap?.[e];
|
|
194
213
|
if ((0, import_component.matchesComponentNaming)(e)) {
|
|
195
|
-
element[e] = deepMergeExtends(elementProp, extendProp);
|
|
214
|
+
element[e] = deepMergeExtends(elementProp, extendProp, nestedSourcemap, sourceName, nestedPreBuilt);
|
|
196
215
|
} else {
|
|
197
|
-
deepMergeExtends(elementProp, extendProp);
|
|
216
|
+
deepMergeExtends(elementProp, extendProp, nestedSourcemap, sourceName, nestedPreBuilt);
|
|
198
217
|
}
|
|
199
218
|
}
|
|
200
219
|
if (e === "extends" || e === "childExtends" || e === "childExtendsRecursive") {
|
|
@@ -209,10 +228,24 @@ const deepMergeExtends = (element, extend) => {
|
|
|
209
228
|
}
|
|
210
229
|
return element;
|
|
211
230
|
};
|
|
212
|
-
const
|
|
213
|
-
|
|
231
|
+
const trackSourcemapDeep = (sourcemap, obj, sourceName) => {
|
|
232
|
+
for (const key in obj) {
|
|
233
|
+
if (!Object.prototype.hasOwnProperty.call(obj, key)) continue;
|
|
234
|
+
if (key === "__proto__" || key === "constructor" || key === "prototype") continue;
|
|
235
|
+
const val = obj[key];
|
|
236
|
+
if ((0, import_types.isObject)(val) && !(0, import_types.isArray)(val)) {
|
|
237
|
+
sourcemap[key] = sourcemap[key] || {};
|
|
238
|
+
trackSourcemapDeep(sourcemap[key], val, sourceName);
|
|
239
|
+
} else {
|
|
240
|
+
sourcemap[key] = sourceName;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
const cloneAndMergeArrayExtend = (stack, sourcemap, extendNames) => {
|
|
245
|
+
return stack.reduce((acc, current, i) => {
|
|
214
246
|
const cloned = (0, import_object.deepClone)(current);
|
|
215
|
-
|
|
247
|
+
const sourceName = extendNames ? extendNames[i] : void 0;
|
|
248
|
+
return deepMergeExtends(acc, cloned, sourcemap, sourceName);
|
|
216
249
|
}, {});
|
|
217
250
|
};
|
|
218
251
|
const mapStringsWithContextComponents = (extend, context, options = {}, variant) => {
|
|
@@ -235,11 +268,12 @@ const mapStringsWithContextComponents = (extend, context, options = {}, variant)
|
|
|
235
268
|
const jointStacks = (extendStack, childExtendsStack) => {
|
|
236
269
|
return [].concat(extendStack.slice(0, 1)).concat(childExtendsStack.slice(0, 1)).concat(extendStack.slice(1)).concat(childExtendsStack.slice(1));
|
|
237
270
|
};
|
|
238
|
-
const getExtendsStack = (extend, context) => {
|
|
271
|
+
const getExtendsStack = (extend, context, nameStack, componentNameMap) => {
|
|
239
272
|
if (!extend) return [];
|
|
240
273
|
if (extend.__hash) return getHashedExtend(extend) || [];
|
|
241
274
|
const processed = /* @__PURE__ */ new Set();
|
|
242
|
-
const stack = flattenExtend(extend, [], context, processed);
|
|
275
|
+
const stack = flattenExtend(extend, [], context, processed, nameStack, void 0, componentNameMap);
|
|
276
|
+
if (nameStack) return stack;
|
|
243
277
|
return getExtendsStackRegistry(extend, stack);
|
|
244
278
|
};
|
|
245
279
|
const addExtend = (newExtends, elementExtends) => {
|
|
@@ -346,6 +380,8 @@ const createExtendsStack = (element, parent, options = {}) => {
|
|
|
346
380
|
const { props, __ref: ref } = element;
|
|
347
381
|
const context = element.context || parent.context;
|
|
348
382
|
const variant = element.variant || props?.variant;
|
|
383
|
+
const sourcemap = isSourcemapEnabled(options);
|
|
384
|
+
const originalExtendNames = sourcemap ? [...ref.__extends] : null;
|
|
349
385
|
const __extends = (0, import_array.removeDuplicatesInArray)(
|
|
350
386
|
ref.__extends.map((val, i) => {
|
|
351
387
|
return mapStringsWithContextComponents(
|
|
@@ -356,15 +392,40 @@ const createExtendsStack = (element, parent, options = {}) => {
|
|
|
356
392
|
);
|
|
357
393
|
})
|
|
358
394
|
);
|
|
359
|
-
|
|
360
|
-
|
|
395
|
+
if (sourcemap) {
|
|
396
|
+
const componentNameMap = /* @__PURE__ */ new WeakMap();
|
|
397
|
+
for (let i = 0; i < __extends.length; i++) {
|
|
398
|
+
const resolved = __extends[i];
|
|
399
|
+
const originalName = originalExtendNames[i];
|
|
400
|
+
if (resolved && (0, import_types.isObject)(resolved) && (0, import_types.isString)(originalName)) {
|
|
401
|
+
componentNameMap.set(resolved, originalName);
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
const nameStack = [];
|
|
405
|
+
const stack = getExtendsStack(__extends, context, nameStack, componentNameMap);
|
|
406
|
+
ref.__extendsStack = stack;
|
|
407
|
+
ref.__extendsNames = nameStack;
|
|
408
|
+
} else {
|
|
409
|
+
const stack = getExtendsStack(__extends, context);
|
|
410
|
+
ref.__extendsStack = stack;
|
|
411
|
+
}
|
|
361
412
|
return ref.__extendsStack;
|
|
362
413
|
};
|
|
363
414
|
const finalizeExtends = (element, parent, options = {}) => {
|
|
364
415
|
const { __ref: ref } = element;
|
|
365
416
|
const { __extendsStack } = ref;
|
|
366
|
-
|
|
367
|
-
|
|
417
|
+
if (isSourcemapEnabled(options)) {
|
|
418
|
+
const sourcemapAcc = {};
|
|
419
|
+
const extendNames = ref.__extendsNames || [];
|
|
420
|
+
const flattenExtends = cloneAndMergeArrayExtend(__extendsStack, sourcemapAcc, extendNames);
|
|
421
|
+
const appliedSourcemap = {};
|
|
422
|
+
deepMergeExtends(element, flattenExtends, appliedSourcemap, void 0, sourcemapAcc);
|
|
423
|
+
ref.__sourcemap = appliedSourcemap;
|
|
424
|
+
} else {
|
|
425
|
+
const flattenExtends = cloneAndMergeArrayExtend(__extendsStack);
|
|
426
|
+
deepMergeExtends(element, flattenExtends);
|
|
427
|
+
}
|
|
428
|
+
return element;
|
|
368
429
|
};
|
|
369
430
|
const applyExtends = (element, parent, options = {}) => {
|
|
370
431
|
createElementExtends(element, parent, options);
|
package/dist/cjs/methods.js
CHANGED
|
@@ -353,7 +353,20 @@ function variables(obj = {}) {
|
|
|
353
353
|
}
|
|
354
354
|
function call(fnKey, ...args) {
|
|
355
355
|
const context = this.context;
|
|
356
|
-
|
|
356
|
+
const fn = context.utils?.[fnKey] || context.functions?.[fnKey] || context.methods?.[fnKey] || context.snippets?.[fnKey];
|
|
357
|
+
if (!fn) return;
|
|
358
|
+
try {
|
|
359
|
+
const result = fn.call(this, ...args);
|
|
360
|
+
if (result && typeof result.then === "function") {
|
|
361
|
+
result.catch((err) => {
|
|
362
|
+
this.error = err;
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
return result;
|
|
366
|
+
} catch (err) {
|
|
367
|
+
this.error = err;
|
|
368
|
+
if (context?.strictMode) throw err;
|
|
369
|
+
}
|
|
357
370
|
}
|
|
358
371
|
function isMethod(param, element) {
|
|
359
372
|
return Boolean(import_keys.METHODS.has(param) || element?.context?.methods?.[param]);
|
package/dist/cjs/node.js
CHANGED
|
@@ -31,5 +31,5 @@ const isHtmlElement = (obj) => {
|
|
|
31
31
|
return (typeof HTMLElement === "object" ? obj instanceof import_globals.window.HTMLElement : obj && typeof obj === "object" && obj !== null && obj.nodeType === 1 && typeof obj.nodeName === "string") || false;
|
|
32
32
|
};
|
|
33
33
|
const isDOMNode = (obj) => {
|
|
34
|
-
return typeof import_globals.window !== "undefined" && (obj instanceof import_globals.window.Node || obj instanceof import_globals.window.Window || obj === import_globals.window || obj === document);
|
|
34
|
+
return typeof import_globals.window !== "undefined" && (import_globals.window.Node && obj instanceof import_globals.window.Node || import_globals.window.Window && obj instanceof import_globals.window.Window || obj === import_globals.window || obj === document);
|
|
35
35
|
};
|
package/dist/cjs/props.js
CHANGED
|
@@ -43,6 +43,30 @@ var import_types = require("./types.js");
|
|
|
43
43
|
var import_string = require("./string.js");
|
|
44
44
|
const RE_UPPER = /^[A-Z]/;
|
|
45
45
|
const RE_DIGITS = /^\d+$/;
|
|
46
|
+
const ELEMENT_INDICATOR_KEYS = /* @__PURE__ */ new Set([
|
|
47
|
+
"extend",
|
|
48
|
+
"props",
|
|
49
|
+
"text",
|
|
50
|
+
"tag",
|
|
51
|
+
"on",
|
|
52
|
+
"if",
|
|
53
|
+
"childExtend",
|
|
54
|
+
"children",
|
|
55
|
+
"childrenAs",
|
|
56
|
+
"state",
|
|
57
|
+
"html",
|
|
58
|
+
"attr",
|
|
59
|
+
"define",
|
|
60
|
+
"content"
|
|
61
|
+
]);
|
|
62
|
+
const looksLikeElement = (value) => {
|
|
63
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
64
|
+
for (const k in value) {
|
|
65
|
+
if (ELEMENT_INDICATOR_KEYS.has(k)) return true;
|
|
66
|
+
if (RE_UPPER.test(k)) return true;
|
|
67
|
+
}
|
|
68
|
+
return false;
|
|
69
|
+
};
|
|
46
70
|
const createProps = (element, parent, key) => {
|
|
47
71
|
const { props, __ref: ref } = element;
|
|
48
72
|
ref.__propsStack = [];
|
|
@@ -67,7 +91,7 @@ function pickupPropsFromElement(obj, opts = {}) {
|
|
|
67
91
|
}
|
|
68
92
|
const hasDefine = (0, import_types.isObject)(this.define?.[key]);
|
|
69
93
|
const hasGlobalDefine = (0, import_types.isObject)(this.context?.define?.[key]);
|
|
70
|
-
const isElement = RE_UPPER.test(key) || RE_DIGITS.test(key);
|
|
94
|
+
const isElement = RE_UPPER.test(key) || RE_DIGITS.test(key) || looksLikeElement(value);
|
|
71
95
|
const isBuiltin = import_keys.DOMQ_PROPERTIES.has(key);
|
|
72
96
|
if (!isElement && !isBuiltin && !hasDefine && !hasGlobalDefine) {
|
|
73
97
|
obj.props[key] = value;
|
package/dist/cjs/triggerEvent.js
CHANGED
|
@@ -35,18 +35,26 @@ const getOnOrPropsEvent = (param, element) => {
|
|
|
35
35
|
};
|
|
36
36
|
const applyEvent = (param, element, state, context, options) => {
|
|
37
37
|
if (!(0, import_types.isFunction)(param)) return;
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
result.
|
|
47
|
-
|
|
38
|
+
try {
|
|
39
|
+
const result = param.call(
|
|
40
|
+
element,
|
|
41
|
+
element,
|
|
42
|
+
state || element.state,
|
|
43
|
+
context || element.context,
|
|
44
|
+
options
|
|
45
|
+
);
|
|
46
|
+
if (result && typeof result.then === "function") {
|
|
47
|
+
result.catch((err) => {
|
|
48
|
+
element.error = err;
|
|
49
|
+
console.error("[DomQL] Async event error:", err);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
return result;
|
|
53
|
+
} catch (err) {
|
|
54
|
+
element.error = err;
|
|
55
|
+
console.error("[DomQL] Event handler error:", err);
|
|
56
|
+
if (element.context?.strictMode) throw err;
|
|
48
57
|
}
|
|
49
|
-
return result;
|
|
50
58
|
};
|
|
51
59
|
const triggerEventOn = (param, element, options) => {
|
|
52
60
|
if (!element) {
|
|
@@ -60,19 +68,27 @@ const triggerEventOn = (param, element, options) => {
|
|
|
60
68
|
};
|
|
61
69
|
const applyEventUpdate = (param, updatedObj, element, state, context, options) => {
|
|
62
70
|
if (!(0, import_types.isFunction)(param)) return;
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
result.
|
|
73
|
-
|
|
71
|
+
try {
|
|
72
|
+
const result = param.call(
|
|
73
|
+
element,
|
|
74
|
+
updatedObj,
|
|
75
|
+
element,
|
|
76
|
+
state || element.state,
|
|
77
|
+
context || element.context,
|
|
78
|
+
options
|
|
79
|
+
);
|
|
80
|
+
if (result && typeof result.then === "function") {
|
|
81
|
+
result.catch((err) => {
|
|
82
|
+
element.error = err;
|
|
83
|
+
console.error("[DomQL] Async event update error:", err);
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
return result;
|
|
87
|
+
} catch (err) {
|
|
88
|
+
element.error = err;
|
|
89
|
+
console.error("[DomQL] Event update error:", err);
|
|
90
|
+
if (element.context?.strictMode) throw err;
|
|
74
91
|
}
|
|
75
|
-
return result;
|
|
76
92
|
};
|
|
77
93
|
const triggerEventOnUpdate = (param, updatedObj, element, options) => {
|
|
78
94
|
const appliedFunction = getOnOrPropsEvent(param, element);
|
package/dist/esm/extends.js
CHANGED
|
@@ -3,6 +3,7 @@ import { matchesComponentNaming } from "./component.js";
|
|
|
3
3
|
import { deepClone, exec } from "./object.js";
|
|
4
4
|
import { isArray, isObject, isString } from "./types.js";
|
|
5
5
|
const ENV = process.env.NODE_ENV;
|
|
6
|
+
const isSourcemapEnabled = (options) => options.sourcemap !== false && ENV !== "production";
|
|
6
7
|
const createExtendsFromKeys = (key) => {
|
|
7
8
|
if (key.includes("+")) {
|
|
8
9
|
return key.split("+").filter(matchesComponentNaming);
|
|
@@ -77,17 +78,17 @@ const getExtendsStackRegistry = (extend, stack) => {
|
|
|
77
78
|
}
|
|
78
79
|
return setHashedExtend(extend, stack);
|
|
79
80
|
};
|
|
80
|
-
const extractArrayExtend = (extend, stack, context, processed = /* @__PURE__ */ new Set()) => {
|
|
81
|
+
const extractArrayExtend = (extend, stack, context, processed = /* @__PURE__ */ new Set(), nameStack, componentNameMap) => {
|
|
81
82
|
for (const each of extend) {
|
|
82
83
|
if (isArray(each)) {
|
|
83
|
-
extractArrayExtend(each, stack, context, processed);
|
|
84
|
+
extractArrayExtend(each, stack, context, processed, nameStack, componentNameMap);
|
|
84
85
|
} else {
|
|
85
|
-
flattenExtend(each, stack, context, processed);
|
|
86
|
+
flattenExtend(each, stack, context, processed, nameStack, void 0, componentNameMap);
|
|
86
87
|
}
|
|
87
88
|
}
|
|
88
89
|
return stack;
|
|
89
90
|
};
|
|
90
|
-
const deepExtend = (extend, stack, context, processed = /* @__PURE__ */ new Set()) => {
|
|
91
|
+
const deepExtend = (extend, stack, context, processed = /* @__PURE__ */ new Set(), nameStack, currentName, componentNameMap) => {
|
|
91
92
|
const extendOflattenExtend = extend.extends || extend.extend;
|
|
92
93
|
const cleanExtend = { ...extend };
|
|
93
94
|
delete cleanExtend.extends;
|
|
@@ -99,26 +100,32 @@ const deepExtend = (extend, stack, context, processed = /* @__PURE__ */ new Set(
|
|
|
99
100
|
}
|
|
100
101
|
if (hasKeys) {
|
|
101
102
|
stack.push(cleanExtend);
|
|
103
|
+
if (nameStack) nameStack.push(currentName);
|
|
102
104
|
}
|
|
103
105
|
if (extendOflattenExtend) {
|
|
104
|
-
flattenExtend(extendOflattenExtend, stack, context, processed);
|
|
106
|
+
flattenExtend(extendOflattenExtend, stack, context, processed, nameStack, currentName, componentNameMap);
|
|
105
107
|
}
|
|
106
108
|
return stack;
|
|
107
109
|
};
|
|
108
|
-
const flattenExtend = (extend, stack, context, processed = /* @__PURE__ */ new Set()) => {
|
|
110
|
+
const flattenExtend = (extend, stack, context, processed = /* @__PURE__ */ new Set(), nameStack, parentName, componentNameMap) => {
|
|
109
111
|
if (!extend) return stack;
|
|
110
112
|
if (processed.has(extend)) return stack;
|
|
111
113
|
if (isArray(extend)) {
|
|
112
|
-
return extractArrayExtend(extend, stack, context, processed);
|
|
114
|
+
return extractArrayExtend(extend, stack, context, processed, nameStack, componentNameMap);
|
|
113
115
|
}
|
|
116
|
+
let currentName = parentName;
|
|
114
117
|
if (isString(extend)) {
|
|
118
|
+
currentName = extend;
|
|
115
119
|
extend = mapStringsWithContextComponents(extend, context);
|
|
120
|
+
} else if (componentNameMap && isObject(extend) && componentNameMap.has(extend)) {
|
|
121
|
+
currentName = componentNameMap.get(extend);
|
|
116
122
|
}
|
|
117
123
|
processed.add(extend);
|
|
118
124
|
if (extend?.extends || extend?.extend) {
|
|
119
|
-
deepExtend(extend, stack, context, processed);
|
|
125
|
+
deepExtend(extend, stack, context, processed, nameStack, currentName, componentNameMap);
|
|
120
126
|
} else if (extend) {
|
|
121
127
|
stack.push(extend);
|
|
128
|
+
if (nameStack) nameStack.push(currentName);
|
|
122
129
|
}
|
|
123
130
|
return stack;
|
|
124
131
|
};
|
|
@@ -131,7 +138,7 @@ const MERGE_EXTENDS_SKIP = /* @__PURE__ */ new Set([
|
|
|
131
138
|
"childExtend",
|
|
132
139
|
"childExtendRecursive"
|
|
133
140
|
]);
|
|
134
|
-
const deepMergeExtends = (element, extend) => {
|
|
141
|
+
const deepMergeExtends = (element, extend, sourcemap, sourceName, preBuiltSourcemap) => {
|
|
135
142
|
extend = deepClone(extend);
|
|
136
143
|
for (const e in extend) {
|
|
137
144
|
if (MERGE_EXTENDS_SKIP.has(e)) continue;
|
|
@@ -141,11 +148,23 @@ const deepMergeExtends = (element, extend) => {
|
|
|
141
148
|
if (Object.prototype.hasOwnProperty.call(extend, e) && e !== "__proto__" && e !== "constructor" && e !== "prototype") {
|
|
142
149
|
if (elementProp === void 0) {
|
|
143
150
|
element[e] = extendProp;
|
|
151
|
+
if (sourcemap && sourceName) {
|
|
152
|
+
if (isObject(extendProp) && !isArray(extendProp)) {
|
|
153
|
+
sourcemap[e] = sourcemap[e] || {};
|
|
154
|
+
trackSourcemapDeep(sourcemap[e], extendProp, sourceName);
|
|
155
|
+
} else {
|
|
156
|
+
sourcemap[e] = sourceName;
|
|
157
|
+
}
|
|
158
|
+
} else if (sourcemap && preBuiltSourcemap?.[e]) {
|
|
159
|
+
sourcemap[e] = preBuiltSourcemap[e];
|
|
160
|
+
}
|
|
144
161
|
} else if (isObject(elementProp) && isObject(extendProp)) {
|
|
162
|
+
const nestedSourcemap = sourcemap ? sourcemap[e] = sourcemap[e] || {} : void 0;
|
|
163
|
+
const nestedPreBuilt = preBuiltSourcemap?.[e];
|
|
145
164
|
if (matchesComponentNaming(e)) {
|
|
146
|
-
element[e] = deepMergeExtends(elementProp, extendProp);
|
|
165
|
+
element[e] = deepMergeExtends(elementProp, extendProp, nestedSourcemap, sourceName, nestedPreBuilt);
|
|
147
166
|
} else {
|
|
148
|
-
deepMergeExtends(elementProp, extendProp);
|
|
167
|
+
deepMergeExtends(elementProp, extendProp, nestedSourcemap, sourceName, nestedPreBuilt);
|
|
149
168
|
}
|
|
150
169
|
}
|
|
151
170
|
if (e === "extends" || e === "childExtends" || e === "childExtendsRecursive") {
|
|
@@ -160,10 +179,24 @@ const deepMergeExtends = (element, extend) => {
|
|
|
160
179
|
}
|
|
161
180
|
return element;
|
|
162
181
|
};
|
|
163
|
-
const
|
|
164
|
-
|
|
182
|
+
const trackSourcemapDeep = (sourcemap, obj, sourceName) => {
|
|
183
|
+
for (const key in obj) {
|
|
184
|
+
if (!Object.prototype.hasOwnProperty.call(obj, key)) continue;
|
|
185
|
+
if (key === "__proto__" || key === "constructor" || key === "prototype") continue;
|
|
186
|
+
const val = obj[key];
|
|
187
|
+
if (isObject(val) && !isArray(val)) {
|
|
188
|
+
sourcemap[key] = sourcemap[key] || {};
|
|
189
|
+
trackSourcemapDeep(sourcemap[key], val, sourceName);
|
|
190
|
+
} else {
|
|
191
|
+
sourcemap[key] = sourceName;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
const cloneAndMergeArrayExtend = (stack, sourcemap, extendNames) => {
|
|
196
|
+
return stack.reduce((acc, current, i) => {
|
|
165
197
|
const cloned = deepClone(current);
|
|
166
|
-
|
|
198
|
+
const sourceName = extendNames ? extendNames[i] : void 0;
|
|
199
|
+
return deepMergeExtends(acc, cloned, sourcemap, sourceName);
|
|
167
200
|
}, {});
|
|
168
201
|
};
|
|
169
202
|
const mapStringsWithContextComponents = (extend, context, options = {}, variant) => {
|
|
@@ -186,11 +219,12 @@ const mapStringsWithContextComponents = (extend, context, options = {}, variant)
|
|
|
186
219
|
const jointStacks = (extendStack, childExtendsStack) => {
|
|
187
220
|
return [].concat(extendStack.slice(0, 1)).concat(childExtendsStack.slice(0, 1)).concat(extendStack.slice(1)).concat(childExtendsStack.slice(1));
|
|
188
221
|
};
|
|
189
|
-
const getExtendsStack = (extend, context) => {
|
|
222
|
+
const getExtendsStack = (extend, context, nameStack, componentNameMap) => {
|
|
190
223
|
if (!extend) return [];
|
|
191
224
|
if (extend.__hash) return getHashedExtend(extend) || [];
|
|
192
225
|
const processed = /* @__PURE__ */ new Set();
|
|
193
|
-
const stack = flattenExtend(extend, [], context, processed);
|
|
226
|
+
const stack = flattenExtend(extend, [], context, processed, nameStack, void 0, componentNameMap);
|
|
227
|
+
if (nameStack) return stack;
|
|
194
228
|
return getExtendsStackRegistry(extend, stack);
|
|
195
229
|
};
|
|
196
230
|
const addExtend = (newExtends, elementExtends) => {
|
|
@@ -297,6 +331,8 @@ const createExtendsStack = (element, parent, options = {}) => {
|
|
|
297
331
|
const { props, __ref: ref } = element;
|
|
298
332
|
const context = element.context || parent.context;
|
|
299
333
|
const variant = element.variant || props?.variant;
|
|
334
|
+
const sourcemap = isSourcemapEnabled(options);
|
|
335
|
+
const originalExtendNames = sourcemap ? [...ref.__extends] : null;
|
|
300
336
|
const __extends = removeDuplicatesInArray(
|
|
301
337
|
ref.__extends.map((val, i) => {
|
|
302
338
|
return mapStringsWithContextComponents(
|
|
@@ -307,15 +343,40 @@ const createExtendsStack = (element, parent, options = {}) => {
|
|
|
307
343
|
);
|
|
308
344
|
})
|
|
309
345
|
);
|
|
310
|
-
|
|
311
|
-
|
|
346
|
+
if (sourcemap) {
|
|
347
|
+
const componentNameMap = /* @__PURE__ */ new WeakMap();
|
|
348
|
+
for (let i = 0; i < __extends.length; i++) {
|
|
349
|
+
const resolved = __extends[i];
|
|
350
|
+
const originalName = originalExtendNames[i];
|
|
351
|
+
if (resolved && isObject(resolved) && isString(originalName)) {
|
|
352
|
+
componentNameMap.set(resolved, originalName);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
const nameStack = [];
|
|
356
|
+
const stack = getExtendsStack(__extends, context, nameStack, componentNameMap);
|
|
357
|
+
ref.__extendsStack = stack;
|
|
358
|
+
ref.__extendsNames = nameStack;
|
|
359
|
+
} else {
|
|
360
|
+
const stack = getExtendsStack(__extends, context);
|
|
361
|
+
ref.__extendsStack = stack;
|
|
362
|
+
}
|
|
312
363
|
return ref.__extendsStack;
|
|
313
364
|
};
|
|
314
365
|
const finalizeExtends = (element, parent, options = {}) => {
|
|
315
366
|
const { __ref: ref } = element;
|
|
316
367
|
const { __extendsStack } = ref;
|
|
317
|
-
|
|
318
|
-
|
|
368
|
+
if (isSourcemapEnabled(options)) {
|
|
369
|
+
const sourcemapAcc = {};
|
|
370
|
+
const extendNames = ref.__extendsNames || [];
|
|
371
|
+
const flattenExtends = cloneAndMergeArrayExtend(__extendsStack, sourcemapAcc, extendNames);
|
|
372
|
+
const appliedSourcemap = {};
|
|
373
|
+
deepMergeExtends(element, flattenExtends, appliedSourcemap, void 0, sourcemapAcc);
|
|
374
|
+
ref.__sourcemap = appliedSourcemap;
|
|
375
|
+
} else {
|
|
376
|
+
const flattenExtends = cloneAndMergeArrayExtend(__extendsStack);
|
|
377
|
+
deepMergeExtends(element, flattenExtends);
|
|
378
|
+
}
|
|
379
|
+
return element;
|
|
319
380
|
};
|
|
320
381
|
const applyExtends = (element, parent, options = {}) => {
|
|
321
382
|
createElementExtends(element, parent, options);
|
package/dist/esm/methods.js
CHANGED
|
@@ -302,7 +302,20 @@ function variables(obj = {}) {
|
|
|
302
302
|
}
|
|
303
303
|
function call(fnKey, ...args) {
|
|
304
304
|
const context = this.context;
|
|
305
|
-
|
|
305
|
+
const fn = context.utils?.[fnKey] || context.functions?.[fnKey] || context.methods?.[fnKey] || context.snippets?.[fnKey];
|
|
306
|
+
if (!fn) return;
|
|
307
|
+
try {
|
|
308
|
+
const result = fn.call(this, ...args);
|
|
309
|
+
if (result && typeof result.then === "function") {
|
|
310
|
+
result.catch((err) => {
|
|
311
|
+
this.error = err;
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
return result;
|
|
315
|
+
} catch (err) {
|
|
316
|
+
this.error = err;
|
|
317
|
+
if (context?.strictMode) throw err;
|
|
318
|
+
}
|
|
306
319
|
}
|
|
307
320
|
function isMethod(param, element) {
|
|
308
321
|
return Boolean(METHODS.has(param) || element?.context?.methods?.[param]);
|
package/dist/esm/node.js
CHANGED
|
@@ -6,7 +6,7 @@ const isHtmlElement = (obj) => {
|
|
|
6
6
|
return (typeof HTMLElement === "object" ? obj instanceof window.HTMLElement : obj && typeof obj === "object" && obj !== null && obj.nodeType === 1 && typeof obj.nodeName === "string") || false;
|
|
7
7
|
};
|
|
8
8
|
const isDOMNode = (obj) => {
|
|
9
|
-
return typeof window !== "undefined" && (obj instanceof window.Node || obj instanceof window.Window || obj === window || obj === document);
|
|
9
|
+
return typeof window !== "undefined" && (window.Node && obj instanceof window.Node || window.Window && obj instanceof window.Window || obj === window || obj === document);
|
|
10
10
|
};
|
|
11
11
|
export {
|
|
12
12
|
isDOMNode,
|
package/dist/esm/props.js
CHANGED
|
@@ -5,6 +5,30 @@ import { is, isArray, isFunction, isObject, isObjectLike } from "./types.js";
|
|
|
5
5
|
import { lowercaseFirstLetter } from "./string.js";
|
|
6
6
|
const RE_UPPER = /^[A-Z]/;
|
|
7
7
|
const RE_DIGITS = /^\d+$/;
|
|
8
|
+
const ELEMENT_INDICATOR_KEYS = /* @__PURE__ */ new Set([
|
|
9
|
+
"extend",
|
|
10
|
+
"props",
|
|
11
|
+
"text",
|
|
12
|
+
"tag",
|
|
13
|
+
"on",
|
|
14
|
+
"if",
|
|
15
|
+
"childExtend",
|
|
16
|
+
"children",
|
|
17
|
+
"childrenAs",
|
|
18
|
+
"state",
|
|
19
|
+
"html",
|
|
20
|
+
"attr",
|
|
21
|
+
"define",
|
|
22
|
+
"content"
|
|
23
|
+
]);
|
|
24
|
+
const looksLikeElement = (value) => {
|
|
25
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
26
|
+
for (const k in value) {
|
|
27
|
+
if (ELEMENT_INDICATOR_KEYS.has(k)) return true;
|
|
28
|
+
if (RE_UPPER.test(k)) return true;
|
|
29
|
+
}
|
|
30
|
+
return false;
|
|
31
|
+
};
|
|
8
32
|
const createProps = (element, parent, key) => {
|
|
9
33
|
const { props, __ref: ref } = element;
|
|
10
34
|
ref.__propsStack = [];
|
|
@@ -29,7 +53,7 @@ function pickupPropsFromElement(obj, opts = {}) {
|
|
|
29
53
|
}
|
|
30
54
|
const hasDefine = isObject(this.define?.[key]);
|
|
31
55
|
const hasGlobalDefine = isObject(this.context?.define?.[key]);
|
|
32
|
-
const isElement = RE_UPPER.test(key) || RE_DIGITS.test(key);
|
|
56
|
+
const isElement = RE_UPPER.test(key) || RE_DIGITS.test(key) || looksLikeElement(value);
|
|
33
57
|
const isBuiltin = DOMQ_PROPERTIES.has(key);
|
|
34
58
|
if (!isElement && !isBuiltin && !hasDefine && !hasGlobalDefine) {
|
|
35
59
|
obj.props[key] = value;
|