vueless 0.0.495 → 0.0.497

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.
@@ -11,8 +11,8 @@ import {
11
11
  computed,
12
12
  } from "vue";
13
13
 
14
- import { cx, cva, setColor, getColor, vuelessConfig, mergeConfigs } from "../utils/ui.ts";
15
- import { cloneDeep, isCSR } from "../utils/helper.ts";
14
+ import { cx, cva, setColor, getColor, vuelessConfig, getMergedConfig } from "../utils/ui.ts";
15
+ import { isCSR } from "../utils/helper.ts";
16
16
  import {
17
17
  STRATEGY_TYPE,
18
18
  CVA_CONFIG_KEY,
@@ -34,13 +34,6 @@ import type {
34
34
  ExtendedKeyClasses,
35
35
  } from "../types.ts";
36
36
 
37
- interface MergedConfigOptions {
38
- defaultConfig: Component;
39
- globalConfig: Component;
40
- propsConfig?: Component;
41
- vuelessStrategy?: Strategies;
42
- }
43
-
44
37
  /**
45
38
  * Merging component configs in a given sequence (bigger number = bigger priority):
46
39
  * 1. Default component config
@@ -213,41 +206,6 @@ export default function useUI<T>(
213
206
  };
214
207
  }
215
208
 
216
- /**
217
- * Get merged config based on config merging strategy.
218
- */
219
- function getMergedConfig({
220
- defaultConfig,
221
- globalConfig,
222
- propsConfig,
223
- vuelessStrategy,
224
- }: MergedConfigOptions) {
225
- defaultConfig = cloneDeep(defaultConfig) as Component;
226
-
227
- let mergedConfig: Component = {};
228
- const strategy =
229
- !globalConfig && !propsConfig
230
- ? STRATEGY_TYPE.merge
231
- : propsConfig?.strategy || globalConfig?.strategy || vuelessStrategy;
232
-
233
- if (strategy === STRATEGY_TYPE.merge) {
234
- mergedConfig = mergeConfigs({ defaultConfig, globalConfig, propsConfig });
235
- }
236
-
237
- if (strategy === STRATEGY_TYPE.replace) {
238
- mergedConfig = mergeConfigs({ defaultConfig, globalConfig, propsConfig, isReplace: true });
239
- }
240
-
241
- if (strategy === STRATEGY_TYPE.overwrite) {
242
- const isGlobalConfig = globalConfig && Object.keys(globalConfig).length;
243
- const isPropsConfig = propsConfig && Object.keys(propsConfig).length;
244
-
245
- mergedConfig = isPropsConfig ? propsConfig : isGlobalConfig ? globalConfig : defaultConfig;
246
- }
247
-
248
- return mergedConfig;
249
- }
250
-
251
209
  /**
252
210
  * Return base classes.
253
211
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vueless",
3
- "version": "0.0.495",
3
+ "version": "0.0.497",
4
4
  "license": "MIT",
5
5
  "description": "Vue Styleless UI Component Library, powered by Tailwind CSS.",
6
6
  "keywords": [
@@ -558,7 +558,7 @@ function onInputCalendar(value: RangeDate) {
558
558
  <UInput
559
559
  v-if="isVariant.input"
560
560
  :id="elementId"
561
- ref="inputRef"
561
+ ref="input"
562
562
  v-model="userFormatDate"
563
563
  :size="size"
564
564
  :label="label"
@@ -1,8 +1,8 @@
1
1
  import { cloneDeep } from "lodash-es";
2
2
 
3
- import { SYSTEM_CONFIG_KEY } from "../../constants.js";
3
+ import { SYSTEM_CONFIG_KEY, STRATEGY_TYPE } from "../../constants.js";
4
4
 
5
- export function createMergeConfigsFunction(cx) {
5
+ export function createMergeConfigs(cx) {
6
6
  /**
7
7
  * Recursively merge config objects with removing tailwind classes duplicates.
8
8
  * config - final merged config.
@@ -187,6 +187,42 @@ export function createMergeConfigsFunction(cx) {
187
187
  return mergeConfigs;
188
188
  }
189
189
 
190
+ export function createGetMergedConfig(cx) {
191
+ const mergeConfigs = createMergeConfigs(cx);
192
+
193
+ /**
194
+ * Get merged config based on config merging strategy.
195
+ */
196
+ function getMergedConfig({ defaultConfig, globalConfig, propsConfig, vuelessStrategy }) {
197
+ defaultConfig = cloneDeep(defaultConfig);
198
+
199
+ let mergedConfig = {};
200
+ const strategy =
201
+ !globalConfig && !propsConfig
202
+ ? STRATEGY_TYPE.merge
203
+ : propsConfig?.strategy || globalConfig?.strategy || vuelessStrategy;
204
+
205
+ if (strategy === STRATEGY_TYPE.merge) {
206
+ mergedConfig = mergeConfigs({ defaultConfig, globalConfig, propsConfig });
207
+ }
208
+
209
+ if (strategy === STRATEGY_TYPE.replace) {
210
+ mergedConfig = mergeConfigs({ defaultConfig, globalConfig, propsConfig, isReplace: true });
211
+ }
212
+
213
+ if (strategy === STRATEGY_TYPE.overwrite) {
214
+ const isGlobalConfig = globalConfig && Object.keys(globalConfig).length;
215
+ const isPropsConfig = propsConfig && Object.keys(propsConfig).length;
216
+
217
+ mergedConfig = isPropsConfig ? propsConfig : isGlobalConfig ? globalConfig : defaultConfig;
218
+ }
219
+
220
+ return mergedConfig;
221
+ }
222
+
223
+ return getMergedConfig;
224
+ }
225
+
190
226
  /**
191
227
  Turn simplified nested component config to regular config.
192
228
  */
