@ray-js/t-agent-ui-ray 0.2.2-beta-2 → 0.2.3-beta-1
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/ChatContainer/index.js +1 -9
- package/dist/EchartsBlockRender/index.js +8 -10
- package/dist/LazyScrollView/LazyItem/index.d.ts +18 -0
- package/dist/LazyScrollView/LazyItem/index.js +51 -0
- package/dist/LazyScrollView/LazyItem/index.json +3 -0
- package/dist/LazyScrollView/LazyItem/index.tyml +16 -0
- package/dist/LazyScrollView/index.d.ts +26 -0
- package/dist/LazyScrollView/index.js +27 -0
- package/dist/LazyScrollView/index.json +3 -0
- package/dist/LazyScrollView/index.tyml +15 -0
- package/dist/LazyScrollView/lazy-scroll-view.sjs +317 -0
- package/dist/LazyScrollView/weak-ref.sjs +45 -0
- package/dist/MessageInput/MessageInputAIStream/AsrInput.js +2 -2
- package/dist/MessageInput/MessageInputAIStream/Waveform/index.d.ts +9 -0
- package/dist/MessageInput/MessageInputAIStream/Waveform/index.js +52 -0
- package/dist/MessageInput/MessageInputAIStream/Waveform/index.json +3 -0
- package/dist/MessageInput/MessageInputAIStream/Waveform/index.tyml +9 -0
- package/dist/MessageInput/MessageInputAIStream/index.d.ts +1 -0
- package/dist/MessageInput/MessageInputAIStream/index.js +2 -4
- package/dist/MessageList/ScrollBottomView.d.ts +20 -20
- package/dist/MessageList/ScrollBottomView.js +59 -138
- package/dist/MessageList/index.d.ts +5 -8
- package/dist/MessageList/index.js +89 -11
- package/dist/MessageList/index.less +1 -2
- package/dist/MessageRender/index.d.ts +6 -1
- package/dist/MessageRender/index.js +49 -17
- package/dist/MessageRender/index.less +4 -3
- package/dist/TileRender/index.d.ts +2 -1
- package/dist/TileRender/index.js +3 -3
- package/dist/contexts.d.ts +1 -5
- package/dist/hooks/context.d.ts +0 -2
- package/dist/hooks/context.js +0 -6
- package/dist/tiles/BubbleTile/index.js +2 -1
- package/dist/tiles/CardTile/index.less +1 -1
- package/dist/tiles/ExecuteCardTile/index.js +2 -1
- package/dist/tiles/OperateCardTile/Expand.d.ts +2 -1
- package/dist/tiles/OperateCardTile/Expand.js +4 -2
- package/dist/tiles/OperateCardTile/index.js +5 -6
- package/dist/utils/object.d.ts +8 -0
- package/dist/utils/object.js +57 -0
- package/package.json +2 -2
- package/dist/MessageInput/MessageInputAIStream/WaveformVisualizer.d.ts +0 -4
- package/dist/MessageInput/MessageInputAIStream/WaveformVisualizer.js +0 -54
- package/dist/MessageList/LazyView.d.ts +0 -9
- package/dist/MessageList/LazyView.js +0 -57
|
@@ -5,14 +5,23 @@ import "core-js/modules/web.dom-collections.iterator.js";
|
|
|
5
5
|
import './index.less';
|
|
6
6
|
import { View } from '@ray-js/components';
|
|
7
7
|
import React, { useState } from 'react';
|
|
8
|
+
import { ChatMessageStatus } from '@ray-js/t-agent';
|
|
8
9
|
import TileRender from '../TileRender';
|
|
9
10
|
import { useChatAgent, useOnEvent } from '../hooks';
|
|
11
|
+
import LazyItem from '../LazyScrollView/LazyItem/index.js';
|
|
12
|
+
import { objectsId } from '../utils/object';
|
|
13
|
+
import { useStableCallback } from '../hooks/useStableCallback';
|
|
10
14
|
export default function MessageRender(_ref) {
|
|
11
15
|
let {
|
|
12
16
|
message,
|
|
13
17
|
isLatestMessage,
|
|
14
18
|
side,
|
|
15
|
-
showSelect
|
|
19
|
+
showSelect,
|
|
20
|
+
notifyHeightChanged,
|
|
21
|
+
scrollViewId = '',
|
|
22
|
+
index,
|
|
23
|
+
onShowChange,
|
|
24
|
+
show = true
|
|
16
25
|
} = _ref;
|
|
17
26
|
const {
|
|
18
27
|
id,
|
|
@@ -32,36 +41,59 @@ export default function MessageRender(_ref) {
|
|
|
32
41
|
setIsSelected(!!(value !== null && value !== void 0 && value.includes(id)));
|
|
33
42
|
}
|
|
34
43
|
});
|
|
44
|
+
const [_tick, setTick] = useState(() => "".concat(Math.random()));
|
|
45
|
+
const _notifyHeightChanged = useStableCallback(() => {
|
|
46
|
+
notifyHeightChanged();
|
|
47
|
+
setTick("".concat(Math.random()));
|
|
48
|
+
});
|
|
49
|
+
const tick = objectsId(message, _tick);
|
|
35
50
|
if (tiles.length === 0) {
|
|
36
|
-
return /*#__PURE__*/React.createElement(
|
|
51
|
+
return /*#__PURE__*/React.createElement(LazyItem, {
|
|
52
|
+
scrollViewId: scrollViewId,
|
|
53
|
+
itemId: id,
|
|
37
54
|
key: id,
|
|
55
|
+
update: tick,
|
|
56
|
+
index: index,
|
|
57
|
+
ready: message.status === ChatMessageStatus.FINISH,
|
|
38
58
|
className: "t-agent-message-list-row-empty t-agent-message-list-row-".concat(side)
|
|
39
59
|
});
|
|
40
60
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
onClick: () => {
|
|
45
|
-
if (showSelect) {
|
|
46
|
-
const prev = agent.session.get("UIRay.multiSelect.selected") || [];
|
|
47
|
-
isSelected ? agent.session.set("UIRay.multiSelect.selected", prev.filter(i => i !== id)) : agent.session.set("UIRay.multiSelect.selected", [...prev, id]);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}, showSelect && /*#__PURE__*/React.createElement(View, {
|
|
51
|
-
className: "t-agent-message-list-row-check"
|
|
61
|
+
const children = [showSelect ? /*#__PURE__*/React.createElement(View, {
|
|
62
|
+
className: "t-agent-message-list-row-check",
|
|
63
|
+
key: "checkbox"
|
|
52
64
|
}, /*#__PURE__*/React.createElement(View, {
|
|
53
65
|
className: "t-agent-message-list-checkbox-container ".concat(isSelected ? 't-agent-message-list-checkbox-selected' : '')
|
|
54
66
|
}, /*#__PURE__*/React.createElement(View, {
|
|
55
67
|
className: "t-agent-message-list-checkbox-check"
|
|
56
|
-
}))), /*#__PURE__*/React.createElement(View, {
|
|
57
|
-
className: "t-agent-message-list-row t-agent-message-list-row-".concat(side)
|
|
68
|
+
}))) : null, /*#__PURE__*/React.createElement(View, {
|
|
69
|
+
className: "t-agent-message-list-row t-agent-message-list-row-".concat(side),
|
|
70
|
+
key: "tiles"
|
|
58
71
|
}, tiles.map(tile => {
|
|
59
72
|
return /*#__PURE__*/React.createElement(TileRender, {
|
|
60
73
|
tile: tile,
|
|
61
74
|
message: message,
|
|
62
75
|
side: side,
|
|
63
76
|
key: tile.id,
|
|
64
|
-
isLatestMessage: isLatestMessage
|
|
77
|
+
isLatestMessage: isLatestMessage,
|
|
78
|
+
notifyHeightChanged: _notifyHeightChanged
|
|
65
79
|
});
|
|
66
|
-
}))
|
|
80
|
+
}))];
|
|
81
|
+
return /*#__PURE__*/React.createElement(LazyItem, {
|
|
82
|
+
key: id,
|
|
83
|
+
itemId: id,
|
|
84
|
+
index: index,
|
|
85
|
+
className: "t-agent-message-list-row-container",
|
|
86
|
+
update: tick,
|
|
87
|
+
scrollViewId: scrollViewId,
|
|
88
|
+
bindshow: event => {
|
|
89
|
+
onShowChange === null || onShowChange === void 0 || onShowChange(event.detail.show);
|
|
90
|
+
},
|
|
91
|
+
ready: message.status === ChatMessageStatus.FINISH,
|
|
92
|
+
bindclick: () => {
|
|
93
|
+
if (showSelect) {
|
|
94
|
+
const prev = agent.session.get("UIRay.multiSelect.selected") || [];
|
|
95
|
+
isSelected ? agent.session.set("UIRay.multiSelect.selected", prev.filter(i => i !== id)) : agent.session.set("UIRay.multiSelect.selected", [...prev, id]);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}, show && children);
|
|
67
99
|
}
|
|
@@ -5,16 +5,17 @@
|
|
|
5
5
|
.t-agent-message-list-row-check {
|
|
6
6
|
display: flex;
|
|
7
7
|
align-items: flex-end;
|
|
8
|
-
|
|
8
|
+
padding-bottom: calc(var(--t-agent-y-gap) + 24rpx);
|
|
9
9
|
margin-right: 28rpx;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
.t-agent-message-list-row {
|
|
13
|
-
|
|
13
|
+
padding-bottom: var(--t-agent-y-gap);
|
|
14
14
|
display: flex;
|
|
15
15
|
flex-direction: column;
|
|
16
|
-
flex: 1
|
|
16
|
+
flex: 1;
|
|
17
17
|
width: 100%;
|
|
18
|
+
min-width: 0;
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
.t-agent-message-list-row-start {
|
|
@@ -6,6 +6,7 @@ interface Props {
|
|
|
6
6
|
message: ChatMessageObject;
|
|
7
7
|
side: 'start' | 'end' | string;
|
|
8
8
|
isLatestMessage?: boolean;
|
|
9
|
+
notifyHeightChanged: () => void;
|
|
9
10
|
}
|
|
10
|
-
declare const _default: React.MemoExoticComponent<({ tile, message, isLatestMessage, side }: Props) => React.JSX.Element>;
|
|
11
|
+
declare const _default: React.MemoExoticComponent<({ tile, message, isLatestMessage, side, notifyHeightChanged }: Props) => React.JSX.Element>;
|
|
11
12
|
export default _default;
|
package/dist/TileRender/index.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import './index.less';
|
|
2
2
|
import React, { useCallback, useMemo } from 'react';
|
|
3
|
-
import { useChatAgent,
|
|
3
|
+
import { useChatAgent, useRenderOptions } from '../hooks';
|
|
4
4
|
import { TilePropsContext } from '../contexts';
|
|
5
5
|
const TileRender = _ref => {
|
|
6
6
|
let {
|
|
7
7
|
tile,
|
|
8
8
|
message,
|
|
9
9
|
isLatestMessage,
|
|
10
|
-
side
|
|
10
|
+
side,
|
|
11
|
+
notifyHeightChanged
|
|
11
12
|
} = _ref;
|
|
12
13
|
const agent = useChatAgent();
|
|
13
14
|
const emitTileEvent = useCallback(async payload => agent.emitTileEvent(tile.id, payload), [agent, tile.id]);
|
|
14
|
-
const notifyHeightChanged = useNotifyHeightChanged();
|
|
15
15
|
const {
|
|
16
16
|
renderTileAs
|
|
17
17
|
} = useRenderOptions();
|
package/dist/contexts.d.ts
CHANGED
|
@@ -13,15 +13,11 @@ declare const SharedProvider: ({ value, children }: import("react").PropsWithChi
|
|
|
13
13
|
messages: ChatMessageObject[];
|
|
14
14
|
keyboardHeight: number;
|
|
15
15
|
renderOptions: RenderOptions;
|
|
16
|
-
notifyHeightChanged: () => void;
|
|
17
|
-
tickValue: number;
|
|
18
16
|
};
|
|
19
|
-
}>) => import("react").JSX.Element, useSharedState: <K extends "agent" | "messages" | "keyboardHeight" | "renderOptions"
|
|
17
|
+
}>) => import("react").JSX.Element, useSharedState: <K extends "agent" | "messages" | "keyboardHeight" | "renderOptions">(key: K) => {
|
|
20
18
|
agent: UIChatAgent;
|
|
21
19
|
messages: ChatMessageObject[];
|
|
22
20
|
keyboardHeight: number;
|
|
23
21
|
renderOptions: RenderOptions;
|
|
24
|
-
notifyHeightChanged: () => void;
|
|
25
|
-
tickValue: number;
|
|
26
22
|
}[K];
|
|
27
23
|
export { SharedProvider, useSharedState };
|
package/dist/hooks/context.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { Dispatch, SetStateAction } from 'react';
|
|
2
2
|
import { TTTAction } from '../types';
|
|
3
3
|
export declare const useChatAgent: () => import("../contexts").UIChatAgent;
|
|
4
|
-
export declare const useTick: () => number;
|
|
5
|
-
export declare const useNotifyHeightChanged: () => () => void;
|
|
6
4
|
export declare const useAgentMessage: () => import("@ray-js/t-agent").ChatMessageObject[];
|
|
7
5
|
export declare const useRenderOptions: () => import("../types").RenderOptions;
|
|
8
6
|
export declare const useKeyboardHeight: () => number;
|
package/dist/hooks/context.js
CHANGED
|
@@ -4,12 +4,6 @@ import { TilePropsContext, useSharedState } from '../contexts';
|
|
|
4
4
|
export const useChatAgent = () => {
|
|
5
5
|
return useSharedState('agent');
|
|
6
6
|
};
|
|
7
|
-
export const useTick = () => {
|
|
8
|
-
return useSharedState('tickValue');
|
|
9
|
-
};
|
|
10
|
-
export const useNotifyHeightChanged = () => {
|
|
11
|
-
return useSharedState('notifyHeightChanged');
|
|
12
|
-
};
|
|
13
7
|
export const useAgentMessage = () => {
|
|
14
8
|
return useSharedState('messages');
|
|
15
9
|
};
|
|
@@ -113,7 +113,8 @@ const BubbleTile = props => {
|
|
|
113
113
|
tile: t,
|
|
114
114
|
message: message,
|
|
115
115
|
key: t.id,
|
|
116
|
-
isLatestMessage: isLatestMessage
|
|
116
|
+
isLatestMessage: isLatestMessage,
|
|
117
|
+
notifyHeightChanged: props.notifyHeightChanged
|
|
117
118
|
}));
|
|
118
119
|
})(), /*#__PURE__*/React.createElement(LoadingIndicator, {
|
|
119
120
|
status: status
|
|
@@ -161,9 +161,10 @@ export default function ExecuteCardTile(props) {
|
|
|
161
161
|
return /*#__PURE__*/React.createElement(View, {
|
|
162
162
|
className: "t-agent-execute-card-tile"
|
|
163
163
|
}, cards.map(card => {
|
|
164
|
+
const key = "".concat(card.displayType, "-").concat(card.deviceId || card.sceneId);
|
|
164
165
|
return /*#__PURE__*/React.createElement(View, {
|
|
165
166
|
className: "t-agent-execute-card-tile-card",
|
|
166
|
-
key:
|
|
167
|
+
key: key
|
|
167
168
|
}, card.displayType === 'device' && /*#__PURE__*/React.createElement(View, {
|
|
168
169
|
className: "t-agent-execute-card-tile-device",
|
|
169
170
|
onClick: () => handleTap(card)
|
|
@@ -18,6 +18,7 @@ interface ExpandProps {
|
|
|
18
18
|
operations?: IOperations;
|
|
19
19
|
tapDevice?: (e: any) => void;
|
|
20
20
|
tapScene?: (e: any) => void;
|
|
21
|
+
onChangeTab?: (key: string) => void;
|
|
21
22
|
}
|
|
22
|
-
export default function Expand({ operations, tapDevice, tapScene, }: ExpandProps): React.JSX.Element;
|
|
23
|
+
export default function Expand({ operations, tapDevice, tapScene, onChangeTab, }: ExpandProps): React.JSX.Element;
|
|
23
24
|
export {};
|
|
@@ -30,7 +30,8 @@ export default function Expand(_ref) {
|
|
|
30
30
|
more: []
|
|
31
31
|
},
|
|
32
32
|
tapDevice,
|
|
33
|
-
tapScene
|
|
33
|
+
tapScene,
|
|
34
|
+
onChangeTab
|
|
34
35
|
} = _ref;
|
|
35
36
|
const t = useTranslate();
|
|
36
37
|
const deviceCount = (((_operations$device = operations.device) === null || _operations$device === void 0 ? void 0 : _operations$device.length) || 0) + (((_operations$moreDevic = operations.moreDevice) === null || _operations$moreDevic === void 0 ? void 0 : _operations$moreDevic.length) || 0);
|
|
@@ -170,7 +171,8 @@ export default function Expand(_ref) {
|
|
|
170
171
|
className: "t-agent-expand-container"
|
|
171
172
|
}, tabs.length > 0 ? /*#__PURE__*/React.createElement(Tabs, {
|
|
172
173
|
tabs: tabs,
|
|
173
|
-
defaultActiveKey: tabs[0].key
|
|
174
|
+
defaultActiveKey: tabs[0].key,
|
|
175
|
+
onChange: onChangeTab
|
|
174
176
|
}) : /*#__PURE__*/React.createElement(View, {
|
|
175
177
|
className: "t-agent-expand-empty"
|
|
176
178
|
}, /*#__PURE__*/React.createElement(Text, null, t('t-agent.expand.no.details'))));
|
|
@@ -5,7 +5,7 @@ import "core-js/modules/web.dom-collections.iterator.js";
|
|
|
5
5
|
import { Text, View } from '@ray-js/components';
|
|
6
6
|
import React, { useMemo, useState } from 'react';
|
|
7
7
|
import './index.less';
|
|
8
|
-
import {
|
|
8
|
+
import { useTranslate } from '../../hooks';
|
|
9
9
|
import Expand from './Expand';
|
|
10
10
|
import { formatMessage } from '../../utils';
|
|
11
11
|
const handleDesc = (detail, t) => {
|
|
@@ -74,7 +74,8 @@ const handleDesc = (detail, t) => {
|
|
|
74
74
|
export default function OperateCardTile(props) {
|
|
75
75
|
const {
|
|
76
76
|
tile,
|
|
77
|
-
renderDetail
|
|
77
|
+
renderDetail,
|
|
78
|
+
notifyHeightChanged
|
|
78
79
|
} = props;
|
|
79
80
|
const {
|
|
80
81
|
deviceInfo = [],
|
|
@@ -195,9 +196,6 @@ export default function OperateCardTile(props) {
|
|
|
195
196
|
};
|
|
196
197
|
}, [deviceInfo, sceneInfo, changeInfo, t]);
|
|
197
198
|
const desc = useMemo(() => handleDesc(operations, t), [operations, t]);
|
|
198
|
-
const {
|
|
199
|
-
notifyHeightChanged
|
|
200
|
-
} = useTileProps();
|
|
201
199
|
if (!operations.device.length && !operations.scene.length && !operations.moreDevice.length && !operations.moreScene.length) {
|
|
202
200
|
return null;
|
|
203
201
|
}
|
|
@@ -219,6 +217,7 @@ export default function OperateCardTile(props) {
|
|
|
219
217
|
}), showDetail && !renderDetail && /*#__PURE__*/React.createElement(Expand, {
|
|
220
218
|
operations: operations,
|
|
221
219
|
tapDevice: tapDevice,
|
|
222
|
-
tapScene: tapScene
|
|
220
|
+
tapScene: tapScene,
|
|
221
|
+
onChangeTab: () => notifyHeightChanged()
|
|
223
222
|
}));
|
|
224
223
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const objectsId: (...objects: any[]) => string;
|
|
2
|
+
export interface Resolvable<T = void> {
|
|
3
|
+
resolve: (value?: T) => void;
|
|
4
|
+
reject: (reason?: any) => void;
|
|
5
|
+
promise: Promise<T>;
|
|
6
|
+
state: 'pending' | 'fulfilled' | 'rejected';
|
|
7
|
+
}
|
|
8
|
+
export declare const createResolvable: <T = void>() => Resolvable<T>;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import "core-js/modules/esnext.iterator.constructor.js";
|
|
2
|
+
import "core-js/modules/esnext.iterator.map.js";
|
|
3
|
+
import "core-js/modules/web.dom-collections.iterator.js";
|
|
4
|
+
import { generateId } from '@ray-js/t-agent';
|
|
5
|
+
const wm = new WeakMap();
|
|
6
|
+
export const objectsId = function () {
|
|
7
|
+
for (var _len = arguments.length, objects = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
8
|
+
objects[_key] = arguments[_key];
|
|
9
|
+
}
|
|
10
|
+
if (objects.length === 0) {
|
|
11
|
+
return '0@';
|
|
12
|
+
}
|
|
13
|
+
const keys = objects.map((v, i) => {
|
|
14
|
+
if (v === null) {
|
|
15
|
+
return "".concat(i, "-null");
|
|
16
|
+
}
|
|
17
|
+
if (v === undefined) {
|
|
18
|
+
return "".concat(i, "-undefined");
|
|
19
|
+
}
|
|
20
|
+
const type = typeof v;
|
|
21
|
+
if (type === 'object' || type === 'function') {
|
|
22
|
+
if (wm.has(v)) {
|
|
23
|
+
return wm.get(v);
|
|
24
|
+
}
|
|
25
|
+
const id = generateId(16);
|
|
26
|
+
wm.set(v, id);
|
|
27
|
+
return "".concat(i, "-").concat(id);
|
|
28
|
+
}
|
|
29
|
+
return "".concat(i, "-").concat(v);
|
|
30
|
+
});
|
|
31
|
+
return "".concat(objects.length, "@").concat(keys.join('|'));
|
|
32
|
+
};
|
|
33
|
+
export const createResolvable = () => {
|
|
34
|
+
const ret = {
|
|
35
|
+
resolve: null,
|
|
36
|
+
reject: null,
|
|
37
|
+
promise: null,
|
|
38
|
+
state: 'pending'
|
|
39
|
+
};
|
|
40
|
+
ret.promise = new Promise((resolve, reject) => {
|
|
41
|
+
ret.resolve = value => {
|
|
42
|
+
if (ret.state !== 'pending') {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
ret.state = 'fulfilled';
|
|
46
|
+
resolve(value);
|
|
47
|
+
};
|
|
48
|
+
ret.reject = reason => {
|
|
49
|
+
if (ret.state !== 'pending') {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
ret.state = 'rejected';
|
|
53
|
+
reject(reason);
|
|
54
|
+
};
|
|
55
|
+
});
|
|
56
|
+
return ret;
|
|
57
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ray-js/t-agent-ui-ray",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3-beta-1",
|
|
4
4
|
"author": "Tuya.inc",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"private": false,
|
|
@@ -40,5 +40,5 @@
|
|
|
40
40
|
"@types/echarts": "^4.9.22",
|
|
41
41
|
"@types/markdown-it": "^14.1.1"
|
|
42
42
|
},
|
|
43
|
-
"gitHead": "
|
|
43
|
+
"gitHead": "ed9810075246e1261af2fdaa41550070313a98dc"
|
|
44
44
|
}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import "core-js/modules/esnext.iterator.constructor.js";
|
|
2
|
-
import "core-js/modules/esnext.iterator.map.js";
|
|
3
|
-
import "core-js/modules/web.dom-collections.iterator.js";
|
|
4
|
-
import React, { useEffect, useState } from 'react';
|
|
5
|
-
import { View } from '@ray-js/ray';
|
|
6
|
-
export const WaveformVisualizer = /*#__PURE__*/React.memo(_ref => {
|
|
7
|
-
let {
|
|
8
|
-
amplitudeCount
|
|
9
|
-
} = _ref;
|
|
10
|
-
const [bars, setBars] = useState(() => Array.from({
|
|
11
|
-
length: amplitudeCount
|
|
12
|
-
}, (_, index) => /*#__PURE__*/React.createElement(View
|
|
13
|
-
// eslint-disable-next-line react/no-array-index-key
|
|
14
|
-
, {
|
|
15
|
-
key: "asr_wave_".concat(index),
|
|
16
|
-
className: "t-agent-message-input-waveform-bar",
|
|
17
|
-
style: {
|
|
18
|
-
height: 0,
|
|
19
|
-
// 添加渐变色偏移效果
|
|
20
|
-
animationDelay: "".concat(index * 10, "ms")
|
|
21
|
-
}
|
|
22
|
-
})));
|
|
23
|
-
useEffect(() => {
|
|
24
|
-
const handle = _ref2 => {
|
|
25
|
-
let {
|
|
26
|
-
amplitudes
|
|
27
|
-
} = _ref2;
|
|
28
|
-
const bars = (amplitudes || []).map((item, index) => {
|
|
29
|
-
const value = item > 1 ? 1 : item * 100;
|
|
30
|
-
// 将数值映射到高度范围(0-100 → 2px-20px)
|
|
31
|
-
// const height = 2 + (value / 100) * 18;
|
|
32
|
-
return /*#__PURE__*/React.createElement(View
|
|
33
|
-
// eslint-disable-next-line react/no-array-index-key
|
|
34
|
-
, {
|
|
35
|
-
key: "asr_wave_".concat(index),
|
|
36
|
-
className: "t-agent-message-input-waveform-bar",
|
|
37
|
-
style: {
|
|
38
|
-
height: "".concat(value, "%"),
|
|
39
|
-
// 添加渐变色偏移效果
|
|
40
|
-
animationDelay: "".concat(index * 10, "ms")
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
setBars(bars);
|
|
45
|
-
};
|
|
46
|
-
ty.aistream.onRecordAmplitudes(handle);
|
|
47
|
-
return () => {
|
|
48
|
-
ty.aistream.offRecordAmplitudes(handle);
|
|
49
|
-
};
|
|
50
|
-
}, []);
|
|
51
|
-
return /*#__PURE__*/React.createElement(View, {
|
|
52
|
-
className: "t-agent-message-input-waveform-container"
|
|
53
|
-
}, bars);
|
|
54
|
-
});
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import "core-js/modules/es.regexp.exec.js";
|
|
2
|
-
import "core-js/modules/web.dom-collections.iterator.js";
|
|
3
|
-
import { View } from '@ray-js/components';
|
|
4
|
-
import React, { useEffect, useRef, useState } from 'react';
|
|
5
|
-
import { usePageInstance } from '@ray-js/ray';
|
|
6
|
-
const queryHeight = id => {
|
|
7
|
-
return new Promise(resolve => {
|
|
8
|
-
// @ts-ignore
|
|
9
|
-
const query = ty.createSelectorQuery();
|
|
10
|
-
query.select("#".concat(id)).boundingClientRect(res => {
|
|
11
|
-
resolve(res.height);
|
|
12
|
-
}).exec();
|
|
13
|
-
});
|
|
14
|
-
};
|
|
15
|
-
export default function LazyView(props) {
|
|
16
|
-
const {
|
|
17
|
-
id,
|
|
18
|
-
className,
|
|
19
|
-
children,
|
|
20
|
-
containerId
|
|
21
|
-
} = props;
|
|
22
|
-
const [visible, setVisible] = useState(true);
|
|
23
|
-
const heightRef = useRef(0);
|
|
24
|
-
const valid = heightRef.current > 0;
|
|
25
|
-
console.log();
|
|
26
|
-
const page = usePageInstance();
|
|
27
|
-
useEffect(() => {
|
|
28
|
-
// @ts-ignore
|
|
29
|
-
const observer = ty.createIntersectionObserver(page, {
|
|
30
|
-
thresholds: [0, 1],
|
|
31
|
-
initialRatio: 0
|
|
32
|
-
});
|
|
33
|
-
observer.relativeTo("#".concat(containerId), {
|
|
34
|
-
top: 50,
|
|
35
|
-
bottom: 50
|
|
36
|
-
}).observe("#".concat(id), res => {
|
|
37
|
-
setVisible(res.intersectionRatio > 0);
|
|
38
|
-
console.log(id, res);
|
|
39
|
-
});
|
|
40
|
-
return () => {
|
|
41
|
-
observer.disconnect();
|
|
42
|
-
};
|
|
43
|
-
}, [id, containerId]);
|
|
44
|
-
useEffect(() => {
|
|
45
|
-
queryHeight(id).then(height => {
|
|
46
|
-
console.log('queryHeight', id, height);
|
|
47
|
-
heightRef.current = height;
|
|
48
|
-
});
|
|
49
|
-
}, [id]);
|
|
50
|
-
console.log('rerender', id);
|
|
51
|
-
return /*#__PURE__*/React.createElement(View, {
|
|
52
|
-
className: className,
|
|
53
|
-
"data-hide": !visible && valid,
|
|
54
|
-
id: id
|
|
55
|
-
// style={hide ? { visibility: 'hidden' } : null}
|
|
56
|
-
}, children);
|
|
57
|
-
}
|