@ray-js/t-agent-ui-ray 0.1.0-beta-4 → 0.1.0-beta-5
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 +30 -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,7 @@ 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 { useChatAgent } from '.';
|
|
8
|
+
import { useChatAgent, useTranslate } from '.';
|
|
10
9
|
|
|
11
10
|
/**
|
|
12
11
|
* 预定义动作类型
|
|
@@ -34,9 +33,7 @@ export function useLongPress() {
|
|
|
34
33
|
}
|
|
35
34
|
});
|
|
36
35
|
const agent = useChatAgent();
|
|
37
|
-
const
|
|
38
|
-
i18nTranslate: t
|
|
39
|
-
} = useRenderOptions();
|
|
36
|
+
const t = useTranslate();
|
|
40
37
|
const [screenSize, setScreenSize] = useState({
|
|
41
38
|
width: 0,
|
|
42
39
|
height: 0
|
|
@@ -124,11 +121,20 @@ export function useLongPress() {
|
|
|
124
121
|
menuItems.push({
|
|
125
122
|
key: 'like',
|
|
126
123
|
label: t('t-agent.message.action.like'),
|
|
127
|
-
action: () => {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
124
|
+
action: async () => {
|
|
125
|
+
const {
|
|
126
|
+
feedback
|
|
127
|
+
} = agent.plugins.assistant;
|
|
128
|
+
if (typeof feedback === 'function') {
|
|
129
|
+
await feedback({
|
|
130
|
+
requestId: message.id,
|
|
131
|
+
type: 'like'
|
|
132
|
+
});
|
|
133
|
+
ty.showToast({
|
|
134
|
+
title: t('t-agent.message.like.success'),
|
|
135
|
+
icon: 'none'
|
|
136
|
+
});
|
|
137
|
+
}
|
|
132
138
|
}
|
|
133
139
|
});
|
|
134
140
|
break;
|
|
@@ -136,11 +142,20 @@ export function useLongPress() {
|
|
|
136
142
|
menuItems.push({
|
|
137
143
|
key: 'unlike',
|
|
138
144
|
label: t('t-agent.message.action.unlike'),
|
|
139
|
-
action: () => {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
145
|
+
action: async () => {
|
|
146
|
+
const {
|
|
147
|
+
feedback
|
|
148
|
+
} = agent.plugins.assistant;
|
|
149
|
+
if (typeof feedback === 'function') {
|
|
150
|
+
await feedback({
|
|
151
|
+
requestId: message.id,
|
|
152
|
+
type: 'unlike'
|
|
153
|
+
});
|
|
154
|
+
ty.showToast({
|
|
155
|
+
title: t('t-agent.message.unlike.success'),
|
|
156
|
+
icon: 'none'
|
|
157
|
+
});
|
|
158
|
+
}
|
|
144
159
|
}
|
|
145
160
|
});
|
|
146
161
|
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
|
+
};
|