@domql/utils
Advanced tools
Comparing version 2.5.134 to 2.5.138
'use strict' | ||
import { exec, isArray, isFunction, isObject, isString, joinArrays } from '.' | ||
import { | ||
deepCloneWithExtend, | ||
exec, | ||
isArray, | ||
isFunction, | ||
isObject, | ||
isString, | ||
joinArrays, | ||
overwriteDeep | ||
} from '.' | ||
const ENV = process.env.NODE_ENV | ||
@@ -28,6 +37,12 @@ | ||
const checkIfSugar = (element, parent, key) => { | ||
const { extend, props, childExtend, extends: extendProps, childrenExtends, childProps, children, on, $collection, $stateCollection, $propsCollection } = element | ||
const hasComponentAttrs = extend || childExtend || props || on || $collection || $stateCollection || $propsCollection | ||
return !hasComponentAttrs || childProps || extendProps || children || childrenExtends | ||
} | ||
export const extendizeByKey = (element, parent, key) => { | ||
const { context } = parent | ||
const { tag, extend, props, attr, state, childExtend, childProps, on, if: condition, data } = element | ||
const hasComponentAttrs = extend || childExtend || props || state || on || condition || attr || data | ||
const { tag, extend, childrenExtends } = element | ||
const isSugar = checkIfSugar(element) | ||
@@ -48,5 +63,6 @@ const extendFromKey = key.includes('+') | ||
if (element === isExtendKeyComponent) return element | ||
else if (!hasComponentAttrs || childProps) { | ||
else if (isSugar) { | ||
return { | ||
extend: extendFromKey, | ||
childExtend: childrenExtends, | ||
tag, | ||
@@ -72,2 +88,23 @@ props: { ...element } | ||
function getCapitalCaseKeys (obj) { | ||
return Object.keys(obj).filter(key => /^[A-Z]/.test(key)) | ||
} | ||
export const addChildrenIfNotInOriginal = (element, parent, key) => { | ||
const childElems = getCapitalCaseKeys(element.props) | ||
if (!childElems.length) return element | ||
for (const i in childElems) { | ||
const childKey = childElems[i] | ||
const childElem = element[childKey] | ||
const newChild = element.props[childKey] | ||
if (newChild.ignoreExtend) continue | ||
if (!childElem) element[childKey] = deepCloneWithExtend(newChild) | ||
else { | ||
const isSugar = checkIfSugar(childElem) | ||
if (!isSugar) overwriteDeep(element[childKey].props, newChild) | ||
} | ||
} | ||
} | ||
export const applyKeyComponentAsExtend = (element, parent, key) => { | ||
@@ -74,0 +111,0 @@ return extendizeByKey(element, parent, key) || element |
@@ -22,2 +22,3 @@ "use strict"; | ||
addAdditionalExtend: () => addAdditionalExtend, | ||
addChildrenIfNotInOriginal: () => addChildrenIfNotInOriginal, | ||
applyComponentFromContext: () => applyComponentFromContext, | ||
@@ -57,6 +58,11 @@ applyKeyComponentAsExtend: () => applyKeyComponentAsExtend, | ||
}; | ||
const checkIfSugar = (element, parent, key) => { | ||
const { extend, props, childExtend, extends: extendProps, childrenExtends, childProps, children, on, $collection, $stateCollection, $propsCollection } = element; | ||
const hasComponentAttrs = extend || childExtend || props || on || $collection || $stateCollection || $propsCollection; | ||
return !hasComponentAttrs || childProps || extendProps || children || childrenExtends; | ||
}; | ||
const extendizeByKey = (element, parent, key) => { | ||
const { context } = parent; | ||
const { tag, extend, props, attr, state, childExtend, childProps, on, if: condition, data } = element; | ||
const hasComponentAttrs = extend || childExtend || props || state || on || condition || attr || data; | ||
const { tag, extend, childrenExtends } = element; | ||
const isSugar = checkIfSugar(element); | ||
const extendFromKey = key.includes("+") ? key.split("+") : key.includes("_") ? [key.split("_")[0]] : key.includes(".") && !checkIfKeyIsComponent(key.split(".")[1]) ? [key.split(".")[0]] : [key]; | ||
@@ -66,5 +72,6 @@ const isExtendKeyComponent = context && context.components[extendFromKey]; | ||
return element; | ||
else if (!hasComponentAttrs || childProps) { | ||
else if (isSugar) { | ||
return { | ||
extend: extendFromKey, | ||
childExtend: childrenExtends, | ||
tag, | ||
@@ -89,2 +96,24 @@ props: { ...element } | ||
}; | ||
function getCapitalCaseKeys(obj) { | ||
return Object.keys(obj).filter((key) => /^[A-Z]/.test(key)); | ||
} | ||
const addChildrenIfNotInOriginal = (element, parent, key) => { | ||
const childElems = getCapitalCaseKeys(element.props); | ||
if (!childElems.length) | ||
return element; | ||
for (const i in childElems) { | ||
const childKey = childElems[i]; | ||
const childElem = element[childKey]; | ||
const newChild = element.props[childKey]; | ||
if (newChild.ignoreExtend) | ||
continue; | ||
if (!childElem) | ||
element[childKey] = (0, import__.deepCloneWithExtend)(newChild); | ||
else { | ||
const isSugar = checkIfSugar(childElem); | ||
if (!isSugar) | ||
(0, import__.overwriteDeep)(element[childKey].props, newChild); | ||
} | ||
} | ||
}; | ||
const applyKeyComponentAsExtend = (element, parent, key) => { | ||
@@ -91,0 +120,0 @@ return extendizeByKey(element, parent, key) || element; |
{ | ||
"name": "@domql/utils", | ||
"version": "2.5.134", | ||
"version": "2.5.138", | ||
"license": "MIT", | ||
@@ -28,3 +28,3 @@ "type": "module", | ||
}, | ||
"gitHead": "20e65426dc742448bd6dc85211dea3a48ed74ae0", | ||
"gitHead": "91afb60b8354f1a95c3364be94ba74612f907918", | ||
"devDependencies": { | ||
@@ -31,0 +31,0 @@ "@babel/core": "^7.12.0" |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
105082
3134