plain-design 1.0.0-beta.49 → 1.0.0-beta.50

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. package/dist/plain-design.commonjs.min.js +3 -3
  2. package/dist/plain-design.min.js +3 -3
  3. package/dist/report.html +2 -2
  4. package/package.json +1 -1
  5. package/src/packages/components/$file/index.tsx +1 -1
  6. package/src/packages/components/$message/image.service.utils.tsx +2 -2
  7. package/src/packages/components/$object/createObjectService.tsx +3 -3
  8. package/src/packages/components/$upload/createUploadService.tsx +1 -1
  9. package/src/packages/components/Application/theme/theme.ts +1 -1
  10. package/src/packages/components/AutoTable/filter/useTableOption.filter.form.tsx +3 -3
  11. package/src/packages/components/AutoTable/filter/useTableOption.filter.search.tsx +2 -2
  12. package/src/packages/components/AutoTable/setting/useTableOption.setting.all.fitler.tsx +4 -4
  13. package/src/packages/components/AutoTable/setting/useTableOption.setting.cache.tsx +16 -16
  14. package/src/packages/components/AutoTable/setting/useTableOption.setting.config.tsx +11 -11
  15. package/src/packages/components/AutoTable/setting/useTableOption.setting.export.tsx +20 -20
  16. package/src/packages/components/AutoTable/setting/useTableOption.setting.import.tsx +1 -1
  17. package/src/packages/components/AutoTable/setting/useTableOption.setting.senior.filter.tsx +10 -10
  18. package/src/packages/components/AutoTable/setting/useTableOption.setting.senior.sort.tsx +7 -7
  19. package/src/packages/components/AutoTable/setting/useTableOption.setting.tsx +2 -2
  20. package/src/packages/components/AutoTable/use/useTableOption.buttons.tsx +18 -18
  21. package/src/packages/components/AutoTable/use/useTableOption.cache.ts +1 -1
  22. package/src/packages/components/AutoTable/use/useTableOption.check.tsx +1 -1
  23. package/src/packages/components/AutoTable/use/useTableOption.column.popper.tsx +8 -8
  24. package/src/packages/components/AutoTable/use/useTableOption.confirm.tsx +3 -3
  25. package/src/packages/components/AutoTable/use/useTableOption.loading.tsx +1 -1
  26. package/src/packages/components/AutoTable/use/useTableOption.methods.tsx +17 -17
  27. package/src/packages/components/AutoTable/use/useTableOption.pagination.tsx +3 -3
  28. package/src/packages/components/AutoTable/use/useTableOption.sort.ts +5 -5
  29. package/src/packages/components/AutoTable/use/useTableOption.tips.tsx +1 -1
  30. package/src/packages/components/Cascade/createMultipleCascadeRender.tsx +1 -1
  31. package/src/packages/components/Cascade/createSingleCascadeRender.tsx +1 -1
  32. package/src/packages/components/CascadePanel/flat/createCascadeFlatRender.tsx +1 -1
  33. package/src/packages/components/Checkbox/index.tsx +1 -1
  34. package/src/packages/components/CheckboxGroup/index.tsx +2 -2
  35. package/src/packages/components/DatePicker/date.utils.tsx +2 -2
  36. package/src/packages/components/DatePicker/panel/DatePanelDate.tsx +7 -7
  37. package/src/packages/components/DatePicker/panel/DatePanelMonth.tsx +12 -12
  38. package/src/packages/components/Dialog/index.tsx +3 -3
  39. package/src/packages/components/Empty/index.tsx +1 -1
  40. package/src/packages/components/FilterFormMultiple/index.tsx +2 -2
  41. package/src/packages/components/FilterFormSingle/index.tsx +2 -2
  42. package/src/packages/components/FilterService/filter/filter.city.tsx +4 -4
  43. package/src/packages/components/FilterService/filter/filter.date.tsx +4 -4
  44. package/src/packages/components/FilterService/filter/filter.datetime.tsx +2 -2
  45. package/src/packages/components/FilterService/filter/filter.district.tsx +4 -4
  46. package/src/packages/components/FilterService/filter/filter.number.tsx +1 -1
  47. package/src/packages/components/FilterService/filter/filter.province.tsx +4 -4
  48. package/src/packages/components/FilterService/filter/filter.select.tsx +3 -3
  49. package/src/packages/components/FilterService/filter/filter.text.tsx +4 -4
  50. package/src/packages/components/FilterService/filter/fitler.object.tsx +4 -4
  51. package/src/packages/components/FilterService/index.tsx +7 -7
  52. package/src/packages/components/Form/types/any.tsx +6 -6
  53. package/src/packages/components/Form/types/array.tsx +7 -7
  54. package/src/packages/components/Form/types/date.tsx +6 -6
  55. package/src/packages/components/Form/types/email.tsx +1 -1
  56. package/src/packages/components/Form/types/idcard.tsx +1 -1
  57. package/src/packages/components/Form/types/number.tsx +7 -7
  58. package/src/packages/components/Form/types/phone.tsx +1 -1
  59. package/src/packages/components/Form/types/qq.tsx +1 -1
  60. package/src/packages/components/Form/types/string.tsx +7 -7
  61. package/src/packages/components/Formatter/index.tsx +1 -1
  62. package/src/packages/components/Image/index.tsx +3 -3
  63. package/src/packages/components/ImageUploader/index.tsx +2 -2
  64. package/src/packages/components/Object/createObjectRender.multiple.tsx +1 -1
  65. package/src/packages/components/Object/createObjectRender.single.tsx +1 -1
  66. package/src/packages/components/PageThemeUtils/deepmerge.ts +21 -0
  67. package/src/packages/components/PageThemeUtils/index.tsx +108 -53
  68. package/src/packages/components/Pagination/index.tsx +4 -4
  69. package/src/packages/components/Select/SelectPanel.tsx +1 -1
  70. package/src/packages/components/Select/createMultipleSelectRender.tsx +4 -4
  71. package/src/packages/components/Table/editor/PlcAddress.tsx +4 -4
  72. package/src/packages/components/Table/standard/PlcCheck/PlcCheck.multiple.tsx +4 -4
  73. package/src/packages/components/Table/standard/PlcExpand.tsx +2 -2
  74. package/src/packages/components/Table/standard/PlcIndex.tsx +1 -1
  75. package/src/packages/components/Table/standard/PlcOperation/OuterOperation.tsx +1 -1
  76. package/src/packages/components/Table/standard/PlcOperation/PlcOperation.tsx +4 -4
  77. package/src/packages/components/Table/standard/PlcTree/PlcTree.renderNode.tsx +4 -4
  78. package/src/packages/components/Table/table/use/useTableFormEditor.tsx +2 -2
  79. package/src/packages/components/Table/table/use/useTableModifyEditor.tsx +6 -6
  80. package/src/packages/components/ThemeEditor/index.tsx +32 -27
  81. package/src/packages/components/Tree/RenderTreeNode.tsx +1 -1
  82. package/src/packages/components/Upload/index.tsx +12 -12
  83. package/src/packages/components/VirtualTable/index.tsx +1 -1
  84. package/src/packages/components/useDialog/DialogService.tsx +2 -2
  85. package/src/packages/components/useImage/ImageService.tsx +8 -8
  86. package/src/packages/components/useNotice/index.tsx +1 -1
  87. package/src/packages/i18n/i18n.utils.ts +172 -120
  88. package/src/packages/i18n/index.ts +4 -3
  89. package/src/packages/i18n/lang/en-us.ts +4 -3
  90. package/src/packages/i18n/lang/zh-cn.ts +1 -0
