@domql/element 2.33.17 → 2.33.20

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.
@@ -101,19 +101,36 @@ const cloneAndMergeArrayExtend = (stack) => {
101
101
  }, {});
102
102
  };
103
103
  const fallbackStringExtend = (extend, context, options = {}, variant) => {
104
- const COMPONENTS = context && context.components || options.components;
105
- const PAGES = context && context.pages || options.pages;
104
+ const checkIfExists = (key, variant2, onlyVariant) => {
105
+ const COMPONENTS = context && context.components || options.components;
106
+ if (COMPONENTS) {
107
+ const hasVariant = variant2 && COMPONENTS[key + "." + variant2];
108
+ if (onlyVariant) return hasVariant;
109
+ const componentExists = hasVariant || COMPONENTS[key] || COMPONENTS["smbls." + key];
110
+ if (componentExists) return componentExists;
111
+ }
112
+ const PAGES = context && context.pages || options.pages;
113
+ if (PAGES) {
114
+ const pageExists = (key == null ? void 0 : key.startsWith("/")) && PAGES[key];
115
+ if (pageExists) return pageExists;
116
+ }
117
+ };
118
+ if (variant) {
119
+ console.log(extend, variant);
120
+ }
106
121
  if ((0, import_utils.isString)(extend)) {
107
- const componentExists = COMPONENTS && (COMPONENTS[extend + "." + variant] || COMPONENTS[extend] || COMPONENTS["smbls." + extend]);
108
- const pageExists = PAGES && extend.startsWith("/") && PAGES[extend];
109
- if (componentExists) return componentExists;
110
- else if (pageExists) return pageExists;
111
- else {
112
- if (options.verbose && (0, import_utils.isNotProduction)()) {
113
- console.warn("Extend is string but component was not found:", extend);
114
- }
115
- return {};
122
+ const variantExists = checkIfExists(extend, variant);
123
+ if (variantExists) return variantExists;
124
+ if (options.verbose && (0, import_utils.isNotProduction)()) {
125
+ console.warn("Extend is string but component was not found:", extend);
116
126
  }
127
+ return {};
128
+ } else if ((0, import_utils.isArray)(extend)) {
129
+ const extendKey = extend.find((element) => {
130
+ return typeof element === "string";
131
+ });
132
+ const variantExists = checkIfExists(extendKey, variant, true);
133
+ if (variantExists) return variantExists;
117
134
  }
118
135
  return extend;
119
136
  };
@@ -71,19 +71,36 @@ const cloneAndMergeArrayExtend = (stack) => {
71
71
  }, {});
72
72
  };
