zmdms-utils 0.0.72 → 0.0.74

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 (40) hide show
  1. package/dist/es/crypto.d.ts +3 -0
  2. package/dist/es/crypto.js +4 -0
  3. package/dist/es/locales/i18n.d.ts +15 -0
  4. package/dist/es/locales/t-in-non-react.d.ts +17 -0
  5. package/dist/es/locales/t-options.d.ts +7 -0
  6. package/dist/es/locales/use-translation.d.ts +42 -0
  7. package/dist/es/microAppCreator.d.ts +25 -2
  8. package/dist/es/microAppCreator.js +28 -6
  9. package/dist/es/node_modules/html-parse-stringify/dist/html-parse-stringify.module.js +5 -0
  10. package/dist/es/node_modules/i18next/dist/esm/i18next.js +2242 -0
  11. package/dist/es/node_modules/js-base64/base64.js +273 -0
  12. package/dist/es/node_modules/react-i18next/dist/es/Trans.js +47 -0
  13. package/dist/es/node_modules/react-i18next/dist/es/TransWithoutContext.js +312 -0
  14. package/dist/es/node_modules/react-i18next/dist/es/context.js +18 -0
  15. package/dist/es/node_modules/react-i18next/dist/es/defaults.js +21 -0
  16. package/dist/es/node_modules/react-i18next/dist/es/i18nInstance.js +7 -0
  17. package/dist/es/node_modules/react-i18next/dist/es/initReactI18next.js +12 -0
  18. package/dist/es/node_modules/react-i18next/dist/es/unescape.js +27 -0
  19. package/dist/es/node_modules/react-i18next/dist/es/useTranslation.js +112 -0
  20. package/dist/es/node_modules/react-i18next/dist/es/utils.js +63 -0
  21. package/dist/es/node_modules/void-elements/index.js +23 -0
  22. package/dist/es/request.d.ts +1 -1
  23. package/dist/es/request.js +4 -3
  24. package/dist/es/src/locales/i18n.js +16 -0
  25. package/dist/es/src/locales/t-in-non-react.js +54 -0
  26. package/dist/es/src/locales/t-options.js +20 -0
  27. package/dist/es/src/locales/use-translation.js +60 -0
  28. package/dist/index.d.ts +6 -0
  29. package/dist/index.js +6 -0
  30. package/package.json +4 -1
  31. package/src/crypto.ts +6 -0
  32. package/src/index.ts +4 -1
  33. package/src/locales/i18n.ts +18 -0
  34. package/src/locales/index.ts +8 -0
  35. package/src/locales/t-in-non-react.ts +65 -0
  36. package/src/locales/t-options.ts +24 -0
  37. package/src/locales/use-translation.ts +76 -0
  38. package/src/locales//345/244/232/350/257/255/350/250/200.md +1 -0
  39. package/src/microAppCreator.ts +47 -8
  40. package/src/request.ts +5 -4