@@ -1,164 +1,216 @@
1
- import {computed, reactive} from "plain-design-composition";
2
- import {deepIterateObject} from "../utils/deepIterateObject";
1
+ import {createSyncHooks, reactive} from "plain-design-composition";
2
+ import {ZhCnLocale} from './lang/zh-cn';
3
+ import {deepmerge} from "../components/PageThemeUtils/deepmerge";
3
4
 
4
5
  /**
5
- * 获取对象的属性值访问路径字符串联合类型
6
- * 比如 type A = {
7
- * base:{
8
- * confirm:'确定',
9
- * cancel:'取消',
10
- * },
11
- * date:{
12
- * year:'年',
13
- * month:'月',
14
- * date:'日',
15
- * },
16
- * }
17
- * 得到的联合类型是:'base.confirm'|'base.cancel'|'date.year'|'date.month'|'date.date'
6
+ /**
7
+ * 默认语言为中文
18
8
  * @author 韦胜健
19
- * @date 2022.5.2 11:44
9
+ * @date 2023/10/12 15:14
20
10
  */
21
- export type ObjectAccessPaths<T, Prev extends string = '', K = keyof T> =
22
- K extends keyof T ? (
23
- K extends string ? (
24
- T[K] extends Record<string, any> ? ObjectAccessPaths<T[K], `${Prev}.${K}`> : (
25
- `${Prev}.${K}` extends `.${infer L}` ? L : `${Prev}.${K}`
26
- )
27
- ) : never
28
- ) :
29
- never;
30
- // type A = ObjectAccessPaths<tZhCnLocale>
11
+ const DEFAULT_LANG = 'zh-cn';
31
12
 
