react-toolkits 2.11.18 → 2.13.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 +18 -0
- package/lib/index.css +1 -1
- package/lib/index.css.map +1 -1
- package/lib/index.d.ts +232 -253
- package/lib/index.js +319 -271
- package/lib/index.js.map +1 -1
- package/locale/hooks.js +5 -5
- package/locale/hooks.js.map +1 -1
- package/locale/index.js +5 -5
- package/locale/index.js.map +1 -1
- package/package.json +21 -22
package/locale/hooks.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { has, template, get } from 'lodash-es';
|
|
2
|
-
import { createContext,
|
|
2
|
+
import { createContext, useContext, useMemo } from 'react';
|
|
3
3
|
import 'antd';
|
|
4
4
|
import 'swr';
|
|
5
5
|
import { useStore } from 'zustand';
|
|
@@ -9,9 +9,9 @@ import 'jwt-decode';
|
|
|
9
9
|
import 'react/jsx-runtime';
|
|
10
10
|
|
|
11
11
|
// src/components/locale/hooks.ts
|
|
12
|
-
var
|
|
13
|
-
function
|
|
14
|
-
const store = useContext(
|
|
12
|
+
var Context = createContext(null);
|
|
13
|
+
function useContextStore(selector) {
|
|
14
|
+
const store = useContext(Context);
|
|
15
15
|
if (!store) throw new Error("Missing ToolkitsProvider in the tree");
|
|
16
16
|
return useStore(store, selector);
|
|
17
17
|
}
|
|
@@ -19,7 +19,7 @@ if (process.env.NODE_ENV !== "production") ;
|
|
|
19
19
|
|
|
20
20
|
// src/components/locale/hooks.ts
|
|
21
21
|
function useTranslation() {
|
|
22
|
-
const locale2 =
|
|
22
|
+
const locale2 = useContextStore((state) => state.locale);
|
|
23
23
|
const t = useMemo(
|
|
24
24
|
() => (key, data) => has(locale2, key) ? template(get(locale2, key))(data) : key,
|
|
25
25
|
[locale2]
|
package/locale/hooks.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/components/
|
|
1
|
+
{"version":3,"sources":["../src/components/contextProvider/ContextProvider.tsx","../src/components/locale/hooks.ts"],"names":["locale"],"mappings":";;;;;;;;;;;AAeA,IAAM,OAAA,GAAU,cAAmC,IAAI,CAAA;AAEhD,SAAS,gBAAmB,QAAuC,EAAA;AACxE,EAAM,MAAA,KAAA,GAAQ,WAAW,OAAO,CAAA;AAChC,EAAA,IAAI,CAAC,KAAA,EAAa,MAAA,IAAI,MAAM,sCAAsC,CAAA;AAClE,EAAO,OAAA,QAAA,CAAS,OAAO,QAAQ,CAAA;AACjC;AAwDA,IAAI,OAAA,CAAQ,GAAI,CAAA,QAAA,KAAa,YAAc,EAAA;;;AC1DpC,SAAS,cAAiB,GAAA;AAC/B,EAAA,MAAMA,OAAS,GAAA,eAAA,CAAgB,CAAS,KAAA,KAAA,KAAA,CAAM,MAAM,CAAA;AAEpD,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;AAAA,GACT;AAEA,EAAA,OAAO,EAAE,CAAE,EAAA;AACb","file":"hooks.js","sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { App } from 'antd'\nimport type { ComponentType, FC, PropsWithChildren } from 'react'\nimport { createContext, useContext, useRef } from 'react'\nimport { SWRConfig } from 'swr'\nimport type { Head } from 'ts-essentials'\nimport { useStore } from 'zustand'\nimport type { ToolkitsState } from '../../stores'\nimport { createToolkitsStore } from '../../stores'\nimport type { ContextSlice } from '../../stores/context'\nimport type { JsonData } from '../../types'\nimport { Interceptors } from '../interceptors'\n\ntype ContextStore = ReturnType<typeof createToolkitsStore>\n\nconst Context = createContext<ContextStore | null>(null)\n\nexport function useContextStore<T>(selector: (state: ToolkitsState) => T) {\n const store = useContext(Context)\n if (!store) throw new Error('Missing ToolkitsProvider in the tree')\n return useStore(store, selector)\n}\n\nexport type ContextProviderProps = PropsWithChildren<Partial<ContextSlice>>\n\nlet globalState: ToolkitsState\n\nconst Contextrovider: FC<ContextProviderProps> = props => {\n const { children, ...restProps } = props\n const storeRef = useRef<ContextStore>()\n\n if (!storeRef.current) {\n storeRef.current = createToolkitsStore({\n ...globalState,\n ...restProps,\n })\n }\n\n globalState = storeRef.current.getState()\n\n if (!globalState.signInPath) {\n throw new Error('ToolkitsProvider: 请配置 \"signInPath\"')\n }\n\n const { axios } = globalState\n\n return (\n <Context.Provider value={storeRef.current}>\n <App>\n <Interceptors>\n <SWRConfig\n value={{\n fetcher: async (arg: string | Head<Parameters<typeof axios.request>>) => {\n const response =\n typeof arg === 'string' ? await axios.get<JsonData>(arg) : await axios.request<JsonData>(arg)\n return response.data.data\n },\n }}\n >\n {children}\n </SWRConfig>\n </Interceptors>\n </App>\n </Context.Provider>\n )\n}\n\nexport const withContext = (Component: ComponentType, providerProps: Omit<ContextProviderProps, 'children'>) => {\n return (props: any) => {\n return (\n <Contextrovider {...providerProps}>\n <Component {...props} />\n </Contextrovider>\n )\n }\n}\n\nif (process.env.NODE_ENV !== 'production') {\n Contextrovider.displayName = 'Contextrovider'\n}\n\nexport default Contextrovider\n","import { get, has, template } from 'lodash-es'\nimport { useMemo } from 'react'\nimport { useContextStore } 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 = useContextStore(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.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { has, template, get } from 'lodash-es';
|
|
2
|
-
import { createContext,
|
|
2
|
+
import { createContext, useContext, useMemo } from 'react';
|
|
3
3
|
import 'antd';
|
|
4
4
|
import 'swr';
|
|
5
5
|
import { useStore } from 'zustand';
|
|
@@ -9,9 +9,9 @@ import 'jwt-decode';
|
|
|
9
9
|
import 'react/jsx-runtime';
|
|
10
10
|
|
|
11
11
|
// src/components/locale/hooks.ts
|
|
12
|
-
var
|
|
13
|
-
function
|
|
14
|
-
const store = useContext(
|
|
12
|
+
var Context = createContext(null);
|
|
13
|
+
function useContextStore(selector) {
|
|
14
|
+
const store = useContext(Context);
|
|
15
15
|
if (!store) throw new Error("Missing ToolkitsProvider in the tree");
|
|
16
16
|
return useStore(store, selector);
|
|
17
17
|
}
|
|
@@ -19,7 +19,7 @@ if (process.env.NODE_ENV !== "production") ;
|
|
|
19
19
|
|
|
20
20
|
// src/components/locale/hooks.ts
|
|
21
21
|
function useTranslation() {
|
|
22
|
-
const locale2 =
|
|
22
|
+
const locale2 = useContextStore((state) => state.locale);
|
|
23
23
|
const t = useMemo(
|
|
24
24
|
() => (key, data) => has(locale2, key) ? template(get(locale2, key))(data) : key,
|
|
25
25
|
[locale2]
|
package/locale/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/components/
|
|
1
|
+
{"version":3,"sources":["../src/components/contextProvider/ContextProvider.tsx","../src/components/locale/hooks.ts"],"names":["locale"],"mappings":";;;;;;;;;;;AAeA,IAAM,OAAA,GAAU,cAAmC,IAAI,CAAA;AAEhD,SAAS,gBAAmB,QAAuC,EAAA;AACxE,EAAM,MAAA,KAAA,GAAQ,WAAW,OAAO,CAAA;AAChC,EAAA,IAAI,CAAC,KAAA,EAAa,MAAA,IAAI,MAAM,sCAAsC,CAAA;AAClE,EAAO,OAAA,QAAA,CAAS,OAAO,QAAQ,CAAA;AACjC;AAwDA,IAAI,OAAA,CAAQ,GAAI,CAAA,QAAA,KAAa,YAAc,EAAA;;;AC1DpC,SAAS,cAAiB,GAAA;AAC/B,EAAA,MAAMA,OAAS,GAAA,eAAA,CAAgB,CAAS,KAAA,KAAA,KAAA,CAAM,MAAM,CAAA;AAEpD,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;AAAA,GACT;AAEA,EAAA,OAAO,EAAE,CAAE,EAAA;AACb","file":"index.js","sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { App } from 'antd'\nimport type { ComponentType, FC, PropsWithChildren } from 'react'\nimport { createContext, useContext, useRef } from 'react'\nimport { SWRConfig } from 'swr'\nimport type { Head } from 'ts-essentials'\nimport { useStore } from 'zustand'\nimport type { ToolkitsState } from '../../stores'\nimport { createToolkitsStore } from '../../stores'\nimport type { ContextSlice } from '../../stores/context'\nimport type { JsonData } from '../../types'\nimport { Interceptors } from '../interceptors'\n\ntype ContextStore = ReturnType<typeof createToolkitsStore>\n\nconst Context = createContext<ContextStore | null>(null)\n\nexport function useContextStore<T>(selector: (state: ToolkitsState) => T) {\n const store = useContext(Context)\n if (!store) throw new Error('Missing ToolkitsProvider in the tree')\n return useStore(store, selector)\n}\n\nexport type ContextProviderProps = PropsWithChildren<Partial<ContextSlice>>\n\nlet globalState: ToolkitsState\n\nconst Contextrovider: FC<ContextProviderProps> = props => {\n const { children, ...restProps } = props\n const storeRef = useRef<ContextStore>()\n\n if (!storeRef.current) {\n storeRef.current = createToolkitsStore({\n ...globalState,\n ...restProps,\n })\n }\n\n globalState = storeRef.current.getState()\n\n if (!globalState.signInPath) {\n throw new Error('ToolkitsProvider: 请配置 \"signInPath\"')\n }\n\n const { axios } = globalState\n\n return (\n <Context.Provider value={storeRef.current}>\n <App>\n <Interceptors>\n <SWRConfig\n value={{\n fetcher: async (arg: string | Head<Parameters<typeof axios.request>>) => {\n const response =\n typeof arg === 'string' ? await axios.get<JsonData>(arg) : await axios.request<JsonData>(arg)\n return response.data.data\n },\n }}\n >\n {children}\n </SWRConfig>\n </Interceptors>\n </App>\n </Context.Provider>\n )\n}\n\nexport const withContext = (Component: ComponentType, providerProps: Omit<ContextProviderProps, 'children'>) => {\n return (props: any) => {\n return (\n <Contextrovider {...providerProps}>\n <Component {...props} />\n </Contextrovider>\n )\n }\n}\n\nif (process.env.NODE_ENV !== 'production') {\n Contextrovider.displayName = 'Contextrovider'\n}\n\nexport default Contextrovider\n","import { get, has, template } from 'lodash-es'\nimport { useMemo } from 'react'\nimport { useContextStore } 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 = useContextStore(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/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-toolkits",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.13.0",
|
|
5
5
|
"sideEffects": [
|
|
6
6
|
"*.css"
|
|
7
7
|
],
|
|
@@ -35,41 +35,40 @@
|
|
|
35
35
|
"registry": "https://registry.npmjs.org/"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@ant-design/icons": "^5.
|
|
38
|
+
"@ant-design/icons": "^5.5.1",
|
|
39
39
|
"@monaco-editor/react": "^4.6.0",
|
|
40
40
|
"axios": "^1.7.7",
|
|
41
|
-
"dayjs": "^1.11.
|
|
41
|
+
"dayjs": "^1.11.13",
|
|
42
42
|
"immer": "^10.1.1",
|
|
43
43
|
"jwt-decode": "^4.0.0",
|
|
44
44
|
"lodash-es": "^4.17.21",
|
|
45
|
-
"query-string": "^9.1.
|
|
45
|
+
"query-string": "^9.1.1",
|
|
46
46
|
"swr": "^2.2.5",
|
|
47
|
-
"
|
|
48
|
-
"zustand": "^4.5.4"
|
|
47
|
+
"zustand": "^5.0.1"
|
|
49
48
|
},
|
|
50
49
|
"devDependencies": {
|
|
51
|
-
"@esbuild/linux-x64": "^0.
|
|
50
|
+
"@esbuild/linux-x64": "^0.24.0",
|
|
52
51
|
"@types/lodash-es": "^4.17.12",
|
|
53
|
-
"@types/node": "^22.0
|
|
54
|
-
"@types/react": "^18.3.
|
|
55
|
-
"@types/react-dom": "^18.3.
|
|
56
|
-
"antd": "^5.
|
|
57
|
-
"autoprefixer": "^10.4.
|
|
52
|
+
"@types/node": "^22.9.0",
|
|
53
|
+
"@types/react": "^18.3.12",
|
|
54
|
+
"@types/react-dom": "^18.3.1",
|
|
55
|
+
"antd": "^5.22.1",
|
|
56
|
+
"autoprefixer": "^10.4.20",
|
|
58
57
|
"cross-env": "^7.0.3",
|
|
59
|
-
"esbuild": "0.
|
|
60
|
-
"eslint": "^
|
|
61
|
-
"postcss": "^8.4.
|
|
58
|
+
"esbuild": "0.24.0",
|
|
59
|
+
"eslint": "^9.15.0",
|
|
60
|
+
"postcss": "^8.4.49",
|
|
62
61
|
"prettier": "^3.3.3",
|
|
63
62
|
"react": "^18.3.1",
|
|
64
63
|
"react-dom": "^18.3.1",
|
|
65
|
-
"react-router-dom": "^6.
|
|
66
|
-
"tailwindcss": "^3.4.
|
|
67
|
-
"ts-essentials": "^10.0.
|
|
68
|
-
"tsup": "^8.
|
|
69
|
-
"typescript": "^5.
|
|
64
|
+
"react-router-dom": "^6.28.0",
|
|
65
|
+
"tailwindcss": "^3.4.15",
|
|
66
|
+
"ts-essentials": "^10.0.3",
|
|
67
|
+
"tsup": "^8.3.5",
|
|
68
|
+
"typescript": "^5.6.3",
|
|
70
69
|
"@flow97/eslint-config-react": "1.0.3",
|
|
71
|
-
"
|
|
72
|
-
"
|
|
70
|
+
"tsconfig": "0.0.6",
|
|
71
|
+
"tailwind-config": "0.1.2"
|
|
73
72
|
},
|
|
74
73
|
"peerDependencies": {
|
|
75
74
|
"antd": "^5.12.2",
|