@@ -1,3 +1,6 @@
1
+ /**
2
+ * 对称加密和hash
3
+ */
1
4
  declare class Crypto {
2
5
  private aesKey;
3
6
  private desKey;
package/dist/es/crypto.js CHANGED
@@ -1,5 +1,9 @@
1
1
  import CryptoJS from 'crypto-js';
2
+ export { Base64 } from './node_modules/js-base64/base64.js';
2
3
 
4
+ /**
5
+ * 对称加密和hash
6
+ */
3
7
  var Crypto = /** @class */ (function () {
4
8
  function Crypto(aesKey, desKey) {
5
9
  this.aesKey = aesKey;
@@ -0,0 +1,15 @@
1
+ import i18next__default from 'i18next';
2
+ export { default as i18n } from 'i18next';
3
+
4
+ type InitOptions = Parameters<typeof i18next__default.init>;
5
+ /**
6
+ * 初始化逻辑
7
+ * - 本函数主要用于初始化 i18next 实例,同时使用 react-i18next 插件进行 react 组件的支持
8
+ * - 本函数的调用时机,一般是在项目的入口文件中进行调用,如 src/main.tsx 中
9
+ * @param options 参数 同i18next.init 第一个参数
10
+ * @param callback 参数 同i18next.init 第二个参数
11
+ * @returns
12
+ */
13
+ declare function initLocale(options: InitOptions[0], callback?: InitOptions[1]): Promise<i18next__default.TFunction<"translation", undefined>>;
14
+
15
+ export { initLocale };
@@ -0,0 +1,17 @@
1
+ import { TOpionsEx } from './t-options.js';
2
+
3
+ /**
4
+ * 同步版本的 i18n.t 函数(应对在 react 组件外使用的翻译函数)
5
+ * - 如果 i18n 未初始化,则返回默认值或键名
6
+ * - 如果 i18n 初始化后,键名不存在,则返回默认值或键名
7
+ * - 其他正常情况(已经初始化+键名存在),则返回翻译值
8
+ * @description 本函数为在非 react 组件中使用的翻译函数;(在react中请求使用 useTranslate() 返回的 t 函数)
9
+ * @param {string} key
10
+ * @param {TOpionsEx|string} defaultValue 必填值
11
+ * @returns {string}
12
+ * @example
13
+ * const txt = t('someLocaleKey', '兜底默认值');
14
+ */
15
+ declare function safeT(key: string, defaultValueOrOptions: string | TOpionsEx): string;
16
+
17
+ export { safeT };
@@ -0,0 +1,7 @@
1
+ import { TOptions } from 'i18next';
2
+
3
+ interface TOpionsEx extends TOptions {
4
+ defaultValue: string;
5
+ }
6
+
7
+ export { TOpionsEx };
@@ -0,0 +1,42 @@
1
+ import * as i18next from 'i18next';
2
+ import { useTranslation } from 'react-i18next';
3
+ export { Trans } from 'react-i18next';
4
+ import { TOpionsEx } from './t-options.js';
5
+
6
+ type Prams = Parameters<typeof useTranslation>;
7
+ type NS = Prams[0];
8
+ type Options = Prams[1];
9
+ type EnhanceTFunc = (key: string, defaultValueOrOptions: string | TOpionsEx) => string;
10
+ /**
11
+ * 这里只是简单代理一下useTranslation,方便后续扩展或添加其他逻辑
12
+ * @param ns 命名空间 大多数情况下都不需要传入这个参数,除非你用到了命名空间。
13
+ * @param options 其他参数 大多数情况下,都不需要关注这个参数。
14
+ * options.keyPrefix 为所有翻译键添加前缀
15
+ * // JSON 文件:{ "greeting": { "welcome": "Welcome" } }
16
+ * const { t } = useTranslation('common', { keyPrefix: 'greeting' });
17
+ * // 使用时省略前缀
18
+ * t('welcome'); // 等价于 t('greeting:welcome')
19
+ * @returns { t, i18n, ready }
20
+ * t: 翻译方法
21
+ * i18n: i18next实例 访问 i18next 的完整 API(如切换语言、加载命名空间)
22
+ * i18n.changeLanguage('zh-CN'); 使用它切换语言,可以触发组件渲染。但是当前项目中是使用全局刷新的模式,来更新语言的。
23
+ * ready: 是否加载完成
24
+ */
25
+ declare function useZtTranslation(ns?: NS, options?: Options): {
26
+ /**
27
+ * t函数的使用方式:基本上使用1、2两种方式就可以了。
28
+ * 1、t('key') // 基础用法
29
+ * 2、t('greeting', { name: 'John' }); // 对应 JSON: "greeting": "Hello {{name}}"
30
+ * 3、t('auth:login'); // 显式指定命名空间
31
+ *
32
+ * 关于t函数的第二个参数的说明。
33
+ * 为了防止一些异常情况,翻译失败。可以传入一个默认值。这个默认值就是原本的中文就行。
34
+ * 1、t('key', '默认值');
35
+ * 2、t('key', { defaultValue: '默认值', ...otherOptions });
36
+ */
37
+ t: EnhanceTFunc;
38
+ i18n: i18next.i18n;
39
+ ready: boolean;
40
+ };
41
+
42
+ export { useZtTranslation as useTranslation };
@@ -4,20 +4,43 @@
4
4
  * @param microAppOptions 微应用的一些配置
5
5
  */
6
6
  interface IMicroAppOptions {
7
+ /**
8
+ * @deprecated 该属性已废弃,无意义
9
+ */
7
10
  microAppContainerId: string;
8
11
  microAppKey: string;
12
+ /**
13
+ * @deprecated 该属性已废弃,无意义
14
+ */
9
15
  microAppRoot: any;
10
- microAppMountHandle?: (props: any) => void;
11
- microAppUnMountHandle?: (props: any) => void;
16
+ /**
17
+ * 只会在微应用初始化的时候调用一次,下次微应用重新进入时会直接调用 mount 钩子,不会再重复触发 bootstrap
18
+ * 通常我们可以在这里做一些全局变量的初始化,比如不会在 unmount 阶段被销毁的应用级别的缓存等。
19
+ **/
20
+ microAppBootstrapHandle?: () => void;
21
+ /**
22
+ * 应用每次进入都会调用 mount 方法,通常我们在这里触发应用的渲染方法
23
+ */
24
+ microAppMountHandle: (props: any) => void;
25
+ /**
26
+ * 应用每次 切出/卸载 会调用的方法,通常在这里我们会卸载微应用的应用实例
27
+ */
28
+ microAppUnMountHandle: (props: any) => void;
29
+ /**
30
+ * 可选生命周期钩子,仅使用 loadMicroApp 方式加载微应用时生效
31
+ */
32
+ microAppUpdateHandle?: (props: any) => void;
12
33
  }
13
34
  declare function initMicroApp(render: any, microAppOptions: IMicroAppOptions): {
14
35
  bootstrap?: undefined;
15
36
  mount?: undefined;
16
37
  unmount?: undefined;
38
+ update?: undefined;
17
39
  } | {
18
40
  bootstrap: () => Promise<void>;
19
41
  mount: (props: any) => Promise<void>;
20
42
  unmount: (props: any) => Promise<void>;
43
+ update: (props: any) => Promise<void>;
21
44
  };
22
45
 
23
46
  export { IMicroAppOptions, initMicroApp };
@@ -15,7 +15,7 @@ function initMicroApp(render, microAppOptions) {
15
15
  return {};
16
16
  }
17
17
  // 2. 进入微前端环境的运行逻辑
18
- var microAppKey = microAppOptions.microAppKey; microAppOptions.microAppRoot; var microAppMountHandle = microAppOptions.microAppMountHandle, microAppUnMountHandle = microAppOptions.microAppUnMountHandle;
18
+ var microAppKey = microAppOptions.microAppKey, microAppBootstrapHandle = microAppOptions.microAppBootstrapHandle, microAppMountHandle = microAppOptions.microAppMountHandle, microAppUnMountHandle = microAppOptions.microAppUnMountHandle, microAppUpdateHandle = microAppOptions.microAppUpdateHandle;
19
19
  // 唯一key没传 给出开发提示
20
20
  if (!microAppKey) {
21
21
  throw Error("\u6CA1\u6709\u914D\u7F6E\u5FAE\u5E94\u7528\u7684\u552F\u4E00key\u503C\uFF0C\u8FD9\u4F1A\u5BFC\u81F4\u5FAE\u524D\u7AEF\u8FD0\u884C\u51FA\u9519\uFF01");
@@ -27,7 +27,10 @@ function initMicroApp(render, microAppOptions) {
27
27
  function bootstrap() {
28
28
  return __awaiter(this, void 0, void 0, function () {
29
29
  return __generator(this, function (_a) {
30
- console.log("微应用 bootstraped");
30
+ console.log("\u5FAE\u5E94\u7528==".concat(microAppKey, "==bootstraped"));
31
+ if (microAppBootstrapHandle) {
32
+ microAppBootstrapHandle();
33
+ }
31
34
  return [2 /*return*/];
32
35
  });
33
36
  });
@@ -38,8 +41,10 @@ function initMicroApp(render, microAppOptions) {
38
41
  function mount(props) {
39
42
  return __awaiter(this, void 0, void 0, function () {
40
43
  return __generator(this, function (_a) {
41
- console.log("微应用 mount");
42
- microAppMountHandle && microAppMountHandle(props);
44
+ console.log("\u5FAE\u5E94\u7528==".concat(microAppKey, "==mount"));
45
+ if (microAppMountHandle) {
46
+ microAppMountHandle(props);
47
+ }
43
48
  render(props);
44
49
  return [2 /*return*/];
45
50
  });
@@ -51,8 +56,24 @@ function initMicroApp(render, microAppOptions) {
51
56
  function unmount(props) {
52
57
  return __awaiter(this, void 0, void 0, function () {
53
58
  return __generator(this, function (_a) {
54
- console.log("微应用 unmount", props);
55
- microAppUnMountHandle && microAppUnMountHandle(props);
59
+ console.log("\u5FAE\u5E94\u7528==".concat(microAppKey, "==unmount"));
60
+ if (microAppUnMountHandle) {
61
+ microAppUnMountHandle(props);
62
+ }
63
+ return [2 /*return*/];
64
+ });
65
+ });
66
+ }
67
+ /**
68
+ * 应用每次 切出/卸载 会调用的方法,通常在这里我们会卸载微应用的应用实例
69
+ */
70
+ function update(props) {
71
+ return __awaiter(this, void 0, void 0, function () {
72
+ return __generator(this, function (_a) {
73
+ console.log("\u5FAE\u5E94\u7528==".concat(microAppKey, "==update"));
74
+ if (microAppUpdateHandle) {
75
+ microAppUpdateHandle(props);
76
+ }
56
77
  return [2 /*return*/];
57
78
  });
58
79
  });
@@ -61,6 +82,7 @@ function initMicroApp(render, microAppOptions) {
61
82
  bootstrap: bootstrap,
62
83
  mount: mount,
63
84
  unmount: unmount,
85
+ update: update,
64
86
  };
65
87
  }
66
88
 
@@ -0,0 +1,5 @@
1
+ import voidElements from '../../void-elements/index.js';
2
+
3
+ var t=/\s([^'"/\s><]+?)[\s/>]|([^\s=]+)=\s?(".*?"|'.*?')/g;function n(n){var r={type:"tag",name:"",voidElement:!1,attrs:{},children:[]},i=n.match(/<\/?([^\s]+?)[/\s>]/);if(i&&(r.name=i[1],(voidElements[i[1]]||"/"===n.charAt(n.length-2))&&(r.voidElement=!0),r.name.startsWith("!--"))){var s=n.indexOf("--\x3e");return {type:"comment",comment:-1!==s?n.slice(4,s):""}}for(var a=new RegExp(t),c=null;null!==(c=a.exec(n));)if(c[0].trim())if(c[1]){var o=c[1].trim(),l=[o,""];o.indexOf("=")>-1&&(l=o.split("=")),r.attrs[l[0]]=l[1],a.lastIndex--;}else c[2]&&(r.attrs[c[2]]=c[3].trim().substring(1,c[3].length-1));return r}var r=/<[a-zA-Z0-9\-\!\/](?:"[^"]*"|'[^']*'|[^'">])*>/g,i=/^\s*$/,s=Object.create(null);function a(e,t){switch(t.type){case"text":return e+t.content;case"tag":return e+="<"+t.name+(t.attrs?function(e){var t=[];for(var n in e)t.push(n+'="'+e[n]+'"');return t.length?" "+t.join(" "):""}(t.attrs):"")+(t.voidElement?"/>":">"),t.voidElement?e:e+t.children.reduce(a,"")+"</"+t.name+">";case"comment":return e+"\x3c!--"+t.comment+"--\x3e"}}var c={parse:function(e,t){t||(t={}),t.components||(t.components=s);var a,c=[],o=[],l=-1,m=!1;if(0!==e.indexOf("<")){var u=e.indexOf("<");c.push({type:"text",content:-1===u?e:e.substring(0,u)});}return e.replace(r,function(r,s){if(m){if(r!=="</"+a.name+">")return;m=!1;}var u,f="/"!==r.charAt(1),h=r.startsWith("\x3c!--"),p=s+r.length,d=e.charAt(p);if(h){var v=n(r);return l<0?(c.push(v),c):((u=o[l]).children.push(v),c)}if(f&&(l++,"tag"===(a=n(r)).type&&t.components[a.name]&&(a.type="component",m=!0),a.voidElement||m||!d||"<"===d||a.children.push({type:"text",content:e.slice(p,e.indexOf("<",p))}),0===l&&c.push(a),(u=o[l-1])&&u.children.push(a),o[l]=a),(!f||a.voidElement)&&(l>-1&&(a.voidElement||a.name===r.slice(2,-1))&&(l--,a=-1===l?c:o[l]),!m&&"<"!==d&&d)){u=-1===l?c:o[l].children;var x=e.indexOf("<",p),g=e.slice(p,-1===x?void 0:x);i.test(g)&&(g=" "),(x>-1&&l+u.length>=0||" "!==g)&&u.push({type:"text",content:g});}}),c},stringify:function(e){return e.reduce(function(e,t){return e+a("",t)},"")}};
4
+
5
+ export { c as default };