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/locale/en_GB.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { Locale } from './index.js';
2
- import 'react';
3
2
 
4
3
  declare const locale: Locale;
5
4
 
package/locale/hooks.d.ts CHANGED
@@ -1,2 +1 @@
1
1
  export { useTranslation } from './index.js';
2
- import 'react';
package/locale/hooks.js CHANGED
@@ -1,108 +1,20 @@
1
1
  import { has, template, get } from 'lodash-es';
2
- import { createContext, useContext, useMemo } from 'react';
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 LocaleContext = createContext(void 0);
6
- var context_default = LocaleContext;
7
-
8
- // src/components/locale/zh_CN.ts
9
- var locale = {
10
- global: {
11
- noEntitlement: "\u65E0\u6743\u9650\uFF0C\u8BF7\u8054\u7CFB\u7BA1\u7406\u5458\u3002",
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 localeFromContext = useContext(context_default);
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]
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/components/locale/context.ts","../src/components/locale/zh_CN.ts","../src/components/locale/hooks.ts"],"names":["locale"],"mappings":";;;;AAKA,IAAM,aAAA,GAAgB,cAA8C,KAAS,CAAA,CAAA,CAAA;AAE7E,IAAO,eAAQ,GAAA,aAAA,CAAA;;;ACLf,IAAM,MAAiB,GAAA;AAA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;AAAA,IACH,GAAG,iBAAA;AAAA,GACL,CAAA;AAEA,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":["import { createContext } from 'react'\nimport type { Locale } from '.'\n\nexport type LocaleContextProps = Locale\n\nconst LocaleContext = createContext<LocaleContextProps | undefined>(undefined)\n\nexport default LocaleContext\n","import type { Locale } from '.'\n\nconst locale: Locale = {\n global: {\n noEntitlement: '无权限,请联系管理员。',\n name: '名称',\n creationTime: '创建时间',\n operation: '操作',\n update: '更新',\n edit: '编辑',\n delete: '删除',\n selectAll: '全选',\n game: '游戏',\n user: '用户',\n role: '角色',\n username: '用户名',\n password: '密码',\n label: '标签',\n method: '方法',\n route: '路由',\n request: '请求',\n response: '响应',\n add: '添加',\n signIn: '登录',\n },\n SignIn: {\n title: '登录方式',\n thirdParty: '第三方登录',\n signInWithIDass: 'IDass 登录',\n notRegistered: '您还未在平台注册,请联系管理员',\n welcome: '欢迎',\n },\n NotFound: {\n subTitle: '访问的页面不存在',\n buttonText: '返回首页',\n },\n FilterFormWrapper: {\n confirmText: '查询',\n resetText: '重置',\n },\n FormModal: {\n confirmText: '确认',\n cancelText: '取消',\n },\n GameSelect: {\n label: '当前游戏',\n placeholder: '请选择游戏',\n },\n RequireGame: {\n description: '请选择游戏',\n },\n UserWidget: {\n signOutText: '登出',\n },\n UserList: {\n createTitle: '创建用户',\n createSuccessfully: '用户创建成功',\n updateTitle: '更新用户',\n updateSuccessfully: '用户更新成功',\n deleteTitle: '删除用户',\n deleteContent: '确定要删除用户 <%= user %> 吗?',\n deleteSuccessfully: '用户删除成功',\n },\n RoleList: {\n createTitle: '创建角色',\n createSuccessfully: '角色创建成功',\n updateTitle: '更新角色',\n updateSuccessfully: '角色更新成功',\n deleteTitle: '删除角色',\n deleteContent: '确定要删除角色 <%= role %> 吗?',\n deleteSuccessfully: '角色删除成功',\n },\n PermissionList: {\n failedDescription: '获取权限列表失败',\n baseSectionTitle: '平台基础权限',\n gameSectionTitle: '游戏权限',\n gameSectionDescription: '请先选择游戏',\n gameSelectPlaceholder: '请先选择游戏',\n removeText: '移除',\n addText: '添加游戏权限',\n },\n RoleDetail: {\n title: '角色详情',\n },\n InfiniteList: {\n loadingText: '加载中',\n reachEndText: '已经到底了',\n loadMoreText: '加载更多',\n },\n}\n\nexport default locale\n","import { get, has, template } from 'lodash-es'\nimport { useContext, useMemo } from 'react'\nimport type { Locale } from '.'\nimport type { LocaleContextProps } from './context'\nimport LocaleContext from './context'\nimport defaultLocale from './zh_CN'\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 localeFromContext = useContext<LocaleContextProps | undefined>(LocaleContext)\n\n const locale = {\n ...defaultLocale,\n ...localeFromContext,\n }\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"]}
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
- interface LocaleProviderProps {
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 { jsx } from 'react/jsx-runtime';
2
+ import { createContext, useMemo, useContext } from 'react';
3
+ import { useStore } from 'zustand';
4
+ import 'react/jsx-runtime';
4
5
 
5
- // src/components/locale/index.tsx
6
- var LocaleContext = createContext(void 0);
7
- var context_default = LocaleContext;
8
-
9
- // src/components/locale/zh_CN.ts
10
- var locale = {
11
- global: {
12
- noEntitlement: "\u65E0\u6743\u9650\uFF0C\u8BF7\u8054\u7CFB\u7BA1\u7406\u5458\u3002",
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 localeFromContext = useContext(context_default);
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 { locale_default as default, useTranslation };
25
+ export { useTranslation };
121
26
  //# sourceMappingURL=index.js.map
122
27
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/components/locale/context.ts","../src/components/locale/zh_CN.ts","../src/components/locale/hooks.ts","../src/components/locale/index.tsx"],"names":["locale","useMemo"],"mappings":";;;;;AAKA,IAAM,aAAA,GAAgB,cAA8C,KAAS,CAAA,CAAA,CAAA;AAE7E,IAAO,eAAQ,GAAA,aAAA,CAAA;;;ACLf,IAAM,MAAiB,GAAA;AAAA,EACrB,MAAQ,EAAA;AAAA,IACN,aAAe,EAAA,oEAAA;AAAA,IACf,IAAM,EAAA,cAAA;AAAA,IACN,YAAc,EAAA,0BAAA;AAAA,IACd,SAAW,EAAA,cAAA;AAAA,IACX,MAAQ,EAAA,cAAA;AAAA,IACR,IAAM,EAAA,cAAA;AAAA,IACN,MAAQ,EAAA,cAAA;AAAA,IACR,SAAW,EAAA,cAAA;AAAA,IACX,IAAM,EAAA,cAAA;AAAA,IACN,IAAM,EAAA,cAAA;AAAA,IACN,IAAM,EAAA,cAAA;AAAA,IACN,QAAU,EAAA,oBAAA;AAAA,IACV,QAAU,EAAA,cAAA;AAAA,IACV,KAAO,EAAA,cAAA;AAAA,IACP,MAAQ,EAAA,cAAA;AAAA,IACR,KAAO,EAAA,cAAA;AAAA,IACP,OAAS,EAAA,cAAA;AAAA,IACT,QAAU,EAAA,cAAA;AAAA,IACV,GAAK,EAAA,cAAA;AAAA,IACL,MAAQ,EAAA,cAAA;AAAA,GACV;AAAA,EACA,MAAQ,EAAA;AAAA,IACN,KAAO,EAAA,0BAAA;AAAA,IACP,UAAY,EAAA,gCAAA;AAAA,IACZ,eAAiB,EAAA,oBAAA;AAAA,IACjB,aAAe,EAAA,4FAAA;AAAA,IACf,OAAS,EAAA,cAAA;AAAA,GACX;AAAA,EACA,QAAU,EAAA;AAAA,IACR,QAAU,EAAA,kDAAA;AAAA,IACV,UAAY,EAAA,0BAAA;AAAA,GACd;AAAA,EACA,iBAAmB,EAAA;AAAA,IACjB,WAAa,EAAA,cAAA;AAAA,IACb,SAAW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,IACb,YAAc,EAAA,gCAAA;AAAA,IACd,YAAc,EAAA,0BAAA;AAAA,GAChB;AACF,CAAA,CAAA;AAEA,IAAO,aAAQ,GAAA,MAAA,CAAA;;;ACtER,SAAS,cAAiB,GAAA;AAC/B,EAAM,MAAA,iBAAA,GAAoB,WAA2C,eAAa,CAAA,CAAA;AAElF,EAAA,MAAMA,OAAS,GAAA;AAAA,IACb,GAAG,aAAA;AAAA,IACH,GAAG,iBAAA;AAAA,GACL,CAAA;AAEA,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,CAAA;AC+DA,IAAM,iBAA6D,CAAS,KAAA,KAAA;AAC1E,EAAA,MAAM,EAAE,MAAAA,EAAAA,OAAAA,GAAS,EAAC,EAAa,UAAa,GAAA,KAAA,CAAA;AAC5C,EAAM,MAAA,oBAAA,GAAuBC,QAAQ,OAAO,EAAE,GAAGD,OAAO,EAAA,CAAA,EAAI,CAACA,OAAM,CAAC,CAAA,CAAA;AAEpE,EAAA,2BAAQ,eAAc,CAAA,QAAA,EAAd,EAAuB,KAAA,EAAO,sBAAuB,QAAS,EAAA,CAAA,CAAA;AACxE,CAAA,CAAA;AAEA,IAAO,cAAQ,GAAA","file":"index.js","sourcesContent":["import { createContext } from 'react'\nimport type { Locale } from '.'\n\nexport type LocaleContextProps = Locale\n\nconst LocaleContext = createContext<LocaleContextProps | undefined>(undefined)\n\nexport default LocaleContext\n","import type { Locale } from '.'\n\nconst locale: Locale = {\n global: {\n noEntitlement: '无权限,请联系管理员。',\n name: '名称',\n creationTime: '创建时间',\n operation: '操作',\n update: '更新',\n edit: '编辑',\n delete: '删除',\n selectAll: '全选',\n game: '游戏',\n user: '用户',\n role: '角色',\n username: '用户名',\n password: '密码',\n label: '标签',\n method: '方法',\n route: '路由',\n request: '请求',\n response: '响应',\n add: '添加',\n signIn: '登录',\n },\n SignIn: {\n title: '登录方式',\n thirdParty: '第三方登录',\n signInWithIDass: 'IDass 登录',\n notRegistered: '您还未在平台注册,请联系管理员',\n welcome: '欢迎',\n },\n NotFound: {\n subTitle: '访问的页面不存在',\n buttonText: '返回首页',\n },\n FilterFormWrapper: {\n confirmText: '查询',\n resetText: '重置',\n },\n FormModal: {\n confirmText: '确认',\n cancelText: '取消',\n },\n GameSelect: {\n label: '当前游戏',\n placeholder: '请选择游戏',\n },\n RequireGame: {\n description: '请选择游戏',\n },\n UserWidget: {\n signOutText: '登出',\n },\n UserList: {\n createTitle: '创建用户',\n createSuccessfully: '用户创建成功',\n updateTitle: '更新用户',\n updateSuccessfully: '用户更新成功',\n deleteTitle: '删除用户',\n deleteContent: '确定要删除用户 <%= user %> 吗?',\n deleteSuccessfully: '用户删除成功',\n },\n RoleList: {\n createTitle: '创建角色',\n createSuccessfully: '角色创建成功',\n updateTitle: '更新角色',\n updateSuccessfully: '角色更新成功',\n deleteTitle: '删除角色',\n deleteContent: '确定要删除角色 <%= role %> 吗?',\n deleteSuccessfully: '角色删除成功',\n },\n PermissionList: {\n failedDescription: '获取权限列表失败',\n baseSectionTitle: '平台基础权限',\n gameSectionTitle: '游戏权限',\n gameSectionDescription: '请先选择游戏',\n gameSelectPlaceholder: '请先选择游戏',\n removeText: '移除',\n addText: '添加游戏权限',\n },\n RoleDetail: {\n title: '角色详情',\n },\n InfiniteList: {\n loadingText: '加载中',\n reachEndText: '已经到底了',\n loadMoreText: '加载更多',\n },\n}\n\nexport default locale\n","import { get, has, template } from 'lodash-es'\nimport { useContext, useMemo } from 'react'\nimport type { Locale } from '.'\nimport type { LocaleContextProps } from './context'\nimport LocaleContext from './context'\nimport defaultLocale from './zh_CN'\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 localeFromContext = useContext<LocaleContextProps | undefined>(LocaleContext)\n\n const locale = {\n ...defaultLocale,\n ...localeFromContext,\n }\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","import type { FC, PropsWithChildren } from 'react'\nimport { useMemo } from 'react'\nimport LocaleContext from './context'\n\nexport type Locale = {\n global: {\n noEntitlement: string\n name: string\n creationTime: string\n operation: string\n update: string\n edit: string\n delete: string\n selectAll: string\n game: string\n user: string\n role: string\n username: string\n password: string\n label: string\n method: string\n route: string\n request: string\n response: string\n add: string\n signIn: string\n }\n SignIn: {\n title: string\n thirdParty: string\n signInWithIDass: string\n notRegistered: string\n welcome: string\n }\n NotFound: {\n subTitle: string\n buttonText: string\n }\n FilterFormWrapper: {\n confirmText: string\n resetText: string\n }\n FormModal: {\n confirmText: string\n cancelText: string\n }\n GameSelect: {\n label: string\n placeholder: string\n }\n RequireGame: {\n description: string\n }\n UserWidget: {\n signOutText: string\n }\n UserList: {\n createTitle: string\n createSuccessfully: string\n updateTitle: string\n updateSuccessfully: string\n deleteTitle: string\n deleteContent: string\n deleteSuccessfully: string\n }\n RoleList: {\n createTitle: string\n createSuccessfully: string\n updateTitle: string\n updateSuccessfully: string\n deleteTitle: string\n deleteContent: string\n deleteSuccessfully: string\n }\n PermissionList: {\n failedDescription: string\n baseSectionTitle: string\n gameSectionTitle: string\n gameSectionDescription: string\n gameSelectPlaceholder: string\n removeText: string\n addText: string\n }\n RoleDetail: {\n title: string\n }\n InfiniteList: {\n loadingText: string\n reachEndText: string\n loadMoreText: string\n }\n}\n\nexport { useTranslation } from './hooks'\n\nexport interface LocaleProviderProps {\n locale: Locale\n}\n\nconst LocaleProvider: FC<PropsWithChildren<LocaleProviderProps>> = props => {\n const { locale = {} as Locale, children } = props\n const memoizedContextValue = useMemo(() => ({ ...locale }), [locale])\n\n return <LocaleContext.Provider value={memoizedContextValue}>{children}</LocaleContext.Provider>\n}\n\nexport default LocaleProvider\n"]}
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
@@ -1,5 +1,4 @@
1
1
  import { Locale } from './index.js';
2
- import 'react';
3
2
 
4
3
  declare const locale: Locale;
5
4
 
package/locale/ko_KR.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { Locale } from './index.js';
2
- import 'react';
3
2
 
4
3
  declare const locale: Locale;
5
4
 
package/locale/zh_CN.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { Locale } from './index.js';
2
- import 'react';
3
2
 
4
3
  declare const locale: Locale;
5
4
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "react-toolkits",
3
3
  "type": "module",
4
- "version": "2.8.3",
4
+ "version": "2.9.0",
5
5
  "sideEffects": [
6
6
  "*.css"
7
7
  ],