@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.
@@ -1,54 +1,54 @@
1
1
 
2
2
  
3
- > @creekjs/web-components@1.0.9 father:build /Users/ernestwang/Documents/code-resoorce/creek/packages/web-components
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
  info - Clean output directories
7
7
  info - Bundless for src directory to cjs format
8
+ event - Bundless index.tsx to dist/creek-config-provider/index.js (with declaration)
8
9
  event - Bundless CreekConfigContext.tsx to dist/creek-config-provider/CreekConfigContext.js (with declaration)
9
10
  event - Bundless index.ts to dist/creek-hooks/index.js (with declaration)
10
11
  event - Bundless CreekI18nProvider.tsx to dist/creek-config-provider/CreekI18nProvider.js (with declaration)
11
- event - Bundless types.ts to dist/creek-hooks/useApp/types.js (with declaration)
12
- event - Bundless ModalHelper.tsx to dist/creek-hooks/useApp/ModalHelper.js (with declaration)
12
+ event - Bundless DrawerHelper.tsx to dist/creek-hooks/useApp/DrawerHelper.js (with declaration)
13
13
  event - Bundless index.tsx to dist/creek-hooks/useApp/index.js (with declaration)
14
- event - Bundless useViewportHeight.tsx to dist/creek-hooks/useViewportHeight.js (with declaration)
14
+ event - Bundless ModalHelper.tsx to dist/creek-hooks/useApp/ModalHelper.js (with declaration)
15
+ event - Bundless types.ts to dist/creek-hooks/useApp/types.js (with declaration)
15
16
  event - Bundless index.tsx to dist/creek-icon/index.js (with declaration)
17
+ event - Bundless FullScreen.tsx to dist/creek-layout/ActionRender/FullScreen.js (with declaration)
16
18
  event - Bundless index.tsx to dist/creek-keep-alive/index.js (with declaration)
19
+ event - Bundless index.tsx to dist/creek-layout/ActionRender/index.js (with declaration)
20
+ event - Bundless UserInfo.tsx to dist/creek-layout/ActionRender/UserInfo.js (with declaration)
21
+ event - Bundless LayoutSettings.tsx to dist/creek-layout/ActionRender/LayoutSettings.js (with declaration)
17
22
  event - Bundless index.tsx to dist/creek-layout/Exception/index.js (with declaration)
18
- event - Bundless DrawerHelper.tsx to dist/creek-hooks/useApp/DrawerHelper.js (with declaration)
19
- event - Bundless index.tsx to dist/creek-config-provider/index.js (with declaration)
20
- event - Bundless FullScreen.tsx to dist/creek-layout/ActionRender/FullScreen.js (with declaration)
23
+ event - Bundless NotFound.tsx to dist/creek-layout/Exception/NotFound.js (with declaration)
21
24
  event - Bundless CollapseButton.tsx to dist/creek-layout/CollapseButton.js (with declaration)
22
25
  event - Bundless NotFoundPage.tsx to dist/creek-layout/Exception/NotFoundPage.js (with declaration)
23
- event - Bundless NotFound.tsx to dist/creek-layout/Exception/NotFound.js (with declaration)
24
- event - Bundless index.tsx to dist/creek-layout/ActionRender/index.js (with declaration)
25
- event - Bundless useLayoutSettingsStore.ts to dist/creek-layout/useLayoutSettingsStore.js (with declaration)
26
26
  event - Bundless index.tsx to dist/creek-layout/index.js (with declaration)
27
- event - Bundless LayoutSettings.tsx to dist/creek-layout/ActionRender/LayoutSettings.js (with declaration)
28
27
  event - Bundless index.tsx to dist/creek-loading/index.js (with declaration)
29
- event - Bundless index.tsx to dist/creek-page-container/index.js (with declaration)
30
- event - Bundless UserInfo.tsx to dist/creek-layout/ActionRender/UserInfo.js (with declaration)
31
28
  event - Bundless index.tsx to dist/creek-locale-button/index.js (with declaration)
32
29
  event - Bundless index.ts to dist/creek-style/index.js (with declaration)
33
- event - Bundless DensityIcon.tsx to dist/creek-table/components/DensityIcon.js (with declaration)
30
+ event - Bundless scrollbar.ts to dist/creek-style/scrollbar.js (with declaration)
31
+ event - Bundless index.tsx to dist/creek-page-container/index.js (with declaration)
34
32
  event - Bundless EllipsisTooltip.tsx to dist/creek-table/components/EllipsisTooltip.js (with declaration)
