@ecolovo/uniapp-components 2.0.7 → 2.0.9

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.
Files changed (151) hide show
  1. package/components/badge/badge.vue +2 -2
  2. package/components/badge/types.d.ts +0 -2
  3. package/components/badge/types.js +1 -4
  4. package/components/badge/types.ts +0 -6
  5. package/components/button/button.vue +2 -2
  6. package/components/button/types.d.ts +0 -2
  7. package/components/button/types.js +1 -4
  8. package/components/button/types.ts +0 -6
  9. package/components/checkbox/checkbox.vue +2 -2
  10. package/components/checkbox/types.d.ts +0 -2
  11. package/components/checkbox/types.js +1 -4
  12. package/components/checkbox/types.ts +0 -8
  13. package/components/checkbox-group/checkbox-group.vue +2 -2
  14. package/components/checkbox-group/types.d.ts +0 -2
  15. package/components/checkbox-group/types.js +1 -8
  16. package/components/checkbox-group/types.ts +0 -12
  17. package/components/checkbox-group2/checkbox-group2.vue +2 -2
  18. package/components/date-picker/date-picker.vue +2 -2
  19. package/components/date-picker/types.d.ts +0 -2
  20. package/components/date-picker/types.js +1 -4
  21. package/components/date-picker/types.ts +0 -8
  22. package/components/dialog/dialog.vue +2 -2
  23. package/components/dialog/types.d.ts +0 -2
  24. package/components/dialog/types.js +1 -4
  25. package/components/dialog/types.ts +0 -6
  26. package/components/dropdown/dropdown.vue +2 -2
  27. package/components/dropdown/types.d.ts +0 -2
  28. package/components/dropdown/types.js +1 -4
  29. package/components/dropdown/types.ts +0 -8
  30. package/components/empty/empty.vue +2 -2
  31. package/components/empty/types.d.ts +0 -2
  32. package/components/empty/types.js +1 -9
  33. package/components/empty/types.ts +0 -11
  34. package/components/flex/flex.vue +2 -2
  35. package/components/flex/types.d.ts +0 -2
  36. package/components/flex/types.js +1 -4
  37. package/components/flex/types.ts +0 -6
  38. package/components/form/form.vue +2 -2
  39. package/components/form/types.d.ts +0 -2
  40. package/components/form/types.js +1 -4
  41. package/components/form/types.ts +0 -6
  42. package/components/form-item/form-item.vue +2 -2
  43. package/components/form-item/types.d.ts +0 -2
  44. package/components/form-item/types.js +1 -4
  45. package/components/form-item/types.ts +0 -8
  46. package/components/icon/icon.vue +59 -1
  47. package/components/image/image.vue +3 -2
  48. package/components/image/types.d.ts +0 -2
  49. package/components/image/types.js +1 -4
  50. package/components/image/types.ts +0 -6
  51. package/components/input/input.vue +2 -2
  52. package/components/input/password-input.vue +2 -2
  53. package/components/input/types.d.ts +0 -4
  54. package/components/input/types.js +1 -8
  55. package/components/input/types.ts +0 -14
  56. package/components/list-page/list-page.vue +2 -2
  57. package/components/list-page/types.d.ts +0 -2
  58. package/components/list-page/types.js +1 -4
  59. package/components/list-page/types.ts +0 -8
  60. package/components/load-more/load-more.vue +2 -2
  61. package/components/load-more/types.d.ts +0 -2
  62. package/components/load-more/types.js +1 -4
  63. package/components/load-more/types.ts +0 -8
  64. package/components/loading/loading.vue +2 -2
  65. package/components/loading/types.d.ts +0 -2
  66. package/components/loading/types.js +1 -4
  67. package/components/loading/types.ts +0 -8
  68. package/components/message-box/message-box.vue +2 -2
  69. package/components/message-box/types.d.ts +0 -2
  70. package/components/message-box/types.js +1 -4
  71. package/components/message-box/types.ts +0 -8
  72. package/components/number-dialog/number-dialog.vue +2 -2
  73. package/components/number-dialog/types.d.ts +0 -2
  74. package/components/number-dialog/types.js +1 -4
  75. package/components/number-dialog/types.ts +0 -8
  76. package/components/number-input/number-input.vue +2 -2
  77. package/components/number-input/types.d.ts +0 -2
  78. package/components/number-input/types.js +1 -4
  79. package/components/number-input/types.ts +0 -8
  80. package/components/numpad/numpad.vue +2 -2
  81. package/components/numpad/types.d.ts +0 -2
  82. package/components/numpad/types.js +1 -4
  83. package/components/numpad/types.ts +0 -6
  84. package/components/page/page-header.vue +7 -7
  85. package/components/page/page.vue +2 -2
  86. package/components/page/types.d.ts +0 -4
  87. package/components/page/types.js +1 -8
  88. package/components/page/types.ts +0 -14
  89. package/components/picker/picker.vue +2 -2
  90. package/components/picker/types.d.ts +0 -2
  91. package/components/picker/types.js +1 -4
  92. package/components/picker/types.ts +0 -6
  93. package/components/popover/popover.vue +2 -2
  94. package/components/popover/types.d.ts +0 -2
  95. package/components/popover/types.js +1 -4
  96. package/components/popover/types.ts +0 -8
  97. package/components/popup/popup.vue +2 -2
  98. package/components/popup/types.d.ts +0 -2
  99. package/components/popup/types.js +1 -4
  100. package/components/popup/types.ts +0 -6
  101. package/components/price/price.vue +2 -2
  102. package/components/price/types.d.ts +0 -2
  103. package/components/price/types.js +1 -4
  104. package/components/price/types.ts +0 -6
  105. package/components/search/search.vue +2 -2
  106. package/components/search/types.d.ts +0 -2
  107. package/components/search/types.js +1 -4
  108. package/components/search/types.ts +0 -6
  109. package/components/searching/searching.vue +2 -2
  110. package/components/searching/types.d.ts +0 -2
  111. package/components/searching/types.js +1 -4
  112. package/components/searching/types.ts +0 -8
  113. package/components/switch/switch.vue +2 -2
  114. package/components/switch/types.d.ts +0 -2
  115. package/components/switch/types.js +1 -4
  116. package/components/switch/types.ts +0 -6
  117. package/components/tab/tab.vue +2 -2
  118. package/components/tab/types.d.ts +0 -2
  119. package/components/tab/types.js +1 -4
  120. package/components/tab/types.ts +0 -6
  121. package/components/textarea/textarea.vue +2 -2
  122. package/components/textarea/types.d.ts +0 -2
  123. package/components/textarea/types.js +1 -4
  124. package/components/textarea/types.ts +0 -8
  125. package/components/upload/media-upload.vue +4 -3
  126. package/components/upload/types.d.ts +0 -2
  127. package/components/upload/types.js +1 -4
  128. package/components/upload/types.ts +0 -8
  129. package/composable/component-name.js +2 -2
  130. package/composable/component-name.ts +2 -2
  131. package/composable/message-box.d.ts +2 -2
  132. package/composable/message-box.js +6 -6
  133. package/composable/message-box.ts +14 -8
  134. package/composable/page.js +2 -2
  135. package/composable/page.ts +2 -2
  136. package/configs/index.d.ts +9 -45
  137. package/configs/index.js +9 -70
  138. package/configs/index.ts +9 -103
  139. package/globals.d.ts +8 -0
  140. package/globals.ts +7 -0
  141. package/index.d.ts +0 -1
  142. package/index.js +0 -1
  143. package/index.ts +0 -1
  144. package/package.json +1 -1
  145. package/styles/global.scss +3 -0
  146. package/vite.d.ts +22 -0
  147. package/vite.js +68 -0
  148. package/vite.ts +107 -0
  149. package/init.d.ts +0 -21
  150. package/init.js +0 -91
  151. package/init.ts +0 -119
