domql 1.6.26 → 1.6.27
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/package.json +1 -1
- package/src/element/extend.js +9 -2
- package/src/element/utils/component.js +36 -11
package/package.json
CHANGED
package/src/element/extend.js
CHANGED
|
@@ -15,7 +15,14 @@ export const applyExtend = (element, parent, options = {}) => {
|
|
|
15
15
|
let { extend, props, context, __ref } = element
|
|
16
16
|
|
|
17
17
|
const COMPONENTS = (context && context.components) || options.components
|
|
18
|
-
if (isString(extend)
|
|
18
|
+
if (isString(extend)) {
|
|
19
|
+
if (COMPONENTS && COMPONENTS[extend]) extend = COMPONENTS[extend]
|
|
20
|
+
else {
|
|
21
|
+
if (ENV !== 'test' || ENV !== 'development') {
|
|
22
|
+
console.warn('Extend is string but component was not found:', extend)
|
|
23
|
+
} extend = {}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
19
26
|
|
|
20
27
|
const extendStack = getExtendStack(extend)
|
|
21
28
|
|
|
@@ -55,7 +62,7 @@ export const applyExtend = (element, parent, options = {}) => {
|
|
|
55
62
|
stack = [].concat(stack, defaultOptionsExtend)
|
|
56
63
|
}
|
|
57
64
|
|
|
58
|
-
__ref.__extend = stack
|
|
65
|
+
if (__ref) __ref.__extend = stack
|
|
59
66
|
const findAndReplaceStrings = replaceStringsWithComponents(stack, COMPONENTS)
|
|
60
67
|
let mergedExtend = cloneAndMergeArrayExtend(findAndReplaceStrings)
|
|
61
68
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
import { exec, isArray, isFunction, isObject, isString, overwriteDeep } from '@domql/utils'
|
|
4
|
+
import { applyExtend } from '../extend'
|
|
4
5
|
const ENV = process.env.NODE_ENV
|
|
5
6
|
|
|
6
7
|
export const checkIfKeyIsComponent = (key) => {
|
|
@@ -10,6 +11,15 @@ export const checkIfKeyIsComponent = (key) => {
|
|
|
10
11
|
return /^[A-Z]*$/.test(firstCharKey)
|
|
11
12
|
}
|
|
12
13
|
|
|
14
|
+
export const addAdditionalExtend = (newExtend, element) => {
|
|
15
|
+
const { extend } = element
|
|
16
|
+
const preserveExtend = isArray(extend) ? extend : [extend]
|
|
17
|
+
return {
|
|
18
|
+
...element,
|
|
19
|
+
extend: [newExtend].concat(preserveExtend)
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
13
23
|
export const extendizeByKey = (element, parent, key) => {
|
|
14
24
|
const { extend, props, state, childExtend, childProps, on } = element
|
|
15
25
|
const hasComponentAttrs = extend || childExtend || props || state || on
|
|
@@ -27,12 +37,7 @@ export const extendizeByKey = (element, parent, key) => {
|
|
|
27
37
|
extend: extendKey
|
|
28
38
|
}
|
|
29
39
|
} else if (extend) {
|
|
30
|
-
|
|
31
|
-
const preserveExtend = isArray(extend) ? extend : [extend]
|
|
32
|
-
return {
|
|
33
|
-
...element,
|
|
34
|
-
extend: [extendKey].concat(preserveExtend)
|
|
35
|
-
}
|
|
40
|
+
addAdditionalExtend(extendKey, element)
|
|
36
41
|
} else if (isFunction(element)) {
|
|
37
42
|
return {
|
|
38
43
|
extend: extendKey,
|
|
@@ -74,12 +79,32 @@ export const hasVariantProp = (element) => {
|
|
|
74
79
|
if (isObject(props) || isString(props.variant)) return true
|
|
75
80
|
}
|
|
76
81
|
|
|
82
|
+
export const overwriteVariant = (element, variant, variantProps) => {
|
|
83
|
+
let variantElement = element[variant]
|
|
84
|
+
if (!variantElement) return
|
|
85
|
+
const props = isObject(variantProps) ? variantProps : {}
|
|
86
|
+
if (isString(variantElement)) {
|
|
87
|
+
variantElement = {
|
|
88
|
+
extend: [{ props }, variantElement]
|
|
89
|
+
}
|
|
90
|
+
} else if (variantElement.extend) {
|
|
91
|
+
variantElement = addAdditionalExtend({ props }, variantElement)
|
|
92
|
+
}
|
|
93
|
+
return overwriteDeep(element, applyExtend(variantElement)) // TODO: check why string is not working
|
|
94
|
+
}
|
|
95
|
+
|
|
77
96
|
export const applyVariant = (element) => {
|
|
97
|
+
const { props } = element
|
|
78
98
|
if (!hasVariantProp(element)) return element
|
|
79
|
-
const { variant } =
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
99
|
+
const { variant } = props
|
|
100
|
+
overwriteVariant(element, `.${variant}`)
|
|
101
|
+
|
|
102
|
+
const elKeys = Object.keys(element).filter((key) => isVariant(key))
|
|
103
|
+
elKeys.forEach((variant) => {
|
|
104
|
+
const slicedVariantElementKey = variant.slice(1)
|
|
105
|
+
const variantElementProps = props[slicedVariantElementKey]
|
|
106
|
+
if (variantElementProps) overwriteVariant(element, variant, variantElementProps)
|
|
107
|
+
})
|
|
108
|
+
|
|
84
109
|
return element
|
|
85
110
|
}
|