vueless 1.5.1-beta.4 → 1.5.1-beta.6

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": "1.5.1-beta.4",
3
+ "version": "1.5.1-beta.6",
4
4
  "description": "Vue Styleless UI Component Library, powered by Tailwind CSS.",
5
5
  "author": "Johnny Grid <hello@vueless.com> (https://vueless.com)",
6
6
  "homepage": "https://vueless.com",
@@ -35,7 +35,7 @@
35
35
  "@tailwindcss/postcss": "^4.2.4",
36
36
  "@tailwindcss/vite": "^4.2.4",
37
37
  "@types/lodash-es": "^4.17.12",
38
- "cva": "^1.0.0-beta.4",
38
+ "cva": "1.0.0-beta.10",
39
39
  "lodash-es": "^4.18.1",
40
40
  "rolldown": "^1.1.5",
41
41
  "svgo": "^4.0.1",
@@ -1,6 +1,6 @@
1
1
  export function getVuelessConfig(basePath?: string): Promise<Object>;
2
2
  export let vuelessConfig: {};
3
- export const cx: import("cva").CX;
3
+ export const cx: import("cva").CX<import("cva").ClassValue>;
4
4
  export const getMergedConfig: ({ defaultConfig, globalConfig, propsConfig, unstyled }: {
5
5
  defaultConfig: any;
6
6
  globalConfig: any;
@@ -2,7 +2,8 @@ import fs from "node:fs";
2
2
  import path from "node:path";
3
3
  import { cwd } from "node:process";
4
4
  import { pathToFileURL } from "node:url";
5
- import { defineConfig } from "cva";
5
+ import { cx as cvaCx } from "cva";
6
+ import { defineConfig } from "cva/config";
6
7
  import { merge } from "lodash-es";
7
8
  import { extendTailwindMerge } from "tailwind-merge";
8
9
 
@@ -57,6 +58,7 @@ const twMerge = extendTailwindMerge(
57
58
  * – remove all Vueless nested component names ({U...} strings) from the class list string.
58
59
  */
59
60
  export const { cx } = defineConfig({
61
+ cx: cvaCx,
60
62
  hooks: {
61
63
  onComplete: (classNames) => twMerge(classNames).replace(NESTED_COMPONENT_PATTERN_REG_EXP, ""),
62
64
  },
@@ -0,0 +1,48 @@
1
+ import { describe, it, expect, vi, beforeEach } from "vitest";
2
+
3
+ import { COLOR_MODE_KEY } from "../../constants.js";
4
+ import { loadSSRVuelessConfig, setVuelessConfig, vuelessConfig } from "../ui";
5
+
6
+ import type { Config } from "../../types";
7
+
8
+ /* jsdom doesn't implement matchMedia, which theme.ts evaluates on import. */
9
+ const prefersDark = { matches: false, addEventListener: vi.fn(), removeEventListener: vi.fn() };
10
+
11
+ window.matchMedia = vi.fn(() => prefersDark) as unknown as typeof window.matchMedia;
12
+
13
+ const { getThemeCookieName } = await import("../theme");
14
+
15
+ beforeEach(() => {
16
+ Object.keys(vuelessConfig).forEach((key) => delete vuelessConfig[key as keyof Config]);
17
+ });
18
+
19
+ describe("loadSSRVuelessConfig", () => {
20
+ it.each([
21
+ ["resolves", () => ({ cookiePrefix: "from-file" })],
22
+ [
23
+ "fails",
24
+ () => {
25
+ throw new Error("Cannot find module '/vueless.config'");
26
+ },
27
+ ],
28
+ ])("keeps the injected config when a deferred import %s", async (_, settle: () => Config) => {
29
+ let release!: () => void;
30
+ const released = new Promise<void>((resolve) => (release = resolve));
31
+
32
+ const loading = loadSSRVuelessConfig(() => released.then(() => ({ default: settle() })));
33
+
34
+ setVuelessConfig({ cookiePrefix: "app-a" });
35
+ expect(getThemeCookieName(COLOR_MODE_KEY)).toBe(`app-a-${COLOR_MODE_KEY}`);
36
+
37
+ release();
38
+ await loading;
39
+
40
+ expect(getThemeCookieName(COLOR_MODE_KEY)).toBe(`app-a-${COLOR_MODE_KEY}`);
41
+ });
42
+
43
+ it("uses the imported config when none was injected", async () => {
44
+ await loadSSRVuelessConfig(async () => ({ default: { cookiePrefix: "from-file" } }));
45
+
46
+ expect(getThemeCookieName(COLOR_MODE_KEY)).toBe(`from-file-${COLOR_MODE_KEY}`);
47
+ });
48
+ });
package/utils/ui.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { merge } from "lodash-es";
2
- import { defineConfig } from "cva";
2
+ import { cx as cvaCx } from "cva";
3
+ import { defineConfig } from "cva/config";
3
4
  import { extendTailwindMerge } from "tailwind-merge";
4
5
 
5
6
  import { isCSR, isSSR } from "./helper";
@@ -7,6 +8,7 @@ import { createGetMergedConfig } from "./node/mergeConfigs";
7
8
  import { COMPONENT_NAME as U_ICON } from "../ui.image-icon/constants";
8
9
  import { ICON_NON_PROPS_DEFAULTS, TAILWIND_MERGE_EXTENSION } from "../constants";
9
10
 
11
+ import type { CVAVariantShape } from "cva";
10
12
  import type {
11
13
  Config,
12
14
  UnknownObject,
@@ -46,17 +48,22 @@ if (isCSR) {
46
48
  )[0] || {};
47
49
  }
48
50
 
49
- if (isSSR) {
50
- (async () => {
51
- try {
52
- // @ts-expect-error: vueless.config.{js,ts} is optional
53
- vuelessConfig = (await import(/* @vite-ignore */ "/vueless.config")).default;
54
- } catch {
55
- vuelessConfig = {};
56
- }
57
- })();
51
+ /** Load Vueless config on the server; a config injected via `createVueless` meanwhile wins. */
52
+ export async function loadSSRVuelessConfig(
53
+ // @ts-expect-error: vueless.config.{js,ts} is optional
54
+ importConfig = () => import(/* @vite-ignore */ "/vueless.config"),
55
+ ) {
56
+ try {
57
+ const { default: config } = await importConfig();
58
+
59
+ if (!Object.keys(vuelessConfig).length) vuelessConfig = config;
60
+ } catch {
61
+ /* No config file: keep the current config. */
62
+ }
58
63
  }
59
64
 
65
+ if (isSSR) loadSSRVuelessConfig();
66
+
60
67
  /**
61
68
  * Extend twMerge (tailwind merge) by vueless and user config:
62
69
  */
@@ -75,6 +82,7 @@ export const {
75
82
  compose,
76
83
  cva: classVarianceAuthority,
77
84
  } = defineConfig({
85
+ cx: cvaCx,
78
86
  hooks: {
79
87
  onComplete: (classNames) => twMerge(classNames),
80
88
  },
@@ -83,7 +91,12 @@ export const {
83
91
  export const getMergedConfig = createGetMergedConfig(cx) as GetMergedConfig;
84
92
 
85
93
  /* This allows skipping some CVA config keys in vueless config. */
86
- export const cva = ({ base = "", variants = {}, compoundVariants = [], defaultVariants = {} }) =>
94
+ export const cva = ({
95
+ base = "",
96
+ variants = {} as CVAVariantShape,
97
+ compoundVariants = [],
98
+ defaultVariants = {},
99
+ }) =>
87
100
  classVarianceAuthority({
88
101
  base,
89
102
  variants,