@creekjs/web-components 1.0.10 → 1.0.12
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/.turbo/turbo-father$colon$build.log +23 -23
- package/dist/creek-config-provider/CreekConfigContext.d.ts +0 -4
- package/dist/creek-config-provider/CreekConfigContext.js.map +2 -2
- package/dist/creek-config-provider/CreekI18nProvider.d.ts +5 -4
- package/dist/creek-config-provider/CreekI18nProvider.js +53 -30
- package/dist/creek-config-provider/CreekI18nProvider.js.map +2 -2
- package/dist/creek-config-provider/index.js +5 -1
- package/dist/creek-config-provider/index.js.map +3 -3
- package/dist/creek-layout/index.js +12 -6
- package/dist/creek-layout/index.js.map +3 -3
- package/dist/creek-locale-button/index.js +4 -4
- package/dist/creek-locale-button/index.js.map +1 -1
- package/dist/locales/{en-US.js → en_US.js} +2 -2
- package/dist/locales/{en-US.js.map → en_US.js.map} +1 -1
- package/dist/locales/{zh-CN.js → zh_CN.js} +2 -2
- package/dist/locales/{zh-CN.js.map → zh_CN.js.map} +1 -1
- package/i18n.config.ts +5 -2
- package/package.json +3 -3
- package/src/creek-config-provider/CreekConfigContext.tsx +0 -4
- package/src/creek-config-provider/CreekI18nProvider.tsx +65 -37
- package/src/creek-config-provider/index.tsx +8 -4
- package/src/creek-layout/index.tsx +20 -9
- package/src/creek-locale-button/index.tsx +4 -4
- /package/dist/locales/{en-US.d.ts → en_US.d.ts} +0 -0
- /package/dist/locales/{zh-CN.d.ts → zh_CN.d.ts} +0 -0
- /package/src/locales/{en-US.ts → en_US.ts} +0 -0
- /package/src/locales/{zh-CN.ts → zh_CN.ts} +0 -0
|
@@ -1,54 +1,54 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
-
> @creekjs/web-components@1.0.
|
|
3
|
+
> @creekjs/web-components@1.0.11 father:build /Users/ernestwang/Documents/code-resoorce/creek/packages/web-components
|
|
4
4
|
> father build
|
|
5
5
|
|
|
6
6
|
[36minfo[39m - Clean output directories
|
|
7
7
|
[36minfo[39m - Bundless for [33msrc[39m directory to [33mcjs[39m format
|
|
8
|
+
[35mevent[39m - Bundless [90mindex.tsx[39m to [90mdist/creek-config-provider/index.js[39m (with declaration)
|
|
8
9
|
[35mevent[39m - Bundless [90mCreekConfigContext.tsx[39m to [90mdist/creek-config-provider/CreekConfigContext.js[39m (with declaration)
|
|
9
10
|
[35mevent[39m - Bundless [90mindex.ts[39m to [90mdist/creek-hooks/index.js[39m (with declaration)
|
|
10
11
|
[35mevent[39m - Bundless [90mCreekI18nProvider.tsx[39m to [90mdist/creek-config-provider/CreekI18nProvider.js[39m (with declaration)
|
|
11
|
-
[35mevent[39m - Bundless [
|
|
12
|
-
[35mevent[39m - Bundless [90mModalHelper.tsx[39m to [90mdist/creek-hooks/useApp/ModalHelper.js[39m (with declaration)
|
|
12
|
+
[35mevent[39m - Bundless [90mDrawerHelper.tsx[39m to [90mdist/creek-hooks/useApp/DrawerHelper.js[39m (with declaration)
|
|
13
13
|
[35mevent[39m - Bundless [90mindex.tsx[39m to [90mdist/creek-hooks/useApp/index.js[39m (with declaration)
|
|
14
|
-
[35mevent[39m - Bundless [
|
|
14
|
+
[35mevent[39m - Bundless [90mModalHelper.tsx[39m to [90mdist/creek-hooks/useApp/ModalHelper.js[39m (with declaration)
|
|
15
|
+
[35mevent[39m - Bundless [90mtypes.ts[39m to [90mdist/creek-hooks/useApp/types.js[39m (with declaration)
|
|
15
16
|
[35mevent[39m - Bundless [90mindex.tsx[39m to [90mdist/creek-icon/index.js[39m (with declaration)
|
|
17
|
+
[35mevent[39m - Bundless [90mFullScreen.tsx[39m to [90mdist/creek-layout/ActionRender/FullScreen.js[39m (with declaration)
|
|
16
18
|
[35mevent[39m - Bundless [90mindex.tsx[39m to [90mdist/creek-keep-alive/index.js[39m (with declaration)
|
|
19
|
+
[35mevent[39m - Bundless [90mindex.tsx[39m to [90mdist/creek-layout/ActionRender/index.js[39m (with declaration)
|
|
20
|
+
[35mevent[39m - Bundless [90mUserInfo.tsx[39m to [90mdist/creek-layout/ActionRender/UserInfo.js[39m (with declaration)
|
|
21
|
+
[35mevent[39m - Bundless [90mLayoutSettings.tsx[39m to [90mdist/creek-layout/ActionRender/LayoutSettings.js[39m (with declaration)
|
|
17
22
|
[35mevent[39m - Bundless [90mindex.tsx[39m to [90mdist/creek-layout/Exception/index.js[39m (with declaration)
|
|
18
|
-
[35mevent[39m - Bundless [
|
|
19
|
-
[35mevent[39m - Bundless [90mindex.tsx[39m to [90mdist/creek-config-provider/index.js[39m (with declaration)
|
|
20
|
-
[35mevent[39m - Bundless [90mFullScreen.tsx[39m to [90mdist/creek-layout/ActionRender/FullScreen.js[39m (with declaration)
|
|
23
|
+
[35mevent[39m - Bundless [90mNotFound.tsx[39m to [90mdist/creek-layout/Exception/NotFound.js[39m (with declaration)
|
|
21
24
|
[35mevent[39m - Bundless [90mCollapseButton.tsx[39m to [90mdist/creek-layout/CollapseButton.js[39m (with declaration)
|
|
22
25
|
[35mevent[39m - Bundless [90mNotFoundPage.tsx[39m to [90mdist/creek-layout/Exception/NotFoundPage.js[39m (with declaration)
|
|
23
|
-
[35mevent[39m - Bundless [90mNotFound.tsx[39m to [90mdist/creek-layout/Exception/NotFound.js[39m (with declaration)
|
|
24
|
-
[35mevent[39m - Bundless [90mindex.tsx[39m to [90mdist/creek-layout/ActionRender/index.js[39m (with declaration)
|
|
25
|
-
[35mevent[39m - Bundless [90museLayoutSettingsStore.ts[39m to [90mdist/creek-layout/useLayoutSettingsStore.js[39m (with declaration)
|
|
26
26
|
[35mevent[39m - Bundless [90mindex.tsx[39m to [90mdist/creek-layout/index.js[39m (with declaration)
|
|
27
|
-
[35mevent[39m - Bundless [90mLayoutSettings.tsx[39m to [90mdist/creek-layout/ActionRender/LayoutSettings.js[39m (with declaration)
|
|
28
27
|
[35mevent[39m - Bundless [90mindex.tsx[39m to [90mdist/creek-loading/index.js[39m (with declaration)
|
|
29
|
-
[35mevent[39m - Bundless [90mindex.tsx[39m to [90mdist/creek-page-container/index.js[39m (with declaration)
|
|
30
|
-
[35mevent[39m - Bundless [90mUserInfo.tsx[39m to [90mdist/creek-layout/ActionRender/UserInfo.js[39m (with declaration)
|
|
31
28
|
[35mevent[39m - Bundless [90mindex.tsx[39m to [90mdist/creek-locale-button/index.js[39m (with declaration)
|
|
32
29
|
[35mevent[39m - Bundless [90mindex.ts[39m to [90mdist/creek-style/index.js[39m (with declaration)
|
|
33
|
-
[35mevent[39m - Bundless [
|
|
30
|
+
[35mevent[39m - Bundless [90mscrollbar.ts[39m to [90mdist/creek-style/scrollbar.js[39m (with declaration)
|
|
31
|
+
[35mevent[39m - Bundless [90mindex.tsx[39m to [90mdist/creek-page-container/index.js[39m (with declaration)
|
|
34
32
|
[35mevent[39m - Bundless [90mEllipsisTooltip.tsx[39m to [90mdist/creek-table/components/EllipsisTooltip.js[39m (with declaration)
|
|
35
|
-
[35mevent[39m - Bundless [
|
|
33
|
+
[35mevent[39m - Bundless [90mDensityIcon.tsx[39m to [90mdist/creek-table/components/DensityIcon.js[39m (with declaration)
|
|
36
34
|
[35mevent[39m - Bundless [90mindex.ts[39m to [90mdist/creek-table/hooks/index.js[39m (with declaration)
|
|
35
|
+
[35mevent[39m - Bundless [90mindex.tsx[39m to [90mdist/creek-table/components/index.js[39m (with declaration)
|
|
37
36
|
[35mevent[39m - Bundless [90museAdaptiveToolBar.tsx[39m to [90mdist/creek-table/hooks/useAdaptiveToolBar.js[39m (with declaration)
|
|
38
|
-
[35mevent[39m - Bundless [90mscrollbar.ts[39m to [90mdist/creek-style/scrollbar.js[39m (with declaration)
|
|
39
|
-
[35mevent[39m - Bundless [90museAutoWidthColumns.tsx[39m to [90mdist/creek-table/hooks/useAutoWidthColumns.js[39m (with declaration)
|
|
40
37
|
[35mevent[39m - Bundless [90museEllipsisColumns.tsx[39m to [90mdist/creek-table/hooks/useEllipsisColumns.js[39m (with declaration)
|
|
38
|
+
[35mevent[39m - Bundless [90museAutoWidthColumns.tsx[39m to [90mdist/creek-table/hooks/useAutoWidthColumns.js[39m (with declaration)
|
|
41
39
|
[35mevent[39m - Bundless [90museIndexColumn.tsx[39m to [90mdist/creek-table/hooks/useIndexColumn.js[39m (with declaration)
|
|
42
40
|
[35mevent[39m - Bundless [90museResizableColumns.tsx[39m to [90mdist/creek-table/hooks/useResizableColumns.js[39m (with declaration)
|
|
43
41
|
[35mevent[39m - Bundless [90museElementDistance.tsx[39m to [90mdist/creek-table/hooks/useElementDistance.js[39m (with declaration)
|
|
42
|
+
[35mevent[39m - Bundless [90mindex.tsx[39m to [90mdist/creek-table/index.js[39m (with declaration)
|
|
44
43
|
[35mevent[39m - Bundless [90museTableOptions.tsx[39m to [90mdist/creek-table/hooks/useTableOptions.js[39m (with declaration)
|
|
45
44
|
[35mevent[39m - Bundless [90museTableScrollHeight.tsx[39m to [90mdist/creek-table/hooks/useTableScrollHeight.js[39m (with declaration)
|
|
46
|
-
[35mevent[39m - Bundless [90mSearchTable.tsx[39m to [90mdist/creek-table/SearchTable.js[39m (with declaration)
|
|
47
45
|
[35mevent[39m - Bundless [90mtype.ts[39m to [90mdist/creek-table/type.js[39m (with declaration)
|
|
48
|
-
[35mevent[39m - Bundless [
|
|
46
|
+
[35mevent[39m - Bundless [90mzh_CN.ts[39m to [90mdist/locales/zh_CN.js[39m (with declaration)
|
|
47
|
+
[35mevent[39m - Bundless [90museViewportHeight.tsx[39m to [90mdist/creek-hooks/useViewportHeight.js[39m (with declaration)
|
|
49
48
|
[35mevent[39m - Bundless [90mindex.tsx[39m to [90mdist/index.js[39m (with declaration)
|
|
50
|
-
[35mevent[39m - Bundless [
|
|
51
|
-
[35mevent[39m - Bundless [
|
|
52
|
-
[35mevent[39m - Bundless [
|
|
49
|
+
[35mevent[39m - Bundless [90museLayoutSettingsStore.ts[39m to [90mdist/creek-layout/useLayoutSettingsStore.js[39m (with declaration)
|
|
50
|
+
[35mevent[39m - Bundless [90men_US.ts[39m to [90mdist/locales/en_US.js[39m (with declaration)
|
|
51
|
+
[35mevent[39m - Bundless [90museStatusColumns.tsx[39m to [90mdist/creek-table/hooks/useStatusColumns.js[39m (with declaration)
|
|
52
|
+
[35mevent[39m - Bundless [90mSearchTable.tsx[39m to [90mdist/creek-table/SearchTable.js[39m (with declaration)
|
|
53
53
|
[35mevent[39m - Generate declaration files...
|
|
54
|
-
[35mevent[39m - Transformed successfully in
|
|
54
|
+
[35mevent[39m - Transformed successfully in 6572 ms (45 files)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/creek-config-provider/CreekConfigContext.tsx"],
|
|
4
|
-
"sourcesContent": ["import { createContext } from 'react';\n\nexport type CreekConfigContextProps = {\n iconFontCNs?: string[];\n
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA8B;
|
|
4
|
+
"sourcesContent": ["import { createContext } from 'react';\n\nexport type CreekConfigContextProps = {\n iconFontCNs?: string[];\n};\n\nexport const CreekConfigContext = createContext<CreekConfigContextProps>({});\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA8B;AAMvB,IAAM,yBAAqB,4BAAuC,CAAC,CAAC;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,22 +1,23 @@
|
|
|
1
1
|
import type { ReactNode } from 'react';
|
|
2
|
+
export type LocaleCode = 'en_US' | 'zh_CN';
|
|
2
3
|
export interface CreekI18nProviderProps {
|
|
3
4
|
children?: ReactNode;
|
|
4
5
|
/**
|
|
5
6
|
* 语言标识
|
|
6
|
-
* @default '
|
|
7
|
+
* @default 'zh_CN'
|
|
7
8
|
*/
|
|
8
|
-
locale?:
|
|
9
|
+
locale?: LocaleCode;
|
|
9
10
|
/**
|
|
10
11
|
* 国际化语言包,透传给 react-intl
|
|
11
12
|
*/
|
|
12
13
|
messages?: Record<string, string>;
|
|
13
14
|
}
|
|
14
15
|
export declare const LocaleContext: import("react").Context<{
|
|
15
|
-
locale:
|
|
16
|
+
locale: LocaleCode;
|
|
16
17
|
changeLocale: (lang: string) => void;
|
|
17
18
|
}>;
|
|
18
19
|
export declare const useAppLocale: () => {
|
|
19
|
-
locale:
|
|
20
|
+
locale: LocaleCode;
|
|
20
21
|
changeLocale: (lang: string) => void;
|
|
21
22
|
};
|
|
22
23
|
export declare const CreekI18nProvider: (props: CreekI18nProviderProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -36,52 +36,75 @@ __export(CreekI18nProvider_exports, {
|
|
|
36
36
|
module.exports = __toCommonJS(CreekI18nProvider_exports);
|
|
37
37
|
var import_react = require("react");
|
|
38
38
|
var import_react2 = require("@creekjs/i18n/react");
|
|
39
|
-
var import_en_US = __toESM(require("../locales/
|
|
40
|
-
var import_zh_CN = __toESM(require("../locales/
|
|
39
|
+
var import_en_US = __toESM(require("../locales/en_US"));
|
|
40
|
+
var import_zh_CN = __toESM(require("../locales/zh_CN"));
|
|
41
41
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
42
|
-
var DEFAULT_LOCALE = "
|
|
42
|
+
var DEFAULT_LOCALE = "zh_CN";
|
|
43
|
+
var SUPPORTED_LOCALES = ["zh_CN", "en_US"];
|
|
44
|
+
var toUnderscoreLocale = (input) => {
|
|
45
|
+
if (!input)
|
|
46
|
+
return DEFAULT_LOCALE;
|
|
47
|
+
const normalized = input.replace("-", "_");
|
|
48
|
+
return SUPPORTED_LOCALES.includes(normalized) ? normalized : DEFAULT_LOCALE;
|
|
49
|
+
};
|
|
43
50
|
var MESSAGES_MAP = {
|
|
44
|
-
|
|
45
|
-
|
|
51
|
+
zh_CN: import_zh_CN.default,
|
|
52
|
+
en_US: import_en_US.default
|
|
46
53
|
};
|
|
47
54
|
var LocaleContext = (0, import_react.createContext)({
|
|
48
|
-
locale: (0, import_react2.getLocale)()
|
|
55
|
+
locale: toUnderscoreLocale((0, import_react2.getLocale)()),
|
|
49
56
|
changeLocale: (lang) => {
|
|
50
57
|
}
|
|
51
58
|
});
|
|
52
59
|
var useAppLocale = () => (0, import_react.useContext)(LocaleContext);
|
|
53
60
|
var CreekI18nProvider = (props) => {
|
|
54
|
-
var _a;
|
|
55
61
|
const { children, locale, messages } = props;
|
|
56
62
|
const parentIntl = (0, import_react.useContext)(import_react2.IntlContext);
|
|
57
|
-
const [
|
|
63
|
+
const [internalLocale, setInternalLocale] = (0, import_react.useState)();
|
|
58
64
|
const changeLocale = (0, import_react.useCallback)((lang) => {
|
|
59
|
-
|
|
60
|
-
|
|
65
|
+
const underscore = toUnderscoreLocale(lang);
|
|
66
|
+
(0, import_react2.setLocale)(underscore, false);
|
|
67
|
+
setInternalLocale(underscore);
|
|
61
68
|
}, []);
|
|
62
|
-
const currentLocale = (
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
const finalMessages = {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
69
|
+
const currentLocale = (0, import_react.useMemo)(() => {
|
|
70
|
+
var _a;
|
|
71
|
+
const rawLocale = internalLocale || locale || (parentIntl == null ? void 0 : parentIntl.locale) || ((_a = (0, import_react2.getIntl)()) == null ? void 0 : _a.locale) || DEFAULT_LOCALE;
|
|
72
|
+
return toUnderscoreLocale(rawLocale);
|
|
73
|
+
}, [internalLocale, locale, parentIntl == null ? void 0 : parentIntl.locale]);
|
|
74
|
+
const safeConfig = (0, import_react.useMemo)(() => {
|
|
75
|
+
const intlConfig = parentIntl || (0, import_react2.getIntl)() || {};
|
|
76
|
+
return {
|
|
77
|
+
formats: intlConfig.formats,
|
|
78
|
+
defaultLocale: intlConfig.defaultLocale,
|
|
79
|
+
defaultFormats: intlConfig.defaultFormats,
|
|
80
|
+
onError: intlConfig.onError
|
|
81
|
+
};
|
|
82
|
+
}, [parentIntl]);
|
|
83
|
+
const finalMessages = (0, import_react.useMemo)(() => {
|
|
84
|
+
var _a, _b;
|
|
85
|
+
let baseMessages = {};
|
|
86
|
+
if (parentIntl && parentIntl.locale === currentLocale.replace("_", "-")) {
|
|
87
|
+
baseMessages = parentIntl.messages;
|
|
88
|
+
} else {
|
|
89
|
+
baseMessages = ((_a = import_react2.appLocales) == null ? void 0 : _a[currentLocale]) || ((_b = (0, import_react2.getIntl)()) == null ? void 0 : _b.messages) || {};
|
|
90
|
+
}
|
|
91
|
+
return {
|
|
92
|
+
...baseMessages,
|
|
93
|
+
...MESSAGES_MAP[currentLocale] || import_zh_CN.default,
|
|
94
|
+
...messages || {}
|
|
95
|
+
};
|
|
96
|
+
}, [parentIntl, currentLocale, messages]);
|
|
81
97
|
(0, import_react.useEffect)(() => {
|
|
82
98
|
(0, import_react2.setLocaleMessages)(currentLocale, finalMessages);
|
|
83
99
|
}, [currentLocale, finalMessages]);
|
|
84
|
-
|
|
100
|
+
const contextValue = (0, import_react.useMemo)(
|
|
101
|
+
() => ({
|
|
102
|
+
locale: currentLocale,
|
|
103
|
+
changeLocale
|
|
104
|
+
}),
|
|
105
|
+
[currentLocale, changeLocale]
|
|
106
|
+
);
|
|
107
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react2.IntlProvider, { ...safeConfig, locale: currentLocale.replace("_", "-"), messages: finalMessages, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LocaleContext.Provider, { value: contextValue, children }) });
|
|
85
108
|
};
|
|
86
109
|
// Annotate the CommonJS export names for ESM import in node:
|
|
87
110
|
0 && (module.exports = {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/creek-config-provider/CreekI18nProvider.tsx"],
|
|
4
|
-
"sourcesContent": ["import type { ReactNode } from 'react';\nimport { createContext, useCallback, useContext, useEffect, useState } from 'react';\n\nimport { IntlContext, IntlProvider, getIntl, getLocale, setLocale, setLocaleMessages } from '@creekjs/i18n/react';\n\nimport enUS from '../locales/
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,
|
|
4
|
+
"sourcesContent": ["import type { ReactNode } from 'react';\nimport { createContext, useCallback, useContext, useEffect, useMemo, useState } from 'react';\n\nimport { IntlContext, IntlProvider, appLocales, getIntl, getLocale, setLocale, setLocaleMessages } from '@creekjs/i18n/react';\n\nimport enUS from '../locales/en_US';\nimport zhCN from '../locales/zh_CN';\n\nconst DEFAULT_LOCALE = 'zh_CN';\n\nexport type LocaleCode = 'en_US' | 'zh_CN';\n\nconst SUPPORTED_LOCALES: LocaleCode[] = ['zh_CN', 'en_US'];\n\nconst toUnderscoreLocale = (input?: string): LocaleCode => {\n if (!input) return DEFAULT_LOCALE;\n const normalized = input.replace('-', '_') as LocaleCode;\n return SUPPORTED_LOCALES.includes(normalized) ? normalized : DEFAULT_LOCALE;\n};\n\nexport interface CreekI18nProviderProps {\n children?: ReactNode;\n /**\n * 语言标识\n * @default 'zh_CN'\n */\n locale?: LocaleCode;\n /**\n * 国际化语言包,透传给 react-intl\n */\n messages?: Record<string, string>;\n}\n\nconst MESSAGES_MAP: Record<LocaleCode, Record<string, string>> = {\n zh_CN: zhCN,\n en_US: enUS,\n};\n\nexport const LocaleContext = createContext({\n locale: toUnderscoreLocale(getLocale()),\n changeLocale: (lang: string) => {},\n});\n\nexport const useAppLocale = () => useContext(LocaleContext);\n\nexport const CreekI18nProvider = (props: CreekI18nProviderProps) => {\n const { children, locale, messages } = props;\n\n // 获取父级 intl context\n const parentIntl = useContext(IntlContext);\n\n // 内部维护的 locale 状态,仅在调用 changeLocale 时更新\n const [internalLocale, setInternalLocale] = useState<string>();\n\n const changeLocale = useCallback((lang: string) => {\n const underscore = toUnderscoreLocale(lang);\n setLocale(underscore, false);\n setInternalLocale(underscore);\n }, []);\n\n // 1. 确定最终生效的 locale\n // 优先级:当前组件内部的 state > props.locale > parentIntl.locale > 全局默认\n const currentLocale = useMemo(() => {\n const rawLocale = internalLocale || locale || parentIntl?.locale || getIntl()?.locale || DEFAULT_LOCALE;\n return toUnderscoreLocale(rawLocale);\n }, [internalLocale, locale, parentIntl?.locale]);\n\n // 2. 提取父级上下文的安全配置 (避免将 IntlShape 的内部方法直接传给 IntlProvider)\n const safeConfig = useMemo(() => {\n const intlConfig = parentIntl || getIntl() || {};\n return {\n formats: intlConfig.formats,\n defaultLocale: intlConfig.defaultLocale,\n defaultFormats: intlConfig.defaultFormats,\n onError: intlConfig.onError,\n };\n }, [parentIntl]);\n\n // 3. 确定最终的 messages\n // 避免使用 stale 的 parentIntl.messages\n const finalMessages = useMemo(() => {\n let baseMessages: Record<string, any> = {};\n if (parentIntl && parentIntl.locale === currentLocale.replace('_', '-')) {\n baseMessages = parentIntl.messages;\n } else {\n // 优先从 appLocales 中获取对应语言的 messages\n baseMessages = appLocales?.[currentLocale] || getIntl()?.messages || {};\n }\n\n return {\n ...baseMessages,\n ...(MESSAGES_MAP[currentLocale] || zhCN),\n ...(messages || {}),\n };\n }, [parentIntl, currentLocale, messages]);\n\n // 4. 同步给全局 globalIntl,确保非 React 组件能够拿到\n useEffect(() => {\n setLocaleMessages(currentLocale, finalMessages);\n }, [currentLocale, finalMessages]);\n\n const contextValue = useMemo(\n () => ({\n locale: currentLocale,\n changeLocale,\n }),\n [currentLocale, changeLocale],\n );\n\n return (\n <IntlProvider {...safeConfig} locale={currentLocale.replace('_', '-')} messages={finalMessages}>\n <LocaleContext.Provider value={contextValue}>{children}</LocaleContext.Provider>\n </IntlProvider>\n );\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAAqF;AAErF,IAAAA,gBAAwG;AAExG,mBAAiB;AACjB,mBAAiB;AAyGX;AAvGN,IAAM,iBAAiB;AAIvB,IAAM,oBAAkC,CAAC,SAAS,OAAO;AAEzD,IAAM,qBAAqB,CAAC,UAA+B;AACzD,MAAI,CAAC;AAAO,WAAO;AACnB,QAAM,aAAa,MAAM,QAAQ,KAAK,GAAG;AACzC,SAAO,kBAAkB,SAAS,UAAU,IAAI,aAAa;AAC/D;AAeA,IAAM,eAA2D;AAAA,EAC/D,OAAO,aAAAC;AAAA,EACP,OAAO,aAAAC;AACT;AAEO,IAAM,oBAAgB,4BAAc;AAAA,EACzC,QAAQ,uBAAmB,yBAAU,CAAC;AAAA,EACtC,cAAc,CAAC,SAAiB;AAAA,EAAC;AACnC,CAAC;AAEM,IAAM,eAAe,UAAM,yBAAW,aAAa;AAEnD,IAAM,oBAAoB,CAAC,UAAkC;AAClE,QAAM,EAAE,UAAU,QAAQ,SAAS,IAAI;AAGvC,QAAM,iBAAa,yBAAW,yBAAW;AAGzC,QAAM,CAAC,gBAAgB,iBAAiB,QAAI,uBAAiB;AAE7D,QAAM,mBAAe,0BAAY,CAAC,SAAiB;AACjD,UAAM,aAAa,mBAAmB,IAAI;AAC1C,iCAAU,YAAY,KAAK;AAC3B,sBAAkB,UAAU;AAAA,EAC9B,GAAG,CAAC,CAAC;AAIL,QAAM,oBAAgB,sBAAQ,MAAM;AA9DtC;AA+DI,UAAM,YAAY,kBAAkB,WAAU,yCAAY,aAAU,gCAAQ,MAAR,mBAAW,WAAU;AACzF,WAAO,mBAAmB,SAAS;AAAA,EACrC,GAAG,CAAC,gBAAgB,QAAQ,yCAAY,MAAM,CAAC;AAG/C,QAAM,iBAAa,sBAAQ,MAAM;AAC/B,UAAM,aAAa,kBAAc,uBAAQ,KAAK,CAAC;AAC/C,WAAO;AAAA,MACL,SAAS,WAAW;AAAA,MACpB,eAAe,WAAW;AAAA,MAC1B,gBAAgB,WAAW;AAAA,MAC3B,SAAS,WAAW;AAAA,IACtB;AAAA,EACF,GAAG,CAAC,UAAU,CAAC;AAIf,QAAM,oBAAgB,sBAAQ,MAAM;AAhFtC;AAiFI,QAAI,eAAoC,CAAC;AACzC,QAAI,cAAc,WAAW,WAAW,cAAc,QAAQ,KAAK,GAAG,GAAG;AACvE,qBAAe,WAAW;AAAA,IAC5B,OAAO;AAEL,uBAAe,qDAAa,qBAAkB,gCAAQ,MAAR,mBAAW,aAAY,CAAC;AAAA,IACxE;AAEA,WAAO;AAAA,MACL,GAAG;AAAA,MACH,GAAI,aAAa,aAAa,KAAK,aAAAD;AAAA,MACnC,GAAI,YAAY,CAAC;AAAA,IACnB;AAAA,EACF,GAAG,CAAC,YAAY,eAAe,QAAQ,CAAC;AAGxC,8BAAU,MAAM;AACd,yCAAkB,eAAe,aAAa;AAAA,EAChD,GAAG,CAAC,eAAe,aAAa,CAAC;AAEjC,QAAM,mBAAe;AAAA,IACnB,OAAO;AAAA,MACL,QAAQ;AAAA,MACR;AAAA,IACF;AAAA,IACA,CAAC,eAAe,YAAY;AAAA,EAC9B;AAEA,SACE,4CAAC,8BAAc,GAAG,YAAY,QAAQ,cAAc,QAAQ,KAAK,GAAG,GAAG,UAAU,eAC/E,sDAAC,cAAc,UAAd,EAAuB,OAAO,cAAe,UAAS,GACzD;AAEJ;",
|
|
6
6
|
"names": ["import_react", "zhCN", "enUS"]
|
|
7
7
|
}
|
|
@@ -44,6 +44,10 @@ var import_useLayoutSettingsStore = require("../creek-layout/useLayoutSettingsSt
|
|
|
44
44
|
var import_CreekConfigContext = require("./CreekConfigContext");
|
|
45
45
|
var import_CreekI18nProvider = require("./CreekI18nProvider");
|
|
46
46
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
47
|
+
var ANTD_LOCALE_MAP = {
|
|
48
|
+
zh_CN: import_zh_CN.default,
|
|
49
|
+
en_US: import_en_US.default
|
|
50
|
+
};
|
|
47
51
|
var InnerConfigProvider = (props) => {
|
|
48
52
|
var _a;
|
|
49
53
|
const { children, theme, ...more } = props;
|
|
@@ -62,7 +66,7 @@ var InnerConfigProvider = (props) => {
|
|
|
62
66
|
}
|
|
63
67
|
} : {}
|
|
64
68
|
);
|
|
65
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd.ConfigProvider, { locale: locale
|
|
69
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd.ConfigProvider, { locale: ANTD_LOCALE_MAP[locale] || import_zh_CN.default, theme: finalTheme, ...more, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_CreekConfigContext.CreekConfigContext.Provider, { value: more, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_antd.App, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_creek_hooks.AppProvider, { children }) }) }) });
|
|
66
70
|
};
|
|
67
71
|
var CreekConfigProvider = (props) => {
|
|
68
72
|
const { children, locale, messages, ...more } = props;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/creek-config-provider/index.tsx"],
|
|
4
|
-
"sourcesContent": ["import type { ConfigProviderProps } from 'antd';\nimport { App, ConfigProvider } from 'antd';\nimport enUS_antd from 'antd/locale/en_US';\nimport zhCN_antd from 'antd/locale/zh_CN';\nimport merge from 'lodash/merge';\n\nimport { AppProvider } from '../creek-hooks';\nimport { useLayoutSettingsStore } from '../creek-layout/useLayoutSettingsStore';\nimport { CreekConfigContext, CreekConfigContextProps } from './CreekConfigContext';\nimport { CreekI18nProvider, CreekI18nProviderProps, LocaleContext, useAppLocale } from './CreekI18nProvider';\n\nexport type CreekConfigProviderProps = CreekConfigContextProps & Omit<ConfigProviderProps, 'locale'> & CreekI18nProviderProps;\n\nexport { CreekI18nProvider, LocaleContext, useAppLocale };\nexport type { CreekI18nProviderProps };\n\nconst InnerConfigProvider = (props: Omit<CreekConfigProviderProps, 'locale' | 'messages'>) => {\n const { children, theme, ...more } = props;\n const { locale } = useAppLocale();\n const settingsStore = useLayoutSettingsStore();\n\n const activeColorPrimary = settingsStore.colorPrimary || theme?.token?.colorPrimary;\n\n let finalTheme = merge(\n {},\n theme,\n activeColorPrimary\n ? {\n token: {\n colorPrimary: activeColorPrimary,\n colorLink: activeColorPrimary,\n colorLinkHover: activeColorPrimary,\n colorLinkActive: activeColorPrimary,\n },\n }\n : {}
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,kBAAoC;AACpC,mBAAsB;AACtB,mBAAsB;AACtB,mBAAkB;AAElB,yBAA4B;AAC5B,oCAAuC;AACvC,gCAA4D;AAC5D,+
|
|
6
|
-
"names": ["
|
|
4
|
+
"sourcesContent": ["import type { ConfigProviderProps } from 'antd';\nimport { App, ConfigProvider } from 'antd';\nimport enUS_antd from 'antd/locale/en_US';\nimport zhCN_antd from 'antd/locale/zh_CN';\nimport merge from 'lodash/merge';\n\nimport { AppProvider } from '../creek-hooks';\nimport { useLayoutSettingsStore } from '../creek-layout/useLayoutSettingsStore';\nimport { CreekConfigContext, CreekConfigContextProps } from './CreekConfigContext';\nimport { CreekI18nProvider, CreekI18nProviderProps, LocaleCode, LocaleContext, useAppLocale } from './CreekI18nProvider';\n\nconst ANTD_LOCALE_MAP: Record<LocaleCode, any> = {\n zh_CN: zhCN_antd,\n en_US: enUS_antd,\n};\n\nexport type CreekConfigProviderProps = CreekConfigContextProps & Omit<ConfigProviderProps, 'locale'> & CreekI18nProviderProps;\n\nexport { CreekI18nProvider, LocaleContext, useAppLocale };\nexport type { CreekI18nProviderProps };\n\nconst InnerConfigProvider = (props: Omit<CreekConfigProviderProps, 'locale' | 'messages'>) => {\n const { children, theme, ...more } = props;\n const { locale } = useAppLocale();\n const settingsStore = useLayoutSettingsStore();\n\n const activeColorPrimary = settingsStore.colorPrimary || theme?.token?.colorPrimary;\n\n let finalTheme = merge(\n {},\n theme,\n activeColorPrimary\n ? {\n token: {\n colorPrimary: activeColorPrimary,\n colorLink: activeColorPrimary,\n colorLinkHover: activeColorPrimary,\n colorLinkActive: activeColorPrimary,\n },\n }\n : {},\n );\n\n return (\n <ConfigProvider locale={ANTD_LOCALE_MAP[locale] || zhCN_antd} theme={finalTheme} {...more}>\n <CreekConfigContext.Provider value={more as any}>\n <App>\n <AppProvider>{children}</AppProvider>\n </App>\n </CreekConfigContext.Provider>\n </ConfigProvider>\n );\n};\n\nexport const CreekConfigProvider = (props: CreekConfigProviderProps) => {\n const { children, locale, messages, ...more } = props;\n\n return (\n <CreekI18nProvider locale={locale} messages={messages}>\n <InnerConfigProvider {...more}>{children}</InnerConfigProvider>\n </CreekI18nProvider>\n );\n};\n\nCreekConfigProvider.CreekConfigContext = CreekConfigContext;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,kBAAoC;AACpC,mBAAsB;AACtB,mBAAsB;AACtB,mBAAkB;AAElB,yBAA4B;AAC5B,oCAAuC;AACvC,gCAA4D;AAC5D,+BAAmG;AAsCzF;AApCV,IAAM,kBAA2C;AAAA,EAC/C,OAAO,aAAAA;AAAA,EACP,OAAO,aAAAC;AACT;AAOA,IAAM,sBAAsB,CAAC,UAAiE;AArB9F;AAsBE,QAAM,EAAE,UAAU,OAAO,GAAG,KAAK,IAAI;AACrC,QAAM,EAAE,OAAO,QAAI,uCAAa;AAChC,QAAM,oBAAgB,sDAAuB;AAE7C,QAAM,qBAAqB,cAAc,kBAAgB,oCAAO,UAAP,mBAAc;AAEvE,MAAI,iBAAa,aAAAC;AAAA,IACf,CAAC;AAAA,IACD;AAAA,IACA,qBACI;AAAA,MACE,OAAO;AAAA,QACL,cAAc;AAAA,QACd,WAAW;AAAA,QACX,gBAAgB;AAAA,QAChB,iBAAiB;AAAA,MACnB;AAAA,IACF,IACA,CAAC;AAAA,EACP;AAEA,SACE,4CAAC,8BAAe,QAAQ,gBAAgB,MAAM,KAAK,aAAAC,SAAW,OAAO,YAAa,GAAG,MACnF,sDAAC,6CAAmB,UAAnB,EAA4B,OAAO,MAClC,sDAAC,mBACC,sDAAC,kCAAa,UAAS,GACzB,GACF,GACF;AAEJ;AAEO,IAAM,sBAAsB,CAAC,UAAoC;AACtE,QAAM,EAAE,UAAU,QAAQ,UAAU,GAAG,KAAK,IAAI;AAEhD,SACE,4CAAC,8CAAkB,QAAgB,UACjC,sDAAC,uBAAqB,GAAG,MAAO,UAAS,GAC3C;AAEJ;AAEA,oBAAoB,qBAAqB;",
|
|
6
|
+
"names": ["zhCN_antd", "enUS_antd", "merge", "zhCN_antd"]
|
|
7
7
|
}
|
|
@@ -37,8 +37,9 @@ var import_pro_components = require("@ant-design/pro-components");
|
|
|
37
37
|
var import_ahooks = require("ahooks");
|
|
38
38
|
var import_antd = require("antd");
|
|
39
39
|
var import_lodash = __toESM(require("lodash"));
|
|
40
|
+
var import_react = require("react");
|
|
40
41
|
var import_classnames = __toESM(require("classnames"));
|
|
41
|
-
var
|
|
42
|
+
var import_react2 = require("@creekjs/i18n/react");
|
|
42
43
|
var import_creek_keep_alive = require("../creek-keep-alive");
|
|
43
44
|
var import_creek_locale_button = require("../creek-locale-button");
|
|
44
45
|
var import_scrollbar = require("../creek-style/scrollbar");
|
|
@@ -49,9 +50,9 @@ var import_useLayoutSettingsStore = require("./useLayoutSettingsStore");
|
|
|
49
50
|
__reExport(creek_layout_exports, require("./Exception"), module.exports);
|
|
50
51
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
51
52
|
var MenuName = ({ name, path }) => {
|
|
52
|
-
const t = (0,
|
|
53
|
+
const t = (0, import_react2.useT)();
|
|
53
54
|
const key = !path || path === "/" ? "menu.home" : `menu${path.replace(/\//g, ".")}`;
|
|
54
|
-
return
|
|
55
|
+
return t(key, name);
|
|
55
56
|
};
|
|
56
57
|
var CreekLayout = (props) => {
|
|
57
58
|
const {
|
|
@@ -77,9 +78,10 @@ var CreekLayout = (props) => {
|
|
|
77
78
|
const colorPrimary = settingsStore.colorPrimary || token.colorPrimary;
|
|
78
79
|
const actualKeepAlive = settingsStore.keepAlive ?? keepAlive;
|
|
79
80
|
const _userConfig = { ...userConfig, ...runtimeConfig };
|
|
81
|
+
const intlContext = (0, import_react.useContext)(import_react2.IntlContext);
|
|
82
|
+
const hasI18n = !!intlContext && actualShowLocaleButton;
|
|
80
83
|
const menuDataRender = (0, import_ahooks.useMemoizedFn)((menuData) => {
|
|
81
|
-
|
|
82
|
-
const isLocaleEnabled = ((_a = more.menu) == null ? void 0 : _a.locale) !== false && ((_b = _userConfig.menu) == null ? void 0 : _b.locale) !== false;
|
|
84
|
+
const isLocaleEnabled = hasI18n;
|
|
83
85
|
const mapMenu = (items) => {
|
|
84
86
|
return items.map((item) => {
|
|
85
87
|
return {
|
|
@@ -117,7 +119,11 @@ var CreekLayout = (props) => {
|
|
|
117
119
|
}
|
|
118
120
|
return void 0;
|
|
119
121
|
};
|
|
120
|
-
|
|
122
|
+
const title = findTitle((route == null ? void 0 : route.routes) || []) || pathname;
|
|
123
|
+
if (hasI18n && typeof title === "string") {
|
|
124
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MenuName, { name: title, path: pathname });
|
|
125
|
+
}
|
|
126
|
+
return title;
|
|
121
127
|
});
|
|
122
128
|
const actions = [...extraActions];
|
|
123
129
|
if (actualShowFullScreen) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/creek-layout/index.tsx"],
|
|
4
|
-
"sourcesContent": ["import { ProLayout, ProLayoutProps } from '@ant-design/pro-components';\nimport { useMemoizedFn } from 'ahooks';\nimport { theme } from 'antd';\nimport _ from 'lodash';\n\nimport classnames from 'classnames';\n\nimport { useT } from '@creekjs/i18n/react';\n\nimport { CreekKeepAlive, CreekKeepAliveProps } from '../creek-keep-alive';\nimport { CreekLocaleButton } from '../creek-locale-button';\nimport { GlobalScrollbarStyle } from '../creek-style/scrollbar';\nimport { FullScreen, LayoutSettings } from './ActionRender';\nimport { CollapsedButton, useCollapsedStore } from './CollapseButton';\nimport { Exception } from './Exception';\nimport { useLayoutSettingsStore } from './useLayoutSettingsStore';\n\nexport type LayoutProps = ProLayoutProps & {\n runtimeConfig: ProLayoutProps;\n userConfig?: ProLayoutProps;\n navigate?: (path?: string | number) => void;\n showFullScreen?: boolean;\n showLocaleButton?: boolean;\n showSettingsButton?: boolean;\n initialInfo?: {\n initialState: any;\n loading: boolean;\n setInitialState: () => void;\n };\n keepAlive?: boolean | CreekKeepAliveProps;\n extraActions?: React.ReactNode[];\n};\n\nconst MenuName = ({ name, path }: { name
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,
|
|
6
|
-
"names": ["_", "classnames", "collapsed"]
|
|
4
|
+
"sourcesContent": ["import { MenuDataItem, ProLayout, ProLayoutProps } from '@ant-design/pro-components';\nimport { useMemoizedFn } from 'ahooks';\nimport { theme } from 'antd';\nimport _ from 'lodash';\nimport { useContext } from 'react';\n\nimport classnames from 'classnames';\n\nimport { IntlContext, useT } from '@creekjs/i18n/react';\n\nimport { CreekKeepAlive, CreekKeepAliveProps } from '../creek-keep-alive';\nimport { CreekLocaleButton } from '../creek-locale-button';\nimport { GlobalScrollbarStyle } from '../creek-style/scrollbar';\nimport { FullScreen, LayoutSettings } from './ActionRender';\nimport { CollapsedButton, useCollapsedStore } from './CollapseButton';\nimport { Exception } from './Exception';\nimport { useLayoutSettingsStore } from './useLayoutSettingsStore';\n\nexport type LayoutProps = ProLayoutProps & {\n runtimeConfig: ProLayoutProps;\n userConfig?: ProLayoutProps;\n navigate?: (path?: string | number) => void;\n showFullScreen?: boolean;\n showLocaleButton?: boolean;\n showSettingsButton?: boolean;\n initialInfo?: {\n initialState: any;\n loading: boolean;\n setInitialState: () => void;\n };\n keepAlive?: boolean | CreekKeepAliveProps;\n extraActions?: React.ReactNode[];\n};\n\nconst MenuName = ({ name, path }: { name?: string; path?: string }) => {\n const t = useT();\n const key = !path || path === '/' ? 'menu.home' : `menu${path.replace(/\\//g, '.')}`;\n return t(key, name);\n};\n\nexport const CreekLayout = (props: LayoutProps) => {\n const {\n route,\n userConfig,\n runtimeConfig,\n children,\n location,\n navigate,\n showFullScreen = false,\n showLocaleButton = false,\n showSettingsButton = false,\n keepAlive = false,\n extraActions = [],\n ...more\n } = props;\n\n const { useToken } = theme;\n const { token } = useToken();\n\n const { collapsed } = useCollapsedStore();\n const settingsStore = useLayoutSettingsStore();\n\n const actualShowFullScreen = settingsStore.showFullScreen ?? showFullScreen;\n const actualShowLocaleButton = settingsStore.showLocaleButton ?? showLocaleButton;\n const colorPrimary = settingsStore.colorPrimary || token.colorPrimary;\n const actualKeepAlive = settingsStore.keepAlive ?? keepAlive;\n\n const _userConfig = { ...userConfig, ...runtimeConfig };\n\n const intlContext = useContext(IntlContext);\n const hasI18n = !!intlContext && actualShowLocaleButton;\n\n const menuDataRender = useMemoizedFn((menuData: MenuDataItem[]) => {\n // 根据当前是否开启了国际化(上下文是否存在)以及用户配置来判断是否包裹菜单翻译\n const isLocaleEnabled = hasI18n;\n\n const mapMenu = (items: MenuDataItem[]): MenuDataItem[] => {\n return items.map((item) => {\n return {\n ...item,\n name: (isLocaleEnabled ? <MenuName name={item.name} path={item.path} /> : item.name) as string,\n children: item.children ? mapMenu(item.children) : undefined,\n };\n });\n };\n return mapMenu(menuData);\n });\n\n const menuItemRender: ProLayoutProps['menuItemRender'] = useMemoizedFn((itemProps, defaultDom) => {\n return (\n <span\n onClick={() => {\n if (navigate) {\n navigate(itemProps.path);\n }\n }}\n >\n {defaultDom}\n </span>\n );\n });\n\n const getTabTitle = useMemoizedFn((pathname: string) => {\n const findTitle = (routes: any[]): string | React.ReactNode | undefined => {\n for (const r of routes) {\n if (r.path === pathname) return r.name || r.title;\n if (r.children) {\n const found = findTitle(r.children);\n if (found) return found;\n }\n }\n return undefined;\n };\n const title = findTitle(route?.routes || []) || pathname;\n \n if (hasI18n && typeof title === 'string') {\n return <MenuName name={title} path={pathname} />;\n }\n \n return title;\n });\n\n const actions: React.ReactNode[] = [...extraActions];\n\n if (actualShowFullScreen) {\n actions.push(<FullScreen key=\"full-screen\" />);\n }\n\n if (actualShowLocaleButton) {\n actions.push(<CreekLocaleButton key=\"locale-button\" />);\n }\n\n if (showSettingsButton) {\n actions.push(<LayoutSettings key=\"settings\" defaultShowFullScreen={showFullScreen} defaultShowLocaleButton={showLocaleButton} defaultKeepAlive={_.isBoolean(keepAlive) ? keepAlive : true} />);\n }\n\n const keepAliveProps = _.isBoolean(keepAlive) ? {} : keepAlive;\n\n const layoutContent = (\n <ProLayout\n className={classnames('creek-layout-container', _userConfig?.className)}\n route={route}\n title={_userConfig?.title}\n siderWidth={200}\n location={location}\n menuDataRender={menuDataRender}\n menuItemRender={menuItemRender}\n actionsRender={() => actions}\n token={{\n header: {\n colorBgHeader: '#fff',\n colorHeaderTitle: 'rgba(0, 0, 0, 0.80);',\n colorTextMenuSelected: colorPrimary,\n heightLayoutHeader: 48,\n },\n sider: {\n colorMenuBackground: '#f7f8fa',\n colorBgMenuItemSelected: 'transparent',\n colorTextMenuActive: colorPrimary,\n colorTextMenuSelected: colorPrimary,\n colorTextMenuItemHover: colorPrimary,\n colorTextMenu: '#333',\n },\n pageContainer: {\n paddingBlockPageContainerContent: 0,\n paddingInlinePageContainerContent: 0,\n colorBgPageContainer: 'linear-gradient(180deg, #F7F9FF 0%, #FFF 45.59%);',\n },\n }}\n fixSiderbar\n fixedHeader\n collapsed={collapsed}\n collapsedButtonRender={(collapsed) => {\n return <CollapsedButton collapsed={collapsed} />;\n }}\n {...more}\n >\n <GlobalScrollbarStyle />\n <Exception>{actualKeepAlive ? <CreekKeepAlive getTabTitle={getTabTitle} {...keepAliveProps} /> : children}</Exception>\n </ProLayout>\n );\n\n return layoutContent;\n};\n\nexport * from './Exception';\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAAwD;AACxD,oBAA8B;AAC9B,kBAAsB;AACtB,oBAAc;AACd,mBAA2B;AAE3B,wBAAuB;AAEvB,IAAAA,gBAAkC;AAElC,8BAAoD;AACpD,iCAAkC;AAClC,uBAAqC;AACrC,0BAA2C;AAC3C,4BAAmD;AACnD,uBAA0B;AAC1B,oCAAuC;AAyKvC,iCAAc,wBAzLd;AAgFmC;AA9CnC,IAAM,WAAW,CAAC,EAAE,MAAM,KAAK,MAAwC;AACrE,QAAM,QAAI,oBAAK;AACf,QAAM,MAAM,CAAC,QAAQ,SAAS,MAAM,cAAc,OAAO,KAAK,QAAQ,OAAO,GAAG;AAChF,SAAO,EAAE,KAAK,IAAI;AACpB;AAEO,IAAM,cAAc,CAAC,UAAuB;AACjD,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,iBAAiB;AAAA,IACjB,mBAAmB;AAAA,IACnB,qBAAqB;AAAA,IACrB,YAAY;AAAA,IACZ,eAAe,CAAC;AAAA,IAChB,GAAG;AAAA,EACL,IAAI;AAEJ,QAAM,EAAE,SAAS,IAAI;AACrB,QAAM,EAAE,MAAM,IAAI,SAAS;AAE3B,QAAM,EAAE,UAAU,QAAI,yCAAkB;AACxC,QAAM,oBAAgB,sDAAuB;AAE7C,QAAM,uBAAuB,cAAc,kBAAkB;AAC7D,QAAM,yBAAyB,cAAc,oBAAoB;AACjE,QAAM,eAAe,cAAc,gBAAgB,MAAM;AACzD,QAAM,kBAAkB,cAAc,aAAa;AAEnD,QAAM,cAAc,EAAE,GAAG,YAAY,GAAG,cAAc;AAEtD,QAAM,kBAAc,yBAAW,yBAAW;AAC1C,QAAM,UAAU,CAAC,CAAC,eAAe;AAEjC,QAAM,qBAAiB,6BAAc,CAAC,aAA6B;AAEjE,UAAM,kBAAkB;AAExB,UAAM,UAAU,CAAC,UAA0C;AACzD,aAAO,MAAM,IAAI,CAAC,SAAS;AACzB,eAAO;AAAA,UACL,GAAG;AAAA,UACH,MAAO,kBAAkB,4CAAC,YAAS,MAAM,KAAK,MAAM,MAAM,KAAK,MAAM,IAAK,KAAK;AAAA,UAC/E,UAAU,KAAK,WAAW,QAAQ,KAAK,QAAQ,IAAI;AAAA,QACrD;AAAA,MACF,CAAC;AAAA,IACH;AACA,WAAO,QAAQ,QAAQ;AAAA,EACzB,CAAC;AAED,QAAM,qBAAmD,6BAAc,CAAC,WAAW,eAAe;AAChG,WACE;AAAA,MAAC;AAAA;AAAA,QACC,SAAS,MAAM;AACb,cAAI,UAAU;AACZ,qBAAS,UAAU,IAAI;AAAA,UACzB;AAAA,QACF;AAAA,QAEC;AAAA;AAAA,IACH;AAAA,EAEJ,CAAC;AAED,QAAM,kBAAc,6BAAc,CAAC,aAAqB;AACtD,UAAM,YAAY,CAAC,WAAwD;AACzE,iBAAW,KAAK,QAAQ;AACtB,YAAI,EAAE,SAAS;AAAU,iBAAO,EAAE,QAAQ,EAAE;AAC5C,YAAI,EAAE,UAAU;AACd,gBAAM,QAAQ,UAAU,EAAE,QAAQ;AAClC,cAAI;AAAO,mBAAO;AAAA,QACpB;AAAA,MACF;AACA,aAAO;AAAA,IACT;AACA,UAAM,QAAQ,WAAU,+BAAO,WAAU,CAAC,CAAC,KAAK;AAEhD,QAAI,WAAW,OAAO,UAAU,UAAU;AACxC,aAAO,4CAAC,YAAS,MAAM,OAAO,MAAM,UAAU;AAAA,IAChD;AAEA,WAAO;AAAA,EACT,CAAC;AAED,QAAM,UAA6B,CAAC,GAAG,YAAY;AAEnD,MAAI,sBAAsB;AACxB,YAAQ,KAAK,4CAAC,oCAAe,aAAc,CAAE;AAAA,EAC/C;AAEA,MAAI,wBAAwB;AAC1B,YAAQ,KAAK,4CAAC,kDAAsB,eAAgB,CAAE;AAAA,EACxD;AAEA,MAAI,oBAAoB;AACtB,YAAQ,KAAK,4CAAC,sCAA8B,uBAAuB,gBAAgB,yBAAyB,kBAAkB,kBAAkB,cAAAC,QAAE,UAAU,SAAS,IAAI,YAAY,QAApJ,UAA0J,CAAE;AAAA,EAC/L;AAEA,QAAM,iBAAiB,cAAAA,QAAE,UAAU,SAAS,IAAI,CAAC,IAAI;AAErD,QAAM,gBACJ;AAAA,IAAC;AAAA;AAAA,MACC,eAAW,kBAAAC,SAAW,0BAA0B,2CAAa,SAAS;AAAA,MACtE;AAAA,MACA,OAAO,2CAAa;AAAA,MACpB,YAAY;AAAA,MACZ;AAAA,MACA;AAAA,MACA;AAAA,MACA,eAAe,MAAM;AAAA,MACrB,OAAO;AAAA,QACL,QAAQ;AAAA,UACN,eAAe;AAAA,UACf,kBAAkB;AAAA,UAClB,uBAAuB;AAAA,UACvB,oBAAoB;AAAA,QACtB;AAAA,QACA,OAAO;AAAA,UACL,qBAAqB;AAAA,UACrB,yBAAyB;AAAA,UACzB,qBAAqB;AAAA,UACrB,uBAAuB;AAAA,UACvB,wBAAwB;AAAA,UACxB,eAAe;AAAA,QACjB;AAAA,QACA,eAAe;AAAA,UACb,kCAAkC;AAAA,UAClC,mCAAmC;AAAA,UACnC,sBAAsB;AAAA,QACxB;AAAA,MACF;AAAA,MACA,aAAW;AAAA,MACX,aAAW;AAAA,MACX;AAAA,MACA,uBAAuB,CAACC,eAAc;AACpC,eAAO,4CAAC,yCAAgB,WAAWA,YAAW;AAAA,MAChD;AAAA,MACC,GAAG;AAAA,MAEJ;AAAA,oDAAC,yCAAqB;AAAA,QACtB,4CAAC,8BAAW,4BAAkB,4CAAC,0CAAe,aAA2B,GAAG,gBAAgB,IAAK,UAAS;AAAA;AAAA;AAAA,EAC5G;AAGF,SAAO;AACT;",
|
|
6
|
+
"names": ["import_react", "_", "classnames", "collapsed"]
|
|
7
7
|
}
|
|
@@ -33,14 +33,14 @@ var CreekLocaleButton = () => {
|
|
|
33
33
|
const { locale, changeLocale } = (0, import_creek_config_provider.useAppLocale)();
|
|
34
34
|
const items = [
|
|
35
35
|
{
|
|
36
|
-
key: "
|
|
36
|
+
key: "zh_CN",
|
|
37
37
|
label: t("creek-locale-button.index.jianTiZhongWen", "简体中文"),
|
|
38
|
-
disabled: locale === "
|
|
38
|
+
disabled: locale === "zh_CN"
|
|
39
39
|
},
|
|
40
40
|
{
|
|
41
|
-
key: "
|
|
41
|
+
key: "en_US",
|
|
42
42
|
label: "English",
|
|
43
|
-
disabled: locale === "
|
|
43
|
+
disabled: locale === "en_US"
|
|
44
44
|
}
|
|
45
45
|
];
|
|
46
46
|
const currentLabel = ((_a = items.find((item) => item.key === locale)) == null ? void 0 : _a.label) || "Language";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/creek-locale-button/index.tsx"],
|
|
4
|
-
"sourcesContent": ["import { GlobalOutlined } from '@ant-design/icons';\nimport { Dropdown, Space, Typography } from 'antd';\n\nimport { useT } from '@creekjs/i18n/react';\n\nimport { useAppLocale } from '../creek-config-provider';\n\nexport const CreekLocaleButton = () => {\n const t = useT();\n\n const { locale, changeLocale } = useAppLocale();\n\n const items = [\n {\n key: '
|
|
4
|
+
"sourcesContent": ["import { GlobalOutlined } from '@ant-design/icons';\nimport { Dropdown, Space, Typography } from 'antd';\n\nimport { useT } from '@creekjs/i18n/react';\n\nimport { useAppLocale } from '../creek-config-provider';\n\nexport const CreekLocaleButton = () => {\n const t = useT();\n\n const { locale, changeLocale } = useAppLocale();\n\n const items = [\n {\n key: 'zh_CN',\n label: t('creek-locale-button.index.jianTiZhongWen', '简体中文'),\n disabled: locale === 'zh_CN',\n },\n {\n key: 'en_US',\n label: 'English',\n disabled: locale === 'en_US',\n },\n ];\n\n const currentLabel = items.find((item) => item.key === locale)?.label || 'Language';\n\n return (\n <Dropdown\n menu={{\n items,\n onClick: (e) => changeLocale(e.key),\n }}\n placement=\"bottomRight\"\n >\n <Space size=\"small\" align=\"center\">\n <GlobalOutlined />\n <Typography.Text>{currentLabel}</Typography.Text>\n </Space>\n </Dropdown>\n );\n};\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA+B;AAC/B,kBAA4C;AAE5C,mBAAqB;AAErB,mCAA6B;AA8BvB;AA5BC,IAAM,oBAAoB,MAAM;AAPvC;AAQE,QAAM,QAAI,mBAAK;AAEf,QAAM,EAAE,QAAQ,aAAa,QAAI,2CAAa;AAE9C,QAAM,QAAQ;AAAA,IACZ;AAAA,MACE,KAAK;AAAA,MACL,OAAO,EAAE,4CAA4C,MAAM;AAAA,MAC3D,UAAU,WAAW;AAAA,IACvB;AAAA,IACA;AAAA,MACE,KAAK;AAAA,MACL,OAAO;AAAA,MACP,UAAU,WAAW;AAAA,IACvB;AAAA,EACF;AAEA,QAAM,iBAAe,WAAM,KAAK,CAAC,SAAS,KAAK,QAAQ,MAAM,MAAxC,mBAA2C,UAAS;AAEzE,SACE;AAAA,IAAC;AAAA;AAAA,MACC,MAAM;AAAA,QACJ;AAAA,QACA,SAAS,CAAC,MAAM,aAAa,EAAE,GAAG;AAAA,MACpC;AAAA,MACA,WAAU;AAAA,MAEV,uDAAC,qBAAM,MAAK,SAAQ,OAAM,UACxB;AAAA,oDAAC,+BAAe;AAAA,QAChB,4CAAC,uBAAW,MAAX,EAAiB,wBAAa;AAAA,SACjC;AAAA;AAAA,EACF;AAEJ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -16,7 +16,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
};
|
|
17
17
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
18
|
|
|
19
|
-
// src/locales/
|
|
19
|
+
// src/locales/en_US.ts
|
|
20
20
|
var en_US_exports = {};
|
|
21
21
|
__export(en_US_exports, {
|
|
22
22
|
default: () => en_US_default
|
|
@@ -46,4 +46,4 @@ var en_US_default = {
|
|
|
46
46
|
"creek-locale-button.index.jianTiZhongWen": "Simplified Chinese",
|
|
47
47
|
"creek-layout.ActionRender.LayoutSettings.keepAlive": "Enable Page Cache (Keep Alive)"
|
|
48
48
|
};
|
|
49
|
-
//# sourceMappingURL=
|
|
49
|
+
//# sourceMappingURL=en_US.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../src/locales/
|
|
3
|
+
"sources": ["../../src/locales/en_US.ts"],
|
|
4
4
|
"sourcesContent": ["export default {\n 'creek-keep-alive.index.guanBiDangQian': 'Close Current',\n 'creek-keep-alive.index.guanBiQiTa': 'Close Others',\n 'creek-keep-alive.index.guanBiYouCe': 'Close Right',\n 'creek-layout.ActionRender.FullScreen.tuiChuQuanPing': 'Exit Full Screen',\n 'creek-layout.ActionRender.FullScreen.quanPing': 'Full Screen',\n 'creek-table.components.DensityIcon.kuanSong': 'Loose',\n 'creek-table.components.DensityIcon.zhongDeng': 'Medium',\n 'creek-table.components.DensityIcon.jinCou': 'Compact',\n 'creek-table.components.DensityIcon.biaoGeMiDu(KuanSong)': 'Table Density (Loose)',\n 'creek-table.components.DensityIcon.biaoGeMiDu(ZhongDeng)': 'Table Density (Medium)',\n 'creek-table.components.DensityIcon.biaoGeMiDu(JinCou)': 'Table Density (Compact)',\n 'creek-table.components.DensityIcon.biaoGeMiDu': 'Table Density',\n 'creek-table.components.EllipsisTooltip.fuZhiChengGong': 'Copied Successfully',\n 'creek-table.components.EllipsisTooltip.fuZhiShiBai': 'Copy Failed',\n 'creek-table.components.EllipsisTooltip.fuZhi': 'Copy',\n 'creek-table.hooks.useIndexColumn.xuHao': 'No.',\n 'creek-layout.ActionRender.LayoutSettings.title': 'System Settings',\n 'creek-layout.ActionRender.LayoutSettings.themeColor': 'Theme Color',\n 'creek-layout.ActionRender.LayoutSettings.showFullScreen': 'Show Full Screen Button',\n 'creek-layout.ActionRender.LayoutSettings.showLocaleButton': 'Show Locale Button',\n 'creek-locale-button.index.jianTiZhongWen': 'Simplified Chinese',\n 'creek-layout.ActionRender.LayoutSettings.keepAlive': 'Enable Page Cache (Keep Alive)',\n};\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAO,gBAAQ;AAAA,EACb,yCAAyC;AAAA,EACzC,qCAAqC;AAAA,EACrC,sCAAsC;AAAA,EACtC,uDAAuD;AAAA,EACvD,iDAAiD;AAAA,EACjD,+CAA+C;AAAA,EAC/C,gDAAgD;AAAA,EAChD,6CAA6C;AAAA,EAC7C,2DAA2D;AAAA,EAC3D,4DAA4D;AAAA,EAC5D,yDAAyD;AAAA,EACzD,iDAAiD;AAAA,EACjD,yDAAyD;AAAA,EACzD,sDAAsD;AAAA,EACtD,gDAAgD;AAAA,EAChD,0CAA0C;AAAA,EAC1C,kDAAkD;AAAA,EAClD,uDAAuD;AAAA,EACvD,2DAA2D;AAAA,EAC3D,6DAA6D;AAAA,EAC7D,4CAA4C;AAAA,EAC5C,sDAAsD;AACxD;",
|
|
6
6
|
"names": []
|
|
@@ -16,7 +16,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
};
|
|
17
17
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
18
|
|
|
19
|
-
// src/locales/
|
|
19
|
+
// src/locales/zh_CN.ts
|
|
20
20
|
var zh_CN_exports = {};
|
|
21
21
|
__export(zh_CN_exports, {
|
|
22
22
|
default: () => zh_CN_default
|
|
@@ -46,4 +46,4 @@ var zh_CN_default = {
|
|
|
46
46
|
"creek-locale-button.index.jianTiZhongWen": "简体中文",
|
|
47
47
|
"creek-layout.ActionRender.LayoutSettings.keepAlive": "开启页面缓存 (Keep Alive)"
|
|
48
48
|
};
|
|
49
|
-
//# sourceMappingURL=
|
|
49
|
+
//# sourceMappingURL=zh_CN.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../src/locales/
|
|
3
|
+
"sources": ["../../src/locales/zh_CN.ts"],
|
|
4
4
|
"sourcesContent": ["export default {\n \"creek-keep-alive.index.guanBiDangQian\": \"关闭当前\",\n \"creek-keep-alive.index.guanBiQiTa\": \"关闭其他\",\n \"creek-keep-alive.index.guanBiYouCe\": \"关闭右侧\",\n \"creek-layout.ActionRender.FullScreen.tuiChuQuanPing\": \"退出全屏\",\n \"creek-layout.ActionRender.FullScreen.quanPing\": \"全屏\",\n \"creek-table.components.DensityIcon.kuanSong\": \"宽松\",\n \"creek-table.components.DensityIcon.zhongDeng\": \"中等\",\n \"creek-table.components.DensityIcon.jinCou\": \"紧凑\",\n \"creek-table.components.DensityIcon.biaoGeMiDu(KuanSong)\": \"表格密度 (宽松)\",\n \"creek-table.components.DensityIcon.biaoGeMiDu(ZhongDeng)\": \"表格密度 (中等)\",\n \"creek-table.components.DensityIcon.biaoGeMiDu(JinCou)\": \"表格密度 (紧凑)\",\n \"creek-table.components.DensityIcon.biaoGeMiDu\": \"表格密度\",\n \"creek-table.components.EllipsisTooltip.fuZhiChengGong\": \"复制成功\",\n \"creek-table.components.EllipsisTooltip.fuZhiShiBai\": \"复制失败\",\n \"creek-table.components.EllipsisTooltip.fuZhi\": \"复制\",\n \"creek-table.hooks.useIndexColumn.xuHao\": \"序号\",\n \"creek-layout.ActionRender.LayoutSettings.title\": \"系统设置\",\n \"creek-layout.ActionRender.LayoutSettings.themeColor\": \"主题色\",\n \"creek-layout.ActionRender.LayoutSettings.showFullScreen\": \"展示全屏按钮\",\n \"creek-layout.ActionRender.LayoutSettings.showLocaleButton\": \"展示国际化按钮\",\n \"creek-locale-button.index.jianTiZhongWen\": \"简体中文\",\n \"creek-layout.ActionRender.LayoutSettings.keepAlive\": \"开启页面缓存 (Keep Alive)\"\n};"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAO,gBAAQ;AAAA,EACb,yCAAyC;AAAA,EACzC,qCAAqC;AAAA,EACrC,sCAAsC;AAAA,EACtC,uDAAuD;AAAA,EACvD,iDAAiD;AAAA,EACjD,+CAA+C;AAAA,EAC/C,gDAAgD;AAAA,EAChD,6CAA6C;AAAA,EAC7C,2DAA2D;AAAA,EAC3D,4DAA4D;AAAA,EAC5D,yDAAyD;AAAA,EACzD,iDAAiD;AAAA,EACjD,yDAAyD;AAAA,EACzD,sDAAsD;AAAA,EACtD,gDAAgD;AAAA,EAChD,0CAA0C;AAAA,EAC1C,kDAAkD;AAAA,EAClD,uDAAuD;AAAA,EACvD,2DAA2D;AAAA,EAC3D,6DAA6D;AAAA,EAC7D,4CAA4C;AAAA,EAC5C,sDAAsD;AACxD;",
|
|
6
6
|
"names": []
|
package/i18n.config.ts
CHANGED
|
@@ -4,8 +4,8 @@ module.exports = {
|
|
|
4
4
|
|
|
5
5
|
// 语言包输出的主入口文件路径
|
|
6
6
|
// 注意:实际生成的翻译文件会存放在该文件同级目录下以文件名命名的文件夹中
|
|
7
|
-
// 例如:src/locales/
|
|
8
|
-
localePath: './src/locales/
|
|
7
|
+
// 例如:src/locales/zh_CN.ts -> 生成的文件在 src/locales/zh_CN/ 目录下
|
|
8
|
+
localePath: './src/locales/zh_CN.ts',
|
|
9
9
|
|
|
10
10
|
// 要扫描的文件路径 (Glob)
|
|
11
11
|
path: 'src/**/*.{ts,tsx,js,jsx}',
|
|
@@ -24,4 +24,7 @@ module.exports = {
|
|
|
24
24
|
|
|
25
25
|
// 开启 React Hooks 模式 (useT)
|
|
26
26
|
useT: true,
|
|
27
|
+
|
|
28
|
+
// useT 的导入语句
|
|
29
|
+
useTImportStatement: "import { useT } from '@creekjs/i18n/react'",
|
|
27
30
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@creekjs/web-components",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.12",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"keywords": [],
|
|
@@ -14,13 +14,13 @@
|
|
|
14
14
|
"react-resizable": "^3.1.3",
|
|
15
15
|
"react-router-dom": "^7.13.0",
|
|
16
16
|
"zustand": "^5.0.1",
|
|
17
|
-
"@creekjs/i18n": "^1.0.
|
|
17
|
+
"@creekjs/i18n": "^1.0.2"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
20
|
"@types/lodash": "^4.17.20",
|
|
21
21
|
"@types/react-resizable": "^3.0.8",
|
|
22
22
|
"react-intl": "^6.0.0",
|
|
23
|
-
"@creekjs/i18n-extract": "^1.0.
|
|
23
|
+
"@creekjs/i18n-extract": "^1.0.1"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
26
26
|
"react-intl": ">=3.0.0"
|
|
@@ -1,33 +1,43 @@
|
|
|
1
1
|
import type { ReactNode } from 'react';
|
|
2
|
-
import { createContext, useCallback, useContext, useEffect, useState } from 'react';
|
|
2
|
+
import { createContext, useCallback, useContext, useEffect, useMemo, useState } from 'react';
|
|
3
3
|
|
|
4
|
-
import { IntlContext, IntlProvider, getIntl, getLocale, setLocale, setLocaleMessages } from '@creekjs/i18n/react';
|
|
4
|
+
import { IntlContext, IntlProvider, appLocales, getIntl, getLocale, setLocale, setLocaleMessages } from '@creekjs/i18n/react';
|
|
5
5
|
|
|
6
|
-
import enUS from '../locales/
|
|
7
|
-
import zhCN from '../locales/
|
|
6
|
+
import enUS from '../locales/en_US';
|
|
7
|
+
import zhCN from '../locales/zh_CN';
|
|
8
8
|
|
|
9
|
-
const DEFAULT_LOCALE = '
|
|
9
|
+
const DEFAULT_LOCALE = 'zh_CN';
|
|
10
|
+
|
|
11
|
+
export type LocaleCode = 'en_US' | 'zh_CN';
|
|
12
|
+
|
|
13
|
+
const SUPPORTED_LOCALES: LocaleCode[] = ['zh_CN', 'en_US'];
|
|
14
|
+
|
|
15
|
+
const toUnderscoreLocale = (input?: string): LocaleCode => {
|
|
16
|
+
if (!input) return DEFAULT_LOCALE;
|
|
17
|
+
const normalized = input.replace('-', '_') as LocaleCode;
|
|
18
|
+
return SUPPORTED_LOCALES.includes(normalized) ? normalized : DEFAULT_LOCALE;
|
|
19
|
+
};
|
|
10
20
|
|
|
11
21
|
export interface CreekI18nProviderProps {
|
|
12
22
|
children?: ReactNode;
|
|
13
23
|
/**
|
|
14
24
|
* 语言标识
|
|
15
|
-
* @default '
|
|
25
|
+
* @default 'zh_CN'
|
|
16
26
|
*/
|
|
17
|
-
locale?:
|
|
27
|
+
locale?: LocaleCode;
|
|
18
28
|
/**
|
|
19
29
|
* 国际化语言包,透传给 react-intl
|
|
20
30
|
*/
|
|
21
31
|
messages?: Record<string, string>;
|
|
22
32
|
}
|
|
23
33
|
|
|
24
|
-
const MESSAGES_MAP: Record<
|
|
25
|
-
|
|
26
|
-
|
|
34
|
+
const MESSAGES_MAP: Record<LocaleCode, Record<string, string>> = {
|
|
35
|
+
zh_CN: zhCN,
|
|
36
|
+
en_US: enUS,
|
|
27
37
|
};
|
|
28
38
|
|
|
29
39
|
export const LocaleContext = createContext({
|
|
30
|
-
locale: getLocale()
|
|
40
|
+
locale: toUnderscoreLocale(getLocale()),
|
|
31
41
|
changeLocale: (lang: string) => {},
|
|
32
42
|
});
|
|
33
43
|
|
|
@@ -36,52 +46,70 @@ export const useAppLocale = () => useContext(LocaleContext);
|
|
|
36
46
|
export const CreekI18nProvider = (props: CreekI18nProviderProps) => {
|
|
37
47
|
const { children, locale, messages } = props;
|
|
38
48
|
|
|
39
|
-
//
|
|
49
|
+
// 获取父级 intl context
|
|
40
50
|
const parentIntl = useContext(IntlContext);
|
|
41
51
|
|
|
42
|
-
|
|
52
|
+
// 内部维护的 locale 状态,仅在调用 changeLocale 时更新
|
|
53
|
+
const [internalLocale, setInternalLocale] = useState<string>();
|
|
43
54
|
|
|
44
55
|
const changeLocale = useCallback((lang: string) => {
|
|
45
|
-
|
|
46
|
-
|
|
56
|
+
const underscore = toUnderscoreLocale(lang);
|
|
57
|
+
setLocale(underscore, false);
|
|
58
|
+
setInternalLocale(underscore);
|
|
47
59
|
}, []);
|
|
48
60
|
|
|
49
61
|
// 1. 确定最终生效的 locale
|
|
50
62
|
// 优先级:当前组件内部的 state > props.locale > parentIntl.locale > 全局默认
|
|
51
|
-
const currentLocale =
|
|
63
|
+
const currentLocale = useMemo(() => {
|
|
64
|
+
const rawLocale = internalLocale || locale || parentIntl?.locale || getIntl()?.locale || DEFAULT_LOCALE;
|
|
65
|
+
return toUnderscoreLocale(rawLocale);
|
|
66
|
+
}, [internalLocale, locale, parentIntl?.locale]);
|
|
52
67
|
|
|
53
68
|
// 2. 提取父级上下文的安全配置 (避免将 IntlShape 的内部方法直接传给 IntlProvider)
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
69
|
+
const safeConfig = useMemo(() => {
|
|
70
|
+
const intlConfig = parentIntl || getIntl() || {};
|
|
71
|
+
return {
|
|
72
|
+
formats: intlConfig.formats,
|
|
73
|
+
defaultLocale: intlConfig.defaultLocale,
|
|
74
|
+
defaultFormats: intlConfig.defaultFormats,
|
|
75
|
+
onError: intlConfig.onError,
|
|
76
|
+
};
|
|
77
|
+
}, [parentIntl]);
|
|
61
78
|
|
|
62
79
|
// 3. 确定最终的 messages
|
|
63
80
|
// 避免使用 stale 的 parentIntl.messages
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
81
|
+
const finalMessages = useMemo(() => {
|
|
82
|
+
let baseMessages: Record<string, any> = {};
|
|
83
|
+
if (parentIntl && parentIntl.locale === currentLocale.replace('_', '-')) {
|
|
84
|
+
baseMessages = parentIntl.messages;
|
|
85
|
+
} else {
|
|
86
|
+
// 优先从 appLocales 中获取对应语言的 messages
|
|
87
|
+
baseMessages = appLocales?.[currentLocale] || getIntl()?.messages || {};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return {
|
|
91
|
+
...baseMessages,
|
|
92
|
+
...(MESSAGES_MAP[currentLocale] || zhCN),
|
|
93
|
+
...(messages || {}),
|
|
94
|
+
};
|
|
95
|
+
}, [parentIntl, currentLocale, messages]);
|
|
76
96
|
|
|
77
97
|
// 4. 同步给全局 globalIntl,确保非 React 组件能够拿到
|
|
78
98
|
useEffect(() => {
|
|
79
99
|
setLocaleMessages(currentLocale, finalMessages);
|
|
80
100
|
}, [currentLocale, finalMessages]);
|
|
81
101
|
|
|
102
|
+
const contextValue = useMemo(
|
|
103
|
+
() => ({
|
|
104
|
+
locale: currentLocale,
|
|
105
|
+
changeLocale,
|
|
106
|
+
}),
|
|
107
|
+
[currentLocale, changeLocale],
|
|
108
|
+
);
|
|
109
|
+
|
|
82
110
|
return (
|
|
83
|
-
<IntlProvider {...safeConfig} locale={currentLocale} messages={finalMessages}>
|
|
84
|
-
<LocaleContext.Provider value={
|
|
111
|
+
<IntlProvider {...safeConfig} locale={currentLocale.replace('_', '-')} messages={finalMessages}>
|
|
112
|
+
<LocaleContext.Provider value={contextValue}>{children}</LocaleContext.Provider>
|
|
85
113
|
</IntlProvider>
|
|
86
114
|
);
|
|
87
115
|
};
|
|
@@ -7,7 +7,12 @@ import merge from 'lodash/merge';
|
|
|
7
7
|
import { AppProvider } from '../creek-hooks';
|
|
8
8
|
import { useLayoutSettingsStore } from '../creek-layout/useLayoutSettingsStore';
|
|
9
9
|
import { CreekConfigContext, CreekConfigContextProps } from './CreekConfigContext';
|
|
10
|
-
import { CreekI18nProvider, CreekI18nProviderProps, LocaleContext, useAppLocale } from './CreekI18nProvider';
|
|
10
|
+
import { CreekI18nProvider, CreekI18nProviderProps, LocaleCode, LocaleContext, useAppLocale } from './CreekI18nProvider';
|
|
11
|
+
|
|
12
|
+
const ANTD_LOCALE_MAP: Record<LocaleCode, any> = {
|
|
13
|
+
zh_CN: zhCN_antd,
|
|
14
|
+
en_US: enUS_antd,
|
|
15
|
+
};
|
|
11
16
|
|
|
12
17
|
export type CreekConfigProviderProps = CreekConfigContextProps & Omit<ConfigProviderProps, 'locale'> & CreekI18nProviderProps;
|
|
13
18
|
|
|
@@ -33,12 +38,11 @@ const InnerConfigProvider = (props: Omit<CreekConfigProviderProps, 'locale' | 'm
|
|
|
33
38
|
colorLinkActive: activeColorPrimary,
|
|
34
39
|
},
|
|
35
40
|
}
|
|
36
|
-
: {}
|
|
41
|
+
: {},
|
|
37
42
|
);
|
|
38
43
|
|
|
39
|
-
|
|
40
44
|
return (
|
|
41
|
-
<ConfigProvider locale={locale
|
|
45
|
+
<ConfigProvider locale={ANTD_LOCALE_MAP[locale] || zhCN_antd} theme={finalTheme} {...more}>
|
|
42
46
|
<CreekConfigContext.Provider value={more as any}>
|
|
43
47
|
<App>
|
|
44
48
|
<AppProvider>{children}</AppProvider>
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { ProLayout, ProLayoutProps } from '@ant-design/pro-components';
|
|
1
|
+
import { MenuDataItem, ProLayout, ProLayoutProps } from '@ant-design/pro-components';
|
|
2
2
|
import { useMemoizedFn } from 'ahooks';
|
|
3
3
|
import { theme } from 'antd';
|
|
4
4
|
import _ from 'lodash';
|
|
5
|
+
import { useContext } from 'react';
|
|
5
6
|
|
|
6
7
|
import classnames from 'classnames';
|
|
7
8
|
|
|
8
|
-
import { useT } from '@creekjs/i18n/react';
|
|
9
|
+
import { IntlContext, useT } from '@creekjs/i18n/react';
|
|
9
10
|
|
|
10
11
|
import { CreekKeepAlive, CreekKeepAliveProps } from '../creek-keep-alive';
|
|
11
12
|
import { CreekLocaleButton } from '../creek-locale-button';
|
|
@@ -31,10 +32,10 @@ export type LayoutProps = ProLayoutProps & {
|
|
|
31
32
|
extraActions?: React.ReactNode[];
|
|
32
33
|
};
|
|
33
34
|
|
|
34
|
-
const MenuName = ({ name, path }: { name
|
|
35
|
+
const MenuName = ({ name, path }: { name?: string; path?: string }) => {
|
|
35
36
|
const t = useT();
|
|
36
37
|
const key = !path || path === '/' ? 'menu.home' : `menu${path.replace(/\//g, '.')}`;
|
|
37
|
-
return
|
|
38
|
+
return t(key, name);
|
|
38
39
|
};
|
|
39
40
|
|
|
40
41
|
export const CreekLayout = (props: LayoutProps) => {
|
|
@@ -66,14 +67,18 @@ export const CreekLayout = (props: LayoutProps) => {
|
|
|
66
67
|
|
|
67
68
|
const _userConfig = { ...userConfig, ...runtimeConfig };
|
|
68
69
|
|
|
69
|
-
const
|
|
70
|
-
|
|
70
|
+
const intlContext = useContext(IntlContext);
|
|
71
|
+
const hasI18n = !!intlContext && actualShowLocaleButton;
|
|
71
72
|
|
|
72
|
-
|
|
73
|
+
const menuDataRender = useMemoizedFn((menuData: MenuDataItem[]) => {
|
|
74
|
+
// 根据当前是否开启了国际化(上下文是否存在)以及用户配置来判断是否包裹菜单翻译
|
|
75
|
+
const isLocaleEnabled = hasI18n;
|
|
76
|
+
|
|
77
|
+
const mapMenu = (items: MenuDataItem[]): MenuDataItem[] => {
|
|
73
78
|
return items.map((item) => {
|
|
74
79
|
return {
|
|
75
80
|
...item,
|
|
76
|
-
name: isLocaleEnabled ? <MenuName name={item.name} path={item.path} /> : item.name,
|
|
81
|
+
name: (isLocaleEnabled ? <MenuName name={item.name} path={item.path} /> : item.name) as string,
|
|
77
82
|
children: item.children ? mapMenu(item.children) : undefined,
|
|
78
83
|
};
|
|
79
84
|
});
|
|
@@ -106,7 +111,13 @@ export const CreekLayout = (props: LayoutProps) => {
|
|
|
106
111
|
}
|
|
107
112
|
return undefined;
|
|
108
113
|
};
|
|
109
|
-
|
|
114
|
+
const title = findTitle(route?.routes || []) || pathname;
|
|
115
|
+
|
|
116
|
+
if (hasI18n && typeof title === 'string') {
|
|
117
|
+
return <MenuName name={title} path={pathname} />;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return title;
|
|
110
121
|
});
|
|
111
122
|
|
|
112
123
|
const actions: React.ReactNode[] = [...extraActions];
|
|
@@ -12,14 +12,14 @@ export const CreekLocaleButton = () => {
|
|
|
12
12
|
|
|
13
13
|
const items = [
|
|
14
14
|
{
|
|
15
|
-
key: '
|
|
15
|
+
key: 'zh_CN',
|
|
16
16
|
label: t('creek-locale-button.index.jianTiZhongWen', '简体中文'),
|
|
17
|
-
disabled: locale === '
|
|
17
|
+
disabled: locale === 'zh_CN',
|
|
18
18
|
},
|
|
19
19
|
{
|
|
20
|
-
key: '
|
|
20
|
+
key: 'en_US',
|
|
21
21
|
label: 'English',
|
|
22
|
-
disabled: locale === '
|
|
22
|
+
disabled: locale === 'en_US',
|
|
23
23
|
},
|
|
24
24
|
];
|
|
25
25
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|