@4399ywkf/cli 1.0.8 → 1.0.10

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.
Files changed (96) hide show
  1. package/dist/templates/AntdStaticMethods/index.tsx +20 -0
  2. package/dist/templates/AppTheme.tsx +136 -0
  3. package/dist/templates/DIRECTORY_STRUCTURE.md +141 -0
  4. package/dist/templates/GlobalProvider/AppTheme.tsx +136 -0
  5. package/dist/templates/GlobalProvider/Locale.tsx +84 -0
  6. package/dist/templates/GlobalProvider/Query.tsx +12 -0
  7. package/dist/templates/GlobalProvider/StyleRegistry.tsx +9 -0
  8. package/dist/templates/GlobalProvider/index.tsx +23 -0
  9. package/dist/templates/Locale.tsx +55 -56
  10. package/dist/templates/Query.tsx +12 -0
  11. package/dist/templates/StyleRegistry.tsx +9 -0
  12. package/dist/templates/analyzeUnusedKeys.ts +506 -0
  13. package/dist/templates/app/.i18nrc.js +57 -0
  14. package/dist/templates/app/config/jwt/index.ts +2 -1
  15. package/dist/templates/app/docs/DIRECTORY_STRUCTURE.md +141 -0
  16. package/dist/templates/app/docs/glossary.md +11 -0
  17. package/dist/templates/app/package.json.tpl +7 -15
  18. package/dist/templates/app/scripts/i18nWorkflow/analyzeUnusedKeys.ts +506 -0
  19. package/dist/templates/app/scripts/i18nWorkflow/cleanUnusedKeys.ts +344 -0
  20. package/dist/templates/app/scripts/i18nWorkflow/const.ts +18 -0
  21. package/dist/templates/app/scripts/i18nWorkflow/flattenLocaleKeys.ts +139 -0
  22. package/dist/templates/app/scripts/i18nWorkflow/genDefaultLocale.ts +19 -0
  23. package/dist/templates/app/scripts/i18nWorkflow/genDiff.ts +49 -0
  24. package/dist/templates/app/scripts/i18nWorkflow/i18nConfig.ts +7 -0
  25. package/dist/templates/app/scripts/i18nWorkflow/index.ts +11 -0
  26. package/dist/templates/app/scripts/i18nWorkflow/protectedPatterns.ts +91 -0
  27. package/dist/templates/app/scripts/i18nWorkflow/utils.ts +76 -0
  28. package/dist/templates/app/src/components/AntdStaticMethods/index.tsx +20 -0
  29. package/dist/templates/app/src/index.tsx +0 -4
  30. package/dist/templates/app/src/layout/GlobalProvider/AppTheme.tsx +136 -0
  31. package/dist/templates/app/src/layout/GlobalProvider/Locale.tsx +84 -0
  32. package/dist/templates/app/src/layout/GlobalProvider/Query.tsx +12 -0
  33. package/dist/templates/app/src/layout/GlobalProvider/StyleRegistry.tsx +9 -0
  34. package/dist/templates/app/src/layout/GlobalProvider/index.tsx +23 -0
  35. package/dist/templates/app/src/locales/utils.ts +23 -0
  36. package/dist/templates/app/src/pages/base/index.tsx +170 -79
  37. package/dist/templates/app/src/routes.tsx +2 -2
  38. package/dist/templates/app/tsconfig.json +19 -3
  39. package/dist/templates/base/index.tsx +170 -79
  40. package/dist/templates/cleanUnusedKeys.ts +344 -0
  41. package/dist/templates/components/AntdStaticMethods/index.tsx +20 -0
  42. package/dist/templates/config/jwt/index.ts +2 -1
  43. package/dist/templates/const.ts +18 -0
  44. package/dist/templates/docs/DIRECTORY_STRUCTURE.md +141 -0
  45. package/dist/templates/docs/glossary.md +11 -0
  46. package/dist/templates/flattenLocaleKeys.ts +139 -0
  47. package/dist/templates/genDefaultLocale.ts +19 -0
  48. package/dist/templates/genDiff.ts +49 -0
  49. package/dist/templates/glossary.md +11 -0
  50. package/dist/templates/i18nConfig.ts +7 -0
  51. package/dist/templates/i18nWorkflow/analyzeUnusedKeys.ts +506 -0
  52. package/dist/templates/i18nWorkflow/cleanUnusedKeys.ts +344 -0
  53. package/dist/templates/i18nWorkflow/const.ts +18 -0
  54. package/dist/templates/i18nWorkflow/flattenLocaleKeys.ts +139 -0
  55. package/dist/templates/i18nWorkflow/genDefaultLocale.ts +19 -0
  56. package/dist/templates/i18nWorkflow/genDiff.ts +49 -0
  57. package/dist/templates/i18nWorkflow/i18nConfig.ts +7 -0
  58. package/dist/templates/i18nWorkflow/index.ts +11 -0
  59. package/dist/templates/i18nWorkflow/protectedPatterns.ts +91 -0
  60. package/dist/templates/i18nWorkflow/utils.ts +76 -0
  61. package/dist/templates/index.tsx +170 -79
  62. package/dist/templates/jwt/index.ts +2 -1
  63. package/dist/templates/layout/GlobalProvider/AppTheme.tsx +136 -0
  64. package/dist/templates/layout/GlobalProvider/Locale.tsx +84 -0
  65. package/dist/templates/layout/GlobalProvider/Query.tsx +12 -0
  66. package/dist/templates/layout/GlobalProvider/StyleRegistry.tsx +9 -0
  67. package/dist/templates/layout/GlobalProvider/index.tsx +23 -0
  68. package/dist/templates/locales/utils.ts +23 -0
  69. package/dist/templates/package.json.tpl +7 -15
  70. package/dist/templates/pages/base/index.tsx +170 -79
  71. package/dist/templates/protectedPatterns.ts +91 -0
  72. package/dist/templates/routes.tsx +2 -2
  73. package/dist/templates/scripts/i18nWorkflow/analyzeUnusedKeys.ts +506 -0
  74. package/dist/templates/scripts/i18nWorkflow/cleanUnusedKeys.ts +344 -0
  75. package/dist/templates/scripts/i18nWorkflow/const.ts +18 -0
  76. package/dist/templates/scripts/i18nWorkflow/flattenLocaleKeys.ts +139 -0
  77. package/dist/templates/scripts/i18nWorkflow/genDefaultLocale.ts +19 -0
  78. package/dist/templates/scripts/i18nWorkflow/genDiff.ts +49 -0
  79. package/dist/templates/scripts/i18nWorkflow/i18nConfig.ts +7 -0
  80. package/dist/templates/scripts/i18nWorkflow/index.ts +11 -0
  81. package/dist/templates/scripts/i18nWorkflow/protectedPatterns.ts +91 -0
  82. package/dist/templates/scripts/i18nWorkflow/utils.ts +76 -0
  83. package/dist/templates/src/components/AntdStaticMethods/index.tsx +20 -0
  84. package/dist/templates/src/index.tsx +0 -4
  85. package/dist/templates/src/layout/GlobalProvider/AppTheme.tsx +136 -0
  86. package/dist/templates/src/layout/GlobalProvider/Locale.tsx +84 -0
  87. package/dist/templates/src/layout/GlobalProvider/Query.tsx +12 -0
  88. package/dist/templates/src/layout/GlobalProvider/StyleRegistry.tsx +9 -0
  89. package/dist/templates/src/layout/GlobalProvider/index.tsx +23 -0
  90. package/dist/templates/src/locales/utils.ts +23 -0
  91. package/dist/templates/src/pages/base/index.tsx +170 -79
  92. package/dist/templates/src/routes.tsx +2 -2
  93. package/dist/templates/tsconfig.json +19 -3
  94. package/dist/templates/type.ts +23 -24
  95. package/dist/templates/utils.ts +23 -0
  96. package/package.json +19 -21
