@tdh-ui/unplugin-resolver 1.0.3 → 1.0.5

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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2020-PRESENT TDH Base UI
3
+ Copyright (c) 2020-PRESENT TDH UI Base
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/dist/index.cjs CHANGED
@@ -41,11 +41,7 @@ function resolveDirective(name, options) {
41
41
  if (!options.directives) return;
42
42
  const directives = {
43
43
  Loading: { importName: "ElLoadingDirective", styleName: "loading" },
44
- Popover: { importName: "ElPopoverDirective", styleName: "popover" },
45
- InfiniteScroll: {
46
- importName: "ElInfiniteScroll",
47
- styleName: "infinite-scroll"
48
- }
44
+ Popover: { importName: "ElPopoverDirective", styleName: "popover" }
49
45
  };
50
46
  const directive = directives[name];
51
47
  if (!directive) return;
@@ -89,5 +85,66 @@ function TdhBaseUIResolver(options = {}) {
89
85
  }
90
86
  ];
91
87
  }
88
+ function getBizSideEffects(dirName, options) {
89
+ const { importStyle, ssr } = options;
90
+ const themeFolder = "@tdh-ui/biz/theme-chalk";
91
+ const esComponentsFolder = `@tdh-ui/biz/${ssr ? "lib" : "es"}/components`;
92
+ if (importStyle === "sass")
93
+ return ssr ? [`${themeFolder}/src/base.scss`, `${themeFolder}/src/${dirName}.scss`] : [
94
+ `${esComponentsFolder}/base/style/index`,
95
+ `${esComponentsFolder}/${dirName}/style/index`
96
+ ];
97
+ else if (importStyle === true || importStyle === "css")
98
+ return ssr ? [`${themeFolder}/base.css`, `${themeFolder}/el-${dirName}.css`] : [
99
+ `${esComponentsFolder}/base/style/css`,
100
+ `${esComponentsFolder}/${dirName}/style/css`
101
+ ];
102
+ }
103
+ function resolveBizComponent(name, options) {
104
+ if (options.exclude && name.match(options.exclude)) return;
105
+ if (!/^Tdh[A-Z]/.test(name)) return;
106
+ if (/^ElIcon.+/.test(name)) {
107
+ return {
108
+ name: name.replace(/^ElIcon/, ""),
109
+ from: "@element-plus/icons-vue"
110
+ };
111
+ }
112
+ const partialName = kebabCase(name.slice(3));
113
+ const { ssr } = options;
114
+ return {
115
+ name,
116
+ from: `@tdh-ui/biz/${ssr ? "lib" : "es"}`,
117
+ sideEffects: getBizSideEffects(partialName, options)
118
+ };
119
+ }
120
+ const noStylesBizComponents = [];
121
+ function TdhBizUIResolver(options = {}) {
122
+ let optionsResolved;
123
+ async function resolveOptions() {
124
+ if (optionsResolved) return optionsResolved;
125
+ optionsResolved = {
126
+ ssr: false,
127
+ importStyle: "css",
128
+ exclude: void 0,
129
+ noStylesComponents: options.noStylesComponents || [],
130
+ ...options
131
+ };
132
+ return optionsResolved;
133
+ }
134
+ return [
135
+ {
136
+ type: "component",
137
+ resolve: async (name) => {
138
+ const options2 = await resolveOptions();
139
+ if ([...options2.noStylesComponents, ...noStylesBizComponents].includes(
140
+ name
141
+ ))
142
+ return resolveBizComponent(name, { ...options2, importStyle: false });
143
+ else return resolveBizComponent(name, options2);
144
+ }
145
+ }
146
+ ];
147
+ }
92
148
 
93
149
  exports.TdhBaseUIResolver = TdhBaseUIResolver;
150
+ exports.TdhBizUIResolver = TdhBizUIResolver;
package/dist/index.d.cts CHANGED
@@ -27,7 +27,7 @@ interface TdhBaseUIResolverOptions {
27
27
  noStylesComponents?: string[];
28
28
  }
29
29
  /**
30
- * Resolver for TDH Base UI
30
+ * Resolver for TDH UI Base
31
31
  *
32
32
  * See https://github.com/antfu/vite-plugin-components/pull/28 for more details
33
33
  * See https://github.com/antfu/vite-plugin-components/issues/117 for more details
@@ -37,6 +37,30 @@ interface TdhBaseUIResolverOptions {
37
37
  *
38
38
  */
