@ray-js/t-agent-ui-ray 0.1.0-beta-4 → 0.1.0-beta-6
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/dist/MessageInput/index.js +2 -4
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/index.js +2 -1
- package/dist/hooks/useLongPress.js +31 -15
- package/dist/hooks/useTranslate.d.ts +2 -0
- package/dist/hooks/useTranslate.js +62 -0
- package/dist/i18n/strings.d.ts +499 -0
- package/dist/i18n/strings.js +498 -0
- package/dist/tiles/BubbleTile/index.js +2 -5
- package/dist/tiles/DividerTile/index.d.ts +8 -0
- package/dist/tiles/DividerTile/index.js +16 -0
- package/dist/tiles/DividerTile/index.less +26 -0
- package/dist/tiles/ExecuteCardTile/index.js +2 -4
- package/dist/tiles/OperateCardTile/Expand.js +2 -4
- package/dist/tiles/OperateCardTile/index.js +2 -4
- package/dist/tiles/map.js +3 -1
- package/package.json +2 -2
|
@@ -13,13 +13,11 @@ import imageSvg from './icons/image.svg';
|
|
|
13
13
|
import videoSvg from './icons/video.svg';
|
|
14
14
|
import loadingSvg from './icons/loading.svg';
|
|
15
15
|
import closeCircleSvg from './icons/close-circle.svg';
|
|
16
|
-
import { useAttachmentInput, useChatAgent, useEmitEvent, useIsUnmounted, useOnEvent, useRenderOptions } from '../hooks';
|
|
16
|
+
import { useAttachmentInput, useChatAgent, useEmitEvent, useIsUnmounted, useOnEvent, useRenderOptions, useTranslate } from '../hooks';
|
|
17
17
|
import AsrInput from './AsrInput';
|
|
18
18
|
export default function MessageInput(props) {
|
|
19
19
|
const [moreOpen, setMoreOpen] = useState(false);
|
|
20
|
-
const
|
|
21
|
-
i18nTranslate: t
|
|
22
|
-
} = useRenderOptions();
|
|
20
|
+
const t = useTranslate();
|
|
23
21
|
const [text, setText] = useState('');
|
|
24
22
|
const [asrText, setAsrText] = useState('');
|
|
25
23
|
const attachmentInput = useAttachmentInput();
|
package/dist/hooks/index.d.ts
CHANGED
package/dist/hooks/index.js
CHANGED
|
@@ -5,8 +5,8 @@ import "core-js/modules/esnext.iterator.map.js";
|
|
|
5
5
|
import "core-js/modules/web.dom-collections.iterator.js";
|
|
6
6
|
import { useState, useEffect, useCallback } from 'react';
|
|
7
7
|
import logger from '../logger';
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
8
|
+
import { useChatAgent } from './context';
|
|
9
|
+
import { useTranslate } from './useTranslate';
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* 预定义动作类型
|
|
@@ -34,9 +34,7 @@ export function useLongPress() {
|
|
|
34
34
|
}
|
|
35
35
|
});
|
|
36
36
|
const agent = useChatAgent();
|
|
37
|
-
const
|
|
38
|
-
i18nTranslate: t
|
|
39
|
-
} = useRenderOptions();
|
|
37
|
+
const t = useTranslate();
|
|
40
38
|
const [screenSize, setScreenSize] = useState({
|
|
41
39
|
width: 0,
|
|
42
40
|
height: 0
|
|
@@ -124,11 +122,20 @@ export function useLongPress() {
|
|
|
124
122
|
menuItems.push({
|
|
125
123
|
key: 'like',
|
|
126
124
|
label: t('t-agent.message.action.like'),
|
|
127
|
-
action: () => {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
125
|
+
action: async () => {
|
|
126
|
+
const {
|
|
127
|
+
feedback
|
|
128
|
+
} = agent.plugins.assistant;
|
|
129
|
+
if (typeof feedback === 'function') {
|
|
130
|
+
await feedback({
|
|
131
|
+
requestId: message.id,
|
|
132
|
+
type: 'like'
|
|
133
|
+
});
|
|
134
|
+
ty.showToast({
|
|
135
|
+
title: t('t-agent.message.like.success'),
|
|
136
|
+
icon: 'none'
|
|
137
|
+
});
|
|
138
|
+
}
|
|
132
139
|
}
|
|
133
140
|
});
|
|
134
141
|
break;
|
|
@@ -136,11 +143,20 @@ export function useLongPress() {
|
|
|
136
143
|
menuItems.push({
|
|
137
144
|
key: 'unlike',
|
|
138
145
|
label: t('t-agent.message.action.unlike'),
|
|
139
|
-
action: () => {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
146
|
+
action: async () => {
|
|
147
|
+
const {
|
|
148
|
+
feedback
|
|
149
|
+
} = agent.plugins.assistant;
|
|
150
|
+
if (typeof feedback === 'function') {
|
|
151
|
+
await feedback({
|
|
152
|
+
requestId: message.id,
|
|
153
|
+
type: 'unlike'
|
|
154
|
+
});
|
|
155
|
+
ty.showToast({
|
|
156
|
+
title: t('t-agent.message.unlike.success'),
|
|
157
|
+
icon: 'none'
|
|
158
|
+
});
|
|
159
|
+
}
|
|
144
160
|
}
|
|
145
161
|
});
|
|
146
162
|
break;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import "core-js/modules/es.regexp.exec.js";
|
|
2
|
+
import "core-js/modules/web.dom-collections.iterator.js";
|
|
3
|
+
import { useRenderOptions } from './context';
|
|
4
|
+
import { useCallback } from 'react';
|
|
5
|
+
import strings from '../i18n/strings';
|
|
6
|
+
const keyRE = /^t-agent\./;
|
|
7
|
+
const langRE = {
|
|
8
|
+
'zh-Hans': /^zh([-_](hans|cn|zh))/i,
|
|
9
|
+
'zh-Hant': /^zh([-_](hant|tw|hk|mo))/i,
|
|
10
|
+
en: /^en([-_](us|gb))/i,
|
|
11
|
+
ja: /^ja([-_](jp))/i,
|
|
12
|
+
de: /^de([-_](de))/i,
|
|
13
|
+
fr: /^fr([-_](fr))/i,
|
|
14
|
+
es: /^es([-_](es))/i,
|
|
15
|
+
it: /^it([-_](it))/i
|
|
16
|
+
};
|
|
17
|
+
const keys = Object.keys(langRE);
|
|
18
|
+
const cache = new Map();
|
|
19
|
+
const normalizeLanguage = lang => {
|
|
20
|
+
if (langRE[lang]) {
|
|
21
|
+
return lang;
|
|
22
|
+
}
|
|
23
|
+
if (cache.has(lang)) {
|
|
24
|
+
return cache.get(lang);
|
|
25
|
+
}
|
|
26
|
+
for (const key of keys) {
|
|
27
|
+
if (langRE[key].test(lang)) {
|
|
28
|
+
cache.set(lang, key);
|
|
29
|
+
return key;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
cache.set(lang, 'en');
|
|
33
|
+
// 默认返回英文
|
|
34
|
+
return 'en';
|
|
35
|
+
};
|
|
36
|
+
const translateCache = new Map();
|
|
37
|
+
export const translateWith = (key, i18nTranslate) => {
|
|
38
|
+
if (translateCache.has(key)) {
|
|
39
|
+
return translateCache.get(key);
|
|
40
|
+
}
|
|
41
|
+
const result = i18nTranslate(key);
|
|
42
|
+
// result 全等于 key 说明没有翻译,使用内置翻译
|
|
43
|
+
if (result === key && keyRE.test(key)) {
|
|
44
|
+
var _strings$language;
|
|
45
|
+
let {
|
|
46
|
+
language
|
|
47
|
+
} = ty.getSystemInfoSync();
|
|
48
|
+
language = normalizeLanguage(language);
|
|
49
|
+
if ((_strings$language = strings[language]) !== null && _strings$language !== void 0 && _strings$language[key]) {
|
|
50
|
+
translateCache.set(key, strings[language][key]);
|
|
51
|
+
return strings[language][key];
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
translateCache.set(key, result);
|
|
55
|
+
return result;
|
|
56
|
+
};
|
|
57
|
+
export const useTranslate = () => {
|
|
58
|
+
const {
|
|
59
|
+
i18nTranslate
|
|
60
|
+
} = useRenderOptions();
|
|
61
|
+
return useCallback(key => translateWith(key, i18nTranslate), [i18nTranslate]);
|
|
62
|
+
};
|