@@ -3,11 +3,11 @@ import { merge } from "lodash-es";
3
3
  import { existsSync } from "node:fs";
4
4
  import { readFile } from "node:fs/promises";
5
5
  import { extendTailwindMerge } from "tailwind-merge";
6
- import { isEqual, omit } from "lodash-es";
6
+ import { isEqual } from "lodash-es";
7
7
  import { defineConfig } from "cva";
8
8
 
9
9
  import { vuelessConfig } from "./vuelessConfig.js";
10
- import { createMergeConfigsFunction } from "./mergeConfigs.js";
10
+ import { createGetMergedConfig } from "./mergeConfigs.js";
11
11
  import { getDefaultConfigJson, getDirFiles } from "./helper.js";
12
12
  import {
13
13
  COMPONENTS,
@@ -20,6 +20,8 @@ import {
20
20
  NESTED_COMPONENT_REG_EXP,
21
21
  TAILWIND_COLOR_OPACITY_DELIMITER,
22
22
  TAILWIND_VARIANT_DELIMITER_REG_EXP,
23
+ STRATEGY_TYPE,
24
+ SYSTEM_CONFIG_KEY,
23
25
  } from "../../constants.js";
24
26
 
25
27
  const twMerge = extendTailwindMerge(merge(TAILWIND_MERGE_EXTENSION, vuelessConfig.tailwindMerge));
@@ -30,7 +32,7 @@ export const { cx } = defineConfig({
30
32
  },
31
33
  });
32
34
 
33
- const mergeConfigs = createMergeConfigsFunction(cx);
35
+ const getMergedConfig = createGetMergedConfig(cx);
34
36
 
35
37
  export function clearTailwindSafelist() {
36
38
  process.env.VUELESS_SAFELIST = "";
@@ -122,6 +124,8 @@ function getSafelistClasses(config) {
122
124
  if (Object.prototype.hasOwnProperty.call(config, key)) {
123
125
  const classes = config[key];
124
126
 
127
+ if (key === SYSTEM_CONFIG_KEY.defaults) continue;
128
+
125
129
  if (typeof classes === "object" && Array.isArray(classes)) {
126
130
  safelistItems.push(...classes.map(getSafelistClasses));
127
131
  }
@@ -174,9 +178,16 @@ async function getComponentSafelist(componentName, { colors, vuelessConfigFiles
174
178
  defaultConfig = getDefaultConfigJson(defaultConfigContent);
175
179
  }
176
180
 
177
- const mergedConfig = omit(mergeConfigs({ defaultConfig, globalConfig: customConfig }), [
178
- "defaults",
179
- ]);
181
+ const isStrategyValid =
182
+ vuelessConfig.strategy && Object.values(STRATEGY_TYPE).includes(vuelessConfig.strategy);
183
+
184
+ const vuelessStrategy = isStrategyValid ? vuelessConfig.strategy : STRATEGY_TYPE.merge;
185
+
186
+ const mergedConfig = getMergedConfig({
187
+ defaultConfig,
188
+ globalConfig: customConfig,
189
+ vuelessStrategy,
190
+ });
180
191
 
181
192
  const colorString = `(${colors.join("|")})`;
182
193
 
package/utils/ui.ts CHANGED
@@ -2,7 +2,7 @@ import { merge } from "lodash-es";
2
2
  import { defineConfig } from "cva";
3
3
  import { extendTailwindMerge } from "tailwind-merge";
4
4
  import { cloneDeep, isCSR, isSSR } from "./helper.ts";
5
- import { createMergeConfigsFunction } from "./node/mergeConfigs.js";
5
+ import { createGetMergedConfig } from "./node/mergeConfigs.js";
6
6
  import {
7
7
  BRAND_COLOR,
8
8
  GRAYSCALE_COLOR,
@@ -11,7 +11,23 @@ import {
11
11
  TAILWIND_MERGE_EXTENSION,
12
12
  } from "../constants.js";
13
13
 
14
- import type { BrandColors, Config, ComponentNames, Component, Defaults } from "../types.ts";
14
+ import type {
15
+ BrandColors,
16
+ Config,
17
+ ComponentNames,
18
+ Component,
19
+ Defaults,
20
+ Strategies,
21
+ } from "../types.ts";
22
+
23
+ interface MergedConfigOptions {
24
+ defaultConfig: Component;
25
+ globalConfig: Component;
26
+ propsConfig?: Component;
27
+ vuelessStrategy?: Strategies;
28
+ }
29
+
30
+ type getMergedConfig = (options: MergedConfigOptions) => Component;
15
31
 
16
32
  /**
17
33
  * Load Vueless config from the project root.
@@ -67,7 +83,7 @@ export const {
67
83
  },
68
84
  });
69
85
 
70
- export const mergeConfigs = createMergeConfigsFunction(cx);
86
+ export const getMergedConfig = createGetMergedConfig(cx) as getMergedConfig;
71
87
 
72
88
  /* This allows skipping some CVA config keys in vueless config. */
73
89
  export const cva = ({ base = "", variants = {}, compoundVariants = [], defaultVariants = {} }) =>
package/web-types.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "framework": "vue",
3
3
  "name": "vueless",
4
- "version": "0.0.495",
4
+ "version": "0.0.497",
5
5
  "contributions": {
6
6
  "html": {
7
7
  "description-markup": "markdown",