@domql/element 2.5.37 → 2.5.40

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.
@@ -40,21 +40,22 @@ const checkIfKeyIsComponent = (key) => {
40
40
  return /^[A-Z]*$/.test(firstCharKey);
41
41
  };
42
42
  const addAdditionalExtend = (newExtend, element) => {
43
- const { extend } = element;
44
- const preserveExtend = (0, import_utils.isArray)(extend) ? extend : [extend];
45
- return {
46
- ...element,
47
- extend: [newExtend].concat(preserveExtend)
48
- };
43
+ const { extend: elementExtend } = element;
44
+ const originalArray = (0, import_utils.isArray)(elementExtend) ? elementExtend : [elementExtend];
45
+ const receivedArray = (0, import_utils.isArray)(newExtend) ? newExtend : [newExtend];
46
+ const extend = (0, import_utils.joinArrays)(receivedArray, originalArray);
47
+ return { ...element, extend };
49
48
  };
50
49
  const extendizeByKey = (element, parent, key) => {
51
- const { tag, extend, props, state, childExtend, childProps, on, if: condition } = element;
52
- const hasComponentAttrs = extend || childExtend || props || state || on || condition;
53
- const componentKey = key.includes("_") ? key.split("_")[0] : key.includes(".") ? key.split(".")[0] : key;
54
- const extendKey = componentKey || key;
55
- if (!hasComponentAttrs || childProps) {
50
+ const { context, tag, extend, props, attr, state, childExtend, childProps, on, if: condition } = element;
51
+ const hasComponentAttrs = extend || childExtend || props || state || on || condition || attr;
52
+ const extendFromKey = key.includes("+") ? key.split("+") : key.includes("_") ? key.split("_")[0] : key.includes(".") ? key.split(".")[0] : key;
53
+ const isExtendKeyComponent = context == null ? void 0 : context.components[extendFromKey];
54
+ if (element === isExtendKeyComponent)
55
+ return element;
56
+ else if (!hasComponentAttrs || childProps) {
56
57
  return {
57
- extend: extendKey,
58
+ extend: extendFromKey,
58
59
  tag,
59
60
  props: { ...element }
60
61
  };
@@ -62,14 +63,13 @@ const extendizeByKey = (element, parent, key) => {
62
63
  return {
63
64
  ...element,
64
65
  tag,
65
- extend: extendKey
66
+ extend: extendFromKey
66
67
  };
67
68
  } else if (extend) {
68
- addAdditionalExtend(extendKey, element);
69
+ return addAdditionalExtend(extendFromKey, element);
69
70
  } else if ((0, import_utils.isFunction)(element)) {
70
- console.log(element);
71
71
  return {
72
- extend: extendKey,
72
+ extend: extendFromKey,
73
73
  tag,
74
74
  props: { ...(0, import_utils.exec)(element, parent) }
75
75
  };
@@ -86,8 +86,9 @@ const applyComponentFromContext = (element, parent, options) => {
86
86
  const { extend } = element;
87
87
  const execExtend = (0, import_utils.exec)(extend, element);
88
88
  if ((0, import_utils.isString)(execExtend)) {
89
- if (components[execExtend])
90
- element.extend = components[execExtend];
89
+ const componentExists = components[execExtend] || components["smbls." + execExtend];
90
+ if (componentExists)
91
+ element.extend = componentExists;
91
92
  else {
92
93
  if ((ENV === "test" || ENV === "development") && options.verbose) {
93
94
  console.warn(execExtend, "is not in library", components, element);
@@ -126,7 +126,6 @@ const fallbackStringExtend = (extend, context, options = {}) => {
126
126
  const COMPONENTS = context && context.components || options.components;
127
127
  if ((0, import_utils.isString)(extend)) {
128
128
  const componentExists = COMPONENTS[extend] || COMPONENTS["smbls." + extend];
129
- console.log(extend, componentExists);
130
129
  if (COMPONENTS && componentExists) {
131
130
  return componentExists;
132
131
  } else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@domql/element",
3
- "version": "2.5.37",
3
+ "version": "2.5.40",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "module": "index.js",
@@ -31,7 +31,7 @@
31
31
  "@domql/state": "latest",
32
32
  "@domql/utils": "latest"
33
33
  },
34
- "gitHead": "1cba51181175cc713dc6d55a4cd2b10e456e1315",
34
+ "gitHead": "536a661204a0377cb6dbb415eba1081ac156048d",
35
35
  "devDependencies": {
36
36
  "@babel/core": "^7.12.0"
37
37
  }
@@ -1,6 +1,6 @@
1
1
  'use strict'
2
2
 
3
- import { exec, isArray, isFunction, isObject, isString, overwriteDeep } from '@domql/utils'
3
+ import { exec, isArray, isFunction, isObject, isString, joinArrays, overwriteDeep } from '@domql/utils'
4
4
  import { applyExtend } from '../extend'
5
5
  const ENV = process.env.NODE_ENV
6
6
 
@@ -12,25 +12,31 @@ export const checkIfKeyIsComponent = (key) => {
12
12
  }
13
13
 
14
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
- }
15
+ const { extend: elementExtend } = element
16
+ const originalArray = isArray(elementExtend) ? elementExtend : [elementExtend]
17
+ const receivedArray = isArray(newExtend) ? newExtend : [newExtend]
18
+ const extend = joinArrays(receivedArray, originalArray)
19
+ return { ...element, extend }
21
20
  }
22
21
 
23
22
  export const extendizeByKey = (element, parent, key) => {
24
- const { tag, extend, props, state, childExtend, childProps, on, if: condition } = element
25
- const hasComponentAttrs = extend || childExtend || props || state || on || condition
26
- const componentKey = key.includes('_')
27
- ? key.split('_')[0]
28
- : key.includes('.') ? key.split('.')[0] : key
29
- const extendKey = componentKey || key
30
-
31
- if (!hasComponentAttrs || childProps) {
23
+ const { context, tag, extend, props, attr, state, childExtend, childProps, on, if: condition } = element
24
+ const hasComponentAttrs = extend || childExtend || props || state || on || condition || attr
25
+
26
+ const extendFromKey = key.includes('+')
27
+ ? key.split('+')
28
+ : key.includes('_')
29
+ ? key.split('_')[0]
30
+ : key.includes('.')
31
+ ? key.split('.')[0]
32
+ : key
33
+
34
+ const isExtendKeyComponent = context?.components[extendFromKey]
35
+
36
+ if (element === isExtendKeyComponent) return element
37
+ else if (!hasComponentAttrs || childProps) {
32
38
  return {
33
- extend: extendKey,
39
+ extend: extendFromKey,
34
40
  tag,
35
41
  props: { ...element }
36
42
  }
@@ -38,14 +44,13 @@ export const extendizeByKey = (element, parent, key) => {
38
44
  return {
39
45
  ...element,
40
46
  tag,
41
- extend: extendKey
47
+ extend: extendFromKey
42
48
  }
43
49
  } else if (extend) {
44
- addAdditionalExtend(extendKey, element)
50
+ return addAdditionalExtend(extendFromKey, element)
45
51
  } else if (isFunction(element)) {
46
- console.log(element)
47
52
  return {
48
- extend: extendKey,
53
+ extend: extendFromKey,
49
54
  tag,
50
55
  props: { ...exec(element, parent) }
51
56
  }
@@ -65,7 +70,8 @@ export const applyComponentFromContext = (element, parent, options) => {
65
70
  const { extend } = element
66
71
  const execExtend = exec(extend, element)
67
72
  if (isString(execExtend)) {
68
- if (components[execExtend]) element.extend = components[execExtend]
73
+ const componentExists = components[execExtend] || components['smbls.' + execExtend]
74
+ if (componentExists) element.extend = componentExists
69
75
  else {
70
76
  if ((ENV === 'test' || ENV === 'development') && options.verbose) {
71
77
  console.warn(execExtend, 'is not in library', components, element)
@@ -94,7 +94,6 @@ export const fallbackStringExtend = (extend, context, options = {}) => {
94
94
  const COMPONENTS = (context && context.components) || options.components
95
95
  if (isString(extend)) {
96
96
  const componentExists = COMPONENTS[extend] || COMPONENTS['smbls.' + extend]
97
- console.log(extend, componentExists)
98
97
  if (COMPONENTS && componentExists) {
99
98
  return componentExists
100
99
  } else {