35
- event - Bundless index.tsx to dist/creek-table/components/index.js (with declaration)
33
+ event - Bundless DensityIcon.tsx to dist/creek-table/components/DensityIcon.js (with declaration)
36
34
  event - Bundless index.ts to dist/creek-table/hooks/index.js (with declaration)
35
+ event - Bundless index.tsx to dist/creek-table/components/index.js (with declaration)
37
36
  event - Bundless useAdaptiveToolBar.tsx to dist/creek-table/hooks/useAdaptiveToolBar.js (with declaration)
38
- event - Bundless scrollbar.ts to dist/creek-style/scrollbar.js (with declaration)
39
- event - Bundless useAutoWidthColumns.tsx to dist/creek-table/hooks/useAutoWidthColumns.js (with declaration)
40
37
  event - Bundless useEllipsisColumns.tsx to dist/creek-table/hooks/useEllipsisColumns.js (with declaration)
38
+ event - Bundless useAutoWidthColumns.tsx to dist/creek-table/hooks/useAutoWidthColumns.js (with declaration)
41
39
  event - Bundless useIndexColumn.tsx to dist/creek-table/hooks/useIndexColumn.js (with declaration)
42
40
  event - Bundless useResizableColumns.tsx to dist/creek-table/hooks/useResizableColumns.js (with declaration)
43
41
  event - Bundless useElementDistance.tsx to dist/creek-table/hooks/useElementDistance.js (with declaration)
42
+ event - Bundless index.tsx to dist/creek-table/index.js (with declaration)
44
43
  event - Bundless useTableOptions.tsx to dist/creek-table/hooks/useTableOptions.js (with declaration)
45
44
  event - Bundless useTableScrollHeight.tsx to dist/creek-table/hooks/useTableScrollHeight.js (with declaration)
46
- event - Bundless SearchTable.tsx to dist/creek-table/SearchTable.js (with declaration)
47
45
  event - Bundless type.ts to dist/creek-table/type.js (with declaration)
48
- event - Bundless useStatusColumns.tsx to dist/creek-table/hooks/useStatusColumns.js (with declaration)
46
+ event - Bundless zh_CN.ts to dist/locales/zh_CN.js (with declaration)
47
+ event - Bundless useViewportHeight.tsx to dist/creek-hooks/useViewportHeight.js (with declaration)
49
48
  event - Bundless index.tsx to dist/index.js (with declaration)
50
- event - Bundless en-US.ts to dist/locales/en-US.js (with declaration)
51
- event - Bundless index.tsx to dist/creek-table/index.js (with declaration)
52
- event - Bundless zh-CN.ts to dist/locales/zh-CN.js (with declaration)
49
+ event - Bundless useLayoutSettingsStore.ts to dist/creek-layout/useLayoutSettingsStore.js (with declaration)
50
+ event - Bundless en_US.ts to dist/locales/en_US.js (with declaration)
51
+ event - Bundless useStatusColumns.tsx to dist/creek-table/hooks/useStatusColumns.js (with declaration)
52
+ event - Bundless SearchTable.tsx to dist/creek-table/SearchTable.js (with declaration)
53
53
  event - Generate declaration files...
54
- event - Transformed successfully in 4375 ms (45 files)
54
+ event - Transformed successfully in 6572 ms (45 files)
@@ -1,9 +1,5 @@
1
1
  /// <reference types="react" />
2
2
  export type CreekConfigContextProps = {
3
3
  iconFontCNs?: string[];
4
- /**
5
- * 国际化语言包
6
- */
7
- locale?: Record<string, string>;
8
4
  };
9
5
  export declare const CreekConfigContext: import("react").Context<CreekConfigContextProps>;
@@ -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 /**\n * 国际化语言包\n */\n locale?: Record<string, string>;\n};\n\nexport const CreekConfigContext = createContext<CreekConfigContextProps>({});\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA8B;AAUvB,IAAM,yBAAqB,4BAAuC,CAAC,CAAC;",
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 'zh-CN'
7
+ * @default 'zh_CN'
7
8
  */
8
- locale?: string;
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: string;
16
+ locale: LocaleCode;
16
17
  changeLocale: (lang: string) => void;
17
18
  }>;