package/configs/index.js CHANGED
@@ -1,73 +1,12 @@
1
- import defaultIconfonts from '../resources/iconfont/uniapp_ui_icon/iconfont.json';
2
1
  /** 组件前缀 */
3
- let componentPrefix = 'app';
2
+ export const EC_COMPONENT_PREFIX = 'app';
4
3
  /** 首页路径 */
5
- let homePath = '/pages/index/index';
4
+ export const EC_HOME_PATH = '/pages/index/index';
5
+ /** iconFont json 文件列表 */
6
+ export const EC_ICON_FONT = [];
7
+ /** 是否使用内部 iconFont */
8
+ export const EC_USE_INNER_ICON = true;
6
9
  /** tabbar 列表 */
7
- let tabbarList = [];
8
- /**
9
- * 设置组件前缀
10
- *
11
- * @param prefix 组件前缀
12
- */
13
- function setComponentPrefix(prefix = 'app') {
14
- if (!prefix)
15
- throw new Error('组件前缀不能为空');
16
- componentPrefix = prefix;
17
- }
18
- /**
19
- * 设置首页路径
20
- *
21
- * @param path 首页路径
22
- */
23
- function setHomePath(path = '/pages/index/index') {
24
- if (!path)
25
- throw new Error('app 首页不能为空');
26
- homePath = path;
27
- }
28
- /**
29
- * 设置 tabbar 列表
30
- *
31
- * @param list tabbar 列表
32
- */
33
- function setTabbarList(list = []) {
34
- if (!list)
35
- throw new Error('tabbar 列表不能为空');
36
- tabbarList = list;
37
- }
38
- /** iconfont 图标 map */
39
- const iconMap = new Map();
40
- /**
41
- * 添加单个图标
42
- *
43
- * @param fontFamily 字体文件名
44
- * @param prefix 图标前缀
45
- * @param name 图标名称
46
- */
47
- function addIconToMap(fontFamily, prefix, name) {
48
- if (iconMap.has(name)) {
49
- // eslint-disable-next-line no-console
50
- console.warn(`图标库 "${fontFamily}" 中的图标 "${name}" 在图标库 "${iconMap.get(name).fontFamily}" 中已存在,新的图标将会覆盖已存在的同名图标`);
51
- }
52
- iconMap.set(name, {
53
- fontFamily,
54
- prefix,
55
- name,
56
- });
57
- }
58
- /**
59
- * 添加一组图标,传入 iconfont.json 文件内容
60
- *
61
- * @param iconJson iconfont.json 文件内容
62
- */
63
- function addIcons(iconJson) {
64
- const fontFamily = iconJson.font_family;
65
- const prefix = iconJson.css_prefix_text;
66
- const glyphs = iconJson.glyphs;
67
- glyphs.forEach((glyph) => {
68
- addIconToMap(fontFamily, prefix, glyph.font_class);
69
- });
70
- }
71
- // 添加内部图标库
72
- addIcons(defaultIconfonts);
73
- export { componentPrefix, homePath, tabbarList, setComponentPrefix, setHomePath, setTabbarList, iconMap, addIcons, };
10
+ export const EC_TABBAR_LIST = [];
11
+ /** 组件默认属性配置 */
12
+ export const EC_DEFAULT_PROPS = {};
package/configs/index.ts CHANGED
@@ -1,108 +1,14 @@
1
- import defaultIconfonts from '../resources/iconfont/uniapp_ui_icon/iconfont.json';
2
1
  import type { TabBarItem } from '@ecolovo/utils';
