@veltra/vite 1.0.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.
@@ -0,0 +1,23 @@
1
+ import { ComponentResolver } from "unplugin-vue-components/types";
2
+
3
+ //#region src/resolver.d.ts
4
+ interface VeltraDesktopUIResolverOptions {
5
+ /**
6
+ * Whether to import component styles as side effects.
7
+ * @default true
8
+ */
9
+ importStyle?: boolean;
10
+ }
11
+ /**
12
+ * Resolver for `unplugin-vue-components` that auto-imports `@veltra/desktop`
13
+ * components and their style side effects.
14
+ *
15
+ * Style resolution relies on `@veltra/desktop` package exports conditions:
16
+ * - **development** (Vite dev): resolves to `src/components/<dir>/style.ts`
17
+ * (source SCSS pipeline, full HMR)
18
+ * - **production** (Vite build): resolves to `dist/components/<dir>/style.js`
19
+ * (pre-compiled, CSS already injected)
20
+ */
21
+ declare function VeltraDesktopUIResolver(options?: VeltraDesktopUIResolverOptions): ComponentResolver;
22
+ //#endregion
23
+ export { VeltraDesktopUIResolver, type VeltraDesktopUIResolverOptions };
package/dist/index.mjs ADDED
@@ -0,0 +1,52 @@
1
+ //#region src/resolver.ts
2
+ /**
3
+ * Components that reside in another component's directory and share its style entry.
4
+ *
5
+ * These components don't have their own `style.ts` — they live inside a parent
6
+ * component directory and use the parent's style (e.g. `UButtonGroup` lives in
7
+ * `button/` and uses `button/style.ts`).
8
+ */
9
+ const SHARED_STYLE_DIR = {
10
+ "button-group": "button",
11
+ "action-group": "action",
12
+ "card-header": "card",
13
+ "card-cover": "card",
14
+ "card-content": "card",
15
+ "card-action": "card",
16
+ "checkbox-button": "checkbox",
17
+ "grid-item": "grid",
18
+ "list-item": "list",
19
+ "menu-sub": "menu",
20
+ "menu-item": "menu"
21
+ };
22
+ function pascalToKebab(str) {
23
+ return str.replace(/[A-Z]/g, (char, index) => (index > 0 ? "-" : "") + char.toLowerCase());
24
+ }
25
+ /**
26
+ * Resolver for `unplugin-vue-components` that auto-imports `@veltra/desktop`
27
+ * components and their style side effects.
28
+ *
29
+ * Style resolution relies on `@veltra/desktop` package exports conditions:
30
+ * - **development** (Vite dev): resolves to `src/components/<dir>/style.ts`
31
+ * (source SCSS pipeline, full HMR)
32
+ * - **production** (Vite build): resolves to `dist/components/<dir>/style.js`
33
+ * (pre-compiled, CSS already injected)
34
+ */
35
+ function VeltraDesktopUIResolver(options = {}) {
36
+ const { importStyle = true } = options;
37
+ return {
38
+ type: "component",
39
+ resolve(name) {
40
+ if (!/^U[A-Z]/.test(name)) return;
41
+ const kebabName = pascalToKebab(name.slice(1));
42
+ const styleDir = SHARED_STYLE_DIR[kebabName] ?? kebabName;
43
+ return {
44
+ name,
45
+ from: "@veltra/desktop",
46
+ sideEffects: importStyle ? `@veltra/desktop/components/${styleDir}/style` : void 0
47
+ };
48
+ }
49
+ };
50
+ }
51
+ //#endregion
52
+ export { VeltraDesktopUIResolver };
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "@veltra/vite",
3
+ "version": "1.0.6",
4
+ "description": "Vite helpers for Veltra UI (e.g. unplugin-vue-components resolver for @veltra/desktop)",
5
+ "files": [
6
+ "dist",
7
+ "src"
8
+ ],
9
+ "type": "module",
10
+ "exports": {
11
+ ".": {
12
+ "types": "./dist/index.d.mts",
13
+ "import": "./dist/index.mjs"
14
+ }
15
+ },
16
+ "scripts": {
17
+ "build": "tsdown",
18
+ "check-types": "tsc -p tsconfig.json --noEmit"
19
+ },
20
+ "devDependencies": {
21
+ "@veltra/desktop": "workspace:*"
22
+ },
23
+ "peerDependencies": {
24
+ "@veltra/desktop": "1.0.6",
25
+ "unplugin-vue-components": ">=32.0.0"
26
+ }
27
+ }
package/src/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export { VeltraDesktopUIResolver } from './resolver'
2
+ export type { VeltraDesktopUIResolverOptions } from './resolver'
@@ -0,0 +1,66 @@
1
+ import type { ComponentResolver } from 'unplugin-vue-components/types'
2
+
3
+ export interface VeltraDesktopUIResolverOptions {
4
+ /**
5
+ * Whether to import component styles as side effects.
6
+ * @default true
7
+ */
8
+ importStyle?: boolean
9
+ }
10
+
11
+ /**
12
+ * Components that reside in another component's directory and share its style entry.
13
+ *
14
+ * These components don't have their own `style.ts` — they live inside a parent
15
+ * component directory and use the parent's style (e.g. `UButtonGroup` lives in
16
+ * `button/` and uses `button/style.ts`).
17
+ */
18
+ const SHARED_STYLE_DIR: Record<string, string> = {
19
+ 'button-group': 'button',
20
+ 'action-group': 'action',
21
+ 'card-header': 'card',
22
+ 'card-cover': 'card',
23
+ 'card-content': 'card',
24
+ 'card-action': 'card',
25
+ 'checkbox-button': 'checkbox',
26
+ 'grid-item': 'grid',
27
+ 'list-item': 'list',
28
+ 'menu-sub': 'menu',
29
+ 'menu-item': 'menu'
30
+ }
31
+
32
+ function pascalToKebab(str: string): string {
33
+ return str.replace(/[A-Z]/g, (char, index) => (index > 0 ? '-' : '') + char.toLowerCase())
34
+ }
35
+
36
+ /**
37
+ * Resolver for `unplugin-vue-components` that auto-imports `@veltra/desktop`
38
+ * components and their style side effects.
39
+ *
40
+ * Style resolution relies on `@veltra/desktop` package exports conditions:
41
+ * - **development** (Vite dev): resolves to `src/components/<dir>/style.ts`
42
+ * (source SCSS pipeline, full HMR)
43
+ * - **production** (Vite build): resolves to `dist/components/<dir>/style.js`
44
+ * (pre-compiled, CSS already injected)
45
+ */
46
+ export function VeltraDesktopUIResolver(
47
+ options: VeltraDesktopUIResolverOptions = {}
48
+ ): ComponentResolver {
49
+ const { importStyle = true } = options
50
+
51
+ return {
52
+ type: 'component',
53
+ resolve(name: string) {
54
+ if (!/^U[A-Z]/.test(name)) return
55
+
56
+ const kebabName = pascalToKebab(name.slice(1))
57
+ const styleDir = SHARED_STYLE_DIR[kebabName] ?? kebabName
58
+
59
+ return {
60
+ name,
61
+ from: '@veltra/desktop',
62
+ sideEffects: importStyle ? `@veltra/desktop/components/${styleDir}/style` : undefined
63
+ }
64
+ }
65
+ }
66
+ }