18
19
  export declare const useAppLocale: () => {
19
- locale: string;
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/en-US"));
40
- var import_zh_CN = __toESM(require("../locales/zh-CN"));
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 = "zh-CN";
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
- [DEFAULT_LOCALE]: import_zh_CN.default,
45
- "en-US": import_en_US.default
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)() || DEFAULT_LOCALE,
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 [intl, setIntl] = (0, import_react.useState)(() => (0, import_react2.getIntl)());
63
+ const [internalLocale, setInternalLocale] = (0, import_react.useState)();
58
64
  const changeLocale = (0, import_react.useCallback)((lang) => {
59
- (0, import_react2.setLocale)(lang, false);
60
- setIntl((0, import_react2.getIntl)());
65
+ const underscore = toUnderscoreLocale(lang);
66
+ (0, import_react2.setLocale)(underscore, false);
67
+ setInternalLocale(underscore);
61
68
  }, []);
62
- const currentLocale = (intl == null ? void 0 : intl.locale) || locale || (parentIntl == null ? void 0 : parentIntl.locale) || DEFAULT_LOCALE;
63
- const intlConfig = parentIntl || intl || {};
64
- const safeConfig = {
65
- formats: intlConfig.formats,
66
- defaultLocale: intlConfig.defaultLocale,
67
- defaultFormats: intlConfig.defaultFormats,
68
- onError: intlConfig.onError
69
- };
70
- let baseMessages = {};
71
- if (parentIntl && parentIntl.locale === currentLocale) {
72
- baseMessages = parentIntl.messages;
73
- } else {
74
- baseMessages = ((_a = (0, import_react2.getIntl)()) == null ? void 0 : _a.messages) || {};
75
- }
76
- const finalMessages = {
77
- ...baseMessages,
78
- ...MESSAGES_MAP[currentLocale] || import_zh_CN.default,
79
- ...messages || {}
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
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react2.IntlProvider, { ...safeConfig, locale: currentLocale, messages: finalMessages, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LocaleContext.Provider, { value: { locale: currentLocale, changeLocale }, children }) });
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/en-US';\nimport zhCN from '../locales/zh-CN';\n\nconst DEFAULT_LOCALE = 'zh-CN';\n\nexport interface CreekI18nProviderProps {\n children?: ReactNode;\n /**\n * 语言标识\n * @default 'zh-CN'\n */\n locale?: string;\n /**\n * 国际化语言包,透传给 react-intl\n */\n messages?: Record<string, string>;\n}\n\nconst MESSAGES_MAP: Record<string, Record<string, string>> = {\n [DEFAULT_LOCALE]: zhCN,\n 'en-US': enUS,\n};\n\nexport const LocaleContext = createContext({\n locale: getLocale() || DEFAULT_LOCALE,\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 // Try to get parent intl context\n const parentIntl = useContext(IntlContext);\n\n const [intl, setIntl] = useState(() => getIntl());\n\n const changeLocale = useCallback((lang: string) => {\n setLocale(lang, false);\n setIntl(getIntl());\n }, []);\n\n // 1. 确定最终生效的 locale\n // 优先级:当前组件内部的 state > props.locale > parentIntl.locale > 全局默认\n const currentLocale = intl?.locale || locale || parentIntl?.locale || DEFAULT_LOCALE;\n\n // 2. 提取父级上下文的安全配置 (避免将 IntlShape 的内部方法直接传给 IntlProvider)\n const intlConfig = parentIntl || intl || {};\n const safeConfig = {\n formats: intlConfig.formats,\n defaultLocale: intlConfig.defaultLocale,\n defaultFormats: intlConfig.defaultFormats,\n onError: intlConfig.onError,\n };\n\n // 3. 确定最终的 messages\n // 避免使用 stale 的 parentIntl.messages\n let baseMessages = {};\n if (parentIntl && parentIntl.locale === currentLocale) {\n baseMessages = parentIntl.messages;\n } else {\n baseMessages = getIntl()?.messages || {};\n }\n\n const finalMessages = {\n ...baseMessages,\n ...(MESSAGES_MAP[currentLocale] || zhCN),\n ...(messages || {}),\n };\n\n // 4. 同步给全局 globalIntl,确保非 React 组件能够拿到\n useEffect(() => {\n setLocaleMessages(currentLocale, finalMessages);\n }, [currentLocale, finalMessages]);\n\n return (\n <IntlProvider {...safeConfig} locale={currentLocale} messages={finalMessages}>\n <LocaleContext.Provider value={{ locale: currentLocale, changeLocale }}>{children}</LocaleContext.Provider>\n </IntlProvider>\n );\n};\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAA4E;AAE5E,IAAAA,gBAA4F;AAE5F,mBAAiB;AACjB,mBAAiB;AA6EX;AA3EN,IAAM,iBAAiB;AAevB,IAAM,eAAuD;AAAA,EAC3D,CAAC,cAAc,GAAG,aAAAC;AAAA,EAClB,SAAS,aAAAC;AACX;AAEO,IAAM,oBAAgB,4BAAc;AAAA,EACzC,YAAQ,yBAAU,KAAK;AAAA,EACvB,cAAc,CAAC,SAAiB;AAAA,EAAC;AACnC,CAAC;AAEM,IAAM,eAAe,UAAM,yBAAW,aAAa;AAEnD,IAAM,oBAAoB,CAAC,UAAkC;AAnCpE;AAoCE,QAAM,EAAE,UAAU,QAAQ,SAAS,IAAI;AAGvC,QAAM,iBAAa,yBAAW,yBAAW;AAEzC,QAAM,CAAC,MAAM,OAAO,QAAI,uBAAS,UAAM,uBAAQ,CAAC;AAEhD,QAAM,mBAAe,0BAAY,CAAC,SAAiB;AACjD,iCAAU,MAAM,KAAK;AACrB,gBAAQ,uBAAQ,CAAC;AAAA,EACnB,GAAG,CAAC,CAAC;AAIL,QAAM,iBAAgB,6BAAM,WAAU,WAAU,yCAAY,WAAU;AAGtE,QAAM,aAAa,cAAc,QAAQ,CAAC;AAC1C,QAAM,aAAa;AAAA,IACjB,SAAS,WAAW;AAAA,IACpB,eAAe,WAAW;AAAA,IAC1B,gBAAgB,WAAW;AAAA,IAC3B,SAAS,WAAW;AAAA,EACtB;AAIA,MAAI,eAAe,CAAC;AACpB,MAAI,cAAc,WAAW,WAAW,eAAe;AACrD,mBAAe,WAAW;AAAA,EAC5B,OAAO;AACL,qBAAe,gCAAQ,MAAR,mBAAW,aAAY,CAAC;AAAA,EACzC;AAEA,QAAM,gBAAgB;AAAA,IACpB,GAAG;AAAA,IACH,GAAI,aAAa,aAAa,KAAK,aAAAD;AAAA,IACnC,GAAI,YAAY,CAAC;AAAA,EACnB;AAGA,8BAAU,MAAM;AACd,yCAAkB,eAAe,aAAa;AAAA,EAChD,GAAG,CAAC,eAAe,aAAa,CAAC;AAEjC,SACE,4CAAC,8BAAc,GAAG,YAAY,QAAQ,eAAe,UAAU,eAC7D,sDAAC,cAAc,UAAd,EAAuB,OAAO,EAAE,QAAQ,eAAe,aAAa,GAAI,UAAS,GACpF;AAEJ;",
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 === "en-US" ? import_en_US.default : 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 }) }) }) });
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 : {}\n );\n\n\n return (\n <ConfigProvider locale={locale === 'en-US' ? enUS_antd : 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,+BAAuF;AAkC7E;AA3BV,IAAM,sBAAsB,CAAC,UAAiE;AAhB9F;AAiBE,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,aAAAA;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;AAGA,SACE,4CAAC,8BAAe,QAAQ,WAAW,UAAU,aAAAC,UAAY,aAAAC,SAAW,OAAO,YAAa,GAAG,MACzF,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": ["merge", "enUS_antd", "zhCN_antd"]
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 import_react = require("@creekjs/i18n/react");
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, import_react.useT)();
53
+ const t = (0, import_react2.useT)();
53
54
  const key = !path || path === "/" ? "menu.home" : `menu${path.replace(/\//g, ".")}`;
54
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: t(key, name) });
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
- var _a, _b;
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
- return findTitle((route == null ? void 0 : route.routes) || []) || pathname;
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: 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 menuDataRender = useMemoizedFn((menuData: any[]) => {\n const isLocaleEnabled = more.menu?.locale !== false && _userConfig.menu?.locale !== false;\n\n const mapMenu = (items: any[]): any[] => {\n return items.map((item) => {\n return {\n ...item,\n name: isLocaleEnabled ? <MenuName name={item.name} path={item.path} /> : item.name,\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 return findTitle(route?.routes || []) || pathname;\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": "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",
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: "zh-CN",
36
+ key: "zh_CN",
37
37
  label: t("creek-locale-button.index.jianTiZhongWen", "简体中文"),
38
- disabled: locale === "zh-CN"
38
+ disabled: locale === "zh_CN"
39
39
  },
40
40
  {
41
- key: "en-US",
41
+ key: "en_US",
42
42
  label: "English",
43
- disabled: locale === "en-US"
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: '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"],
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/en-US.ts
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=en-US.js.map
49
+ //# sourceMappingURL=en_US.js.map
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../src/locales/en-US.ts"],
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/zh-CN.ts
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=zh-CN.js.map
49
+ //# sourceMappingURL=zh_CN.js.map
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../src/locales/zh-CN.ts"],
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/zh-CN.ts -> 生成的文件在 src/locales/zh-CN/ 目录下
8
- localePath: './src/locales/zh-CN.ts',
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.10",
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.1"
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.0"
23
+ "@creekjs/i18n-extract": "^1.0.1"
24
24
  },
25
25
  "peerDependencies": {
26
26
  "react-intl": ">=3.0.0"
@@ -2,10 +2,6 @@ import { createContext } from 'react';
2
2
 
3
3
  export type CreekConfigContextProps = {
4
4
  iconFontCNs?: string[];
5
- /**
6
- * 国际化语言包
7
- */
8
- locale?: Record<string, string>;
9
5
  };
10
6
 
11
7
  export const CreekConfigContext = createContext<CreekConfigContextProps>({});
@@ -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/en-US';
7
- import zhCN from '../locales/zh-CN';
6
+ import enUS from '../locales/en_US';
7
+ import zhCN from '../locales/zh_CN';
8
8
 
9
- const DEFAULT_LOCALE = 'zh-CN';
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 'zh-CN'
25
+ * @default 'zh_CN'
16
26
  */
17
- locale?: string;
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<string, Record<string, string>> = {
25
- [DEFAULT_LOCALE]: zhCN,
26
- 'en-US': enUS,
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() || DEFAULT_LOCALE,
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
- // Try to get parent intl context
49
+ // 获取父级 intl context
40
50
  const parentIntl = useContext(IntlContext);
41
51
 
42
- const [intl, setIntl] = useState(() => getIntl());
52
+ // 内部维护的 locale 状态,仅在调用 changeLocale 时更新
53
+ const [internalLocale, setInternalLocale] = useState<string>();
43
54
 
44
55
  const changeLocale = useCallback((lang: string) => {
45
- setLocale(lang, false);
46
- setIntl(getIntl());
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 = intl?.locale || locale || parentIntl?.locale || DEFAULT_LOCALE;
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 intlConfig = parentIntl || intl || {};
55
- const safeConfig = {
56
- formats: intlConfig.formats,
57
- defaultLocale: intlConfig.defaultLocale,
58
- defaultFormats: intlConfig.defaultFormats,
59
- onError: intlConfig.onError,
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
- let baseMessages = {};
65
- if (parentIntl && parentIntl.locale === currentLocale) {
66
- baseMessages = parentIntl.messages;
67
- } else {
68
- baseMessages = getIntl()?.messages || {};
69
- }
70
-
71
- const finalMessages = {
72
- ...baseMessages,
73
- ...(MESSAGES_MAP[currentLocale] || zhCN),
74
- ...(messages || {}),
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={{ locale: currentLocale, changeLocale }}>{children}</LocaleContext.Provider>
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 === 'en-US' ? enUS_antd : zhCN_antd} theme={finalTheme} {...more}>
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: string; path?: string }) => {
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 <>{t(key, name)}</>;
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 menuDataRender = useMemoizedFn((menuData: any[]) => {
70
- const isLocaleEnabled = more.menu?.locale !== false && _userConfig.menu?.locale !== false;
70
+ const intlContext = useContext(IntlContext);
71
+ const hasI18n = !!intlContext && actualShowLocaleButton;
71
72
 
72
- const mapMenu = (items: any[]): any[] => {
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
- return findTitle(route?.routes || []) || pathname;
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: 'zh-CN',
15
+ key: 'zh_CN',
16
16
  label: t('creek-locale-button.index.jianTiZhongWen', '简体中文'),
17
- disabled: locale === 'zh-CN',
17
+ disabled: locale === 'zh_CN',
18
18
  },
19
19
  {
20
- key: 'en-US',
20
+ key: 'en_US',
21
21
  label: 'English',
22
- disabled: locale === 'en-US',
22
+ disabled: locale === 'en_US',
23
23
  },
24
24
  ];
25
25
 
File without changes
File without changes
File without changes
File without changes