@lobehub/chat 0.54.0 → 0.54.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +50 -0
- package/package.json +1 -1
- package/src/components/SelectWithImg/index.tsx +41 -21
- package/src/components/SelectWithImg/styles.ts +36 -21
- package/src/features/AgentSetting/AgentConfig/index.tsx +11 -8
- package/src/layout/index.tsx +10 -6
- package/src/locales/create.ts +11 -7
- package/src/locales/resources/en_US.ts +13 -1
- package/src/pages/settings/Settings/Common.tsx +2 -0
- package/src/pages/settings/layout.tsx +7 -7
- package/src/store/global/hooks/index.ts +1 -0
- package/src/store/global/hooks/useHydrated.ts +1 -1
- package/src/store/global/hooks/useOnFinishHydrationGlobal.ts +3 -3
- package/src/locales/index.ts +0 -5
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,56 @@
|
|
|
2
2
|
|
|
3
3
|
# Changelog
|
|
4
4
|
|
|
5
|
+
### [Version 0.54.2](https://github.com/lobehub/lobe-chat/compare/v0.54.1...v0.54.2)
|
|
6
|
+
|
|
7
|
+
<sup>Released on **2023-08-16**</sup>
|
|
8
|
+
|
|
9
|
+
#### 💄 Styles
|
|
10
|
+
|
|
11
|
+
- **misc**: 修正图片选项的样式问题.
|
|
12
|
+
|
|
13
|
+
<br/>
|
|
14
|
+
|
|
15
|
+
<details>
|
|
16
|
+
<summary><kbd>Improvements and Fixes</kbd></summary>
|
|
17
|
+
|
|
18
|
+
#### Styles
|
|
19
|
+
|
|
20
|
+
- **misc**: 修正图片选项的样式问题 ([5f576cb](https://github.com/lobehub/lobe-chat/commit/5f576cb))
|
|
21
|
+
|
|
22
|
+
</details>
|
|
23
|
+
|
|
24
|
+
<div align="right">
|
|
25
|
+
|
|
26
|
+
[](#readme-top)
|
|
27
|
+
|
|
28
|
+
</div>
|
|
29
|
+
|
|
30
|
+
### [Version 0.54.1](https://github.com/lobehub/lobe-chat/compare/v0.54.0...v0.54.1)
|
|
31
|
+
|
|
32
|
+
<sup>Released on **2023-08-16**</sup>
|
|
33
|
+
|
|
34
|
+
#### 🐛 Bug Fixes
|
|
35
|
+
|
|
36
|
+
- **misc**: 修正 i18n 失效的问题.
|
|
37
|
+
|
|
38
|
+
<br/>
|
|
39
|
+
|
|
40
|
+
<details>
|
|
41
|
+
<summary><kbd>Improvements and Fixes</kbd></summary>
|
|
42
|
+
|
|
43
|
+
#### What's fixed
|
|
44
|
+
|
|
45
|
+
- **misc**: 修正 i18n 失效的问题, closes [#80](https://github.com/lobehub/lobe-chat/issues/80) ([b8d957b](https://github.com/lobehub/lobe-chat/commit/b8d957b))
|
|
46
|
+
|
|
47
|
+
</details>
|
|
48
|
+
|
|
49
|
+
<div align="right">
|
|
50
|
+
|
|
51
|
+
[](#readme-top)
|
|
52
|
+
|
|
53
|
+
</div>
|
|
54
|
+
|
|
5
55
|
## [Version 0.54.0](https://github.com/lobehub/lobe-chat/compare/v0.53.0...v0.54.0)
|
|
6
56
|
|
|
7
57
|
<sup>Released on **2023-08-15**</sup>
|
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Icon, IconProps } from '@lobehub/ui';
|
|
2
2
|
import { SelectProps } from 'antd';
|
|
3
|
-
import { type CSSProperties, ReactNode, memo
|
|
3
|
+
import { type CSSProperties, ReactNode, memo } from 'react';
|
|
4
4
|
import { Flexbox } from 'react-layout-kit';
|
|
5
|
+
import useControlledState from 'use-merge-value';
|
|
5
6
|
|
|
6
7
|
import { useStyles } from './styles';
|
|
7
8
|
|
|
@@ -14,14 +15,20 @@ export interface SelectWithImgOptionItem {
|
|
|
14
15
|
|
|
15
16
|
export interface SelectWithImgProps {
|
|
16
17
|
className?: string;
|
|
18
|
+
classNames?: {
|
|
19
|
+
img?: string;
|
|
20
|
+
};
|
|
17
21
|
defaultValue?: SelectProps['defaultValue'];
|
|
18
|
-
|
|
19
|
-
imgStyle?: CSSProperties;
|
|
22
|
+
height: number;
|
|
20
23
|
onChange?: (value: this['value']) => void;
|
|
21
24
|
options?: SelectWithImgOptionItem[];
|
|
22
|
-
size?: number;
|
|
23
25
|
style?: CSSProperties;
|
|
26
|
+
|
|
27
|
+
styles?: {
|
|
28
|
+
img?: CSSProperties;
|
|
29
|
+
};
|
|
24
30
|
value?: SelectProps['value'];
|
|
31
|
+
width: number;
|
|
25
32
|
}
|
|
26
33
|
|
|
27
34
|
const SelectWithImg = memo<SelectWithImgProps>(
|
|
@@ -32,21 +39,23 @@ const SelectWithImg = memo<SelectWithImgProps>(
|
|
|
32
39
|
defaultValue,
|
|
33
40
|
onChange,
|
|
34
41
|
options,
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
42
|
+
width,
|
|
43
|
+
height,
|
|
44
|
+
styles: outStyles = {},
|
|
45
|
+
classNames = {},
|
|
38
46
|
}) => {
|
|
39
|
-
const [currentValue, setCurrentValue] =
|
|
40
|
-
|
|
47
|
+
const [currentValue, setCurrentValue] = useControlledState<string>(defaultValue, {
|
|
48
|
+
defaultValue,
|
|
49
|
+
onChange,
|
|
50
|
+
value,
|
|
51
|
+
});
|
|
41
52
|
|
|
42
|
-
|
|
43
|
-
onChange?.(currentValue);
|
|
44
|
-
}, [currentValue]);
|
|
53
|
+
const { styles, cx } = useStyles();
|
|
45
54
|
|
|
46
55
|
return (
|
|
47
|
-
<Flexbox className={className} gap={
|
|
56
|
+
<Flexbox className={className} gap={16} horizontal style={style}>
|
|
48
57
|
{options?.map((item) => {
|
|
49
|
-
const isActive =
|
|
58
|
+
const isActive = item.value === currentValue;
|
|
50
59
|
return (
|
|
51
60
|
<Flexbox
|
|
52
61
|
align={'center'}
|
|
@@ -55,13 +64,24 @@ const SelectWithImg = memo<SelectWithImgProps>(
|
|
|
55
64
|
key={item.value}
|
|
56
65
|
onClick={() => setCurrentValue(item.value)}
|
|
57
66
|
>
|
|
58
|
-
<
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
67
|
+
<div
|
|
68
|
+
className={cx(styles.imgCtn, isActive && styles.imgActive, classNames.img)}
|
|
69
|
+
style={{
|
|
70
|
+
...outStyles.img,
|
|
71
|
+
height,
|
|
72
|
+
width,
|
|
73
|
+
}}
|
|
74
|
+
>
|
|
75
|
+
<div
|
|
76
|
+
className={styles.img}
|
|
77
|
+
style={{
|
|
78
|
+
backgroundImage: `url(${item.img})`,
|
|
79
|
+
backgroundSize: 'contain',
|
|
80
|
+
height,
|
|
81
|
+
width,
|
|
82
|
+
}}
|
|
83
|
+
/>
|
|
84
|
+
</div>
|
|
65
85
|
<Flexbox align={'center'} gap={4} horizontal>
|
|
66
86
|
{item.icon && <Icon icon={item.icon} />}
|
|
67
87
|
{item.label}
|
|
@@ -1,27 +1,42 @@
|
|
|
1
1
|
import { createStyles } from 'antd-style';
|
|
2
2
|
|
|
3
|
-
export const useStyles = createStyles(({ css, token }) =>
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
box-shadow: 0 0 0 1px ${token.colorTextDescription};
|
|
3
|
+
export const useStyles = createStyles(({ css, token, cx }) => {
|
|
4
|
+
const hover = css`
|
|
5
|
+
&:hover {
|
|
6
|
+
border-color: ${token.colorText};
|
|
7
|
+
box-shadow: 0 0 0 2px ${token.colorText};
|
|
9
8
|
}
|
|
10
|
-
|
|
11
|
-
container: css`
|
|
12
|
-
cursor: pointer;
|
|
13
|
-
color: ${token.colorTextDescription};
|
|
9
|
+
`;
|
|
14
10
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
11
|
+
const img = cx(css`
|
|
12
|
+
box-shadow: inset 0 0 0 2px ${token.colorSplit};
|
|
13
|
+
transition: all 100ms ${token.motionEaseOut};
|
|
14
|
+
border-radius: ${token.borderRadius}px;
|
|
15
|
+
|
|
16
|
+
${hover}
|
|
17
|
+
`);
|
|
18
|
+
|
|
19
|
+
return {
|
|
20
|
+
active: css`
|
|
21
|
+
color: ${token.colorText};
|
|
22
|
+
`,
|
|
23
|
+
container: css`
|
|
24
|
+
cursor: pointer;
|
|
25
|
+
color: ${token.colorTextDescription};
|
|
26
|
+
`,
|
|
27
|
+
img,
|
|
28
|
+
imgActive: css`
|
|
29
|
+
box-shadow: 0 0 0 2px ${token.colorTextTertiary};
|
|
20
30
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
box-shadow: 0 0 0 2px ${token.colorText};
|
|
31
|
+
.${img} {
|
|
32
|
+
box-shadow: none;
|
|
24
33
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
34
|
+
`,
|
|
35
|
+
imgCtn: css`
|
|
36
|
+
background: ${token.colorFillTertiary};
|
|
37
|
+
border-radius: ${token.borderRadius}px;
|
|
38
|
+
|
|
39
|
+
${hover}
|
|
40
|
+
`,
|
|
41
|
+
};
|
|
42
|
+
});
|
|
@@ -35,13 +35,7 @@ const AgentConfig = memo<AgentConfigProps>(({ config, updateConfig }) => {
|
|
|
35
35
|
{
|
|
36
36
|
children: (
|
|
37
37
|
<SelectWithImg
|
|
38
|
-
|
|
39
|
-
background: `linear-gradient(
|
|
40
|
-
to bottom,
|
|
41
|
-
${isDarkMode ? theme.colorBgElevated : theme.colorBgLayout},
|
|
42
|
-
${theme.colorBgContainer}
|
|
43
|
-
)`,
|
|
44
|
-
}}
|
|
38
|
+
height={86}
|
|
45
39
|
options={[
|
|
46
40
|
{
|
|
47
41
|
icon: MessagesSquare,
|
|
@@ -56,7 +50,16 @@ const AgentConfig = memo<AgentConfigProps>(({ config, updateConfig }) => {
|
|
|
56
50
|
value: 'docs',
|
|
57
51
|
},
|
|
58
52
|
]}
|
|
59
|
-
|
|
53
|
+
styles={{
|
|
54
|
+
img: {
|
|
55
|
+
background: `linear-gradient(
|
|
56
|
+
to bottom,
|
|
57
|
+
${isDarkMode ? theme.colorBgElevated : theme.colorBgLayout},
|
|
58
|
+
${theme.colorBgContainer}
|
|
59
|
+
)`,
|
|
60
|
+
},
|
|
61
|
+
}}
|
|
62
|
+
width={144}
|
|
60
63
|
/>
|
|
61
64
|
),
|
|
62
65
|
label: t('settingChat.chatStyleType.title'),
|
package/src/layout/index.tsx
CHANGED
|
@@ -3,22 +3,26 @@ import { App, ConfigProvider } from 'antd';
|
|
|
3
3
|
import { useThemeMode } from 'antd-style';
|
|
4
4
|
import 'antd/dist/reset.css';
|
|
5
5
|
import Zh_CN from 'antd/locale/zh_CN';
|
|
6
|
+
import { changeLanguage } from 'i18next';
|
|
6
7
|
import { PropsWithChildren, memo, useCallback, useEffect } from 'react';
|
|
7
8
|
|
|
8
|
-
import {
|
|
9
|
+
import { createI18nNext } from '@/locales/create';
|
|
10
|
+
import { useGlobalStore, useOnFinishHydrationGlobal } from '@/store/global';
|
|
9
11
|
import { useSessionStore } from '@/store/session';
|
|
10
12
|
import { GlobalStyle } from '@/styles';
|
|
11
13
|
|
|
12
|
-
import i18n from '../locales';
|
|
13
14
|
import { useStyles } from './style';
|
|
14
15
|
|
|
16
|
+
const i18n = createI18nNext();
|
|
17
|
+
|
|
15
18
|
const Layout = memo<PropsWithChildren>(({ children }) => {
|
|
16
19
|
const { styles } = useStyles();
|
|
17
20
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
useOnFinishHydrationGlobal((state) => {
|
|
22
|
+
i18n.then(() => {
|
|
23
|
+
changeLanguage(state.settings.language);
|
|
24
|
+
});
|
|
25
|
+
});
|
|
22
26
|
|
|
23
27
|
return (
|
|
24
28
|
<ConfigProvider locale={Zh_CN}>
|
package/src/locales/create.ts
CHANGED
|
@@ -7,12 +7,13 @@ import type { Namespaces } from '@/types/locale';
|
|
|
7
7
|
|
|
8
8
|
import resources from './resources';
|
|
9
9
|
|
|
10
|
-
export const createI18nNext = (namespace?: Namespaces[] | Namespaces) => {
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
: ['error', 'common'];
|
|
10
|
+
export const createI18nNext = (params: { namespace?: Namespaces[] | Namespaces } = {}) => {
|
|
11
|
+
const { namespace } = params;
|
|
12
|
+
|
|
13
|
+
const ns: Namespaces[] = isArray(namespace)
|
|
14
|
+
? ['error', 'common', ...namespace]
|
|
15
|
+
: (['error', 'common', namespace].filter(Boolean) as Namespaces[]);
|
|
16
|
+
|
|
16
17
|
return (
|
|
17
18
|
i18n
|
|
18
19
|
// detect user language
|
|
@@ -23,9 +24,12 @@ export const createI18nNext = (namespace?: Namespaces[] | Namespaces) => {
|
|
|
23
24
|
// init i18next
|
|
24
25
|
// for all options read: https://www.i18next.com/overview/configuration-options
|
|
25
26
|
.init({
|
|
26
|
-
// @ts-ignore
|
|
27
27
|
debug: process.env.NODE_ENV === 'development',
|
|
28
28
|
defaultNS: ns,
|
|
29
|
+
// LanguageDetector config, refs: https://github.com/i18next/i18next-browser-languageDetector
|
|
30
|
+
detection: {
|
|
31
|
+
caches: [],
|
|
32
|
+
},
|
|
29
33
|
fallbackLng: 'zh-CN',
|
|
30
34
|
interpolation: {
|
|
31
35
|
escapeValue: false, // not needed for react as it escapes by default
|
|
@@ -1,3 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
import common from '../../../locales/en_US/common.json';
|
|
2
|
+
import empty from '../../../locales/en_US/empty.json';
|
|
3
|
+
import error from '../../../locales/en_US/error.json';
|
|
4
|
+
import plugin from '../../../locales/en_US/plugin.json';
|
|
5
|
+
import setting from '../../../locales/en_US/setting.json';
|
|
6
|
+
|
|
7
|
+
const resources = {
|
|
8
|
+
common,
|
|
9
|
+
empty,
|
|
10
|
+
error,
|
|
11
|
+
plugin,
|
|
12
|
+
setting,
|
|
13
|
+
} as const;
|
|
2
14
|
|
|
3
15
|
export default resources;
|
|
@@ -79,6 +79,7 @@ const Common = memo(() => {
|
|
|
79
79
|
children: (
|
|
80
80
|
<SelectWithImg
|
|
81
81
|
defaultValue={settings.themeMode}
|
|
82
|
+
height={60}
|
|
82
83
|
onChange={setThemeMode}
|
|
83
84
|
options={[
|
|
84
85
|
{
|
|
@@ -100,6 +101,7 @@ const Common = memo(() => {
|
|
|
100
101
|
value: 'auto',
|
|
101
102
|
},
|
|
102
103
|
]}
|
|
104
|
+
width={100}
|
|
103
105
|
/>
|
|
104
106
|
),
|
|
105
107
|
label: t('settingTheme.themeMode.title'),
|
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
import Head from 'next/head';
|
|
2
|
-
import { ReactNode, memo
|
|
2
|
+
import { ReactNode, memo } from 'react';
|
|
3
3
|
import { useTranslation } from 'react-i18next';
|
|
4
4
|
import { Flexbox } from 'react-layout-kit';
|
|
5
5
|
|
|
6
6
|
import SideBar from '@/features/SideBar';
|
|
7
7
|
import { createI18nNext } from '@/locales/create';
|
|
8
|
-
import { useSwitchSideBarOnInit } from '@/store/global';
|
|
8
|
+
import { useOnFinishHydrationGlobal, useSwitchSideBarOnInit } from '@/store/global';
|
|
9
9
|
import { genSiteHeadTitle } from '@/utils/genSiteHeadTitle';
|
|
10
10
|
|
|
11
|
-
const initI18n = createI18nNext('setting');
|
|
11
|
+
const initI18n = createI18nNext({ namespace: 'setting' });
|
|
12
12
|
|
|
13
13
|
const SettingLayout = memo<{ children: ReactNode }>(({ children }) => {
|
|
14
14
|
const { t } = useTranslation('setting');
|
|
15
15
|
const pageTitle = genSiteHeadTitle(t('header.global'));
|
|
16
16
|
|
|
17
|
-
useEffect(() => {
|
|
18
|
-
initI18n.finally();
|
|
19
|
-
}, []);
|
|
20
|
-
|
|
21
17
|
useSwitchSideBarOnInit('settings');
|
|
22
18
|
|
|
19
|
+
useOnFinishHydrationGlobal(() => {
|
|
20
|
+
initI18n.then(() => {});
|
|
21
|
+
});
|
|
22
|
+
|
|
23
23
|
return (
|
|
24
24
|
<>
|
|
25
25
|
<Head>
|
|
@@ -2,7 +2,7 @@ import { useEffect, useState } from 'react';
|
|
|
2
2
|
|
|
3
3
|
import { useGlobalStore } from '../store';
|
|
4
4
|
|
|
5
|
-
export const
|
|
5
|
+
export const useGlobalHydrated = () => {
|
|
6
6
|
// 根据 sessions 是否有值来判断是否已经初始化
|
|
7
7
|
const hasInited = !!Object.values(useGlobalStore.getState().settings).length;
|
|
8
8
|
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { useEffect } from 'react';
|
|
2
2
|
|
|
3
|
-
import { useGlobalStore } from '../store';
|
|
3
|
+
import { GlobalStore, useGlobalStore } from '../store';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* 当 Session 水合完毕后才会执行的 useEffect
|
|
7
7
|
* @param fn
|
|
8
8
|
* @param deps
|
|
9
9
|
*/
|
|
10
|
-
export const useOnFinishHydrationGlobal = (fn: () => void, deps: any[] = []) => {
|
|
10
|
+
export const useOnFinishHydrationGlobal = (fn: (state: GlobalStore) => void, deps: any[] = []) => {
|
|
11
11
|
useEffect(() => {
|
|
12
12
|
const hasRehydrated = useGlobalStore.persist.hasHydrated();
|
|
13
13
|
// 只有当水合完毕后再开始做操作
|
|
14
14
|
if (!hasRehydrated) return;
|
|
15
15
|
|
|
16
|
-
fn();
|
|
16
|
+
fn(useGlobalStore.getState());
|
|
17
17
|
}, deps);
|
|
18
18
|
};
|