yuang-framework-ui-pc 1.1.91 → 1.1.93

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.
@@ -12,7 +12,7 @@ export interface EleAdminResolverOptions {
12
12
  importStyle?: boolean | 'css' | 'sass';
13
13
  }
14
14
  /**
15
- * 按需加载插件(彻底修复undefined路径问题)
15
+ * 按需加载插件:支持所有 Ele/Yu 开头的组件
16
16
  * @param options 参数
17
17
  */
18
18
  export declare function EleAdminResolver(options?: EleAdminResolverOptions): ComponentResolver;
@@ -1,33 +1,22 @@
1
1
  function getSideEffects(path, options) {
2
2
  if (!path) return void 0;
3
- const importStyle = options == null ? void 0 : options.importStyle;
3
+ const importStyle = (options == null ? void 0 : options.importStyle) ?? true;
4
4
  if (!importStyle) {
5
5
  return void 0;
6
6
  }
7
- if (importStyle === "css") {
8
- return `${path}/style/css`;
9
- }
10
- return `${path}/style/index`;
7
+ return importStyle === "css" ? `${path}/style/css` : `${path}/style/index`;
11
8
  }
12
9
  function getStylePath(namePath, packageName, path = "/es") {
13
- const safePath = path || "/es";
14
- if (["", "/es/core", "/lib/core"].includes(safePath)) {
15
- return `${packageName}/es/${namePath}`;
10
+ const safePath = ["", "/es", "/lib", "/es/core", "/lib/core"].includes(path) ? path : "/es";
11
+ if (safePath === "/lib/core") {
12
+ return `${packageName}/lib/${namePath}`;
16
13
  }
17
- const finalPath = safePath.startsWith("/") ? safePath : `/${safePath}`;
18
- return `${packageName}${finalPath}/${namePath}`;
14
+ return `${packageName}/es/${namePath}`;
19
15
  }
20
16
  const componentDependencyMap = {
21
17
  YuFrameworkAttachmentUpload: ["EleUploadList"]
22
- // 可继续添加其他依赖:
23
- // EleTable: ['EleTableColumn'],
24
- // EleForm: ['EleFormItem', 'EleInput']
18
+ // 后续有依赖的组件可继续加:EleTable: ['EleTableColumn']
25
19
  };
26
- const allNeedResolveComponents = /* @__PURE__ */ new Set();
27
- Object.keys(componentDependencyMap).forEach((parent) => allNeedResolveComponents.add(parent));
28
- Object.values(componentDependencyMap).forEach((children) => {
29
- children.forEach((child) => allNeedResolveComponents.add(child));
30
- });
31
20
  function generateComponentResolveConfig(name, options) {
32
21
  const {
33
22
  path = "/es",
@@ -35,31 +24,29 @@ function generateComponentResolveConfig(name, options) {
35
24
  } = options || {};
36
25
  const packageName = "yuang-framework-ui-pc";
37
26
  const namePath = name.replace(/([A-Z])/g, " $1").trim().split(" ").filter(Boolean).join("-").toLowerCase() || name.toLowerCase();
38
- const stylePath = getStylePath(namePath, packageName, path);
27
+ const safePath = path || "/es";
39
28
  let fromPath = "";
40
- if (["", "/es/core", "/lib/core"].includes(path)) {
41
- fromPath = `${packageName}${path || "/es"}`;
29
+ if (["", "/es/core", "/lib/core"].includes(safePath)) {
30
+ fromPath = `${packageName}/${safePath === "/lib/core" ? "lib" : "es"}`;
31
+ } else if (safePath === "/lib") {
32
+ fromPath = `${packageName}/lib/${namePath}/index`;
42
33
  } else {
43
- fromPath = `${packageName}${path.startsWith("/") ? path : "/" + path}/${namePath}/index`;
34
+ fromPath = `${packageName}/es/${namePath}/index`;
35
+ }
36
+ fromPath = fromPath.replace(/undefined/g, "").replace(/\/+/g, "/").replace(/^\/|\/$/g, "");
37
+ if (!fromPath || fromPath === packageName) {
38
+ fromPath = `${packageName}/es/${namePath}`;
44
39
  }
45
- console.log(`[组件解析调试]
46
- 组件名: ${name}
47
- path参数: ${path} (类型: ${typeof path})
48
- namePath: ${namePath}
49
- stylePath: ${stylePath}
50
- fromPath: ${fromPath}
51
- packageName: ${packageName}`);
40
+ const stylePath = getStylePath(namePath, packageName, safePath);
52
41
  const config = {
53
- name: name || "",
54
- // 组件名兜底
55
- from: fromPath || `${packageName}/es`,
56
- // from路径终极兜底
42
+ name: name.trim(),
43
+ // 组件名去空格
44
+ from: fromPath,
45
+ // 核心路径(绝对合法)
57
46
  sideEffects: getSideEffects(stylePath, options)
58
- // 样式路径允许undefined
47
+ // 样式路径(允许undefined
59
48
  };
60
- if (config.from.includes("undefined")) {
61
- console.error(`[严重错误] from路径包含undefined: ${config.from},组件名: ${name}`);
62
- }
49
+ console.log(`[组件解析] ${name} -> 路径: ${config.from},样式: ${config.sideEffects}`);
63
50
  return config;
64
51
  }
65
52
  function EleAdminResolver(options = { path: "/es", exclude: [], importStyle: true }) {
@@ -67,27 +54,16 @@ function EleAdminResolver(options = { path: "/es", exclude: [], importStyle: tru
67
54
  type: "component",
68
55
  resolve: (name) => {
69
56
  const { exclude = [] } = options;
70
- const isMatch = /^(Ele|Yu)/.test(name) && !exclude.includes(name) && allNeedResolveComponents.has(name);
57
+ const isMatch = /^(Ele|Yu)/.test(name) && !exclude.includes(name);
71
58
  console.log(`[匹配校验] 组件名: ${name},是否匹配: ${isMatch}`);
72
- if (isMatch) {
73
- const currentConfig = generateComponentResolveConfig(name, options);
74
- if (currentConfig.from.includes("undefined")) {
75
- console.error(`[当前组件错误] ${name} 的from路径异常: ${currentConfig.from}`);
76
- }
77
- const dependencyList = componentDependencyMap[name];
78
- if (dependencyList && dependencyList.length) {
79
- const dependencyConfigs = dependencyList.map((depName) => {
80
- const depConfig = generateComponentResolveConfig(depName, options);
81
- if (depConfig.from.includes("undefined")) {
82
- console.error(`[依赖组件错误] ${depName} 的from路径异常: ${depConfig.from}`);
83
- }
84
- return depConfig;
85
- });
86
- return [currentConfig, ...dependencyConfigs];
87
- }
88
- return currentConfig;
59
+ if (!isMatch) return void 0;
60
+ const currentConfig = generateComponentResolveConfig(name, options);
61
+ const dependencyList = componentDependencyMap[name];
62
+ if (dependencyList && dependencyList.length) {
63
+ const dependencyConfigs = dependencyList.filter((depName) => !exclude.includes(depName)).map((depName) => generateComponentResolveConfig(depName, options));
64
+ return [currentConfig, ...dependencyConfigs].filter(Boolean);
89
65
  }
90
- return void 0;
66
+ return currentConfig;
91
67
  }
92
68
  };
93
69
  }
@@ -2,34 +2,23 @@
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  function getSideEffects(path, options) {
4
4
  if (!path) return void 0;
5
- const importStyle = options == null ? void 0 : options.importStyle;
5
+ const importStyle = (options == null ? void 0 : options.importStyle) ?? true;
6
6
  if (!importStyle) {
7
7
  return void 0;
8
8
  }
9
- if (importStyle === "css") {
10
- return `${path}/style/css`;
11
- }
12
- return `${path}/style/index`;
9
+ return importStyle === "css" ? `${path}/style/css` : `${path}/style/index`;
13
10
  }
14
11
  function getStylePath(namePath, packageName, path = "/es") {
15
- const safePath = path || "/es";
16
- if (["", "/es/core", "/lib/core"].includes(safePath)) {
17
- return `${packageName}/es/${namePath}`;
12
+ const safePath = ["", "/es", "/lib", "/es/core", "/lib/core"].includes(path) ? path : "/es";
13
+ if (safePath === "/lib/core") {
14
+ return `${packageName}/lib/${namePath}`;
18
15
  }
19
- const finalPath = safePath.startsWith("/") ? safePath : `/${safePath}`;
20
- return `${packageName}${finalPath}/${namePath}`;
16
+ return `${packageName}/es/${namePath}`;
21
17
  }
22
18
  const componentDependencyMap = {
23
19
  YuFrameworkAttachmentUpload: ["EleUploadList"]
24
- // 可继续添加其他依赖:
25
- // EleTable: ['EleTableColumn'],
26
- // EleForm: ['EleFormItem', 'EleInput']
20
+ // 后续有依赖的组件可继续加:EleTable: ['EleTableColumn']
27
21
  };
28
- const allNeedResolveComponents = /* @__PURE__ */ new Set();
29
- Object.keys(componentDependencyMap).forEach((parent) => allNeedResolveComponents.add(parent));
30
- Object.values(componentDependencyMap).forEach((children) => {
31
- children.forEach((child) => allNeedResolveComponents.add(child));
32
- });
33
22
  function generateComponentResolveConfig(name, options) {
34
23
  const {
35
24
  path = "/es",
@@ -37,31 +26,29 @@ function generateComponentResolveConfig(name, options) {
37
26
  } = options || {};
38
27
  const packageName = "yuang-framework-ui-pc";
39
28
  const namePath = name.replace(/([A-Z])/g, " $1").trim().split(" ").filter(Boolean).join("-").toLowerCase() || name.toLowerCase();
40
- const stylePath = getStylePath(namePath, packageName, path);
29
+ const safePath = path || "/es";
41
30
  let fromPath = "";
42
- if (["", "/es/core", "/lib/core"].includes(path)) {
43
- fromPath = `${packageName}${path || "/es"}`;
31
+ if (["", "/es/core", "/lib/core"].includes(safePath)) {
32
+ fromPath = `${packageName}/${safePath === "/lib/core" ? "lib" : "es"}`;
33
+ } else if (safePath === "/lib") {
34
+ fromPath = `${packageName}/lib/${namePath}/index`;
44
35
  } else {
45
- fromPath = `${packageName}${path.startsWith("/") ? path : "/" + path}/${namePath}/index`;
36
+ fromPath = `${packageName}/es/${namePath}/index`;
37
+ }
38
+ fromPath = fromPath.replace(/undefined/g, "").replace(/\/+/g, "/").replace(/^\/|\/$/g, "");
39
+ if (!fromPath || fromPath === packageName) {
40
+ fromPath = `${packageName}/es/${namePath}`;
46
41
  }
47
- console.log(`[组件解析调试]
48
- 组件名: ${name}
49
- path参数: ${path} (类型: ${typeof path})
50
- namePath: ${namePath}
51
- stylePath: ${stylePath}
52
- fromPath: ${fromPath}
53
- packageName: ${packageName}`);
42
+ const stylePath = getStylePath(namePath, packageName, safePath);
54
43
  const config = {
55
- name: name || "",
56
- // 组件名兜底
57
- from: fromPath || `${packageName}/es`,
58
- // from路径终极兜底
44
+ name: name.trim(),
45
+ // 组件名去空格
46
+ from: fromPath,
47
+ // 核心路径(绝对合法)
59
48
  sideEffects: getSideEffects(stylePath, options)
60
- // 样式路径允许undefined
49
+ // 样式路径(允许undefined
61
50
  };
62
- if (config.from.includes("undefined")) {
63
- console.error(`[严重错误] from路径包含undefined: ${config.from},组件名: ${name}`);
64
- }
51
+ console.log(`[组件解析] ${name} -> 路径: ${config.from},样式: ${config.sideEffects}`);
65
52
  return config;
66
53
  }
67
54
  function EleAdminResolver(options = { path: "/es", exclude: [], importStyle: true }) {
@@ -69,27 +56,16 @@ function EleAdminResolver(options = { path: "/es", exclude: [], importStyle: tru
69
56
  type: "component",
70
57
  resolve: (name) => {
71
58
  const { exclude = [] } = options;
72
- const isMatch = /^(Ele|Yu)/.test(name) && !exclude.includes(name) && allNeedResolveComponents.has(name);
59
+ const isMatch = /^(Ele|Yu)/.test(name) && !exclude.includes(name);
73
60
  console.log(`[匹配校验] 组件名: ${name},是否匹配: ${isMatch}`);
74
- if (isMatch) {
75
- const currentConfig = generateComponentResolveConfig(name, options);
76
- if (currentConfig.from.includes("undefined")) {
77
- console.error(`[当前组件错误] ${name} 的from路径异常: ${currentConfig.from}`);
78
- }
79
- const dependencyList = componentDependencyMap[name];
80
- if (dependencyList && dependencyList.length) {
81
- const dependencyConfigs = dependencyList.map((depName) => {
82
- const depConfig = generateComponentResolveConfig(depName, options);
83
- if (depConfig.from.includes("undefined")) {
84
- console.error(`[依赖组件错误] ${depName} 的from路径异常: ${depConfig.from}`);
85
- }
86
- return depConfig;
87
- });
88
- return [currentConfig, ...dependencyConfigs];
89
- }
90
- return currentConfig;
61
+ if (!isMatch) return void 0;
62
+ const currentConfig = generateComponentResolveConfig(name, options);
63
+ const dependencyList = componentDependencyMap[name];
64
+ if (dependencyList && dependencyList.length) {
65
+ const dependencyConfigs = dependencyList.filter((depName) => !exclude.includes(depName)).map((depName) => generateComponentResolveConfig(depName, options));
66
+ return [currentConfig, ...dependencyConfigs].filter(Boolean);
91
67
  }
92
- return void 0;
68
+ return currentConfig;
93
69
  }
94
70
  };
95
71
  }
@@ -12,7 +12,7 @@ export interface EleAdminResolverOptions {
12
12
  importStyle?: boolean | 'css' | 'sass';
13
13
  }
14
14
  /**
15
- * 按需加载插件(彻底修复undefined路径问题)
15
+ * 按需加载插件:支持所有 Ele/Yu 开头的组件
16
16
  * @param options 参数
17
17
  */
18
18
  export declare function EleAdminResolver(options?: EleAdminResolverOptions): ComponentResolver;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yuang-framework-ui-pc",
3
- "version": "1.1.91",
3
+ "version": "1.1.93",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "dev": "vite --host --config vite.global.ts --mode dev",