32
13
  /**
33
- * 将字符串类型分割为元组类型
34
- * base.select.reverse => ['base','select','reverse']
14
+ * 组件内置中文以及英文
35
15
  * @author 韦胜健
36
- * @date 2022.5.2 11:46
16
+ * @date 2023/10/12 15:14
37
17
  */
38
- type Split<Str extends string, Sep extends string, Prev extends any[] = []> = Str extends `${infer L}${Sep}${infer R}` ? [...Prev, L, ...Split<R, Sep>] : [...Prev, Str]
39
- // type A = Split<'base.select.reverse', '.'>
18
+ const LANGS = {
19
+ [DEFAULT_LANG]: ZhCnLocale,
20
+ };
40
21
 
41
22
  /**
42
- * 通过访问路劲元组类型,得到对象中具体属性值的类型
43
- * AccessObjectValue<A,['base','confirm']> 得到的类型是 `确定`
23
+ * 根据中文解析出来允许访问的编码类型
44
24
  * @author 韦胜健
45
- * @date 2022.5.2 11:48
25
+ * @date 2023/10/12 15:14
46
26
  */
47
- type AccessObjectValue<Obj extends Record<string, any>, Path extends string[]> = Path extends [infer L, ...infer R] ? (
48
- L extends keyof Obj ? (R extends string[] ? AccessObjectValue<Obj[L], R> : never) : never
49
- ) : Obj
50
- // type N = AccessObjectValue<tZhCnLocale, ['base', 'confirm']>
27
+ type iFormat<
28
+ T extends Record<string, any>,
29
+ PREV extends string = '',
30
+ K = keyof T
31
+ > = K extends keyof T
32
+ ? T[K] extends Record<any, any>
33
+ ? iFormat<T[K], K extends string ? (PREV extends '' ? K : `${PREV}.${K}`) : ''>
34
+ : [PREV] extends ['']
35
+ ? K
36
+ : K extends string
37
+ ? `${PREV}.${K}`
38
+ : never
39
+ : never;
51
40
 
52
41
  /**
53
- * 将对象类型转换为平铺属性的对象类型,比如A类型转化为
54
- * {
55
- * "base.confirm":"确定",
56
- * "base.cancel":"取消",
57
- * "base.year":"年",
58
- * "base.month":"月",
59
- * "base.date":"日",
60
- * }
42
+ * 允许访问的编码类型
61
43
  * @author 韦胜健
62
- * @date 2022.5.2 11:49
44
+ * @date 2023/10/12 15:14
63
45
  */
