vueless 0.0.498 → 0.0.499

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vueless",
3
- "version": "0.0.498",
3
+ "version": "0.0.499",
4
4
  "license": "MIT",
5
5
  "description": "Vue Styleless UI Component Library, powered by Tailwind CSS.",
6
6
  "keywords": [
@@ -131,10 +131,11 @@ export function createMergeConfigs(cx) {
131
131
  console.error("CompoundVariants should be an array.");
132
132
  }
133
133
 
134
- const globalConfigUniqueItems = cloneDeep(globalConfig.compoundVariants || []);
135
- const propsConfigUniqueItems = cloneDeep(propsConfig.compoundVariants || []);
134
+ const defaultCompoundVariants = expandCompoundVariants(defaultConfig.compoundVariants);
135
+ const globalCompoundVariants = expandCompoundVariants(globalConfig.compoundVariants);
136
+ const propsCompoundVariants = expandCompoundVariants(propsConfig.compoundVariants);
136
137
 
137
- const config = defaultConfig.compoundVariants?.map((defaultConfigItem) => {
138
+ const config = defaultCompoundVariants?.map((defaultConfigItem) => {
138
139
  /**
139
140
  * Compare two objects by keys for match.
140
141
  */
@@ -151,25 +152,27 @@ export function createMergeConfigs(cx) {
151
152
  }
152
153
 
153
154
  /**
154
- * Find the same compound variant item in custom config if exist.
155
+ * Find the same compound variant item in custom config if existed.
155
156
  */
156
157
  function findItem(config = []) {
157
- const globalConfigUniqueItemIndex = globalConfigUniqueItems.findIndex(isSameItem);
158
- const propsConfigUniqueItemIndex = propsConfigUniqueItems.findIndex(isSameItem);
158
+ config = cloneDeep(config);
159
+
160
+ const globalConfigUniqueItemIndex = globalCompoundVariants.findIndex(isSameItem);
161
+ const propsConfigUniqueItemIndex = propsCompoundVariants.findIndex(isSameItem);
159
162
 
160
163
  if (~globalConfigUniqueItemIndex) {
161
- globalConfigUniqueItems.splice(globalConfigUniqueItemIndex, 1);
164
+ globalCompoundVariants.splice(globalConfigUniqueItemIndex, 1);
162
165
  }
163
166
 
164
167
  if (~propsConfigUniqueItemIndex) {
165
- propsConfigUniqueItems.splice(propsConfigUniqueItemIndex, 1);
168
+ propsCompoundVariants.splice(propsConfigUniqueItemIndex, 1);
166
169
  }
167
170
 
168
171
  return config.find(isSameItem);
169
172
  }
170
173
 
171
- const globalConfigItem = findItem(globalConfig.compoundVariants);
172
- const propsConfigItem = findItem(propsConfig.compoundVariants);
174
+ const globalConfigItem = findItem(globalCompoundVariants);
175
+ const propsConfigItem = findItem(propsCompoundVariants);
173
176
 
174
177
  return globalConfigItem || propsConfigItem
175
178
  ? {
@@ -181,7 +184,35 @@ export function createMergeConfigs(cx) {
181
184
  : defaultConfigItem;
182
185
  });
183
186
 
184
- return [...(config || []), ...globalConfigUniqueItems, ...propsConfigUniqueItems];
187
+ return [...(config || []), ...globalCompoundVariants, ...propsCompoundVariants];
188
+ }
189
+
190
+ /**
191
+ * Convert compound variants with arrays in values into compound variants with primitives.
192
+ */
193
+ function expandCompoundVariants(compoundVariants) {
194
+ compoundVariants = cloneDeep(compoundVariants || []);
195
+
196
+ function expand(compoundVariant) {
197
+ const keysWithArray = Object.keys(compoundVariant).filter((key) =>
198
+ Array.isArray(compoundVariant[key]),
199
+ );
200
+
201
+ if (!keysWithArray.length) {
202
+ return [compoundVariant];
203
+ }
204
+
205
+ const [firstKey] = keysWithArray;
206
+ const expandedArray = compoundVariant[firstKey].map((value) => ({
207
+ ...compoundVariant,
208
+ [firstKey]: value,
209
+ }));
210
+
211
+ // Recursively expand the remaining array keys
212
+ return expandedArray.flatMap((expandedCompoundVariant) => expand(expandedCompoundVariant));
213
+ }
214
+
215
+ return compoundVariants.flatMap(expand);
185
216
  }
186
217
 
187
218
  return mergeConfigs;
package/web-types.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "framework": "vue",
3
3
  "name": "vueless",
4
- "version": "0.0.498",
4
+ "version": "0.0.499",
5
5
  "contributions": {
6
6
  "html": {
7
7
  "description-markup": "markdown",