3
2
 
4
3
  /** 组件前缀 */
5
- let componentPrefix = 'app';
4
+ export const EC_COMPONENT_PREFIX = 'app';
6
5
  /** 首页路径 */
7
- let homePath = '/pages/index/index';
6
+ export const EC_HOME_PATH = '/pages/index/index';
7
+ /** iconFont json 文件列表 */
8
+ export const EC_ICON_FONT: IconFontJson[] = [];
9
+ /** 是否使用内部 iconFont */
10
+ export const EC_USE_INNER_ICON = true;
8
11
  /** tabbar 列表 */
9
- let tabbarList: TabBarItem[] = [];
10
-
11
- /**
12
- * 设置组件前缀
13
- *
14
- * @param prefix 组件前缀
15
- */
16
- function setComponentPrefix(prefix: string = 'app') {
17
- if (!prefix) throw new Error('组件前缀不能为空');
18
- componentPrefix = prefix;
19
- }
20
-
21
- /**
22
- * 设置首页路径
23
- *
24
- * @param path 首页路径
25
- */
26
- function setHomePath(path: string = '/pages/index/index') {
27
- if (!path) throw new Error('app 首页不能为空');
28
- homePath = path;
29
- }
30
-
31
- /**
32
- * 设置 tabbar 列表
33
- *
34
- * @param list tabbar 列表
35
- */
36
- function setTabbarList(list: TabBarItem[] = []) {
37
- if (!list) throw new Error('tabbar 列表不能为空');
38
- tabbarList = list;
39
- }
40
-
41
- interface IconInfo {
42
- /** 字体文件名 */
43
- fontFamily: string;
44
- /** 图标前缀 */
45
- prefix: string;
46
- /** 图标名称 */
47
- name: string;
48
- }
49
-
50
- /** iconfont 图标 map */
51
- const iconMap: Map<string, IconInfo> = new Map();
52
-
53
- /**
54
- * 添加单个图标
55
- *
56
- * @param fontFamily 字体文件名
57
- * @param prefix 图标前缀
58
- * @param name 图标名称
59
- */
60
- function addIconToMap(fontFamily: string, prefix: string, name: string) {
61
- if (iconMap.has(name)) {
62
- // eslint-disable-next-line no-console
63
- console.warn(
64
- `图标库 "${fontFamily}" 中的图标 "${name}" 在图标库 "${
65
- iconMap.get(name)!.fontFamily
66
- }" 中已存在,新的图标将会覆盖已存在的同名图标`
67
- );
68
- }
69
- iconMap.set(name, {
70
- fontFamily,
71
- prefix,
72
- name,
73
- });
74
- }
75
-
76
- export interface IconFontJson {
77
- font_family: string;
78
- css_prefix_text: string;
79
- glyphs: { font_class: string }[];
80
- }
81
-
82
- /**
83
- * 添加一组图标,传入 iconfont.json 文件内容
84
- *
85
- * @param iconJson iconfont.json 文件内容
86
- */
87
- function addIcons(iconJson: IconFontJson) {
88
- const fontFamily = iconJson.font_family;
89
- const prefix = iconJson.css_prefix_text;
90
- const glyphs = iconJson.glyphs;
91
- glyphs.forEach((glyph) => {
92
- addIconToMap(fontFamily, prefix, glyph.font_class);
93
- });
94
- }
95
-
96
- // 添加内部图标库
97
- addIcons(defaultIconfonts);
98
-
99
- export {
100
- componentPrefix,
101
- homePath,
102
- tabbarList,
103
- setComponentPrefix,
104
- setHomePath,
105
- setTabbarList,
106
- iconMap,
107
- addIcons,
108
- };
12
+ export const EC_TABBAR_LIST: TabBarItem[] = [];
13
+ /** 组件默认属性配置 */
14
+ export const EC_DEFAULT_PROPS: ComponentsProps = {};
package/globals.d.ts CHANGED
@@ -21,6 +21,14 @@ declare global {
21
21
  deltaY: number;
22
22
  };