64
- type ObjectMap<T extends Record<string, any>> = { [k in ObjectAccessPaths<T>]: AccessObjectValue<T, Split<k, '.'>> }
65
- // type O = ObjectMap<tZhCnLocale>
66
-
67
- /**
68
- * 联合类型转换为交叉类型(函数重载类型就是交叉类型)
69
- * @author 韦胜健
70
- * @date 2022.5.2 11:50
71
- */
72
- type UnionToIntersection<T> = (T extends any ? ((t: T) => void) : never) extends ((r: infer R) => any) ? R : never
73
-
74
- /**
75
- * 创建i18n对象
76
- * @author 韦胜健
77
- * @date 2022.5.2 10:34
78
- */
79
- export function createI18n<Locale extends Record<string, any>, OM = ObjectMap<Locale>, K extends keyof OM = keyof OM>(defaultLocale: Locale): UnionToIntersection<K extends keyof OM ? ((k: K, params?: Record<string, any>) => { d: <D = unknown>(defaultLang?: D) => OM[K] | D }) : never> & {
80
- setLocale: (locale: any) => void,
81
- setDefaultLocale: (defaultLocale: any) => void,
82
- getLocale: () => Locale,
83
- getDefaultLocale: () => Locale,
84
- } {
46
+ type iStandardLangPath = iFormat<typeof ZhCnLocale>;
85
47
 
48
+ export const i18n = (() => {
86
49
  const state = reactive({
87
- /*当前语言*/
88
- locale: defaultLocale,
89
- /*从当前语言中取不到值得时候,从这个默认语言中取值*/
90
- defaultLocale,
50
+ currentLang: DEFAULT_LANG,
51
+ langs: LANGS as any
91
52
  });
92
53
 
54
+ const hooks = {
55
+ onChangeLang: createSyncHooks<() => void>(),
56
+ onUpdateLangs: createSyncHooks<() => void>()
57
+ };
58
+
93
59
  /**
94
- * 将多层级的对象拍平为一层的对象
60
+ * 使用指定的语言转化编码
95
61
  * @author 韦胜健
96
- * @date 2022.5.2 12:04
62
+ * @date 2023/10/11 9:28
63
+ * @param lang 指定的域名名字
64
+ * @param path 要转换的编码
65
+ * @param options 转换编码时的格式化参数
97
66
  */
98
- const getMapObject = <Obj extends Record<string, any>>(obj: Obj): ObjectMap<Obj> => {
99
- const map = {} as any;
100
- deepIterateObject(obj, (key, value, accessPath) => {
101
- if (typeof value === "string") {
102
- map[accessPath?.join('.')] = value;
103
- }
104
- });
105
- return map;
67
+ const intlWithLang = (lang: string, path: string, options: any): string | undefined => {
68
+ if (!state.langs[lang]) {
69
+ console.log({ langs: state.langs, lang });
70
+ throw new Error(`不存在多语言:${lang}`);
71
+ }
72
+ const array = path.split('.');
73
+ let current = state.langs[lang];
74
+ for (let i = 0, j = array.length; i < j; i++) {
75
+ const property = array[i];
76
+ let value = current[property];
77
+ if (i === j - 1) return !options ? value : formatLang(value, options);
78
+ if (!value) return '';
79
+ current = value;
80
+ }
81
+ return '';
106
82
  };
107
83
 
108
- const map = computed(() => ({
109
- locale: getMapObject(state.locale),
110
- defaultLocale: getMapObject(state.defaultLocale)
111
- }));
112
-
113
84
  /**
114
- * 设置当前语言
85
+ * 使用当前语言转换编码
115
86
  * @author 韦胜健
116
- * @date 2022.5.2 10:33
87
+ * @date 2023/10/11 9:29
117
88
  */
118
- const setLocale = (locale: Locale) => state.locale = locale as any;
89
+ const $t = (path: string, options?: Record<string, any>) => {
90
+ let { currentLang } = state;
91
+ if (!state.langs[currentLang]) {
92
+ currentLang = DEFAULT_LANG;
93
+ }
94
+ const isDefaultLang = currentLang === DEFAULT_LANG;
95
+
96
+ let valString = intlWithLang(currentLang, path, options);
97
+
98
+ if (!valString) {
99
+ if (!isDefaultLang) {
100
+ valString = intlWithLang(DEFAULT_LANG, path, options);
101
+ }
102
+ }
103
+
104
+ return valString;
105
+ };
106
+
119
107
  /**
120
- * 设置默认语言
108
+ * 类似于$t, 可以指定默认展示文本,当多语言配置即使默认语言也没有办法转化这个编码时
121
109
  * @author 韦胜健
122
- * @date 2022.5.2 10:33
110
+ * @date 2023/10/12 15:12
123
111
  */
124
- const setDefaultLocale = (defaultLocale: Locale) => state.defaultLocale = defaultLocale as any;
112
+ const $intl = (path: string, options?: Record<string, any>) => {
113
+ return {
114
+ d: (desc: string) => {
115
+ const valString = $t(path, options);
116
+ if (!!valString) {
117
+ return valString;
118
+ }
119
+ return desc;
120
+ }
121
+ };
122
+ };
123
+
124
+ const $it = (path: iStandardLangPath, options?: Record<string, any>) => {
125
+ return $intl(path, options);
126
+ };
125
127
 
126
128
  /**
127
- * 获取当前语言
129
+ * 应用指定语言
128
130
  * @author 韦胜健
129
- * @date 2024.4.20 8:49
131
+ * @date 2023/10/11 9:29
130
132
  */
131
- const getLocale = () => state.locale;
132
-
133
+ const use = (lang: string, locale: any) => {
134
+ state.currentLang = lang;
135
+ state.langs[lang] = locale;
136
+ hooks.onChangeLang.exec(undefined);
137
+ };
133
138
  /**
134
- * 获取默认语言
139
+ * 切换至指定语言
135
140
  * @author 韦胜健
136
- * @date 2024.4.20 8:49
141
+ * @date 2023/10/11 9:30
137
142
  */
138
- const getDefaultLocale = () => state.defaultLocale;
139
-
143
+ const switchTo = async (lang: string, loadMethod?: () => any) => {
144
+ let locale = !loadMethod ? state.langs[lang] : await loadMethod();
145
+ use(lang, locale);
146
+ };
147
+ /**
148
+ * 获取当前使用的语言
149
+ * @author 韦胜健
150
+ * @date 2023/10/11 9:30
151
+ */
152
+ const getCurrentLanguage = () => {
153
+ return state.currentLang;
154
+ };
140
155
  /**
141
- * 取值
156
+ * 设置语言
142
157
  * @author 韦胜健
143
- * @date 2022.5.2 10:33
158
+ * @date 2023/10/11 9:30
144
159
  */
145
- const getter = (path: string, params?: Record<string, any>) => {
146
- let value = (map.value.locale as any)[path];
147
- if (!value) {
148
- value = (map.value.defaultLocale as any)[path];
160
+ const setLangs = (langs: any) => {
161
+ state.langs = deepmerge(state.langs, langs);
162
+ hooks.onUpdateLangs.exec(undefined);
163
+ };
164
+
165
+ return {
166
+ $t,
167
+ $intl,
168
+ $it,
169
+ use,
170
+ switchTo,
171
+ getCurrentLanguage,
172
+ setLangs,
173
+ DEFAULT_LANG,
174
+ state,
175
+ hooks,
176
+ };
177
+ })();
178
+
179
+ const formatLang = (() => {
180
+ const hasOwnProperty = Object.prototype.hasOwnProperty;
181
+
182
+ function hasOwn(obj: any, key: string) {
183
+ return hasOwnProperty.call(obj, key);
184
+ }
185
+
186
+ const RE_NARGS = /(%|)\{([0-9a-zA-Z_]+)\}/g;
187
+
188
+ const format = (string: string | null | undefined, ...args: any) => {
189
+ if (string == null || string.length === 0) {
190
+ return null;
149
191
  }
150
- return {
151
- d: (defaultString: string) => {
152
- if (!!value) {
153
- if (/\{.+\}/.test(value)) {
154
- value = (value as string).replace(/\{(.+?)\}/, (input, group1) => params?.[group1]);
155
- }
156
- return value;
192
+ if (args.length === 1 && typeof args[0] === 'object') {
193
+ args = args[0];
194
+ }
195
+
196
+ if (!args || !args.hasOwnProperty) {
197
+ args = {};
198
+ }
199
+
200
+ return string.replace(RE_NARGS, (match, prefix, i, index) => {
201
+ let result;
202
+
203
+ if (string[index - 1] === '{' && string[index + match.length] === '}') {
204
+ return i;
205
+ } else {
206
+ result = hasOwn(args, i) ? args[i] : null;
207
+ if (result === null || result === undefined) {
208
+ return '';
157
209
  }
158
- return defaultString || '';
159
- },
160
- };
161
- };
162
210
 
163
- return Object.assign(getter, { setLocale, setDefaultLocale, getLocale, getDefaultLocale }) as any;
164
- }
211
+ return result;
212
+ }
213
+ });
214
+ };
215
+ return format;
216
+ })();
@@ -1,4 +1,5 @@
1
- import {createI18n} from "./i18n.utils";
2
- import {ZhCnLocale} from "./lang/zh-cn";
1
+ import {i18n} from './i18n.utils';
3
2
 
4
- export const i18n = createI18n(ZhCnLocale);
3
+ export default i18n;
4
+
5
+ export {i18n};
@@ -190,10 +190,11 @@ export const EnUsLocale: tZhCnLocale = {
190
190
  alignLeft: 'left',
191
191
  alignCenter: 'center',
192
192
  alignRight: 'right',
193
- exportCurrentPageData: 'export current page data',
194
- exportDataInTable: 'export data showed in table',
193
+ exportCurrentPageData: 'Export current page data',
194
+ exportDataInTable: 'Export data showed in table',
195
+ exportCurrentAllData: 'Export current all data',
195
196
  exportAllDataWithFilterSortMaybeFailedWithLargeData: 'export all data by sort and filter condition(maybe failed with latge data)',
196
- selectDataToExport: 'select data to export',
197
+ selectDataToExport: 'Select data to export',
197
198
  customSelectDataToExport: 'custom select data to export',
198
199
  selectExportType: 'select export type',
199
200
  selectExportFields: 'select export fields',
@@ -190,6 +190,7 @@ export const ZhCnLocale = {
190
190
  alignRight: '右对齐',
191
191
  exportCurrentPageData: '导出当前页数据',
192
192
  exportDataInTable: '导出表格当前显示的数据',
193
+ exportCurrentAllData: '导出当前所有数据',
193
194
  exportAllDataWithFilterSortMaybeFailedWithLargeData: '根据当前的筛选排序条件导出所有数据(数据量比较大的话可能会导出失败)',
194
195
  selectDataToExport: '选择需要导出的数据',
195
196
  customSelectDataToExport: '自定义选择导出需要的数据',