@@ -0,0 +1,20 @@
1
+ // Entry component
2
+ import { App } from 'antd';
3
+ import type { MessageInstance } from 'antd/es/message/interface';
4
+ import type { ModalStaticFunctions } from 'antd/es/modal/confirm';
5
+ import type { NotificationInstance } from 'antd/es/notification/interface';
6
+ import { memo } from 'react';
7
+
8
+ let message: MessageInstance;
9
+ let notification: NotificationInstance;
10
+ let modal: Omit<ModalStaticFunctions, 'warn'>;
11
+
12
+ export default memo(() => {
13
+ const staticFunction = App.useApp();
14
+ message = staticFunction.message;
15
+ modal = staticFunction.modal;
16
+ notification = staticFunction.notification;
17
+ return null;
18
+ });
19
+
20
+ export { message, modal, notification };
@@ -0,0 +1,136 @@
1
+ import ThemeProvider from "@/components/ThemeProvider";
2
+ import { CLOUD_THEME_APPEARANCE } from "@/const/theme";
3
+ import { setCookie } from "@/utils/cookie";
4
+
5
+ // import { useGlobalStore } from "@store/global";
6
+ import React, { memo, useEffect, type ReactNode } from "react";
7
+
8
+ import { SYSTEM_PREFIX } from "@/const/system";
9
+ import { GlobalStyle } from "@/styles";
10
+ import { useUserStore } from "@store/user";
11
+ import { createStaticStyles, cx } from "antd-style";
12
+ import HarmonyOS_Sans_Regular from "@public/fonts/HarmonyOS_Sans_Regular.woff2";
13
+ import AntdStaticMethods from "@/components/AntdStaticMethods";
14
+
15
+ const styles = createStaticStyles(({ css, cssVar }) => ({
16
+ app: css`
17
+ position: relative;
18
+
19
+ overscroll-behavior: none;
20
+ display: flex;
21
+ flex-direction: column;
22
+ align-items: center;
23
+
24
+ height: 100%;
25
+ min-height: 100dvh;
26
+ max-height: 100dvh;
27
+
28
+ @media (min-device-width: 576px) {
29
+ overflow: hidden;
30
+ }
31
+ `,
32
+ // scrollbar-width and scrollbar-color are supported from Chrome 121
33
+ // https://developer.mozilla.org/en-US/docs/Web/CSS/scrollbar-color
34
+ scrollbar: css`
35
+ scrollbar-color: ${cssVar.colorFill} transparent;
36
+ scrollbar-width: thin;
37
+
38
+ #lobe-mobile-scroll-container {
39
+ scrollbar-width: none;
40
+
41
+ ::-webkit-scrollbar {
42
+ width: 0;
43
+ height: 0;
44
+ }
45
+ }
46
+ `,
47
+
48
+ // so this is a polyfill for older browsers
49
+ scrollbarPolyfill: css`
50
+ ::-webkit-scrollbar {
51
+ width: 0.75em;
52
+ height: 0.75em;
53
+ }
54
+
55
+ ::-webkit-scrollbar-thumb {
56
+ border-radius: 10px;
57
+ }
58
+
59
+ :hover::-webkit-scrollbar-thumb {
60
+ border: 3px solid transparent;
61
+ background-color: ${cssVar.colorText};
62
+ background-clip: content-box;
63
+ }
64
+
65
+ ::-webkit-scrollbar-track {
66
+ background-color: transparent;
67
+ }
68
+ `,
69
+ }));
70
+
71
+ interface AppThemeProps {
72
+ children: ReactNode;
73
+ }
74
+
75
+ const AppTheme = memo(({ children }: AppThemeProps) => {
76
+ const themeMode = useUserStore((s) => s.themeMode);
77
+ const animationMode = useUserStore((s) => s.animationMode);
78
+ const neutralColor = useUserStore((s) => s.neutralColor);
79
+ const primaryColor = useUserStore((s) => s.primaryColor);
80
+
81
+ useEffect(() => {
82
+ // Update data-theme accordingly if user selects light or dark
83
+ if (themeMode !== "auto") {
84
+ document.documentElement.dataset.theme = themeMode;
85
+ return;
86
+ }
87
+
88
+ // For auto mode, we need to watch system preferences
89
+ const mediaQuery = window.matchMedia("(prefers-color-scheme: dark)");
90
+
91
+ // Set initial theme based on system preference
92
+ document.documentElement.dataset.theme = mediaQuery.matches
93
+ ? "dark"
94
+ : "light";
95
+
96
+ // Update theme when system preference changes
97
+ function handleChange(e) {
98
+ document.documentElement.dataset.theme = e.matches ? "dark" : "light";
99
+ }
100
+
101
+ mediaQuery.addEventListener("change", handleChange);
102
+ return () => mediaQuery.removeEventListener("change", handleChange);
103
+ }, [themeMode]);
104
+
105
+ return (
106
+ <ThemeProvider
107
+ prefixCls={SYSTEM_PREFIX}
108
+ appearance={themeMode !== "auto" ? themeMode : undefined}
109
+ className={cx(styles.app, styles.scrollbar, styles.scrollbarPolyfill)}
110
+ customTheme={{
111
+ neutralColor: neutralColor,
112
+ primaryColor: primaryColor,
113
+ }}
114
+ customFonts={[HarmonyOS_Sans_Regular]}
115
+ theme={{
116
+ cssVar: true,
117
+ token: {
118
+ motion: animationMode !== "disabled",
119
+ motionUnit: animationMode === "agile" ? 0.05 : 0.1,
120
+ },
121
+ }}
122
+ themeMode={themeMode}
123
+ onAppearanceChange={(appearance) => {
124
+ if (themeMode !== "auto") return;
125
+
126
+ setCookie(CLOUD_THEME_APPEARANCE, appearance);
127
+ }}
128
+ >
129
+ {children}
130
+ <AntdStaticMethods />
131
+ <GlobalStyle />
132
+ </ThemeProvider>
133
+ );
134
+ });
135
+
136
+ export default AppTheme;
@@ -0,0 +1,141 @@
1
+ # 企业脚手架目录规划说明
2
+
3
+ ## 1. 现状概览
4
+
5
+ ```
6
+ app/
7
+ ├── config/ # 构建 + 运行时配置混放
8
+ │ ├── env/ # 环境变量文件
9
+ │ ├── jwt/ # 运行时
10
+ │ ├── request/ # 运行时
11
+ │ ├── router/ # 渲染入口(renderClient)
12
+ │ └── rspack/ # 构建
13
+ ├── locales/ # 文案 JSON(与 src/locales 双源)
14
+ ├── public/
15
+ ├── scripts/
16
+ ├── src/
17
+ │ ├── bootstrap/
18
+ │ ├── color/ # 设计 token 色板
19
+ │ ├── components/
20
+ │ ├── config/ # 仅 env.ts(与根 config 易混淆)
21
+ │ ├── const/
22
+ │ ├── layout/
23
+ │ ├── locales/ # i18n 逻辑 + TS 文案
24
+ │ ├── micro/
25
+ │ ├── pages/
26
+ │ ├── routes.tsx
27
+ │ ├── styles/ # 全局样式 + theme 算法
28
+ │ ├── types/
29
+ │ └── utils/
30
+ └── store/ # 与 src 平级
31
+ ├── middleware/
32
+ └── user/
33
+ ```
34
+
35
+ ---
36
+
37
+ ## 2. 结论:整体可用,有几处需约定或收敛
38
+
39
+ - **做得好的**:`store` 独立、按 agent/slice 拆分;`pages` + `layout` + `components` 分层清晰;构建配置集中在 `config/rspack`、环境变量在 `config/env`,便于维护。
40
+ - **需要约定的**:根目录 `config` 与 `src/config` 的职责边界、`locales` 双源、`color`/`styles`/`theme` 的归属。
41
+ - **可优化项**:收敛「配置与文案」的入口、统一命名(如 `const` vs `constants`)、可选能力(如 `micro`)在文档中说明。
42
+
43
+ ---
44
+
45
+ ## 3. 问题与建议
46
+
47
+ ### 3.1 config 双位置(根 config vs src/config)
48
+
49
+ | 位置 | 内容 | 问题 |
50
+ |------------|----------------|------------------------------|
51
+ | 根 `config/` | env 文件、rspack、request、jwt、router | 构建与运行时混在同一层 |
52
+ | `src/config/` | 仅 `env.ts`(zod 解析) | 新人易困惑「改 env 改哪边」 |
53
+
54
+ **建议(二选一或折中):**
55
+
56
+ - **方案 A(推荐)**:约定「根 `config/` = 仅构建与环境文件」:只放 `env/`、`rspack/`;把 `request/`、`jwt/`、`router/` 迁到 `src/config/`(或 `src/core/`),alias 保持 `@config` 指向 `src/config`,构建配置单独用 `config/rspack` 路径。这样「构建配置在根 config,运行时配置在 src」边界清晰。
57
+ - **方案 B**:维持现状,在 README 中明确写清:「环境变量与构建用根 `config/`,运行时解析用 `src/config/env.ts`;请求/路由等由根 `config/` 的模块提供」,减少误改。
58
+
59
+ ### 3.2 locales 双源(根 locales vs src/locales)
60
+
61
+ - 根 `locales/zh-CN/common.json` 与 `src/locales/default/common.ts` 内容重复,且有脚本把 TS 转 JSON。
62
+ - **建议**:选单一数据源。若以 i18n 代码为主,保留 `src/locales`,删除根 `locales/` 和转换脚本,构建或运行时从 `src/locales` 生成/加载;若以 JSON 为主,则只保留根 `locales/`,在 README 中说明「文案只放根 locales」。
63
+
64
+ ### 3.3 store 与 src 平级
65
+
66
+ - `store/` 在项目根与 `src/` 平级,符合「状态与 UI 分离」的常见企业习惯;alias `@store` 指向根下 `store` 也合理。
67
+ - **建议**:保持现状;在 README 或本说明中写一句:「业务 UI 在 `src/`,领域状态在 `store/`,按 agent/slice 拆分」,避免被误挪进 `src`。
68
+
69
+ ### 3.4 src 内部:color / styles / theme
70
+
71
+ - `color/`:色板与 token 数据;`styles/`:全局样式、antd 覆盖、**theme 算法与 customToken**;`types/` 中还有 `customStylish`、`customToken`。
72
+ - 问题:主题相关分散在 `color`、`styles/theme`、`styles`、`types`,新人找「改主题」入口不直观。
73
+ - **建议**:
74
+ - 要么保留 `color/` 但在 README 标明「设计 token 与色板,被 `styles/theme` 消费」;
75
+ - 要么将 `color/` 收进 `styles/theme/`(如 `styles/theme/color/`),入口统一为 `styles/theme`,减少顶层目录。
76
+ - 不强求一步到位,但需在文档中画一条线:**主题与 token 的入口是 `src/styles/theme`(及可选 `src/color`)**。
77
+
78
+ ### 3.5 横切目录:const / types / utils
79
+
80
+ - `const/`、`types/`、`utils/` 是常见横切层,结构合理。
81
+ - 小问题:`const/constants.ts` 当前为空;`types` 里既有全局类型又有与 theme 强相关的类型。
82
+ - **建议**:`const` 保留,删除或补全 `constants.ts`,避免空文件;在 README 或本说明中约定「全局业务常量放 `const/`,组件/页面私有常量随模块」。`types` 可注明「与 theme/样式强相关的类型与 `styles/theme` 同目录或在本目录集中维护」,二选一即可。
83
+
84
+ ### 3.6 可选能力:micro、bootstrap
85
+
86
+ - `micro/` 仅 Garfish,已作为可选项;`bootstrap/` 仅应用启动逻辑。
87
+ - **建议**:保持 `micro/` 在 `src` 下,README 中说明「微前端为可选项,入口与配置见 xxx」。`bootstrap/` 可保留;若希望根入口更短,可把 `bootstrapWithEnv()` 的实现迁到 `src/index.tsx` 或 `src/config/bootstrap.ts`,只保留单文件也可。
88
+
89
+ ### 3.7 pages 与路由
90
+
91
+ - `pages/` 下有 404、base、index 等;路由定义在 `src/routes.tsx`,渲染入口在 `config/router/index.tsx`。
92
+ - **建议**:约定「路由表仅由 `src/routes.tsx` 维护;`config/router` 只负责 `renderClient` 与挂载」,在 README 或本说明写清,避免在 `config/router` 里再配路由造成双源。
93
+
94
+ ### 3.8 根目录与脚本
95
+
96
+ - 根目录的 `tsconfig`、`tailwind`、`postcss`、`scripts/` 等符合常规,无需调整。
97
+ - `scripts/` 若仅剩「locales 转 JSON」且已决定废弃根 `locales/`,可删除该脚本;否则保留并注明用途。
98
+
99
+ ---
100
+
101
+ ## 4. 推荐约定(最小改动版)
102
+
103
+ 在不做大范围迁移的前提下,建议先做「约定文档化 + 少量收敛」:
104
+
105
+ 1. **配置**:在 README 中写清「根 `config/` = 构建与环境文件;运行时配置与请求/路由实现来自 `@config`(当前指向根 config,或你们改为 src/config)」。
106
+ 2. **文案**:选定 locales 单一数据源(推荐 `src/locales`),删除或弃用另一侧及转换脚本。
107
+ 3. **主题**:在 README 中标明「主题与 token 入口:`src/styles/theme`,色板数据见 `src/color`(可选)」。
108
+ 4. **store**:说明「全局状态在根 `store/`,按 agent/slice 划分,与 `src` 并列」。
109
+ 5. **路由**:说明「路由表只在 `src/routes.tsx` 维护;`config/router` 仅负责渲染与挂载」。
110
+ 6. **空文件**:删除或补全 `src/const/constants.ts`。
111
+
112
+ 若后续要做更大调整,再考虑:把 request/jwt/router 迁入 `src/config` 或 `src/core`、将 `color` 并入 `styles/theme` 等。
113
+
114
+ ---
115
+
116
+ ## 5. 可选:目标结构示意(供长期演进参考)
117
+
118
+ ```
119
+ app/
120
+ ├── config/ # 仅构建与环境
121
+ │ ├── env/
122
+ │ └── rspack/
123
+ ├── public/
124
+ ├── scripts/
125
+ ├── src/
126
+ │ ├── config/ # 运行时:env 解析、request、router 挂载等
127
+ │ ├── core/ # 可选:bootstrap、微前端入口等
128
+ │ ├── layout/
129
+ │ ├── pages/
130
+ │ ├── components/
131
+ │ ├── styles/ # 全局样式 + theme(含 token/color 或引用)
132
+ │ ├── locales/ # 单一 i18n 数据源
133
+ │ ├── const/
134
+ │ ├── types/
135
+ │ ├── utils/
136
+ │ ├── routes.tsx
137
+ │ └── index.tsx
138
+ └── store/
139
+ ```
140
+
141
+ 当前模板不必立刻改成上述结构,可先落实「约定 + 文档 + 删除冗余」,再按团队习惯逐步演进。
@@ -0,0 +1,136 @@
1
+ import ThemeProvider from "@/components/ThemeProvider";
2
+ import { CLOUD_THEME_APPEARANCE } from "@/const/theme";
3
+ import { setCookie } from "@/utils/cookie";
4
+
5
+ // import { useGlobalStore } from "@store/global";
6
+ import React, { memo, useEffect, type ReactNode } from "react";
7
+
8
+ import { SYSTEM_PREFIX } from "@/const/system";
9
+ import { GlobalStyle } from "@/styles";
10
+ import { useUserStore } from "@store/user";
11
+ import { createStaticStyles, cx } from "antd-style";
12
+ import HarmonyOS_Sans_Regular from "@public/fonts/HarmonyOS_Sans_Regular.woff2";
13
+ import AntdStaticMethods from "@/components/AntdStaticMethods";
14
+
15
+ const styles = createStaticStyles(({ css, cssVar }) => ({
16
+ app: css`
17
+ position: relative;
18
+
19
+ overscroll-behavior: none;
20
+ display: flex;
21
+ flex-direction: column;
22
+ align-items: center;
23
+
24
+ height: 100%;
25
+ min-height: 100dvh;
26
+ max-height: 100dvh;
27
+
28
+ @media (min-device-width: 576px) {
29
+ overflow: hidden;
30
+ }
31
+ `,
32
+ // scrollbar-width and scrollbar-color are supported from Chrome 121
33
+ // https://developer.mozilla.org/en-US/docs/Web/CSS/scrollbar-color
34
+ scrollbar: css`
35
+ scrollbar-color: ${cssVar.colorFill} transparent;
36
+ scrollbar-width: thin;
37
+
38
+ #lobe-mobile-scroll-container {
39
+ scrollbar-width: none;
40
+
41
+ ::-webkit-scrollbar {
42
+ width: 0;
43
+ height: 0;
44
+ }
45
+ }
46
+ `,
47
+
48
+ // so this is a polyfill for older browsers
49
+ scrollbarPolyfill: css`
50
+ ::-webkit-scrollbar {
51
+ width: 0.75em;
52
+ height: 0.75em;
53
+ }
54
+
55
+ ::-webkit-scrollbar-thumb {
56
+ border-radius: 10px;
57
+ }
58
+
59
+ :hover::-webkit-scrollbar-thumb {
60
+ border: 3px solid transparent;
61
+ background-color: ${cssVar.colorText};
62
+ background-clip: content-box;
63
+ }
64
+
65
+ ::-webkit-scrollbar-track {
66
+ background-color: transparent;
67
+ }
68
+ `,
69
+ }));
70
+
71
+ interface AppThemeProps {
72
+ children: ReactNode;
73
+ }
74
+
75
+ const AppTheme = memo(({ children }: AppThemeProps) => {
76
+ const themeMode = useUserStore((s) => s.themeMode);
77
+ const animationMode = useUserStore((s) => s.animationMode);
78
+ const neutralColor = useUserStore((s) => s.neutralColor);
79
+ const primaryColor = useUserStore((s) => s.primaryColor);
80
+
81
+ useEffect(() => {
82
+ // Update data-theme accordingly if user selects light or dark
83
+ if (themeMode !== "auto") {
84
+ document.documentElement.dataset.theme = themeMode;
85
+ return;
86
+ }
87
+
88
+ // For auto mode, we need to watch system preferences
89
+ const mediaQuery = window.matchMedia("(prefers-color-scheme: dark)");
90
+
91
+ // Set initial theme based on system preference
92
+ document.documentElement.dataset.theme = mediaQuery.matches
93
+ ? "dark"
94
+ : "light";
95
+
96
+ // Update theme when system preference changes
97
+ function handleChange(e) {
98
+ document.documentElement.dataset.theme = e.matches ? "dark" : "light";
99
+ }
100
+
101
+ mediaQuery.addEventListener("change", handleChange);
102
+ return () => mediaQuery.removeEventListener("change", handleChange);
103
+ }, [themeMode]);
104
+
105
+ return (
106
+ <ThemeProvider
107
+ prefixCls={SYSTEM_PREFIX}
108
+ appearance={themeMode !== "auto" ? themeMode : undefined}
109
+ className={cx(styles.app, styles.scrollbar, styles.scrollbarPolyfill)}
110
+ customTheme={{
111
+ neutralColor: neutralColor,
112
+ primaryColor: primaryColor,
113
+ }}
114
+ customFonts={[HarmonyOS_Sans_Regular]}
115
+ theme={{
116
+ cssVar: true,
117
+ token: {
118
+ motion: animationMode !== "disabled",
119
+ motionUnit: animationMode === "agile" ? 0.05 : 0.1,
120
+ },
121
+ }}
122
+ themeMode={themeMode}
123
+ onAppearanceChange={(appearance) => {
124
+ if (themeMode !== "auto") return;
125
+
126
+ setCookie(CLOUD_THEME_APPEARANCE, appearance);
127
+ }}
128
+ >
129
+ {children}
130
+ <AntdStaticMethods />
131
+ <GlobalStyle />
132
+ </ThemeProvider>
133
+ );
134
+ });
135
+
136
+ export default AppTheme;
@@ -0,0 +1,84 @@
1
+ import { ConfigProvider } from 'antd';
2
+ import dayjs from 'dayjs';
3
+ import { type PropsWithChildren, memo, useEffect, useState } from 'react';
4
+ import { isRtlLang } from 'rtl-detect';
5
+
6
+ import { createI18nNext } from '@/locales/create';
7
+ import { getAntdLocale } from '@/utils/locale';
8
+
9
+
10
+ const updateDayjs = async (lang: string) => {
11
+ let dayJSLocale;
12
+ try {
13
+ // dayjs locale is using `en` instead of `en-US`
14
+ // refs: https://github.com/lobehub/lobe-chat/issues/3396
15
+ const locale = lang!.toLowerCase() === 'en-us' ? 'en' : lang!.toLowerCase();
16
+
17
+ dayJSLocale = await import(`dayjs/locale/${locale}.js`);
18
+ } catch {
19
+ console.warn(`dayjs locale for ${lang} not found, fallback to en`);
20
+ dayJSLocale = await import(`dayjs/locale/en.js`);
21
+ }
22
+
23
+ dayjs.locale(dayJSLocale.default);
24
+ };
25
+
26
+ interface LocaleLayoutProps extends PropsWithChildren {
27
+ antdLocale?: any;
28
+ defaultLang?: string;
29
+ }
30
+
31
+ const Locale = memo<LocaleLayoutProps>(({ children, defaultLang, antdLocale }) => {
32
+ const [i18n] = useState(() => createI18nNext(defaultLang));
33
+ const [lang, setLang] = useState(defaultLang);
34
+ const [locale, setLocale] = useState(antdLocale);
35
+
36
+ if (!i18n.instance.isInitialized)
37
+ i18n.init().then(async () => {
38
+ if (!lang) return;
39
+
40
+ await updateDayjs(lang);
41
+ });
42
+
43
+ // handle i18n instance language change
44
+ useEffect(() => {
45
+ const handleLang = async (lng: string) => {
46
+ setLang(lng);
47
+
48
+ if (lang === lng) return;
49
+
50
+ const newLocale = await getAntdLocale(lng);
51
+ setLocale(newLocale);
52
+
53
+ await updateDayjs(lng);
54
+ };
55
+
56
+ i18n.instance.on('languageChanged', handleLang);
57
+ return () => {
58
+ i18n.instance.off('languageChanged', handleLang);
59
+ };
60
+ }, [i18n, lang]);
61
+
62
+ // detect document direction
63
+ const documentDir = isRtlLang(lang!) ? 'rtl' : 'ltr';
64
+
65
+ return (
66
+ <ConfigProvider
67
+ direction={documentDir}
68
+ locale={locale}
69
+ theme={{
70
+ components: {
71
+ Button: {
72
+ contentFontSizeSM: 12,
73
+ },
74
+ },
75
+ }}
76
+ >
77
+ {children}
78
+ </ConfigProvider>
79
+ );
80
+ });
81
+
82
+ Locale.displayName = 'Locale';
83
+
84
+ export default Locale;
@@ -0,0 +1,12 @@
1
+ import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
2
+ import React, { type PropsWithChildren, useEffect, useState } from 'react';
3
+
4
+ const QueryProvider = ({ children }: PropsWithChildren) => {
5
+ const [queryClient] = useState(() => new QueryClient());
6
+
7
+ return (
8
+ <QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
9
+ );
10
+ };
11
+
12
+ export default QueryProvider;
@@ -0,0 +1,9 @@
1
+ import { StyleProvider } from 'antd-style';
2
+ import { type PropsWithChildren } from 'react';
3
+
4
+
5
+ const StyleRegistry = ({ children }: PropsWithChildren) => {
6
+ return <StyleProvider>{children}</StyleProvider>;
7
+ };
8
+
9
+ export default StyleRegistry;
@@ -0,0 +1,23 @@
1
+ import StyleRegistry from "./StyleRegistry";
2
+ import AppTheme from "./AppTheme";
3
+ import QueryProvider from "./Query";
4
+ import Locale from "./Locale";
5
+ import { Outlet } from "react-router";
6
+
7
+ interface GlobalProviderProps {
8
+
9
+ }
10
+
11
+ export default function GlobalProvider({ }: GlobalProviderProps) {
12
+ return (
13
+ <StyleRegistry>
14
+ <Locale>
15
+ <AppTheme>
16
+ <QueryProvider>
17
+ <Outlet />
18
+ </QueryProvider>
19
+ </AppTheme>
20
+ </Locale>
21
+ </StyleRegistry>
22
+ );
23
+ }