@domql/utils 2.5.134 → 2.5.138

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 CHANGED
@@ -1,6 +1,15 @@
1
1
  'use strict'
2
2
 
3
- import { exec, isArray, isFunction, isObject, isString, joinArrays } from '.'
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, props, attr, state, childExtend, childProps, on, if: condition, data } = element
31
- const hasComponentAttrs = extend || childExtend || props || state || on || condition || attr || data
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,9 +59,10 @@ 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 (!hasComponentAttrs || childProps) {
62
+ else if (isSugar) {
48
63
  return {
49
64
  extend: extendFromKey,
65
+ childExtend: childrenExtends,
50
66
  tag,
51
67
  props: { ...element }
52
68
  }
@@ -67,6 +83,27 @@ export const extendizeByKey = (element, parent, key) => {
67
83
  }
68
84
  }
69
85
 
86
+ function getCapitalCaseKeys (obj) {
87
+ return Object.keys(obj).filter(key => /^[A-Z]/.test(key))
88
+ }
89
+
90
+ export const addChildrenIfNotInOriginal = (element, parent, key) => {
91
+ const childElems = getCapitalCaseKeys(element.props)
92
+ if (!childElems.length) return element
93
+
94
+ for (const i in childElems) {
95
+ const childKey = childElems[i]
96
+ const childElem = element[childKey]
97
+ const newChild = element.props[childKey]
98
+ if (newChild.ignoreExtend) continue
99
+ if (!childElem) element[childKey] = deepCloneWithExtend(newChild)
100
+ else {
101
+ const isSugar = checkIfSugar(childElem)
102
+ if (!isSugar) overwriteDeep(element[childKey].props, newChild)
103
+ }
104
+ }
105
+ }
106
+
70
107
  export const applyKeyComponentAsExtend = (element, parent, key) => {
71
108
  return extendizeByKey(element, parent, key) || element
72
109
  }
@@ -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,17 +54,23 @@ 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, props, attr, state, childExtend, childProps, on, if: condition, data } = element;
59
- const hasComponentAttrs = extend || childExtend || props || state || on || condition || attr || data;
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 (!hasComponentAttrs || childProps) {
70
+ else if (isSugar) {
65
71
  return {
66
72
  extend: extendFromKey,
73
+ childExtend: childrenExtends,
67
74
  tag,
68
75
  props: { ...element }
69
76
  };
@@ -83,6 +90,28 @@ const extendizeByKey = (element, parent, key) => {
83
90
  };
84
91
  }
85
92
  };
93
+ function getCapitalCaseKeys(obj) {
94
+ return Object.keys(obj).filter((key) => /^[A-Z]/.test(key));
95
+ }
96
+ const addChildrenIfNotInOriginal = (element, parent, key) => {
97
+ const childElems = getCapitalCaseKeys(element.props);
98
+ if (!childElems.length)
99
+ return element;
100
+ for (const i in childElems) {
101
+ const childKey = childElems[i];
102
+ const childElem = element[childKey];
103
+ const newChild = element.props[childKey];
104
+ if (newChild.ignoreExtend)
105
+ continue;
106
+ if (!childElem)
107
+ element[childKey] = (0, import__.deepCloneWithExtend)(newChild);
108
+ else {
109
+ const isSugar = checkIfSugar(childElem);
110
+ if (!isSugar)
111
+ (0, import__.overwriteDeep)(element[childKey].props, newChild);
112
+ }
113
+ }
114
+ };
86
115
  const applyKeyComponentAsExtend = (element, parent, key) => {
87
116
  return extendizeByKey(element, parent, key) || element;
88
117
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@domql/utils",
3
- "version": "2.5.134",
3
+ "version": "2.5.138",
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": "20e65426dc742448bd6dc85211dea3a48ed74ae0",
28
+ "gitHead": "91afb60b8354f1a95c3364be94ba74612f907918",
29
29
  "devDependencies": {
30
30
  "@babel/core": "^7.12.0"
31
31
  }