23
23
  }
24
+ /** iconFont Json 文件内容 */
25
+ interface IconFontJson {
26
+ font_family: string;
27
+ css_prefix_text: string;
28
+ glyphs: {
29
+ font_class: string;
30
+ }[];
31
+ }
24
32
  namespace UniApp {
25
33
  type EventWithDetail<T extends Record<string, any>> = {
26
34
  detail: T;
package/globals.ts CHANGED
@@ -25,6 +25,13 @@ declare global {
25
25
  };
26
26
  }
27
27
 
28
+ /** iconFont Json 文件内容 */
29
+ interface IconFontJson {
30
+ font_family: string;
31
+ css_prefix_text: string;
32
+ glyphs: { font_class: string }[];
33
+ }
34
+
28
35
  // eslint-disable-next-line @typescript-eslint/no-namespace
29
36
  namespace UniApp {
30
37
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
package/index.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  export * from './globals';
2
- export { default as init } from './init';
3
2
  export { default as componentEasyCom } from './easyCom';
4
3
  export * from './composable';
5
4
  export type { ImageProps } from './components/image/types';
package/index.js CHANGED
@@ -1,5 +1,4 @@
1
1
  export * from './globals';
2
- export { default as init } from './init';
3
2
  export { default as componentEasyCom } from './easyCom';
4
3
  export * from './composable';
5
4
  export * from './components/message-box/message-box';
package/index.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  export * from './globals';
2
- export { default as init } from './init';
3
2
  export { default as componentEasyCom } from './easyCom';
4
3
 
5
4
  export * from './composable';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ecolovo/uniapp-components",
3
- "version": "2.0.7",
3
+ "version": "2.0.9",
4
4
  "description": "Ecolovo UniApp Vue3 组件库",
5
5
  "keywords": [
6
6
  "components",
@@ -101,6 +101,9 @@ page {
101
101
  }
102
102
 
103
103
  // flex
104
+ .flexible {
105
+ display: flex;
106
+ }
104
107
  .flex-1 {
105
108
  flex: 1;
106
109
  }
package/vite.d.ts ADDED
@@ -0,0 +1,22 @@
1
+ import type { Plugin } from 'vite';
2
+ import type { TabBarItem } from '@ecolovo/utils';
3
+ export interface ComponentsConfigs {
4
+ /** 组件前缀,默认为 'app' */
5
+ prefix?: string;
6
+ /** 首页路径 */
7
+ homePath?: string;
8
+ /** iconFont json 文件列表 */
9
+ iconFonts?: IconFontJson[];
10
+ /** 是否使用内部 iconFont */
11
+ useInnerIcon?: boolean;
12
+ /** tabbar 页面列表 */
13
+ tabbarList?: TabBarItem[];
14
+ /** 组件默认参数配置 */
15
+ componentsProps?: ComponentsProps;
16
+ }
17
+ /**
18
+ * 覆盖 @ecolovo/uniapp-components 库中 configs/index 导出变量的默认值。
19
+ * 原理:在 load 阶段拦截库的 configs/index 源码,将 `export const xxx = 默认值;`
20
+ * 中的默认值替换为插件配置的字面量,不修改库源文件本身。
21
+ */
22
+ export default function configComponents(options?: ComponentsConfigs): Plugin;
package/vite.js ADDED
@@ -0,0 +1,68 @@
1
+ import fs from 'node:fs';
2
+ const configKeys = {
3
+ prefix: 'EC_COMPONENT_PREFIX',
4
+ homePath: 'EC_HOME_PATH',
5
+ iconFonts: 'EC_ICON_FONT',
6
+ useInnerIcon: 'EC_USE_INNER_ICON',
7
+ tabbarList: 'EC_TABBAR_LIST',
8
+ componentsProps: 'EC_DEFAULT_PROPS',
9
+ };
10
+ /**
11
+ * 匹配 uniapp-components 库中的 configs/index 入口文件(.ts / .js 两种产物)
12
+ */
13
+ const CONFIGS_INDEX_RE = /@ecolovo[\\/]uniapp-components[\\/]configs[\\/]index\.([cm]?[jt]s)$/;
14
+ /** 将配置值序列化为合法的 JS 表达式 */
15
+ function serializeValue(value) {
16
+ return JSON.stringify(value, null, '\t');
17
+ }
18
+ /**
19
+ * 覆盖 @ecolovo/uniapp-components 库中 configs/index 导出变量的默认值。
20
+ * 原理:在 load 阶段拦截库的 configs/index 源码,将 `export const xxx = 默认值;`
21
+ * 中的默认值替换为插件配置的字面量,不修改库源文件本身。
22
+ */
23
+ export default function configComponents(options = {}) {
24
+ // 转换结果缓存(key: 文件路径)
25
+ const cache = new Map();
26
+ return {
27
+ name: 'vite-plugin-config-ecolovo-components',
28
+ enforce: 'pre',
29
+ config() {
30
+ return {
31
+ optimizeDeps: {
32
+ // 避免依赖预构建(esbuild)抢先打包该库,确保 load 钩子能拦截到源码
33
+ exclude: ['@ecolovo/uniapp-components'],
34
+ },
35
+ };
36
+ },
37
+ load(id) {
38
+ const file = id.split('?')[0];
39
+ const posixPath = file.replace(/\\/g, '/');
40
+ // 只处理库的 configs/index 运行时源码,跳过类型声明文件
41
+ if (/\.d\.ts$/.test(posixPath) ||
42
+ !CONFIGS_INDEX_RE.test(posixPath)) {
43
+ return null;
44
+ }
45
+ const cached = cache.get(file);
46
+ if (cached !== undefined)
47
+ return cached;
48
+ let result = fs.readFileSync(file, 'utf-8');
49
+ for (const [key, value] of Object.entries(options)) {
50
+ // 值为 undefined 时保留库的默认值
51
+ if (value === undefined)
52
+ continue;
53
+ const realKey = configKeys[key];
54
+ // 匹配 `export const KEY ... = 默认值;`,默认值以语句内首个分号/换行结束
55
+ const re = new RegExp(`(export\\s+(?:const|let|var)\\s+${realKey}\\b[^=]*?=\\s*)([^;\\n]+)(;)`);
56
+ if (!re.test(result)) {
57
+ this.warn(`[default-params] configs/index 中未找到导出变量 ${realKey},已跳过替换`);
58
+ continue;
59
+ }
60
+ result = result.replace(re, (_match, prefix, _old, semi) => {
61
+ return prefix + serializeValue(value) + semi;
62
+ });
63
+ }
64
+ cache.set(file, result);
65
+ return result;
66
+ },
67
+ };
68
+ }
package/vite.ts ADDED
@@ -0,0 +1,107 @@
1
+ import fs from 'node:fs';
2
+ import type { Plugin } from 'vite';
3
+ import type { TabBarItem } from '@ecolovo/utils';
4
+
5
+ export interface ComponentsConfigs {
6
+ /** 组件前缀,默认为 'app' */
7
+ prefix?: string;
8
+ /** 首页路径 */
9
+ homePath?: string;
10
+ /** iconFont json 文件列表 */
11
+ iconFonts?: IconFontJson[];
12
+ /** 是否使用内部 iconFont */
13
+ useInnerIcon?: boolean;
14
+ /** tabbar 页面列表 */
15
+ tabbarList?: TabBarItem[];
16
+ /** 组件默认参数配置 */
17
+ componentsProps?: ComponentsProps;
18
+ }
19
+
20
+ const configKeys = {
21
+ prefix: 'EC_COMPONENT_PREFIX',
22
+ homePath: 'EC_HOME_PATH',
23
+ iconFonts: 'EC_ICON_FONT',
24
+ useInnerIcon: 'EC_USE_INNER_ICON',
25
+ tabbarList: 'EC_TABBAR_LIST',
26
+ componentsProps: 'EC_DEFAULT_PROPS',
27
+ } as const;
28
+
29
+ /**
30
+ * 匹配 uniapp-components 库中的 configs/index 入口文件(.ts / .js 两种产物)
31
+ */
32
+ const CONFIGS_INDEX_RE =
33
+ /@ecolovo[\\/]uniapp-components[\\/]configs[\\/]index\.([cm]?[jt]s)$/;
34
+
35
+ /** 将配置值序列化为合法的 JS 表达式 */
36
+ function serializeValue(value: unknown): string {
37
+ return JSON.stringify(value, null, '\t');
38
+ }
39
+
40
+ /**
41
+ * 覆盖 @ecolovo/uniapp-components 库中 configs/index 导出变量的默认值。
42
+ * 原理:在 load 阶段拦截库的 configs/index 源码,将 `export const xxx = 默认值;`
43
+ * 中的默认值替换为插件配置的字面量,不修改库源文件本身。
44
+ */
45
+ export default function configComponents(
46
+ options: ComponentsConfigs = {}
47
+ ): Plugin {
48
+ // 转换结果缓存(key: 文件路径)
49
+ const cache = new Map<string, string>();
50
+
51
+ return {
52
+ name: 'vite-plugin-config-ecolovo-components',
53
+ enforce: 'pre',
54
+ config() {
55
+ return {
56
+ optimizeDeps: {
57
+ // 避免依赖预构建(esbuild)抢先打包该库,确保 load 钩子能拦截到源码
58
+ exclude: ['@ecolovo/uniapp-components'],
59
+ },
60
+ };
61
+ },
62
+ load(id) {
63
+ const file = id.split('?')[0];
64
+ const posixPath = file.replace(/\\/g, '/');
65
+
66
+ // 只处理库的 configs/index 运行时源码,跳过类型声明文件
67
+ if (
68
+ /\.d\.ts$/.test(posixPath) ||
69
+ !CONFIGS_INDEX_RE.test(posixPath)
70
+ ) {
71
+ return null;
72
+ }
73
+
74
+ const cached = cache.get(file);
75
+ if (cached !== undefined) return cached;
76
+
77
+ let result = fs.readFileSync(file, 'utf-8');
78
+
79
+ for (const [key, value] of Object.entries(options)) {
80
+ // 值为 undefined 时保留库的默认值
81
+ if (value === undefined) continue;
82
+
83
+ const realKey = configKeys[key as keyof typeof configKeys];
84
+
85
+ // 匹配 `export const KEY ... = 默认值;`,默认值以语句内首个分号/换行结束
86
+ const re = new RegExp(
87
+ `(export\\s+(?:const|let|var)\\s+${realKey}\\b[^=]*?=\\s*)([^;\\n]+)(;)`
88
+ );
89
+ if (!re.test(result)) {
90
+ this.warn(
91
+ `[default-params] configs/index 中未找到导出变量 ${realKey},已跳过替换`
92
+ );
93
+ continue;
94
+ }
95
+ result = result.replace(
96
+ re,
97
+ (_match, prefix: string, _old: string, semi: string) => {
98
+ return prefix + serializeValue(value) + semi;
99
+ }
100
+ );
101
+ }
102
+
103
+ cache.set(file, result);
104
+ return result;
105
+ },
106
+ };
107
+ }
package/init.d.ts DELETED
@@ -1,21 +0,0 @@
1
- import type { TabBarItem } from '@ecolovo/utils';
2
- import type { IconFontJson } from './configs';
3
- /** 组件库初始化配置 */
4
- interface InitOptions {
5
- /** 组件前缀 */
6
- componentPrefix?: string;
7
- /** 首页路径 */
8
- homePath?: string;
9
- /** tabbar 页面列表 */
10
- tabbarList?: TabBarItem[];
11
- /** iconfont 图标 json 文件 */
12
- iconfont?: IconFontJson | IconFontJson[];
13
- /** 修改组件库默认配置 */
14
- componentsProps?: ComponentsProps;
15
- }
16
- /**
17
- * 组件库初始化方法,在使用组件库前调用
18
- * @param options 组件库初始化配置
19
- */
20
- declare function init(options?: InitOptions): void;
21
- export default init;
package/init.js DELETED
@@ -1,91 +0,0 @@
1
- import { setComponentPrefix, setHomePath, addIcons, setTabbarList, } from './configs';
2
- import { setDefaultBadgeProps } from './components/badge/types';
3
- import { setDefaultButtonProps } from './components/button/types';
4
- import { setDefaultCheckboxProps } from './components/checkbox/types';
5
- import { setDefaultCheckboxGroupProps } from './components/checkbox-group/types';
6
- import { setDefaultDatePickerProps } from './components/date-picker/types';
7
- import { setDefaultDialogProps } from './components/dialog/types';
8
- import { setDefaultDropdownProps } from './components/dropdown/types';
9
- import { setDefaultEmptyProps } from './components/empty/types';
10
- import { setDefaultFlexProps } from './components/flex/types';
11
- import { setDefaultFormProps } from './components/form/types';
12
- import { setDefaultFormItemProps } from './components/form-item/types';
13
- import { setDefaultImageProps } from './components/image/types';
14
- import { setDefaultInputProps, setDefaultPasswordInputProps, } from './components/input/types';
15
- import { setDefaultListPageProps } from './components/list-page/types';
16
- import { setDefaultLoadMoreProps } from './components/load-more/types';
17
- import { setDefaultLoadingProps } from './components/loading/types';
18
- import { setDefaultMessageBoxProps } from './components/message-box/types';
19
- import { setDefaultNumberDialogProps } from './components/number-dialog/types';
20
- import { setDefaultNumberInputProps } from './components/number-input/types';
21
- import { setDefaultNumpadProps } from './components/numpad/types';
22
- import { setDefaultPageProps, setDefaultPageHeaderProps, } from './components/page/types';
23
- import { setDefaultPickerProps } from './components/picker/types';
24
- import { setDefaultPopoverProps } from './components/popover/types';
25
- import { setDefaultPopupProps } from './components/popup/types';
26
- import { setDefaultPriceProps } from './components/price/types';
27
- import { setDefaultSearchProps } from './components/search/types';
28
- import { setDefaultSearchingProps } from './components/searching/types';
29
- import { setDefaultSwitchProps } from './components/switch/types';
30
- import { setDefaultTabProps } from './components/tab/types';
31
- import { setDefaultTextareaProps } from './components/textarea/types';
32
- import { setDefaultMediaUploadProps } from './components/upload/types';
33
- /**
34
- * 组件库初始化方法,在使用组件库前调用
35
- * @param options 组件库初始化配置
36
- */
37
- function init(options = {}) {
38
- if (options.componentPrefix) {
39
- setComponentPrefix(options.componentPrefix);
40
- }
41
- if (options.homePath) {
42
- setHomePath(options.homePath);
43
- }
44
- if (options.tabbarList) {
45
- setTabbarList(options.tabbarList);
46
- }
47
- if (options.iconfont) {
48
- if (Array.isArray(options.iconfont)) {
49
- options.iconfont.forEach(addIcons);
50
- }
51
- else {
52
- addIcons(options.iconfont);
53
- }
54
- }
55
- if (options.componentsProps) {
56
- setDefaultBadgeProps(options.componentsProps.badge);
57
- setDefaultButtonProps(options.componentsProps.button);
58
- setDefaultCheckboxProps(options.componentsProps.checkbox);
59
- setDefaultCheckboxGroupProps(options.componentsProps.checkboxGroup);
60
- setDefaultDatePickerProps(options.componentsProps.datePicker);
61
- setDefaultDialogProps(options.componentsProps.dialog);
62
- setDefaultDropdownProps(options.componentsProps.dropdown);
63
- setDefaultEmptyProps(options.componentsProps.empty);
64
- setDefaultFlexProps(options.componentsProps.flex);
65
- setDefaultFormProps(options.componentsProps.form);
66
- setDefaultFormItemProps(options.componentsProps.formItem);
67
- setDefaultImageProps(options.componentsProps.image);
68
- setDefaultInputProps(options.componentsProps.input);
69
- setDefaultPasswordInputProps(options.componentsProps.passwordInput);
70
- setDefaultListPageProps(options.componentsProps.listPage);
71
- setDefaultLoadMoreProps(options.componentsProps.loadMore);
72
- setDefaultLoadingProps(options.componentsProps.loading);
73
- setDefaultMessageBoxProps(options.componentsProps.messageBox);
74
- setDefaultNumberDialogProps(options.componentsProps.numberDialog);
75
- setDefaultNumberInputProps(options.componentsProps.numberInput);
76
- setDefaultNumpadProps(options.componentsProps.numpad);
77
- setDefaultPageProps(options.componentsProps.page);
78
- setDefaultPageHeaderProps(options.componentsProps.pageHeader);
79
- setDefaultPickerProps(options.componentsProps.picker);
80
- setDefaultPopoverProps(options.componentsProps.popover);
81
- setDefaultPopupProps(options.componentsProps.popup);
82
- setDefaultPriceProps(options.componentsProps.price);
83
- setDefaultSearchProps(options.componentsProps.search);
84
- setDefaultSearchingProps(options.componentsProps.searching);
85
- setDefaultSwitchProps(options.componentsProps.switch);
86
- setDefaultTabProps(options.componentsProps.tab);
87
- setDefaultTextareaProps(options.componentsProps.textarea);
88
- setDefaultMediaUploadProps(options.componentsProps.mediaUpload);
89
- }
90
- }
91
- export default init;