@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/esm/triggerEvent.js
CHANGED
|
@@ -9,18 +9,26 @@ const getOnOrPropsEvent = (param, element) => {
|
|
|
9
9
|
};
|
|
10
10
|
const applyEvent = (param, element, state, context, options) => {
|
|
11
11
|
if (!isFunction(param)) return;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
result.
|
|
21
|
-
|
|
12
|
+
try {
|
|
13
|
+
const result = param.call(
|
|
14
|
+
element,
|
|
15
|
+
element,
|
|
16
|
+
state || element.state,
|
|
17
|
+
context || element.context,
|
|
18
|
+
options
|
|
19
|
+
);
|
|
20
|
+
if (result && typeof result.then === "function") {
|
|
21
|
+
result.catch((err) => {
|
|
22
|
+
element.error = err;
|
|
23
|
+
console.error("[DomQL] Async event error:", err);
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
return result;
|
|
27
|
+
} catch (err) {
|
|
28
|
+
element.error = err;
|
|
29
|
+
console.error("[DomQL] Event handler error:", err);
|
|
30
|
+
if (element.context?.strictMode) throw err;
|
|
22
31
|
}
|
|
23
|
-
return result;
|
|
24
32
|
};
|
|
25
33
|
const triggerEventOn = (param, element, options) => {
|
|
26
34
|
if (!element) {
|
|
@@ -34,19 +42,27 @@ const triggerEventOn = (param, element, options) => {
|
|
|
34
42
|
};
|
|
35
43
|
const applyEventUpdate = (param, updatedObj, element, state, context, options) => {
|
|
36
44
|
if (!isFunction(param)) return;
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
result.
|
|
47
|
-
|
|
45
|
+
try {
|
|
46
|
+
const result = param.call(
|
|
47
|
+
element,
|
|
48
|
+
updatedObj,
|
|
49
|
+
element,
|
|
50
|
+
state || element.state,
|
|
51
|
+
context || element.context,
|
|
52
|
+
options
|
|
53
|
+
);
|
|
54
|
+
if (result && typeof result.then === "function") {
|
|
55
|
+
result.catch((err) => {
|
|
56
|
+
element.error = err;
|
|
57
|
+
console.error("[DomQL] Async event update error:", err);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
return result;
|
|
61
|
+
} catch (err) {
|
|
62
|
+
element.error = err;
|
|
63
|
+
console.error("[DomQL] Event update error:", err);
|
|
64
|
+
if (element.context?.strictMode) throw err;
|
|
48
65
|
}
|
|
49
|
-
return result;
|
|
50
66
|
};
|
|
51
67
|
const triggerEventOnUpdate = (param, updatedObj, element, options) => {
|
|
52
68
|
const appliedFunction = getOnOrPropsEvent(param, element);
|
package/dist/iife/index.js
CHANGED
|
@@ -257,7 +257,7 @@ var DomqlUtils = (() => {
|
|
|
257
257
|
return (typeof HTMLElement === "object" ? obj instanceof window2.HTMLElement : obj && typeof obj === "object" && obj !== null && obj.nodeType === 1 && typeof obj.nodeName === "string") || false;
|
|
258
258
|
};
|
|
259
259
|
var isDOMNode = (obj) => {
|
|
260
|
-
return typeof window2 !== "undefined" && (obj instanceof window2.Node || obj instanceof window2.Window || obj === window2 || obj === document);
|
|
260
|
+
return typeof window2 !== "undefined" && (window2.Node && obj instanceof window2.Node || window2.Window && obj instanceof window2.Window || obj === window2 || obj === document);
|
|
261
261
|
};
|
|
262
262
|
|
|
263
263
|
// types.js
|
|
@@ -1586,6 +1586,7 @@ var DomqlUtils = (() => {
|
|
|
1586
1586
|
|
|
1587
1587
|
// extends.js
|
|
1588
1588
|
var ENV3 = process.env.NODE_ENV;
|
|
1589
|
+
var isSourcemapEnabled = (options) => options.sourcemap !== false && ENV3 !== "production";
|
|
1589
1590
|
var createExtendsFromKeys = (key) => {
|
|
1590
1591
|
if (key.includes("+")) {
|
|
1591
1592
|
return key.split("+").filter(matchesComponentNaming);
|
|
@@ -1660,17 +1661,17 @@ var DomqlUtils = (() => {
|
|
|
1660
1661
|
}
|
|
1661
1662
|
return setHashedExtend(extend, stack);
|
|
1662
1663
|
};
|
|
1663
|
-
var extractArrayExtend = (extend, stack, context, processed = /* @__PURE__ */ new Set()) => {
|
|
1664
|
+
var extractArrayExtend = (extend, stack, context, processed = /* @__PURE__ */ new Set(), nameStack, componentNameMap) => {
|
|
1664
1665
|
for (const each of extend) {
|
|
1665
1666
|
if (isArray(each)) {
|
|
1666
|
-
extractArrayExtend(each, stack, context, processed);
|
|
1667
|
+
extractArrayExtend(each, stack, context, processed, nameStack, componentNameMap);
|
|
1667
1668
|
} else {
|
|
1668
|
-
flattenExtend(each, stack, context, processed);
|
|
1669
|
+
flattenExtend(each, stack, context, processed, nameStack, void 0, componentNameMap);
|
|
1669
1670
|
}
|
|
1670
1671
|
}
|
|
1671
1672
|
return stack;
|
|
1672
1673
|
};
|
|
1673
|
-
var deepExtend = (extend, stack, context, processed = /* @__PURE__ */ new Set()) => {
|
|
1674
|
+
var deepExtend = (extend, stack, context, processed = /* @__PURE__ */ new Set(), nameStack, currentName, componentNameMap) => {
|
|
1674
1675
|
const extendOflattenExtend = extend.extends || extend.extend;
|
|
1675
1676
|
const cleanExtend = { ...extend };
|
|
1676
1677
|
delete cleanExtend.extends;
|
|
@@ -1682,26 +1683,32 @@ var DomqlUtils = (() => {
|
|
|
1682
1683
|
}
|
|
1683
1684
|
if (hasKeys) {
|
|
1684
1685
|
stack.push(cleanExtend);
|
|
1686
|
+
if (nameStack) nameStack.push(currentName);
|
|
1685
1687
|
}
|
|
1686
1688
|
if (extendOflattenExtend) {
|
|
1687
|
-
flattenExtend(extendOflattenExtend, stack, context, processed);
|
|
1689
|
+
flattenExtend(extendOflattenExtend, stack, context, processed, nameStack, currentName, componentNameMap);
|
|
1688
1690
|
}
|
|
1689
1691
|
return stack;
|
|
1690
1692
|
};
|
|
1691
|
-
var flattenExtend = (extend, stack, context, processed = /* @__PURE__ */ new Set()) => {
|
|
1693
|
+
var flattenExtend = (extend, stack, context, processed = /* @__PURE__ */ new Set(), nameStack, parentName, componentNameMap) => {
|
|
1692
1694
|
if (!extend) return stack;
|
|
1693
1695
|
if (processed.has(extend)) return stack;
|
|
1694
1696
|
if (isArray(extend)) {
|
|
1695
|
-
return extractArrayExtend(extend, stack, context, processed);
|
|
1697
|
+
return extractArrayExtend(extend, stack, context, processed, nameStack, componentNameMap);
|
|
1696
1698
|
}
|
|
1699
|
+
let currentName = parentName;
|
|
1697
1700
|
if (isString(extend)) {
|
|
1701
|
+
currentName = extend;
|
|
1698
1702
|
extend = mapStringsWithContextComponents(extend, context);
|
|
1703
|
+
} else if (componentNameMap && isObject(extend) && componentNameMap.has(extend)) {
|
|
1704
|
+
currentName = componentNameMap.get(extend);
|
|
1699
1705
|
}
|
|
1700
1706
|
processed.add(extend);
|
|
1701
1707
|
if (extend?.extends || extend?.extend) {
|
|
1702
|
-
deepExtend(extend, stack, context, processed);
|
|
1708
|
+
deepExtend(extend, stack, context, processed, nameStack, currentName, componentNameMap);
|
|
1703
1709
|
} else if (extend) {
|
|
1704
1710
|
stack.push(extend);
|
|
1711
|
+
if (nameStack) nameStack.push(currentName);
|
|
1705
1712
|
}
|
|
1706
1713
|
return stack;
|
|
1707
1714
|
};
|
|
@@ -1714,7 +1721,7 @@ var DomqlUtils = (() => {
|
|
|
1714
1721
|
"childExtend",
|
|
1715
1722
|
"childExtendRecursive"
|
|
1716
1723
|
]);
|
|
1717
|
-
var deepMergeExtends = (element, extend) => {
|
|
1724
|
+
var deepMergeExtends = (element, extend, sourcemap, sourceName, preBuiltSourcemap) => {
|
|
1718
1725
|
extend = deepClone(extend);
|
|
1719
1726
|
for (const e in extend) {
|
|
1720
1727
|
if (MERGE_EXTENDS_SKIP.has(e)) continue;
|
|
@@ -1724,11 +1731,23 @@ var DomqlUtils = (() => {
|
|
|
1724
1731
|
if (Object.prototype.hasOwnProperty.call(extend, e) && e !== "__proto__" && e !== "constructor" && e !== "prototype") {
|
|
1725
1732
|
if (elementProp === void 0) {
|
|
1726
1733
|
element[e] = extendProp;
|
|
1734
|
+
if (sourcemap && sourceName) {
|
|
1735
|
+
if (isObject(extendProp) && !isArray(extendProp)) {
|
|
1736
|
+
sourcemap[e] = sourcemap[e] || {};
|
|
1737
|
+
trackSourcemapDeep(sourcemap[e], extendProp, sourceName);
|
|
1738
|
+
} else {
|
|
1739
|
+
sourcemap[e] = sourceName;
|
|
1740
|
+
}
|
|
1741
|
+
} else if (sourcemap && preBuiltSourcemap?.[e]) {
|
|
1742
|
+
sourcemap[e] = preBuiltSourcemap[e];
|
|
1743
|
+
}
|
|
1727
1744
|
} else if (isObject(elementProp) && isObject(extendProp)) {
|
|
1745
|
+
const nestedSourcemap = sourcemap ? sourcemap[e] = sourcemap[e] || {} : void 0;
|
|
1746
|
+
const nestedPreBuilt = preBuiltSourcemap?.[e];
|
|
1728
1747
|
if (matchesComponentNaming(e)) {
|
|
1729
|
-
element[e] = deepMergeExtends(elementProp, extendProp);
|
|
1748
|
+
element[e] = deepMergeExtends(elementProp, extendProp, nestedSourcemap, sourceName, nestedPreBuilt);
|
|
1730
1749
|
} else {
|
|
1731
|
-
deepMergeExtends(elementProp, extendProp);
|
|
1750
|
+
deepMergeExtends(elementProp, extendProp, nestedSourcemap, sourceName, nestedPreBuilt);
|
|
1732
1751
|
}
|
|
1733
1752
|
}
|
|
1734
1753
|
if (e === "extends" || e === "childExtends" || e === "childExtendsRecursive") {
|
|
@@ -1743,10 +1762,24 @@ var DomqlUtils = (() => {
|
|
|
1743
1762
|
}
|
|
1744
1763
|
return element;
|
|
1745
1764
|
};
|
|
1746
|
-
var
|
|
1747
|
-
|
|
1765
|
+
var trackSourcemapDeep = (sourcemap, obj, sourceName) => {
|
|
1766
|
+
for (const key in obj) {
|
|
1767
|
+
if (!Object.prototype.hasOwnProperty.call(obj, key)) continue;
|
|
1768
|
+
if (key === "__proto__" || key === "constructor" || key === "prototype") continue;
|
|
1769
|
+
const val = obj[key];
|
|
1770
|
+
if (isObject(val) && !isArray(val)) {
|
|
1771
|
+
sourcemap[key] = sourcemap[key] || {};
|
|
1772
|
+
trackSourcemapDeep(sourcemap[key], val, sourceName);
|
|
1773
|
+
} else {
|
|
1774
|
+
sourcemap[key] = sourceName;
|
|
1775
|
+
}
|
|
1776
|
+
}
|
|
1777
|
+
};
|
|
1778
|
+
var cloneAndMergeArrayExtend = (stack, sourcemap, extendNames) => {
|
|
1779
|
+
return stack.reduce((acc, current, i) => {
|
|
1748
1780
|
const cloned = deepClone(current);
|
|
1749
|
-
|
|
1781
|
+
const sourceName = extendNames ? extendNames[i] : void 0;
|
|
1782
|
+
return deepMergeExtends(acc, cloned, sourcemap, sourceName);
|
|
1750
1783
|
}, {});
|
|
1751
1784
|
};
|
|
1752
1785
|
var mapStringsWithContextComponents = (extend, context, options = {}, variant) => {
|
|
@@ -1769,11 +1802,12 @@ var DomqlUtils = (() => {
|
|
|
1769
1802
|
var jointStacks = (extendStack, childExtendsStack) => {
|
|
1770
1803
|
return [].concat(extendStack.slice(0, 1)).concat(childExtendsStack.slice(0, 1)).concat(extendStack.slice(1)).concat(childExtendsStack.slice(1));
|
|
1771
1804
|
};
|
|
1772
|
-
var getExtendsStack = (extend, context) => {
|
|
1805
|
+
var getExtendsStack = (extend, context, nameStack, componentNameMap) => {
|
|
1773
1806
|
if (!extend) return [];
|
|
1774
1807
|
if (extend.__hash) return getHashedExtend(extend) || [];
|
|
1775
1808
|
const processed = /* @__PURE__ */ new Set();
|
|
1776
|
-
const stack = flattenExtend(extend, [], context, processed);
|
|
1809
|
+
const stack = flattenExtend(extend, [], context, processed, nameStack, void 0, componentNameMap);
|
|
1810
|
+
if (nameStack) return stack;
|
|
1777
1811
|
return getExtendsStackRegistry(extend, stack);
|
|
1778
1812
|
};
|
|
1779
1813
|
var addExtend = (newExtends, elementExtends) => {
|
|
@@ -1880,6 +1914,8 @@ var DomqlUtils = (() => {
|
|
|
1880
1914
|
const { props, __ref: ref } = element;
|
|
1881
1915
|
const context = element.context || parent.context;
|
|
1882
1916
|
const variant = element.variant || props?.variant;
|
|
1917
|
+
const sourcemap = isSourcemapEnabled(options);
|
|
1918
|
+
const originalExtendNames = sourcemap ? [...ref.__extends] : null;
|
|
1883
1919
|
const __extends = removeDuplicatesInArray(
|
|
1884
1920
|
ref.__extends.map((val, i) => {
|
|
1885
1921
|
return mapStringsWithContextComponents(
|
|
@@ -1890,15 +1926,40 @@ var DomqlUtils = (() => {
|
|
|
1890
1926
|
);
|
|
1891
1927
|
})
|
|
1892
1928
|
);
|
|
1893
|
-
|
|
1894
|
-
|
|
1929
|
+
if (sourcemap) {
|
|
1930
|
+
const componentNameMap = /* @__PURE__ */ new WeakMap();
|
|
1931
|
+
for (let i = 0; i < __extends.length; i++) {
|
|
1932
|
+
const resolved = __extends[i];
|
|
1933
|
+
const originalName = originalExtendNames[i];
|
|
1934
|
+
if (resolved && isObject(resolved) && isString(originalName)) {
|
|
1935
|
+
componentNameMap.set(resolved, originalName);
|
|
1936
|
+
}
|
|
1937
|
+
}
|
|
1938
|
+
const nameStack = [];
|
|
1939
|
+
const stack = getExtendsStack(__extends, context, nameStack, componentNameMap);
|
|
1940
|
+
ref.__extendsStack = stack;
|
|
1941
|
+
ref.__extendsNames = nameStack;
|
|
1942
|
+
} else {
|
|
1943
|
+
const stack = getExtendsStack(__extends, context);
|
|
1944
|
+
ref.__extendsStack = stack;
|
|
1945
|
+
}
|
|
1895
1946
|
return ref.__extendsStack;
|
|
1896
1947
|
};
|
|
1897
1948
|
var finalizeExtends = (element, parent, options = {}) => {
|
|
1898
1949
|
const { __ref: ref } = element;
|
|
1899
1950
|
const { __extendsStack } = ref;
|
|
1900
|
-
|
|
1901
|
-
|
|
1951
|
+
if (isSourcemapEnabled(options)) {
|
|
1952
|
+
const sourcemapAcc = {};
|
|
1953
|
+
const extendNames = ref.__extendsNames || [];
|
|
1954
|
+
const flattenExtends = cloneAndMergeArrayExtend(__extendsStack, sourcemapAcc, extendNames);
|
|
1955
|
+
const appliedSourcemap = {};
|
|
1956
|
+
deepMergeExtends(element, flattenExtends, appliedSourcemap, void 0, sourcemapAcc);
|
|
1957
|
+
ref.__sourcemap = appliedSourcemap;
|
|
1958
|
+
} else {
|
|
1959
|
+
const flattenExtends = cloneAndMergeArrayExtend(__extendsStack);
|
|
1960
|
+
deepMergeExtends(element, flattenExtends);
|
|
1961
|
+
}
|
|
1962
|
+
return element;
|
|
1902
1963
|
};
|
|
1903
1964
|
var applyExtends = (element, parent, options = {}) => {
|
|
1904
1965
|
createElementExtends(element, parent, options);
|
|
@@ -1943,6 +2004,30 @@ var DomqlUtils = (() => {
|
|
|
1943
2004
|
// props.js
|
|
1944
2005
|
var RE_UPPER = /^[A-Z]/;
|
|
1945
2006
|
var RE_DIGITS = /^\d+$/;
|
|
2007
|
+
var ELEMENT_INDICATOR_KEYS = /* @__PURE__ */ new Set([
|
|
2008
|
+
"extend",
|
|
2009
|
+
"props",
|
|
2010
|
+
"text",
|
|
2011
|
+
"tag",
|
|
2012
|
+
"on",
|
|
2013
|
+
"if",
|
|
2014
|
+
"childExtend",
|
|
2015
|
+
"children",
|
|
2016
|
+
"childrenAs",
|
|
2017
|
+
"state",
|
|
2018
|
+
"html",
|
|
2019
|
+
"attr",
|
|
2020
|
+
"define",
|
|
2021
|
+
"content"
|
|
2022
|
+
]);
|
|
2023
|
+
var looksLikeElement = (value) => {
|
|
2024
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
2025
|
+
for (const k in value) {
|
|
2026
|
+
if (ELEMENT_INDICATOR_KEYS.has(k)) return true;
|
|
2027
|
+
if (RE_UPPER.test(k)) return true;
|
|
2028
|
+
}
|
|
2029
|
+
return false;
|
|
2030
|
+
};
|
|
1946
2031
|
var createProps = (element, parent, key) => {
|
|
1947
2032
|
const { props, __ref: ref } = element;
|
|
1948
2033
|
ref.__propsStack = [];
|
|
@@ -1967,7 +2052,7 @@ var DomqlUtils = (() => {
|
|
|
1967
2052
|
}
|
|
1968
2053
|
const hasDefine = isObject(this.define?.[key]);
|
|
1969
2054
|
const hasGlobalDefine = isObject(this.context?.define?.[key]);
|
|
1970
|
-
const isElement = RE_UPPER.test(key) || RE_DIGITS.test(key);
|
|
2055
|
+
const isElement = RE_UPPER.test(key) || RE_DIGITS.test(key) || looksLikeElement(value);
|
|
1971
2056
|
const isBuiltin = DOMQ_PROPERTIES.has(key);
|
|
1972
2057
|
if (!isElement && !isBuiltin && !hasDefine && !hasGlobalDefine) {
|
|
1973
2058
|
obj.props[key] = value;
|
|
@@ -2392,18 +2477,26 @@ var DomqlUtils = (() => {
|
|
|
2392
2477
|
};
|
|
2393
2478
|
var applyEvent = (param, element, state, context, options) => {
|
|
2394
2479
|
if (!isFunction(param)) return;
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
result.
|
|
2404
|
-
|
|
2480
|
+
try {
|
|
2481
|
+
const result = param.call(
|
|
2482
|
+
element,
|
|
2483
|
+
element,
|
|
2484
|
+
state || element.state,
|
|
2485
|
+
context || element.context,
|
|
2486
|
+
options
|
|
2487
|
+
);
|
|
2488
|
+
if (result && typeof result.then === "function") {
|
|
2489
|
+
result.catch((err) => {
|
|
2490
|
+
element.error = err;
|
|
2491
|
+
console.error("[DomQL] Async event error:", err);
|
|
2492
|
+
});
|
|
2493
|
+
}
|
|
2494
|
+
return result;
|
|
2495
|
+
} catch (err) {
|
|
2496
|
+
element.error = err;
|
|
2497
|
+
console.error("[DomQL] Event handler error:", err);
|
|
2498
|
+
if (element.context?.strictMode) throw err;
|
|
2405
2499
|
}
|
|
2406
|
-
return result;
|
|
2407
2500
|
};
|
|
2408
2501
|
var triggerEventOn = (param, element, options) => {
|
|
2409
2502
|
if (!element) {
|
|
@@ -2417,19 +2510,27 @@ var DomqlUtils = (() => {
|
|
|
2417
2510
|
};
|
|
2418
2511
|
var applyEventUpdate = (param, updatedObj, element, state, context, options) => {
|
|
2419
2512
|
if (!isFunction(param)) return;
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
result.
|
|
2430
|
-
|
|
2513
|
+
try {
|
|
2514
|
+
const result = param.call(
|
|
2515
|
+
element,
|
|
2516
|
+
updatedObj,
|
|
2517
|
+
element,
|
|
2518
|
+
state || element.state,
|
|
2519
|
+
context || element.context,
|
|
2520
|
+
options
|
|
2521
|
+
);
|
|
2522
|
+
if (result && typeof result.then === "function") {
|
|
2523
|
+
result.catch((err) => {
|
|
2524
|
+
element.error = err;
|
|
2525
|
+
console.error("[DomQL] Async event update error:", err);
|
|
2526
|
+
});
|
|
2527
|
+
}
|
|
2528
|
+
return result;
|
|
2529
|
+
} catch (err) {
|
|
2530
|
+
element.error = err;
|
|
2531
|
+
console.error("[DomQL] Event update error:", err);
|
|
2532
|
+
if (element.context?.strictMode) throw err;
|
|
2431
2533
|
}
|
|
2432
|
-
return result;
|
|
2433
2534
|
};
|
|
2434
2535
|
var triggerEventOnUpdate = (param, updatedObj, element, options) => {
|
|
2435
2536
|
const appliedFunction = getOnOrPropsEvent(param, element);
|
|
@@ -2745,7 +2846,20 @@ var DomqlUtils = (() => {
|
|
|
2745
2846
|
}
|
|
2746
2847
|
function call(fnKey, ...args) {
|
|
2747
2848
|
const context = this.context;
|
|
2748
|
-
|
|
2849
|
+
const fn = context.utils?.[fnKey] || context.functions?.[fnKey] || context.methods?.[fnKey] || context.snippets?.[fnKey];
|
|
2850
|
+
if (!fn) return;
|
|
2851
|
+
try {
|
|
2852
|
+
const result = fn.call(this, ...args);
|
|
2853
|
+
if (result && typeof result.then === "function") {
|
|
2854
|
+
result.catch((err) => {
|
|
2855
|
+
this.error = err;
|
|
2856
|
+
});
|
|
2857
|
+
}
|
|
2858
|
+
return result;
|
|
2859
|
+
} catch (err) {
|
|
2860
|
+
this.error = err;
|
|
2861
|
+
if (context?.strictMode) throw err;
|
|
2862
|
+
}
|
|
2749
2863
|
}
|
|
2750
2864
|
function isMethod(param, element) {
|
|
2751
2865
|
return Boolean(METHODS.has(param) || element?.context?.methods?.[param]);
|
package/extends.js
CHANGED
|
@@ -5,6 +5,7 @@ import { matchesComponentNaming } from './component.js'
|
|
|
5
5
|
import { deepClone, exec } from './object.js'
|
|
6
6
|
import { isArray, isObject, isString } from './types.js'
|
|
7
7
|
const ENV = process.env.NODE_ENV
|
|
8
|
+
const isSourcemapEnabled = (options) => options.sourcemap !== false && ENV !== 'production'
|
|
8
9
|
|
|
9
10
|
export const createExtendsFromKeys = key => {
|
|
10
11
|
if (key.includes('+')) {
|
|
@@ -112,19 +113,21 @@ export const extractArrayExtend = (
|
|
|
112
113
|
extend,
|
|
113
114
|
stack,
|
|
114
115
|
context,
|
|
115
|
-
processed = new Set()
|
|
116
|
+
processed = new Set(),
|
|
117
|
+
nameStack,
|
|
118
|
+
componentNameMap
|
|
116
119
|
) => {
|
|
117
120
|
for (const each of extend) {
|
|
118
121
|
if (isArray(each)) {
|
|
119
|
-
extractArrayExtend(each, stack, context, processed)
|
|
122
|
+
extractArrayExtend(each, stack, context, processed, nameStack, componentNameMap)
|
|
120
123
|
} else {
|
|
121
|
-
flattenExtend(each, stack, context, processed)
|
|
124
|
+
flattenExtend(each, stack, context, processed, nameStack, undefined, componentNameMap)
|
|
122
125
|
}
|
|
123
126
|
}
|
|
124
127
|
return stack
|
|
125
128
|
}
|
|
126
129
|
|
|
127
|
-
export const deepExtend = (extend, stack, context, processed = new Set()) => {
|
|
130
|
+
export const deepExtend = (extend, stack, context, processed = new Set(), nameStack, currentName, componentNameMap) => {
|
|
128
131
|
const extendOflattenExtend = extend.extends || extend.extend
|
|
129
132
|
// Remove extends/extend properties before adding to stack
|
|
130
133
|
const cleanExtend = { ...extend }
|
|
@@ -134,9 +137,10 @@ export const deepExtend = (extend, stack, context, processed = new Set()) => {
|
|
|
134
137
|
for (const _k in cleanExtend) { hasKeys = true; break } // eslint-disable-line
|
|
135
138
|
if (hasKeys) {
|
|
136
139
|
stack.push(cleanExtend)
|
|
140
|
+
if (nameStack) nameStack.push(currentName)
|
|
137
141
|
}
|
|
138
142
|
if (extendOflattenExtend) {
|
|
139
|
-
flattenExtend(extendOflattenExtend, stack, context, processed)
|
|
143
|
+
flattenExtend(extendOflattenExtend, stack, context, processed, nameStack, currentName, componentNameMap)
|
|
140
144
|
}
|
|
141
145
|
return stack
|
|
142
146
|
}
|
|
@@ -145,25 +149,34 @@ export const flattenExtend = (
|
|
|
145
149
|
extend,
|
|
146
150
|
stack,
|
|
147
151
|
context,
|
|
148
|
-
processed = new Set()
|
|
152
|
+
processed = new Set(),
|
|
153
|
+
nameStack,
|
|
154
|
+
parentName,
|
|
155
|
+
componentNameMap
|
|
149
156
|
) => {
|
|
150
157
|
if (!extend) return stack
|
|
151
158
|
if (processed.has(extend)) return stack
|
|
152
159
|
|
|
153
160
|
if (isArray(extend)) {
|
|
154
|
-
return extractArrayExtend(extend, stack, context, processed)
|
|
161
|
+
return extractArrayExtend(extend, stack, context, processed, nameStack, componentNameMap)
|
|
155
162
|
}
|
|
156
163
|
|
|
164
|
+
let currentName = parentName
|
|
157
165
|
if (isString(extend)) {
|
|
166
|
+
currentName = extend
|
|
158
167
|
extend = mapStringsWithContextComponents(extend, context)
|
|
168
|
+
} else if (componentNameMap && isObject(extend) && componentNameMap.has(extend)) {
|
|
169
|
+
// Resolve name from pre-built map (top-level resolved extends)
|
|
170
|
+
currentName = componentNameMap.get(extend)
|
|
159
171
|
}
|
|
160
172
|
|
|
161
173
|
processed.add(extend)
|
|
162
174
|
|
|
163
175
|
if (extend?.extends || extend?.extend) {
|
|
164
|
-
deepExtend(extend, stack, context, processed)
|
|
176
|
+
deepExtend(extend, stack, context, processed, nameStack, currentName, componentNameMap)
|
|
165
177
|
} else if (extend) {
|
|
166
178
|
stack.push(extend)
|
|
179
|
+
if (nameStack) nameStack.push(currentName)
|
|
167
180
|
}
|
|
168
181
|
|
|
169
182
|
return stack
|
|
@@ -173,7 +186,7 @@ const MERGE_EXTENDS_SKIP = new Set([
|
|
|
173
186
|
'parent', 'node', '__ref', '__proto__', 'extend', 'childExtend', 'childExtendRecursive'
|
|
174
187
|
])
|
|
175
188
|
|
|
176
|
-
export const deepMergeExtends = (element, extend) => {
|
|
189
|
+
export const deepMergeExtends = (element, extend, sourcemap, sourceName, preBuiltSourcemap) => {
|
|
177
190
|
// Clone extend to prevent mutations
|
|
178
191
|
extend = deepClone(extend)
|
|
179
192
|
|
|
@@ -194,14 +207,28 @@ export const deepMergeExtends = (element, extend) => {
|
|
|
194
207
|
if (elementProp === undefined) {
|
|
195
208
|
// For undefined properties in element, copy from extend
|
|
196
209
|
element[e] = extendProp
|
|
210
|
+
// Track sourcemap for this property
|
|
211
|
+
if (sourcemap && sourceName) {
|
|
212
|
+
if (isObject(extendProp) && !isArray(extendProp)) {
|
|
213
|
+
sourcemap[e] = sourcemap[e] || {}
|
|
214
|
+
trackSourcemapDeep(sourcemap[e], extendProp, sourceName)
|
|
215
|
+
} else {
|
|
216
|
+
sourcemap[e] = sourceName
|
|
217
|
+
}
|
|
218
|
+
} else if (sourcemap && preBuiltSourcemap?.[e]) {
|
|
219
|
+
// Copy sourcemap entry from pre-built sourcemap (used in finalizeExtends)
|
|
220
|
+
sourcemap[e] = preBuiltSourcemap[e]
|
|
221
|
+
}
|
|
197
222
|
} else if (isObject(elementProp) && isObject(extendProp)) {
|
|
198
223
|
// For objects, merge based on type
|
|
224
|
+
const nestedSourcemap = sourcemap ? (sourcemap[e] = sourcemap[e] || {}) : undefined
|
|
225
|
+
const nestedPreBuilt = preBuiltSourcemap?.[e]
|
|
199
226
|
if (matchesComponentNaming(e)) {
|
|
200
227
|
// For components, override base properties with extended ones
|
|
201
|
-
element[e] = deepMergeExtends(elementProp, extendProp)
|
|
228
|
+
element[e] = deepMergeExtends(elementProp, extendProp, nestedSourcemap, sourceName, nestedPreBuilt)
|
|
202
229
|
} else {
|
|
203
230
|
// For other objects, merge normally
|
|
204
|
-
deepMergeExtends(elementProp, extendProp)
|
|
231
|
+
deepMergeExtends(elementProp, extendProp, nestedSourcemap, sourceName, nestedPreBuilt)
|
|
205
232
|
}
|
|
206
233
|
}
|
|
207
234
|
|
|
@@ -225,12 +252,27 @@ export const deepMergeExtends = (element, extend) => {
|
|
|
225
252
|
return element
|
|
226
253
|
}
|
|
227
254
|
|
|
228
|
-
|
|
229
|
-
|
|
255
|
+
const trackSourcemapDeep = (sourcemap, obj, sourceName) => {
|
|
256
|
+
for (const key in obj) {
|
|
257
|
+
if (!Object.prototype.hasOwnProperty.call(obj, key)) continue
|
|
258
|
+
if (key === '__proto__' || key === 'constructor' || key === 'prototype') continue
|
|
259
|
+
const val = obj[key]
|
|
260
|
+
if (isObject(val) && !isArray(val)) {
|
|
261
|
+
sourcemap[key] = sourcemap[key] || {}
|
|
262
|
+
trackSourcemapDeep(sourcemap[key], val, sourceName)
|
|
263
|
+
} else {
|
|
264
|
+
sourcemap[key] = sourceName
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
export const cloneAndMergeArrayExtend = (stack, sourcemap, extendNames) => {
|
|
270
|
+
return stack.reduce((acc, current, i) => {
|
|
230
271
|
// Clone current extend to avoid mutations
|
|
231
272
|
const cloned = deepClone(current)
|
|
273
|
+
const sourceName = extendNames ? extendNames[i] : undefined
|
|
232
274
|
// Merge into accumulator, giving priority to current extend
|
|
233
|
-
return deepMergeExtends(acc, cloned)
|
|
275
|
+
return deepMergeExtends(acc, cloned, sourcemap, sourceName)
|
|
234
276
|
}, {})
|
|
235
277
|
}
|
|
236
278
|
|
|
@@ -271,11 +313,12 @@ export const jointStacks = (extendStack, childExtendsStack) => {
|
|
|
271
313
|
}
|
|
272
314
|
|
|
273
315
|
// init
|
|
274
|
-
export const getExtendsStack = (extend, context) => {
|
|
316
|
+
export const getExtendsStack = (extend, context, nameStack, componentNameMap) => {
|
|
275
317
|
if (!extend) return []
|
|
276
318
|
if (extend.__hash) return getHashedExtend(extend) || []
|
|
277
319
|
const processed = new Set()
|
|
278
|
-
const stack = flattenExtend(extend, [], context, processed)
|
|
320
|
+
const stack = flattenExtend(extend, [], context, processed, nameStack, undefined, componentNameMap)
|
|
321
|
+
if (nameStack) return stack
|
|
279
322
|
return getExtendsStackRegistry(extend, stack)
|
|
280
323
|
}
|
|
281
324
|
|
|
@@ -416,6 +459,10 @@ export const createExtendsStack = (element, parent, options = {}) => {
|
|
|
416
459
|
|
|
417
460
|
const variant = element.variant || props?.variant
|
|
418
461
|
|
|
462
|
+
// Keep original string names before resolution for sourcemap tracking
|
|
463
|
+
const sourcemap = isSourcemapEnabled(options)
|
|
464
|
+
const originalExtendNames = sourcemap ? [...ref.__extends] : null
|
|
465
|
+
|
|
419
466
|
const __extends = removeDuplicatesInArray(
|
|
420
467
|
ref.__extends.map((val, i) => {
|
|
421
468
|
return mapStringsWithContextComponents(
|
|
@@ -427,8 +474,24 @@ export const createExtendsStack = (element, parent, options = {}) => {
|
|
|
427
474
|
})
|
|
428
475
|
)
|
|
429
476
|
|
|
430
|
-
|
|
431
|
-
|
|
477
|
+
if (sourcemap) {
|
|
478
|
+
// Build a map from resolved component objects to their original string names
|
|
479
|
+
const componentNameMap = new WeakMap()
|
|
480
|
+
for (let i = 0; i < __extends.length; i++) {
|
|
481
|
+
const resolved = __extends[i]
|
|
482
|
+
const originalName = originalExtendNames[i]
|
|
483
|
+
if (resolved && isObject(resolved) && isString(originalName)) {
|
|
484
|
+
componentNameMap.set(resolved, originalName)
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
const nameStack = []
|
|
488
|
+
const stack = getExtendsStack(__extends, context, nameStack, componentNameMap)
|
|
489
|
+
ref.__extendsStack = stack
|
|
490
|
+
ref.__extendsNames = nameStack
|
|
491
|
+
} else {
|
|
492
|
+
const stack = getExtendsStack(__extends, context)
|
|
493
|
+
ref.__extendsStack = stack
|
|
494
|
+
}
|
|
432
495
|
|
|
433
496
|
return ref.__extendsStack
|
|
434
497
|
}
|
|
@@ -436,9 +499,21 @@ export const createExtendsStack = (element, parent, options = {}) => {
|
|
|
436
499
|
export const finalizeExtends = (element, parent, options = {}) => {
|
|
437
500
|
const { __ref: ref } = element
|
|
438
501
|
const { __extendsStack } = ref
|
|
439
|
-
const flattenExtends = cloneAndMergeArrayExtend(__extendsStack)
|
|
440
502
|
|
|
441
|
-
|
|
503
|
+
if (isSourcemapEnabled(options)) {
|
|
504
|
+
const sourcemapAcc = {}
|
|
505
|
+
const extendNames = ref.__extendsNames || []
|
|
506
|
+
const flattenExtends = cloneAndMergeArrayExtend(__extendsStack, sourcemapAcc, extendNames)
|
|
507
|
+
// Only keep sourcemap entries for properties actually merged into element
|
|
508
|
+
const appliedSourcemap = {}
|
|
509
|
+
deepMergeExtends(element, flattenExtends, appliedSourcemap, undefined, sourcemapAcc)
|
|
510
|
+
ref.__sourcemap = appliedSourcemap
|
|
511
|
+
} else {
|
|
512
|
+
const flattenExtends = cloneAndMergeArrayExtend(__extendsStack)
|
|
513
|
+
deepMergeExtends(element, flattenExtends)
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
return element
|
|
442
517
|
}
|
|
443
518
|
|
|
444
519
|
export const applyExtends = (element, parent, options = {}) => {
|
package/methods.js
CHANGED
|
@@ -377,12 +377,25 @@ export function variables (obj = {}) {
|
|
|
377
377
|
*/
|
|
378
378
|
export function call (fnKey, ...args) {
|
|
379
379
|
const context = this.context
|
|
380
|
-
|
|
380
|
+
const fn = (
|
|
381
381
|
context.utils?.[fnKey] ||
|
|
382
382
|
context.functions?.[fnKey] ||
|
|
383
383
|
context.methods?.[fnKey] ||
|
|
384
384
|
context.snippets?.[fnKey]
|
|
385
|
-
)
|
|
385
|
+
)
|
|
386
|
+
if (!fn) return
|
|
387
|
+
try {
|
|
388
|
+
const result = fn.call(this, ...args)
|
|
389
|
+
if (result && typeof result.then === 'function') {
|
|
390
|
+
result.catch((err) => {
|
|
391
|
+
this.error = err
|
|
392
|
+
})
|
|
393
|
+
}
|
|
394
|
+
return result
|
|
395
|
+
} catch (err) {
|
|
396
|
+
this.error = err
|
|
397
|
+
if (context?.strictMode) throw err
|
|
398
|
+
}
|
|
386
399
|
}
|
|
387
400
|
|
|
388
401
|
export function isMethod (param, element) {
|