@domql/utils 2.5.151 → 2.5.153

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
@@ -6,10 +6,8 @@ import {
6
6
  isArray,
7
7
  isFunction,
8
8
  isObject,
9
- isObjectLike,
10
9
  isString,
11
- joinArrays,
12
- overwriteDeep
10
+ joinArrays
13
11
  } from '.'
14
12
  const ENV = process.env.NODE_ENV
15
13
 
@@ -36,13 +34,13 @@ export const addAdditionalExtend = (newExtend, element) => {
36
34
  return { ...element, extend }
37
35
  }
38
36
 
39
- const checkIfSugar = (element, parent, key) => {
37
+ export const checkIfSugar = (element, parent, key) => {
40
38
  const {
41
39
  extend,
42
40
  props,
43
41
  childExtend,
44
42
  extends: extendProps,
45
- childrenExtends,
43
+ childExtends,
46
44
  childProps,
47
45
  children,
48
46
  on,
@@ -51,15 +49,16 @@ const checkIfSugar = (element, parent, key) => {
51
49
  $propsCollection
52
50
  } = element
53
51
  const hasComponentAttrs = extend || childExtend || props || on || $collection || $stateCollection || $propsCollection
54
- if (hasComponentAttrs && (childProps || extendProps || children || childrenExtends)) {
55
- parent.error('Sugar component includes params for builtin components', { verbose: true })
52
+ if (hasComponentAttrs && (childProps || extendProps || children || childExtends)) {
53
+ const logErr = (parent || element)?.error
54
+ if (logErr) logErr('Sugar component includes params for builtin components', { verbose: true })
56
55
  }
57
- return !hasComponentAttrs || childProps || extendProps || children || childrenExtends
56
+ return !hasComponentAttrs || childProps || extendProps || children || childExtends
58
57
  }
59
58
 
60
59
  export const extendizeByKey = (element, parent, key) => {
61
60
  const { context } = parent
62
- const { tag, extend, childrenExtends } = element
61
+ const { tag, extend, childExtends } = element
63
62
  const isSugar = checkIfSugar(element, parent, key)
64
63
 
65
64
  const extendFromKey = key.includes('+')
@@ -78,7 +77,7 @@ export const extendizeByKey = (element, parent, key) => {
78
77
  tag,
79
78
  props: { ...element }
80
79
  })
81
- if (childrenExtends) newElem.childExtend = childrenExtends
80
+ if (childExtends) newElem.childExtend = childExtends
82
81
  return newElem
83
82
  } else if (!extend || extend === true) {
84
83
  return {
@@ -97,7 +96,7 @@ export const extendizeByKey = (element, parent, key) => {
97
96
  }
98
97
  }
99
98
 
100
- function getCapitalCaseKeys (obj) {
99
+ export function getCapitalCaseKeys (obj) {
101
100
  return Object.keys(obj).filter(key => /^[A-Z]/.test(key))
102
101
  }
103
102
 
@@ -109,20 +108,22 @@ export const addChildrenIfNotInOriginal = (element, parent, key) => {
109
108
  const childKey = childElems[i]
110
109
  const childElem = element[childKey]
111
110
  const newChild = element.props[childKey]
111
+
112
+ const assignChild = (val) => {
113
+ element[childKey] = val
114
+ delete element.props[childKey]
115
+ }
116
+
112
117
  if (newChild?.ignoreExtend) continue
113
- if (!childElem) element[childKey] = deepCloneWithExtend(newChild)
118
+ if (newChild === null) assignChild(null)
119
+ else if (!childElem) assignChild(deepCloneWithExtend(newChild))
114
120
  else {
115
- const isSugar = checkIfSugar(childElem, parent, key)
116
- if (!isSugar) continue
117
- const inheritedChildElem = element[childKey].props
118
- if (isObjectLike(newChild)) {
119
- overwriteDeep(inheritedChildElem, newChild)
120
- } else if (isFunction(newChild)) {
121
- element[childKey] = {
122
- extend: element[childKey],
123
- props: newChild
124
- }
125
- }
121
+ const isSugarChildElem = checkIfSugar(childElem, parent, key)
122
+ if (isSugarChildElem) continue
123
+ assignChild({
124
+ extend: element[childKey],
125
+ props: newChild
126
+ })
126
127
  }
127
128
  }
128
129
  }
@@ -24,7 +24,9 @@ __export(component_exports, {
24
24
  applyKeyComponentAsExtend: () => applyKeyComponentAsExtend,
25
25
  checkIfKeyIsComponent: () => checkIfKeyIsComponent,
26
26
  checkIfKeyIsProperty: () => checkIfKeyIsProperty,
27
+ checkIfSugar: () => checkIfSugar,
27
28
  extendizeByKey: () => extendizeByKey,
29
+ getCapitalCaseKeys: () => getCapitalCaseKeys,
28
30
  getChildrenComponentsByKey: () => getChildrenComponentsByKey,
29
31
  getExtendsInElement: () => getExtendsInElement,
30
32
  hasVariantProp: () => hasVariantProp,
@@ -58,12 +60,13 @@ const addAdditionalExtend = (newExtend, element) => {
58
60
  return { ...element, extend };
59
61
  };
60
62
  const checkIfSugar = (element, parent, key) => {
63
+ var _a;
61
64
  const {
62
65
  extend,
63
66
  props,
64
67
  childExtend,
65
68
  extends: extendProps,
66
- childrenExtends,
69
+ childExtends,
67
70
  childProps,
68
71
  children,
69
72
  on,
@@ -72,14 +75,16 @@ const checkIfSugar = (element, parent, key) => {
72
75
  $propsCollection
73
76
  } = element;
74
77
  const hasComponentAttrs = extend || childExtend || props || on || $collection || $stateCollection || $propsCollection;
75
- if (hasComponentAttrs && (childProps || extendProps || children || childrenExtends)) {
76
- parent.error("Sugar component includes params for builtin components", { verbose: true });
78
+ if (hasComponentAttrs && (childProps || extendProps || children || childExtends)) {
79
+ const logErr = (_a = parent || element) == null ? void 0 : _a.error;
80
+ if (logErr)
81
+ logErr("Sugar component includes params for builtin components", { verbose: true });
77
82
  }
78
- return !hasComponentAttrs || childProps || extendProps || children || childrenExtends;
83
+ return !hasComponentAttrs || childProps || extendProps || children || childExtends;
79
84
  };
80
85
  const extendizeByKey = (element, parent, key) => {
81
86
  const { context } = parent;
82
- const { tag, extend, childrenExtends } = element;
87
+ const { tag, extend, childExtends } = element;
83
88
  const isSugar = checkIfSugar(element, parent, key);
84
89
  const extendFromKey = key.includes("+") ? key.split("+") : key.includes("_") ? [key.split("_")[0]] : key.includes(".") && !checkIfKeyIsComponent(key.split(".")[1]) ? [key.split(".")[0]] : [key];
85
90
  const isExtendKeyComponent = context && context.components[extendFromKey];
@@ -91,8 +96,8 @@ const extendizeByKey = (element, parent, key) => {
91
96
  tag,
92
97
  props: { ...element }
93
98
  });
94
- if (childrenExtends)
95
- newElem.childExtend = childrenExtends;
99
+ if (childExtends)
100
+ newElem.childExtend = childExtends;
96
101
  return newElem;
97
102
  } else if (!extend || extend === true) {
98
103
  return {
@@ -121,23 +126,24 @@ const addChildrenIfNotInOriginal = (element, parent, key) => {
121
126
  const childKey = childElems[i];
122
127
  const childElem = element[childKey];
123
128
  const newChild = element.props[childKey];
129
+ const assignChild = (val) => {
130
+ element[childKey] = val;
131
+ delete element.props[childKey];
132
+ };
124
133
  if (newChild == null ? void 0 : newChild.ignoreExtend)
125
134
  continue;
126
- if (!childElem)
127
- element[childKey] = (0, import__.deepCloneWithExtend)(newChild);
135
+ if (newChild === null)
136
+ assignChild(null);
137
+ else if (!childElem)
138
+ assignChild((0, import__.deepCloneWithExtend)(newChild));
128
139
  else {
129
- const isSugar = checkIfSugar(childElem, parent, key);
130
- if (!isSugar)
140
+ const isSugarChildElem = checkIfSugar(childElem, parent, key);
141
+ if (isSugarChildElem)
131
142
  continue;
132
- const inheritedChildElem = element[childKey].props;
133
- if ((0, import__.isObjectLike)(newChild)) {
134
- (0, import__.overwriteDeep)(inheritedChildElem, newChild);
135
- } else if ((0, import__.isFunction)(newChild)) {
136
- element[childKey] = {
137
- extend: element[childKey],
138
- props: newChild
139
- };
140
- }
143
+ assignChild({
144
+ extend: element[childKey],
145
+ props: newChild
146
+ });
141
147
  }
142
148
  }
143
149
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@domql/utils",
3
- "version": "2.5.151",
3
+ "version": "2.5.153",
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": "f37b51f84b8bca80b8bce7887e83d61ac25eb3d5",
28
+ "gitHead": "ebf5debf658fdae4ec5a99b541b2518c7767e6a8",
29
29
  "devDependencies": {
30
30
  "@babel/core": "^7.12.0"
31
31
  }