@domql/utils 2.5.134 → 2.5.139
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/component.js +43 -5
- package/dist/cjs/component.js +35 -4
- package/package.json +2 -2
package/component.js
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
deepCloneWithExtend,
|
|
5
|
+
exec,
|
|
6
|
+
isArray,
|
|
7
|
+
isFunction,
|
|
8
|
+
isObject,
|
|
9
|
+
isString,
|
|
10
|
+
joinArrays,
|
|
11
|
+
overwriteDeep
|
|
12
|
+
} from '.'
|
|
4
13
|
const ENV = process.env.NODE_ENV
|
|
5
14
|
|
|
6
15
|
export const checkIfKeyIsComponent = (key) => {
|
|
@@ -25,10 +34,16 @@ export const addAdditionalExtend = (newExtend, element) => {
|
|
|
25
34
|
return { ...element, extend }
|
|
26
35
|
}
|
|
27
36
|
|
|
37
|
+
const checkIfSugar = (element, parent, key) => {
|
|
38
|
+
const { extend, props, childExtend, extends: extendProps, childrenExtends, childProps, children, on, $collection, $stateCollection, $propsCollection } = element
|
|
39
|
+
const hasComponentAttrs = extend || childExtend || props || on || $collection || $stateCollection || $propsCollection
|
|
40
|
+
return !hasComponentAttrs || childProps || extendProps || children || childrenExtends
|
|
41
|
+
}
|
|
42
|
+
|
|
28
43
|
export const extendizeByKey = (element, parent, key) => {
|
|
29
44
|
const { context } = parent
|
|
30
|
-
const { tag, extend,
|
|
31
|
-
const
|
|
45
|
+
const { tag, extend, childrenExtends } = element
|
|
46
|
+
const isSugar = checkIfSugar(element)
|
|
32
47
|
|
|
33
48
|
const extendFromKey = key.includes('+')
|
|
34
49
|
? key.split('+') // get array of componentKeys
|
|
@@ -44,12 +59,14 @@ export const extendizeByKey = (element, parent, key) => {
|
|
|
44
59
|
const isExtendKeyComponent = context && context.components[extendFromKey]
|
|
45
60
|
|
|
46
61
|
if (element === isExtendKeyComponent) return element
|
|
47
|
-
else if (
|
|
48
|
-
|
|
62
|
+
else if (isSugar) {
|
|
63
|
+
const newElem = {
|
|
49
64
|
extend: extendFromKey,
|
|
50
65
|
tag,
|
|
51
66
|
props: { ...element }
|
|
52
67
|
}
|
|
68
|
+
if (childrenExtends) newElem.childExtend = childrenExtends
|
|
69
|
+
return newElem
|
|
53
70
|
} else if (!extend || extend === true) {
|
|
54
71
|
return {
|
|
55
72
|
...element,
|
|
@@ -67,6 +84,27 @@ export const extendizeByKey = (element, parent, key) => {
|
|
|
67
84
|
}
|
|
68
85
|
}
|
|
69
86
|
|
|
87
|
+
function getCapitalCaseKeys (obj) {
|
|
88
|
+
return Object.keys(obj).filter(key => /^[A-Z]/.test(key))
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export const addChildrenIfNotInOriginal = (element, parent, key) => {
|
|
92
|
+
const childElems = getCapitalCaseKeys(element.props)
|
|
93
|
+
if (!childElems.length) return element
|
|
94
|
+
|
|
95
|
+
for (const i in childElems) {
|
|
96
|
+
const childKey = childElems[i]
|
|
97
|
+
const childElem = element[childKey]
|
|
98
|
+
const newChild = element.props[childKey]
|
|
99
|
+
if (newChild.ignoreExtend) continue
|
|
100
|
+
if (!childElem) element[childKey] = deepCloneWithExtend(newChild)
|
|
101
|
+
else {
|
|
102
|
+
const isSugar = checkIfSugar(childElem)
|
|
103
|
+
if (!isSugar) overwriteDeep(element[childKey].props, newChild)
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
70
108
|
export const applyKeyComponentAsExtend = (element, parent, key) => {
|
|
71
109
|
return extendizeByKey(element, parent, key) || element
|
|
72
110
|
}
|
package/dist/cjs/component.js
CHANGED
|
@@ -19,6 +19,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
19
19
|
var component_exports = {};
|
|
20
20
|
__export(component_exports, {
|
|
21
21
|
addAdditionalExtend: () => addAdditionalExtend,
|
|
22
|
+
addChildrenIfNotInOriginal: () => addChildrenIfNotInOriginal,
|
|
22
23
|
applyComponentFromContext: () => applyComponentFromContext,
|
|
23
24
|
applyKeyComponentAsExtend: () => applyKeyComponentAsExtend,
|
|
24
25
|
checkIfKeyIsComponent: () => checkIfKeyIsComponent,
|
|
@@ -53,20 +54,28 @@ const addAdditionalExtend = (newExtend, element) => {
|
|
|
53
54
|
const extend = (0, import__.joinArrays)(receivedArray, originalArray);
|
|
54
55
|
return { ...element, extend };
|
|
55
56
|
};
|
|
57
|
+
const checkIfSugar = (element, parent, key) => {
|
|
58
|
+
const { extend, props, childExtend, extends: extendProps, childrenExtends, childProps, children, on, $collection, $stateCollection, $propsCollection } = element;
|
|
59
|
+
const hasComponentAttrs = extend || childExtend || props || on || $collection || $stateCollection || $propsCollection;
|
|
60
|
+
return !hasComponentAttrs || childProps || extendProps || children || childrenExtends;
|
|
61
|
+
};
|
|
56
62
|
const extendizeByKey = (element, parent, key) => {
|
|
57
63
|
const { context } = parent;
|
|
58
|
-
const { tag, extend,
|
|
59
|
-
const
|
|
64
|
+
const { tag, extend, childrenExtends } = element;
|
|
65
|
+
const isSugar = checkIfSugar(element);
|
|
60
66
|
const extendFromKey = key.includes("+") ? key.split("+") : key.includes("_") ? [key.split("_")[0]] : key.includes(".") && !checkIfKeyIsComponent(key.split(".")[1]) ? [key.split(".")[0]] : [key];
|
|
61
67
|
const isExtendKeyComponent = context && context.components[extendFromKey];
|
|
62
68
|
if (element === isExtendKeyComponent)
|
|
63
69
|
return element;
|
|
64
|
-
else if (
|
|
65
|
-
|
|
70
|
+
else if (isSugar) {
|
|
71
|
+
const newElem = {
|
|
66
72
|
extend: extendFromKey,
|
|
67
73
|
tag,
|
|
68
74
|
props: { ...element }
|
|
69
75
|
};
|
|
76
|
+
if (childrenExtends)
|
|
77
|
+
newElem.childExtend = childrenExtends;
|
|
78
|
+
return newElem;
|
|
70
79
|
} else if (!extend || extend === true) {
|
|
71
80
|
return {
|
|
72
81
|
...element,
|
|
@@ -83,6 +92,28 @@ const extendizeByKey = (element, parent, key) => {
|
|
|
83
92
|
};
|
|
84
93
|
}
|
|
85
94
|
};
|
|
95
|
+
function getCapitalCaseKeys(obj) {
|
|
96
|
+
return Object.keys(obj).filter((key) => /^[A-Z]/.test(key));
|
|
97
|
+
}
|
|
98
|
+
const addChildrenIfNotInOriginal = (element, parent, key) => {
|
|
99
|
+
const childElems = getCapitalCaseKeys(element.props);
|
|
100
|
+
if (!childElems.length)
|
|
101
|
+
return element;
|
|
102
|
+
for (const i in childElems) {
|
|
103
|
+
const childKey = childElems[i];
|
|
104
|
+
const childElem = element[childKey];
|
|
105
|
+
const newChild = element.props[childKey];
|
|
106
|
+
if (newChild.ignoreExtend)
|
|
107
|
+
continue;
|
|
108
|
+
if (!childElem)
|
|
109
|
+
element[childKey] = (0, import__.deepCloneWithExtend)(newChild);
|
|
110
|
+
else {
|
|
111
|
+
const isSugar = checkIfSugar(childElem);
|
|
112
|
+
if (!isSugar)
|
|
113
|
+
(0, import__.overwriteDeep)(element[childKey].props, newChild);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
};
|
|
86
117
|
const applyKeyComponentAsExtend = (element, parent, key) => {
|
|
87
118
|
return extendizeByKey(element, parent, key) || element;
|
|
88
119
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@domql/utils",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.139",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "index.js",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"build": "yarn build:cjs",
|
|
26
26
|
"prepublish": "rimraf -I dist && yarn build && yarn copy:package:cjs"
|
|
27
27
|
},
|
|
28
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "db49c6131a93bd7e9c1f1c95bc5de7752a8f48d1",
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@babel/core": "^7.12.0"
|
|
31
31
|
}
|