73
73
  const fallbackStringExtend = (extend, context, options = {}, variant) => {
74
- const COMPONENTS = context && context.components || options.components;
75
- const PAGES = context && context.pages || options.pages;
74
+ const checkIfExists = (key, variant2, onlyVariant) => {
75
+ const COMPONENTS = context && context.components || options.components;
76
+ if (COMPONENTS) {
77
+ const hasVariant = variant2 && COMPONENTS[key + "." + variant2];
78
+ if (onlyVariant) return hasVariant;
79
+ const componentExists = hasVariant || COMPONENTS[key] || COMPONENTS["smbls." + key];
80
+ if (componentExists) return componentExists;
81
+ }
82
+ const PAGES = context && context.pages || options.pages;
83
+ if (PAGES) {
84
+ const pageExists = (key == null ? void 0 : key.startsWith("/")) && PAGES[key];
85
+ if (pageExists) return pageExists;
86
+ }
87
+ };
88
+ if (variant) {
89
+ console.log(extend, variant);
90
+ }
76
91
  if (isString(extend)) {
77
- const componentExists = COMPONENTS && (COMPONENTS[extend + "." + variant] || COMPONENTS[extend] || COMPONENTS["smbls." + extend]);
78
- const pageExists = PAGES && extend.startsWith("/") && PAGES[extend];
79
- if (componentExists) return componentExists;
80
- else if (pageExists) return pageExists;
81
- else {
82
- if (options.verbose && isNotProduction()) {
83
- console.warn("Extend is string but component was not found:", extend);
84
- }
85
- return {};
92
+ const variantExists = checkIfExists(extend, variant);
93
+ if (variantExists) return variantExists;
94
+ if (options.verbose && isNotProduction()) {
95
+ console.warn("Extend is string but component was not found:", extend);
86
96
  }
97
+ return {};
98
+ } else if (isArray(extend)) {
99
+ const extendKey = extend.find((element) => {
100
+ return typeof element === "string";
101
+ });
102
+ const variantExists = checkIfExists(extendKey, variant, true);
103
+ if (variantExists) return variantExists;
87
104
  }
88
105
  return extend;
89
106
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@domql/element",
3
- "version": "2.33.17",
3
+ "version": "2.33.20",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "module": "index.js",
@@ -27,12 +27,12 @@
27
27
  "prepublish": "npx rimraf -I dist && npm run build && npm run copy:package:cjs"
28
28
  },
29
29
  "dependencies": {
30
- "@domql/event": "^2.33.17",
31
- "@domql/render": "^2.33.17",
32
- "@domql/state": "^2.33.17",
33
- "@domql/utils": "^2.33.17"
30
+ "@domql/event": "^2.33.20",
31
+ "@domql/render": "^2.33.20",
32
+ "@domql/state": "^2.33.20",
33
+ "@domql/utils": "^2.33.20"
34
34
  },
35
- "gitHead": "b27e25a07197b6fa84bb3d62a583bdc6cc16d5b5",
35
+ "gitHead": "717ab2ed8690b295c7d6c79e31831048f20f4e86",
36
36
  "devDependencies": {
37
37
  "@babel/core": "^7.27.1"
38
38
  }
@@ -15,7 +15,7 @@ export const generateHash = () => Math.random().toString(36).substring(2)
15
15
  export const extendStackRegistry = {}
16
16
  export const extendCachedRegistry = {}
17
17
 
18
- export const getHashedExtend = extend => {
18
+ export const getHashedExtend = (extend) => {
19
19
  return extendStackRegistry[extend.__hash]
20
20
  }
21
21
 
@@ -37,7 +37,7 @@ export const getExtendStackRegistry = (extend, stack) => {
37
37
 
38
38
  // stacking
39
39
  export const extractArrayExtend = (extend, stack, context) => {
40
- extend.forEach(each => flattenExtend(each, stack, context))
40
+ extend.forEach((each) => flattenExtend(each, stack, context))
41
41
  return stack
42
42
  }
43
43
 
@@ -79,7 +79,7 @@ export const deepMergeExtend = (element, extend) => {
79
79
  return element
80
80
  }
81
81
 
82
- export const cloneAndMergeArrayExtend = stack => {
82
+ export const cloneAndMergeArrayExtend = (stack) => {
83
83
  return stack.reduce((a, c) => {
84
84
  return deepMergeExtend(a, deepClone(c))
85
85
  }, {})
@@ -91,23 +91,39 @@ export const fallbackStringExtend = (
91
91
  options = {},
92
92
  variant
93
93
  ) => {
94
- const COMPONENTS = (context && context.components) || options.components
95
- const PAGES = (context && context.pages) || options.pages
94
+ const checkIfExists = (key, variant, onlyVariant) => {
95
+ const COMPONENTS = (context && context.components) || options.components
96
+ if (COMPONENTS) {
97
+ const hasVariant = variant && COMPONENTS[key + '.' + variant]
98
+ if (onlyVariant) return hasVariant
99
+ const componentExists =
100
+ hasVariant || COMPONENTS[key] || COMPONENTS['smbls.' + key] // add shared libraries
101
+ if (componentExists) return componentExists
102
+ }
103
+ const PAGES = (context && context.pages) || options.pages
104
+ if (PAGES) {
105
+ const pageExists = key?.startsWith('/') && PAGES[key]
106
+ if (pageExists) return pageExists
107
+ }
108
+ }
109
+
110
+ if (variant) {
111
+ console.log(extend, variant)
112
+ }
113
+
96
114
  if (isString(extend)) {
97
- const componentExists =
98
- COMPONENTS &&
99
- (COMPONENTS[extend + '.' + variant] ||
100
- COMPONENTS[extend] ||
101
- COMPONENTS['smbls.' + extend])
102
- const pageExists = PAGES && extend.startsWith('/') && PAGES[extend]
103
- if (componentExists) return componentExists
104
- else if (pageExists) return pageExists
105
- else {
106
- if (options.verbose && isNotProduction()) {
107
- console.warn('Extend is string but component was not found:', extend)
108
- }
109
- return {}
115
+ const variantExists = checkIfExists(extend, variant)
116
+ if (variantExists) return variantExists
117
+ if (options.verbose && isNotProduction()) {
118
+ console.warn('Extend is string but component was not found:', extend)
110
119
  }
120
+ return {}
121
+ } else if (isArray(extend)) {
122
+ const extendKey = extend.find((element) => {
123
+ return typeof element === 'string'
124
+ })
125
+ const variantExists = checkIfExists(extendKey, variant, true)
126
+ if (variantExists) return variantExists
111
127
  }
112
128
  return extend
113
129
  }
@@ -129,7 +145,7 @@ export const getExtendStack = (extend, context) => {
129
145
  return getExtendStackRegistry(extend, stack)
130
146
  }
131
147
 
132
- export const getExtendMerged = extend => {
148
+ export const getExtendMerged = (extend) => {
133
149
  const stack = getExtendStack(extend)
134
150
  return cloneAndMergeArrayExtend(stack)
135
151
  }