39
39
  declare function TdhBaseUIResolver(options?: TdhBaseUIResolverOptions): ComponentResolver[];
40
+ interface TdhBizUIResolverOptions {
41
+ /**
42
+ * import style css or sass with components
43
+ *
44
+ * @default 'css'
45
+ */
46
+ importStyle?: boolean | 'css' | 'sass';
47
+ /**
48
+ * use commonjs lib & source css or scss for ssr
49
+ */
50
+ ssr?: boolean;
51
+ /**
52
+ * exclude component name, if match do not resolve the name
53
+ */
54
+ exclude?: RegExp;
55
+ /**
56
+ * a list of component names that have no styles, so resolving their styles file should be prevented
57
+ */
58
+ noStylesComponents?: string[];
59
+ }
60
+ /**
61
+ * Resolver for TDH UI Biz
62
+ */
63
+ declare function TdhBizUIResolver(options?: TdhBizUIResolverOptions): ComponentResolver[];
40
64
 
41
- export { TdhBaseUIResolver };
42
- export type { TdhBaseUIResolverOptions };
65
+ export { TdhBaseUIResolver, TdhBizUIResolver };
66
+ export type { TdhBaseUIResolverOptions, TdhBizUIResolverOptions };
package/dist/index.d.mts CHANGED
@@ -27,7 +27,7 @@ interface TdhBaseUIResolverOptions {
27
27
  noStylesComponents?: string[];
28
28
  }
29
29
  /**
30
- * Resolver for TDH Base UI
30
+ * Resolver for TDH UI Base
31
31
  *
32
32
  * See https://github.com/antfu/vite-plugin-components/pull/28 for more details
33
33
  * See https://github.com/antfu/vite-plugin-components/issues/117 for more details
@@ -37,6 +37,30 @@ interface TdhBaseUIResolverOptions {
37
37
  *
38
38
  */
39
39
  declare function TdhBaseUIResolver(options?: TdhBaseUIResolverOptions): ComponentResolver[];
40
+ interface TdhBizUIResolverOptions {
41
+ /**
42
+ * import style css or sass with components
43
+ *
44
+ * @default 'css'
45
+ */
46
+ importStyle?: boolean | 'css' | 'sass';
47
+ /**
48
+ * use commonjs lib & source css or scss for ssr
49
+ */
50
+ ssr?: boolean;
51
+ /**
52
+ * exclude component name, if match do not resolve the name
53
+ */
54
+ exclude?: RegExp;
55
+ /**
56
+ * a list of component names that have no styles, so resolving their styles file should be prevented
57
+ */
58
+ noStylesComponents?: string[];
59
+ }
60
+ /**
61
+ * Resolver for TDH UI Biz
62
+ */
63
+ declare function TdhBizUIResolver(options?: TdhBizUIResolverOptions): ComponentResolver[];
40
64
 
41
- export { TdhBaseUIResolver };
42
- export type { TdhBaseUIResolverOptions };
65
+ export { TdhBaseUIResolver, TdhBizUIResolver };
66
+ export type { TdhBaseUIResolverOptions, TdhBizUIResolverOptions };
package/dist/index.d.ts CHANGED
@@ -27,7 +27,7 @@ interface TdhBaseUIResolverOptions {
27
27
  noStylesComponents?: string[];
28
28
  }
29
29
  /**
30
- * Resolver for TDH Base UI
30
+ * Resolver for TDH UI Base
31
31
  *
32
32
  * See https://github.com/antfu/vite-plugin-components/pull/28 for more details
33
33
  * See https://github.com/antfu/vite-plugin-components/issues/117 for more details
@@ -37,6 +37,30 @@ interface TdhBaseUIResolverOptions {
37
37
  *
38
38
  */
39
39
  declare function TdhBaseUIResolver(options?: TdhBaseUIResolverOptions): ComponentResolver[];
