react-toolkits 2.8.3 → 2.9.0
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/CHANGELOG.md +6 -0
- package/lib/index.d.ts +37 -29
- package/lib/index.js +136 -161
- package/lib/index.js.map +1 -1
- package/locale/en_GB.d.ts +0 -1
- package/locale/hooks.d.ts +0 -1
- package/locale/hooks.js +11 -99
- package/locale/hooks.js.map +1 -1
- package/locale/index.d.ts +1 -8
- package/locale/index.js +13 -108
- package/locale/index.js.map +1 -1
- package/locale/ja_JP.d.ts +0 -1
- package/locale/ko_KR.d.ts +0 -1
- package/locale/zh_CN.d.ts +0 -1
- package/package.json +1 -1
package/locale/en_GB.d.ts
CHANGED
package/locale/hooks.d.ts
CHANGED
package/locale/hooks.js
CHANGED
|
@@ -1,108 +1,20 @@
|
|
|
1
1
|
import { has, template, get } from 'lodash-es';
|
|
2
|
-
import { createContext,
|
|
2
|
+
import { createContext, useMemo, useContext } from 'react';
|
|
3
|
+
import { useStore } from 'zustand';
|
|
4
|
+
import 'react/jsx-runtime';
|
|
3
5
|
|
|
4
6
|
// src/components/locale/hooks.ts
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
name: "\u540D\u79F0",
|
|
13
|
-
creationTime: "\u521B\u5EFA\u65F6\u95F4",
|
|
14
|
-
operation: "\u64CD\u4F5C",
|
|
15
|
-
update: "\u66F4\u65B0",
|
|
16
|
-
edit: "\u7F16\u8F91",
|
|
17
|
-
delete: "\u5220\u9664",
|
|
18
|
-
selectAll: "\u5168\u9009",
|
|
19
|
-
game: "\u6E38\u620F",
|
|
20
|
-
user: "\u7528\u6237",
|
|
21
|
-
role: "\u89D2\u8272",
|
|
22
|
-
username: "\u7528\u6237\u540D",
|
|
23
|
-
password: "\u5BC6\u7801",
|
|
24
|
-
label: "\u6807\u7B7E",
|
|
25
|
-
method: "\u65B9\u6CD5",
|
|
26
|
-
route: "\u8DEF\u7531",
|
|
27
|
-
request: "\u8BF7\u6C42",
|
|
28
|
-
response: "\u54CD\u5E94",
|
|
29
|
-
add: "\u6DFB\u52A0",
|
|
30
|
-
signIn: "\u767B\u5F55"
|
|
31
|
-
},
|
|
32
|
-
SignIn: {
|
|
33
|
-
title: "\u767B\u5F55\u65B9\u5F0F",
|
|
34
|
-
thirdParty: "\u7B2C\u4E09\u65B9\u767B\u5F55",
|
|
35
|
-
signInWithIDass: "IDass \u767B\u5F55",
|
|
36
|
-
notRegistered: "\u60A8\u8FD8\u672A\u5728\u5E73\u53F0\u6CE8\u518C\uFF0C\u8BF7\u8054\u7CFB\u7BA1\u7406\u5458",
|
|
37
|
-
welcome: "\u6B22\u8FCE"
|
|
38
|
-
},
|
|
39
|
-
NotFound: {
|
|
40
|
-
subTitle: "\u8BBF\u95EE\u7684\u9875\u9762\u4E0D\u5B58\u5728",
|
|
41
|
-
buttonText: "\u8FD4\u56DE\u9996\u9875"
|
|
42
|
-
},
|
|
43
|
-
FilterFormWrapper: {
|
|
44
|
-
confirmText: "\u67E5\u8BE2",
|
|
45
|
-
resetText: "\u91CD\u7F6E"
|
|
46
|
-
},
|
|
47
|
-
FormModal: {
|
|
48
|
-
confirmText: "\u786E\u8BA4",
|
|
49
|
-
cancelText: "\u53D6\u6D88"
|
|
50
|
-
},
|
|
51
|
-
GameSelect: {
|
|
52
|
-
label: "\u5F53\u524D\u6E38\u620F",
|
|
53
|
-
placeholder: "\u8BF7\u9009\u62E9\u6E38\u620F"
|
|
54
|
-
},
|
|
55
|
-
RequireGame: {
|
|
56
|
-
description: "\u8BF7\u9009\u62E9\u6E38\u620F"
|
|
57
|
-
},
|
|
58
|
-
UserWidget: {
|
|
59
|
-
signOutText: "\u767B\u51FA"
|
|
60
|
-
},
|
|
61
|
-
UserList: {
|
|
62
|
-
createTitle: "\u521B\u5EFA\u7528\u6237",
|
|
63
|
-
createSuccessfully: "\u7528\u6237\u521B\u5EFA\u6210\u529F",
|
|
64
|
-
updateTitle: "\u66F4\u65B0\u7528\u6237",
|
|
65
|
-
updateSuccessfully: "\u7528\u6237\u66F4\u65B0\u6210\u529F",
|
|
66
|
-
deleteTitle: "\u5220\u9664\u7528\u6237",
|
|
67
|
-
deleteContent: "\u786E\u5B9A\u8981\u5220\u9664\u7528\u6237 <%= user %> \u5417\uFF1F",
|
|
68
|
-
deleteSuccessfully: "\u7528\u6237\u5220\u9664\u6210\u529F"
|
|
69
|
-
},
|
|
70
|
-
RoleList: {
|
|
71
|
-
createTitle: "\u521B\u5EFA\u89D2\u8272",
|
|
72
|
-
createSuccessfully: "\u89D2\u8272\u521B\u5EFA\u6210\u529F",
|
|
73
|
-
updateTitle: "\u66F4\u65B0\u89D2\u8272",
|
|
74
|
-
updateSuccessfully: "\u89D2\u8272\u66F4\u65B0\u6210\u529F",
|
|
75
|
-
deleteTitle: "\u5220\u9664\u89D2\u8272",
|
|
76
|
-
deleteContent: "\u786E\u5B9A\u8981\u5220\u9664\u89D2\u8272 <%= role %> \u5417\uFF1F",
|
|
77
|
-
deleteSuccessfully: "\u89D2\u8272\u5220\u9664\u6210\u529F"
|
|
78
|
-
},
|
|
79
|
-
PermissionList: {
|
|
80
|
-
failedDescription: "\u83B7\u53D6\u6743\u9650\u5217\u8868\u5931\u8D25",
|
|
81
|
-
baseSectionTitle: "\u5E73\u53F0\u57FA\u7840\u6743\u9650",
|
|
82
|
-
gameSectionTitle: "\u6E38\u620F\u6743\u9650",
|
|
83
|
-
gameSectionDescription: "\u8BF7\u5148\u9009\u62E9\u6E38\u620F",
|
|
84
|
-
gameSelectPlaceholder: "\u8BF7\u5148\u9009\u62E9\u6E38\u620F",
|
|
85
|
-
removeText: "\u79FB\u9664",
|
|
86
|
-
addText: "\u6DFB\u52A0\u6E38\u620F\u6743\u9650"
|
|
87
|
-
},
|
|
88
|
-
RoleDetail: {
|
|
89
|
-
title: "\u89D2\u8272\u8BE6\u60C5"
|
|
90
|
-
},
|
|
91
|
-
InfiniteList: {
|
|
92
|
-
loadingText: "\u52A0\u8F7D\u4E2D",
|
|
93
|
-
reachEndText: "\u5DF2\u7ECF\u5230\u5E95\u4E86",
|
|
94
|
-
loadMoreText: "\u52A0\u8F7D\u66F4\u591A"
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
var zh_CN_default = locale;
|
|
7
|
+
var ToolkitsContext = createContext(null);
|
|
8
|
+
function useToolkitsContext(selector) {
|
|
9
|
+
const store = useContext(ToolkitsContext);
|
|
10
|
+
if (!store) throw new Error("Missing ToolkitsContext.Provider in the tree");
|
|
11
|
+
return useStore(store, selector);
|
|
12
|
+
}
|
|
13
|
+
if (process.env.NODE_ENV !== "production") ;
|
|
98
14
|
|
|
99
15
|
// src/components/locale/hooks.ts
|
|
100
16
|
function useTranslation() {
|
|
101
|
-
const
|
|
102
|
-
const locale2 = {
|
|
103
|
-
...zh_CN_default,
|
|
104
|
-
...localeFromContext
|
|
105
|
-
};
|
|
17
|
+
const locale2 = useToolkitsContext((state) => state.locale);
|
|
106
18
|
const t = useMemo(
|
|
107
19
|
() => (key, data) => has(locale2, key) ? template(get(locale2, key))(data) : key,
|
|
108
20
|
[locale2]
|
package/locale/hooks.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/components/
|
|
1
|
+
{"version":3,"sources":["../src/components/contextProvider/Provider.tsx","../src/components/locale/hooks.ts"],"names":["locale"],"mappings":";;;;;;AAwCA,IAAM,eAAA,GAAkB,cAAmC,IAAI,CAAA,CAAA;AAExD,SAAS,mBAAsB,QAAsC,EAAA;AAC1E,EAAM,MAAA,KAAA,GAAQ,WAAW,eAAe,CAAA,CAAA;AACxC,EAAA,IAAI,CAAC,KAAA,EAAa,MAAA,IAAI,MAAM,8CAA8C,CAAA,CAAA;AAC1E,EAAO,OAAA,QAAA,CAAS,OAAO,QAAQ,CAAA,CAAA;AACjC,CAAA;AAiBA,IAAI,OAAA,CAAQ,GAAI,CAAA,QAAA,KAAa,YAAc,EAAA,CAE3C;;;AC9CO,SAAS,cAAiB,GAAA;AAC/B,EAAA,MAAMA,OAAS,GAAA,kBAAA,CAAmB,CAAS,KAAA,KAAA,KAAA,CAAM,MAAM,CAAA,CAAA;AAEvD,EAAA,MAAM,CAAI,GAAA,OAAA;AAAA,IACR,MAAM,CAAC,GAAoB,EAAA,IAAA,KACzB,IAAIA,OAAQ,EAAA,GAAG,CAAI,GAAA,QAAA,CAAS,IAAIA,OAAQ,EAAA,GAAa,CAAC,CAAA,CAAE,IAAI,CAAI,GAAA,GAAA;AAAA,IAClE,CAACA,OAAM,CAAA;AAAA,GACT,CAAA;AAEA,EAAA,OAAO,EAAE,CAAE,EAAA,CAAA;AACb","file":"hooks.js","sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport type { FC, PropsWithChildren } from 'react'\nimport { createContext, useContext, useRef } from 'react'\nimport { createStore, useStore } from 'zustand'\nimport type { RequestOptions } from '../../utils/request'\nimport type { Locale } from '../locale'\nimport enGb from '../locale/en_GB'\n\nexport interface ContextProps {\n locale: Locale\n usePermissionApiV2: boolean // 使用 V2 版本的权限接口\n interceptor?: {\n response?: (response: Response, opts: RequestOptions) => Promise<any>\n }\n}\n\nexport interface ContextState extends ContextProps {\n setContext: (props: Partial<ContextProps>) => void\n}\n\nconst createContextStore = (initProps?: Partial<ContextProps>) => {\n const DEFAULT_PROPS: ContextProps = {\n usePermissionApiV2: false,\n locale: enGb,\n }\n\n return createStore<ContextState>()(set => ({\n ...DEFAULT_PROPS,\n ...initProps,\n setContext: props => {\n set({ ...props })\n },\n }))\n}\n\ntype ContextStore = ReturnType<typeof createContextStore>\n\n// 全局的 store 实例,等于最内层的 ContextProvider 所包含的实例。\nexport let contextStore: ContextStore\n\nconst ToolkitsContext = createContext<ContextStore | null>(null)\n\nexport function useToolkitsContext<T>(selector: (state: ContextState) => T) {\n const store = useContext(ToolkitsContext)\n if (!store) throw new Error('Missing ToolkitsContext.Provider in the tree')\n return useStore(store, selector)\n}\n\ntype ContextProviderProps = PropsWithChildren<Partial<ContextProps>>\n\nconst ContextProvider: FC<ContextProviderProps> = props => {\n const { children, ...restProps } = props\n const storeRef = useRef<ContextStore>()\n\n if (!storeRef.current) {\n storeRef.current = createContextStore(restProps)\n }\n\n contextStore = storeRef.current\n\n return <ToolkitsContext.Provider value={storeRef.current}>{children}</ToolkitsContext.Provider>\n}\n\nif (process.env.NODE_ENV !== 'production') {\n ContextProvider.displayName = 'ContextProvider'\n}\n\nexport default ContextProvider\n","import { get, has, template } from 'lodash-es'\nimport { useMemo } from 'react'\nimport { useToolkitsContext } from '../contextProvider'\nimport type { Locale } from './index'\n\ntype Join<K, P> = K extends string | number\n ? P extends string | number\n ? `${K}${'' extends P ? '' : '.'}${P}`\n : never\n : never\n\ntype Paths<T, D extends number = 10> = [D] extends [never]\n ? never\n : T extends object\n ? {\n [K in keyof T]-?: K extends string | number ? `${K}` | Join<K, Paths<T[K]>> : never\n }[keyof T]\n : ''\n\nexport function useTranslation() {\n const locale = useToolkitsContext(state => state.locale)\n\n const t = useMemo(\n () => (key: Paths<Locale>, data?: Record<string, unknown>) =>\n has(locale, key) ? template(get(locale, key as string))(data) : key,\n [locale],\n )\n\n return { t }\n}\n"]}
|
package/locale/index.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { FC, PropsWithChildren } from 'react';
|
|
2
|
-
|
|
3
1
|
type Join<K, P> = K extends string | number ? P extends string | number ? `${K}${'' extends P ? '' : '.'}${P}` : never : never;
|
|
4
2
|
type Paths<T, D extends number = 10> = [D] extends [never] ? never : T extends object ? {
|
|
5
3
|
[K in keyof T]-?: K extends string | number ? `${K}` | Join<K, Paths<T[K]>> : never;
|
|
@@ -97,9 +95,4 @@ type Locale = {
|
|
|
97
95
|
};
|
|
98
96
|
};
|
|
99
97
|
|
|
100
|
-
|
|
101
|
-
locale: Locale;
|
|
102
|
-
}
|
|
103
|
-
declare const LocaleProvider: FC<PropsWithChildren<LocaleProviderProps>>;
|
|
104
|
-
|
|
105
|
-
export { type Locale, type LocaleProviderProps, LocaleProvider as default, useTranslation };
|
|
98
|
+
export { type Locale, useTranslation };
|
package/locale/index.js
CHANGED
|
@@ -1,122 +1,27 @@
|
|
|
1
|
-
import { createContext, useContext, useMemo } from 'react';
|
|
2
1
|
import { has, template, get } from 'lodash-es';
|
|
3
|
-
import {
|
|
2
|
+
import { createContext, useMemo, useContext } from 'react';
|
|
3
|
+
import { useStore } from 'zustand';
|
|
4
|
+
import 'react/jsx-runtime';
|
|
4
5
|
|
|
5
|
-
// src/components/locale/
|
|
6
|
-
var
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
name: "\u540D\u79F0",
|
|
14
|
-
creationTime: "\u521B\u5EFA\u65F6\u95F4",
|
|
15
|
-
operation: "\u64CD\u4F5C",
|
|
16
|
-
update: "\u66F4\u65B0",
|
|
17
|
-
edit: "\u7F16\u8F91",
|
|
18
|
-
delete: "\u5220\u9664",
|
|
19
|
-
selectAll: "\u5168\u9009",
|
|
20
|
-
game: "\u6E38\u620F",
|
|
21
|
-
user: "\u7528\u6237",
|
|
22
|
-
role: "\u89D2\u8272",
|
|
23
|
-
username: "\u7528\u6237\u540D",
|
|
24
|
-
password: "\u5BC6\u7801",
|
|
25
|
-
label: "\u6807\u7B7E",
|
|
26
|
-
method: "\u65B9\u6CD5",
|
|
27
|
-
route: "\u8DEF\u7531",
|
|
28
|
-
request: "\u8BF7\u6C42",
|
|
29
|
-
response: "\u54CD\u5E94",
|
|
30
|
-
add: "\u6DFB\u52A0",
|
|
31
|
-
signIn: "\u767B\u5F55"
|
|
32
|
-
},
|
|
33
|
-
SignIn: {
|
|
34
|
-
title: "\u767B\u5F55\u65B9\u5F0F",
|
|
35
|
-
thirdParty: "\u7B2C\u4E09\u65B9\u767B\u5F55",
|
|
36
|
-
signInWithIDass: "IDass \u767B\u5F55",
|
|
37
|
-
notRegistered: "\u60A8\u8FD8\u672A\u5728\u5E73\u53F0\u6CE8\u518C\uFF0C\u8BF7\u8054\u7CFB\u7BA1\u7406\u5458",
|
|
38
|
-
welcome: "\u6B22\u8FCE"
|
|
39
|
-
},
|
|
40
|
-
NotFound: {
|
|
41
|
-
subTitle: "\u8BBF\u95EE\u7684\u9875\u9762\u4E0D\u5B58\u5728",
|
|
42
|
-
buttonText: "\u8FD4\u56DE\u9996\u9875"
|
|
43
|
-
},
|
|
44
|
-
FilterFormWrapper: {
|
|
45
|
-
confirmText: "\u67E5\u8BE2",
|
|
46
|
-
resetText: "\u91CD\u7F6E"
|
|
47
|
-
},
|
|
48
|
-
FormModal: {
|
|
49
|
-
confirmText: "\u786E\u8BA4",
|
|
50
|
-
cancelText: "\u53D6\u6D88"
|
|
51
|
-
},
|
|
52
|
-
GameSelect: {
|
|
53
|
-
label: "\u5F53\u524D\u6E38\u620F",
|
|
54
|
-
placeholder: "\u8BF7\u9009\u62E9\u6E38\u620F"
|
|
55
|
-
},
|
|
56
|
-
RequireGame: {
|
|
57
|
-
description: "\u8BF7\u9009\u62E9\u6E38\u620F"
|
|
58
|
-
},
|
|
59
|
-
UserWidget: {
|
|
60
|
-
signOutText: "\u767B\u51FA"
|
|
61
|
-
},
|
|
62
|
-
UserList: {
|
|
63
|
-
createTitle: "\u521B\u5EFA\u7528\u6237",
|
|
64
|
-
createSuccessfully: "\u7528\u6237\u521B\u5EFA\u6210\u529F",
|
|
65
|
-
updateTitle: "\u66F4\u65B0\u7528\u6237",
|
|
66
|
-
updateSuccessfully: "\u7528\u6237\u66F4\u65B0\u6210\u529F",
|
|
67
|
-
deleteTitle: "\u5220\u9664\u7528\u6237",
|
|
68
|
-
deleteContent: "\u786E\u5B9A\u8981\u5220\u9664\u7528\u6237 <%= user %> \u5417\uFF1F",
|
|
69
|
-
deleteSuccessfully: "\u7528\u6237\u5220\u9664\u6210\u529F"
|
|
70
|
-
},
|
|
71
|
-
RoleList: {
|
|
72
|
-
createTitle: "\u521B\u5EFA\u89D2\u8272",
|
|
73
|
-
createSuccessfully: "\u89D2\u8272\u521B\u5EFA\u6210\u529F",
|
|
74
|
-
updateTitle: "\u66F4\u65B0\u89D2\u8272",
|
|
75
|
-
updateSuccessfully: "\u89D2\u8272\u66F4\u65B0\u6210\u529F",
|
|
76
|
-
deleteTitle: "\u5220\u9664\u89D2\u8272",
|
|
77
|
-
deleteContent: "\u786E\u5B9A\u8981\u5220\u9664\u89D2\u8272 <%= role %> \u5417\uFF1F",
|
|
78
|
-
deleteSuccessfully: "\u89D2\u8272\u5220\u9664\u6210\u529F"
|
|
79
|
-
},
|
|
80
|
-
PermissionList: {
|
|
81
|
-
failedDescription: "\u83B7\u53D6\u6743\u9650\u5217\u8868\u5931\u8D25",
|
|
82
|
-
baseSectionTitle: "\u5E73\u53F0\u57FA\u7840\u6743\u9650",
|
|
83
|
-
gameSectionTitle: "\u6E38\u620F\u6743\u9650",
|
|
84
|
-
gameSectionDescription: "\u8BF7\u5148\u9009\u62E9\u6E38\u620F",
|
|
85
|
-
gameSelectPlaceholder: "\u8BF7\u5148\u9009\u62E9\u6E38\u620F",
|
|
86
|
-
removeText: "\u79FB\u9664",
|
|
87
|
-
addText: "\u6DFB\u52A0\u6E38\u620F\u6743\u9650"
|
|
88
|
-
},
|
|
89
|
-
RoleDetail: {
|
|
90
|
-
title: "\u89D2\u8272\u8BE6\u60C5"
|
|
91
|
-
},
|
|
92
|
-
InfiniteList: {
|
|
93
|
-
loadingText: "\u52A0\u8F7D\u4E2D",
|
|
94
|
-
reachEndText: "\u5DF2\u7ECF\u5230\u5E95\u4E86",
|
|
95
|
-
loadMoreText: "\u52A0\u8F7D\u66F4\u591A"
|
|
96
|
-
}
|
|
97
|
-
};
|
|
98
|
-
var zh_CN_default = locale;
|
|
6
|
+
// src/components/locale/hooks.ts
|
|
7
|
+
var ToolkitsContext = createContext(null);
|
|
8
|
+
function useToolkitsContext(selector) {
|
|
9
|
+
const store = useContext(ToolkitsContext);
|
|
10
|
+
if (!store) throw new Error("Missing ToolkitsContext.Provider in the tree");
|
|
11
|
+
return useStore(store, selector);
|
|
12
|
+
}
|
|
13
|
+
if (process.env.NODE_ENV !== "production") ;
|
|
99
14
|
|
|
100
15
|
// src/components/locale/hooks.ts
|
|
101
16
|
function useTranslation() {
|
|
102
|
-
const
|
|
103
|
-
const locale2 = {
|
|
104
|
-
...zh_CN_default,
|
|
105
|
-
...localeFromContext
|
|
106
|
-
};
|
|
17
|
+
const locale2 = useToolkitsContext((state) => state.locale);
|
|
107
18
|
const t = useMemo(
|
|
108
19
|
() => (key, data) => has(locale2, key) ? template(get(locale2, key))(data) : key,
|
|
109
20
|
[locale2]
|
|
110
21
|
);
|
|
111
22
|
return { t };
|
|
112
23
|
}
|
|
113
|
-
var LocaleProvider = (props) => {
|
|
114
|
-
const { locale: locale2 = {}, children } = props;
|
|
115
|
-
const memoizedContextValue = useMemo(() => ({ ...locale2 }), [locale2]);
|
|
116
|
-
return /* @__PURE__ */ jsx(context_default.Provider, { value: memoizedContextValue, children });
|
|
117
|
-
};
|
|
118
|
-
var locale_default = LocaleProvider;
|
|
119
24
|
|
|
120
|
-
export {
|
|
25
|
+
export { useTranslation };
|
|
121
26
|
//# sourceMappingURL=index.js.map
|
|
122
27
|
//# sourceMappingURL=index.js.map
|
package/locale/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/components/
|
|
1
|
+
{"version":3,"sources":["../src/components/contextProvider/Provider.tsx","../src/components/locale/hooks.ts"],"names":["locale"],"mappings":";;;;;;AAwCA,IAAM,eAAA,GAAkB,cAAmC,IAAI,CAAA,CAAA;AAExD,SAAS,mBAAsB,QAAsC,EAAA;AAC1E,EAAM,MAAA,KAAA,GAAQ,WAAW,eAAe,CAAA,CAAA;AACxC,EAAA,IAAI,CAAC,KAAA,EAAa,MAAA,IAAI,MAAM,8CAA8C,CAAA,CAAA;AAC1E,EAAO,OAAA,QAAA,CAAS,OAAO,QAAQ,CAAA,CAAA;AACjC,CAAA;AAiBA,IAAI,OAAA,CAAQ,GAAI,CAAA,QAAA,KAAa,YAAc,EAAA,CAE3C;;;AC9CO,SAAS,cAAiB,GAAA;AAC/B,EAAA,MAAMA,OAAS,GAAA,kBAAA,CAAmB,CAAS,KAAA,KAAA,KAAA,CAAM,MAAM,CAAA,CAAA;AAEvD,EAAA,MAAM,CAAI,GAAA,OAAA;AAAA,IACR,MAAM,CAAC,GAAoB,EAAA,IAAA,KACzB,IAAIA,OAAQ,EAAA,GAAG,CAAI,GAAA,QAAA,CAAS,IAAIA,OAAQ,EAAA,GAAa,CAAC,CAAA,CAAE,IAAI,CAAI,GAAA,GAAA;AAAA,IAClE,CAACA,OAAM,CAAA;AAAA,GACT,CAAA;AAEA,EAAA,OAAO,EAAE,CAAE,EAAA,CAAA;AACb","file":"index.js","sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport type { FC, PropsWithChildren } from 'react'\nimport { createContext, useContext, useRef } from 'react'\nimport { createStore, useStore } from 'zustand'\nimport type { RequestOptions } from '../../utils/request'\nimport type { Locale } from '../locale'\nimport enGb from '../locale/en_GB'\n\nexport interface ContextProps {\n locale: Locale\n usePermissionApiV2: boolean // 使用 V2 版本的权限接口\n interceptor?: {\n response?: (response: Response, opts: RequestOptions) => Promise<any>\n }\n}\n\nexport interface ContextState extends ContextProps {\n setContext: (props: Partial<ContextProps>) => void\n}\n\nconst createContextStore = (initProps?: Partial<ContextProps>) => {\n const DEFAULT_PROPS: ContextProps = {\n usePermissionApiV2: false,\n locale: enGb,\n }\n\n return createStore<ContextState>()(set => ({\n ...DEFAULT_PROPS,\n ...initProps,\n setContext: props => {\n set({ ...props })\n },\n }))\n}\n\ntype ContextStore = ReturnType<typeof createContextStore>\n\n// 全局的 store 实例,等于最内层的 ContextProvider 所包含的实例。\nexport let contextStore: ContextStore\n\nconst ToolkitsContext = createContext<ContextStore | null>(null)\n\nexport function useToolkitsContext<T>(selector: (state: ContextState) => T) {\n const store = useContext(ToolkitsContext)\n if (!store) throw new Error('Missing ToolkitsContext.Provider in the tree')\n return useStore(store, selector)\n}\n\ntype ContextProviderProps = PropsWithChildren<Partial<ContextProps>>\n\nconst ContextProvider: FC<ContextProviderProps> = props => {\n const { children, ...restProps } = props\n const storeRef = useRef<ContextStore>()\n\n if (!storeRef.current) {\n storeRef.current = createContextStore(restProps)\n }\n\n contextStore = storeRef.current\n\n return <ToolkitsContext.Provider value={storeRef.current}>{children}</ToolkitsContext.Provider>\n}\n\nif (process.env.NODE_ENV !== 'production') {\n ContextProvider.displayName = 'ContextProvider'\n}\n\nexport default ContextProvider\n","import { get, has, template } from 'lodash-es'\nimport { useMemo } from 'react'\nimport { useToolkitsContext } from '../contextProvider'\nimport type { Locale } from './index'\n\ntype Join<K, P> = K extends string | number\n ? P extends string | number\n ? `${K}${'' extends P ? '' : '.'}${P}`\n : never\n : never\n\ntype Paths<T, D extends number = 10> = [D] extends [never]\n ? never\n : T extends object\n ? {\n [K in keyof T]-?: K extends string | number ? `${K}` | Join<K, Paths<T[K]>> : never\n }[keyof T]\n : ''\n\nexport function useTranslation() {\n const locale = useToolkitsContext(state => state.locale)\n\n const t = useMemo(\n () => (key: Paths<Locale>, data?: Record<string, unknown>) =>\n has(locale, key) ? template(get(locale, key as string))(data) : key,\n [locale],\n )\n\n return { t }\n}\n"]}
|
package/locale/ja_JP.d.ts
CHANGED
package/locale/ko_KR.d.ts
CHANGED
package/locale/zh_CN.d.ts
CHANGED