40
+ interface TdhBizUIResolverOptions {
41
+ /**
42
+ * import style css or sass with components
43
+ *
44
+ * @default 'css'
45
+ */
46
+ importStyle?: boolean | 'css' | 'sass';
47
+ /**
48
+ * use commonjs lib & source css or scss for ssr
49
+ */
50
+ ssr?: boolean;
51
+ /**
52
+ * exclude component name, if match do not resolve the name
53
+ */
54
+ exclude?: RegExp;
55
+ /**
56
+ * a list of component names that have no styles, so resolving their styles file should be prevented
57
+ */
58
+ noStylesComponents?: string[];
59
+ }
60
+ /**
61
+ * Resolver for TDH UI Biz
62
+ */
63
+ declare function TdhBizUIResolver(options?: TdhBizUIResolverOptions): ComponentResolver[];
40
64
 
41
- export { TdhBaseUIResolver };
42
- export type { TdhBaseUIResolverOptions };
65
+ export { TdhBaseUIResolver, TdhBizUIResolver };
66
+ export type { TdhBaseUIResolverOptions, TdhBizUIResolverOptions };
package/dist/index.mjs CHANGED
@@ -39,11 +39,7 @@ function resolveDirective(name, options) {
39
39
  if (!options.directives) return;
40
40
  const directives = {
41
41
  Loading: { importName: "ElLoadingDirective", styleName: "loading" },
42
- Popover: { importName: "ElPopoverDirective", styleName: "popover" },
43
- InfiniteScroll: {
44
- importName: "ElInfiniteScroll",
45
- styleName: "infinite-scroll"
46
- }
42
+ Popover: { importName: "ElPopoverDirective", styleName: "popover" }
47
43
  };
48
44
  const directive = directives[name];
49
45
  if (!directive) return;
@@ -87,5 +83,65 @@ function TdhBaseUIResolver(options = {}) {
87
83
  }
88
84
  ];
89
85
  }
86
+ function getBizSideEffects(dirName, options) {
87
+ const { importStyle, ssr } = options;
88
+ const themeFolder = "@tdh-ui/biz/theme-chalk";
89
+ const esComponentsFolder = `@tdh-ui/biz/${ssr ? "lib" : "es"}/components`;
90
+ if (importStyle === "sass")
91
+ return ssr ? [`${themeFolder}/src/base.scss`, `${themeFolder}/src/${dirName}.scss`] : [
92
+ `${esComponentsFolder}/base/style/index`,
93
+ `${esComponentsFolder}/${dirName}/style/index`
94
+ ];
95
+ else if (importStyle === true || importStyle === "css")
96
+ return ssr ? [`${themeFolder}/base.css`, `${themeFolder}/el-${dirName}.css`] : [
97
+ `${esComponentsFolder}/base/style/css`,
98
+ `${esComponentsFolder}/${dirName}/style/css`
99
+ ];
100
+ }
101
+ function resolveBizComponent(name, options) {
102
+ if (options.exclude && name.match(options.exclude)) return;
103
+ if (!/^Tdh[A-Z]/.test(name)) return;
104
+ if (/^ElIcon.+/.test(name)) {
105
+ return {
106
+ name: name.replace(/^ElIcon/, ""),
107
+ from: "@element-plus/icons-vue"
108
+ };
109
+ }
110
+ const partialName = kebabCase(name.slice(3));
111
+ const { ssr } = options;
112
+ return {
113
+ name,
114
+ from: `@tdh-ui/biz/${ssr ? "lib" : "es"}`,
115
+ sideEffects: getBizSideEffects(partialName, options)
116
+ };
117
+ }
118
+ const noStylesBizComponents = [];
119
+ function TdhBizUIResolver(options = {}) {
120
+ let optionsResolved;
121
+ async function resolveOptions() {
122
+ if (optionsResolved) return optionsResolved;
123
+ optionsResolved = {
124
+ ssr: false,
125
+ importStyle: "css",
126
+ exclude: void 0,
127
+ noStylesComponents: options.noStylesComponents || [],
128
+ ...options
129
+ };
130
+ return optionsResolved;
131
+ }
132
+ return [
133
+ {
134
+ type: "component",
135
+ resolve: async (name) => {
136
+ const options2 = await resolveOptions();
137
+ if ([...options2.noStylesComponents, ...noStylesBizComponents].includes(
138
+ name
139
+ ))
140
+ return resolveBizComponent(name, { ...options2, importStyle: false });
141
+ else return resolveBizComponent(name, options2);
142
+ }
143
+ }
144
+ ];
145
+ }
90
146
 
91
- export { TdhBaseUIResolver };
147
+ export { TdhBaseUIResolver, TdhBizUIResolver };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tdh-ui/unplugin-resolver",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "dist"