@ray-js/t-agent-ui-ray 0.2.1-beta.2 → 0.2.2-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.d.ts +2 -1
- package/dist/ChatContainer/index.js +53 -48
- package/dist/EchartsBlockRender/index.js +6 -4
- package/dist/EchartsBlockRender/index.rjs +35 -9
- package/dist/MessageInput/MessageInputAIStream/WaveformVisualizer.d.ts +2 -2
- package/dist/MessageInput/MessageInputAIStream/WaveformVisualizer.js +30 -23
- package/dist/MessageInput/MessageInputAIStream/index.d.ts +8 -0
- package/dist/MessageInput/MessageInputAIStream/index.js +52 -41
- package/dist/MessageInput/index.d.ts +2 -1
- package/dist/MessageInput/index.js +2 -1
- package/dist/MessageList/LazyView.d.ts +9 -0
- package/dist/MessageList/LazyView.js +57 -0
- package/dist/MessageList/ScrollBottomView.d.ts +46 -0
- package/dist/MessageList/ScrollBottomView.js +202 -0
- package/dist/MessageList/index.d.ts +4 -2
- package/dist/MessageList/index.js +23 -87
- package/dist/MessageList/index.less +15 -4
- package/dist/TileRender/index.js +5 -3
- package/dist/contexts.d.ts +18 -6
- package/dist/contexts.js +5 -17
- package/dist/hooks/context.d.ts +4 -4
- package/dist/hooks/context.js +13 -4
- package/dist/hooks/useStableCallback.d.ts +1 -0
- package/dist/hooks/useStableCallback.js +13 -0
- package/dist/tiles/BubbleTile/index.js +4 -4
- package/dist/tiles/OperateCardTile/index.js +5 -1
- package/dist/types.d.ts +1 -0
- package/dist/utils/createSharedStore.d.ts +4 -0
- package/dist/utils/createSharedStore.js +64 -0
- package/package.json +2 -2
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import "core-js/modules/es.regexp.exec.js";
|
|
3
|
+
import "core-js/modules/web.dom-collections.iterator.js";
|
|
4
|
+
import React, { useCallback, useEffect, useRef, useState, forwardRef, useImperativeHandle } from 'react';
|
|
5
|
+
import { useSleep } from '../hooks/useSleep';
|
|
6
|
+
import { generateId } from '@ray-js/t-agent';
|
|
7
|
+
import { useOnEvent, useTick } from '../hooks';
|
|
8
|
+
import { ScrollView } from '@ray-js/ray';
|
|
9
|
+
import { View } from '@ray-js/components';
|
|
10
|
+
export function useScrollBottomView(params) {
|
|
11
|
+
const [scrollViewId] = useState(() => "ScrollView-".concat(generateId()));
|
|
12
|
+
const contentViewId = "".concat(scrollViewId, "-content");
|
|
13
|
+
const tickValue = useTick();
|
|
14
|
+
const [ready, setReady] = useState(false);
|
|
15
|
+
const [scrollIntoViewFlag, setScrollIntoViewIdFlag] = useState(() => "".concat(Date.now()));
|
|
16
|
+
const [scrollWithAnimation, setScrollWithAnimation] = useState(false);
|
|
17
|
+
const ref = useRef({
|
|
18
|
+
clientHeight: 0,
|
|
19
|
+
needFollow: true,
|
|
20
|
+
following: false,
|
|
21
|
+
lastScrollEvent: null,
|
|
22
|
+
startTimestamp: 0
|
|
23
|
+
});
|
|
24
|
+
const sleep = useSleep();
|
|
25
|
+
const makeScrollBottomEvent = useCallback(() => {
|
|
26
|
+
if (ref.current.lastScrollEvent) {
|
|
27
|
+
const {
|
|
28
|
+
detail,
|
|
29
|
+
currentTarget,
|
|
30
|
+
target
|
|
31
|
+
} = ref.current.lastScrollEvent;
|
|
32
|
+
const {
|
|
33
|
+
scrollTop,
|
|
34
|
+
scrollHeight
|
|
35
|
+
} = detail;
|
|
36
|
+
const newDetail = {
|
|
37
|
+
deltaX: 0,
|
|
38
|
+
scrollLeft: 0,
|
|
39
|
+
scrollTop: scrollHeight - ref.current.clientHeight,
|
|
40
|
+
scrollWidth: detail.scrollWidth,
|
|
41
|
+
scrollHeight,
|
|
42
|
+
deltaY: scrollTop - (scrollHeight - ref.current.clientHeight)
|
|
43
|
+
};
|
|
44
|
+
if (scrollTop === newDetail.scrollTop) {
|
|
45
|
+
// 如果滚动位置没有变化,则不触发事件
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
type: 'scroll',
|
|
50
|
+
timeStamp: Date.now() - ref.current.startTimestamp,
|
|
51
|
+
currentTarget,
|
|
52
|
+
target,
|
|
53
|
+
stopPropagation: () => {},
|
|
54
|
+
detail: newDetail
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
return null;
|
|
58
|
+
}, []);
|
|
59
|
+
const scrollToBottom = useCallback(_ref => {
|
|
60
|
+
let {
|
|
61
|
+
animation,
|
|
62
|
+
follow
|
|
63
|
+
} = _ref;
|
|
64
|
+
if (follow) {
|
|
65
|
+
if (ref.current.needFollow) {
|
|
66
|
+
setScrollIntoViewIdFlag("".concat(Date.now()));
|
|
67
|
+
ref.current.needFollow = true;
|
|
68
|
+
const event = makeScrollBottomEvent();
|
|
69
|
+
if (event) {
|
|
70
|
+
sleep(10).then(() => {
|
|
71
|
+
var _params$onScroll;
|
|
72
|
+
params === null || params === void 0 || (_params$onScroll = params.onScroll) === null || _params$onScroll === void 0 || _params$onScroll.call(params, event);
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
} else {
|
|
77
|
+
if (animation) {
|
|
78
|
+
setScrollWithAnimation(true);
|
|
79
|
+
}
|
|
80
|
+
ref.current.needFollow = true;
|
|
81
|
+
setScrollIntoViewIdFlag("".concat(Date.now()));
|
|
82
|
+
const event = makeScrollBottomEvent();
|
|
83
|
+
if (event) {
|
|
84
|
+
sleep(100).then(() => {
|
|
85
|
+
var _params$onScroll2;
|
|
86
|
+
params === null || params === void 0 || (_params$onScroll2 = params.onScroll) === null || _params$onScroll2 === void 0 || _params$onScroll2.call(params, event);
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
if (animation) {
|
|
90
|
+
sleep(10).then(() => {
|
|
91
|
+
setScrollWithAnimation(false);
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}, []);
|
|
96
|
+
useEffect(() => {
|
|
97
|
+
const getDomTick = () => {
|
|
98
|
+
return new Promise(resolve => {
|
|
99
|
+
// @ts-ignore
|
|
100
|
+
const query = ty.createSelectorQuery();
|
|
101
|
+
query.select("#".concat(scrollViewId)).fields({
|
|
102
|
+
dataset: true
|
|
103
|
+
}, res => {
|
|
104
|
+
resolve(res.dataset.renderTick);
|
|
105
|
+
}).exec();
|
|
106
|
+
});
|
|
107
|
+
};
|
|
108
|
+
const getClientHeight = () => {
|
|
109
|
+
return new Promise(resolve => {
|
|
110
|
+
// @ts-ignore
|
|
111
|
+
const query = ty.createSelectorQuery();
|
|
112
|
+
query.select("#".concat(scrollViewId)).fields({
|
|
113
|
+
size: true
|
|
114
|
+
}, res => {
|
|
115
|
+
resolve(res.height);
|
|
116
|
+
}).exec();
|
|
117
|
+
});
|
|
118
|
+
};
|
|
119
|
+
const scrollViewInterval = setInterval(() => {
|
|
120
|
+
// 外部容器高度变化不频繁,1 秒查一次
|
|
121
|
+
getClientHeight().then(height => {
|
|
122
|
+
ref.current.clientHeight = height;
|
|
123
|
+
});
|
|
124
|
+
}, 1000);
|
|
125
|
+
|
|
126
|
+
// 初始化好 clientHeight
|
|
127
|
+
(async () => {
|
|
128
|
+
let tick = await getDomTick();
|
|
129
|
+
while (tick <= 0) {
|
|
130
|
+
await sleep(1);
|
|
131
|
+
tick = await getDomTick();
|
|
132
|
+
}
|
|
133
|
+
return tick;
|
|
134
|
+
})().then(() => getClientHeight()).then(height => {
|
|
135
|
+
console.log('scrollView clientHeight', height);
|
|
136
|
+
ref.current.clientHeight = height;
|
|
137
|
+
})
|
|
138
|
+
// 渲染完毕后,开始滚动到最底部
|
|
139
|
+
.then(() => scrollToBottom({}))
|
|
140
|
+
// 展示列表
|
|
141
|
+
.then(() => setReady(true));
|
|
142
|
+
return () => {
|
|
143
|
+
clearInterval(scrollViewInterval);
|
|
144
|
+
};
|
|
145
|
+
}, [scrollViewId]);
|
|
146
|
+
let scrollIntoViewId = "".concat(scrollViewId, "-toView-").concat(tickValue, "-").concat(scrollIntoViewFlag);
|
|
147
|
+
if (!ref.current.needFollow) {
|
|
148
|
+
scrollIntoViewId = null;
|
|
149
|
+
}
|
|
150
|
+
return {
|
|
151
|
+
scrollToBottom,
|
|
152
|
+
scrollViewLoading: !ready,
|
|
153
|
+
scrollIntoViewId,
|
|
154
|
+
contentViewProps: {
|
|
155
|
+
contentViewId
|
|
156
|
+
},
|
|
157
|
+
scrollViewProps: {
|
|
158
|
+
'data-render-tick': tickValue,
|
|
159
|
+
id: scrollViewId,
|
|
160
|
+
scrollY: true,
|
|
161
|
+
onScroll: event => {
|
|
162
|
+
var _params$onScroll3;
|
|
163
|
+
ref.current.lastScrollEvent = event;
|
|
164
|
+
const {
|
|
165
|
+
scrollTop,
|
|
166
|
+
scrollHeight
|
|
167
|
+
} = event.detail;
|
|
168
|
+
ref.current.needFollow = scrollHeight - scrollTop <= ref.current.clientHeight + 25;
|
|
169
|
+
params === null || params === void 0 || (_params$onScroll3 = params.onScroll) === null || _params$onScroll3 === void 0 || _params$onScroll3.call(params, event);
|
|
170
|
+
if (!ref.current.startTimestamp) {
|
|
171
|
+
ref.current.startTimestamp = Date.now() - event.timeStamp;
|
|
172
|
+
}
|
|
173
|
+
},
|
|
174
|
+
scrollWithAnimation,
|
|
175
|
+
scrollIntoView: scrollIntoViewId
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
const ScrollBottomView = /*#__PURE__*/forwardRef((props, ref) => {
|
|
180
|
+
const {
|
|
181
|
+
scrollToBottom,
|
|
182
|
+
scrollViewProps,
|
|
183
|
+
scrollIntoViewId,
|
|
184
|
+
contentViewProps,
|
|
185
|
+
scrollViewLoading
|
|
186
|
+
} = useScrollBottomView({
|
|
187
|
+
onScroll: props.onScroll
|
|
188
|
+
});
|
|
189
|
+
useOnEvent('scrollToBottom', scrollToBottom);
|
|
190
|
+
useImperativeHandle(ref, () => ({
|
|
191
|
+
scrollToBottom
|
|
192
|
+
}), [scrollToBottom]);
|
|
193
|
+
return /*#__PURE__*/React.createElement(ScrollView, _extends({
|
|
194
|
+
className: "".concat(props.className || '', " ").concat(scrollViewLoading ? 't-agent-message-list-hide' : ''),
|
|
195
|
+
style: props.style
|
|
196
|
+
}, scrollViewProps), /*#__PURE__*/React.createElement(View, _extends({}, contentViewProps, {
|
|
197
|
+
className: "".concat(props.contentClassName || '')
|
|
198
|
+
}), props.children, /*#__PURE__*/React.createElement(View, {
|
|
199
|
+
id: scrollIntoViewId
|
|
200
|
+
})));
|
|
201
|
+
});
|
|
202
|
+
export default /*#__PURE__*/React.memo(ScrollBottomView);
|
|
@@ -6,6 +6,8 @@ interface Props {
|
|
|
6
6
|
wrapperClassName?: string;
|
|
7
7
|
wrapperStyle?: React.CSSProperties;
|
|
8
8
|
renderTop?: React.ReactNode;
|
|
9
|
+
renderBottom?: React.ReactNode;
|
|
10
|
+
onScroll?: (event: any) => void;
|
|
9
11
|
roleSide?: {
|
|
10
12
|
user?: 'start' | 'end' | string;
|
|
11
13
|
assistant?: 'start' | 'end' | string;
|
|
@@ -18,5 +20,5 @@ interface Props {
|
|
|
18
20
|
tipText: string;
|
|
19
21
|
};
|
|
20
22
|
}
|
|
21
|
-
|
|
22
|
-
export
|
|
23
|
+
declare const MessageList: (props: Props) => React.JSX.Element;
|
|
24
|
+
export default MessageList;
|
|
@@ -1,19 +1,14 @@
|
|
|
1
|
-
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
-
import "core-js/modules/es.array.reverse.js";
|
|
3
1
|
import "core-js/modules/esnext.iterator.constructor.js";
|
|
4
2
|
import "core-js/modules/esnext.iterator.map.js";
|
|
5
3
|
import "core-js/modules/web.dom-collections.iterator.js";
|
|
6
4
|
import './index.less';
|
|
7
5
|
import { View } from '@ray-js/components';
|
|
8
|
-
import React
|
|
9
|
-
import { ScrollView } from '@ray-js/ray';
|
|
10
|
-
import { generateId } from '@ray-js/t-agent';
|
|
6
|
+
import React from 'react';
|
|
11
7
|
import MessageRender from '../MessageRender';
|
|
12
|
-
import { useAgentMessage, useAgentSessionValue
|
|
13
|
-
import
|
|
14
|
-
import {
|
|
15
|
-
|
|
16
|
-
export default function MessageList(props) {
|
|
8
|
+
import { useAgentMessage, useAgentSessionValue } from '../hooks';
|
|
9
|
+
import ScrollBottomView from './ScrollBottomView';
|
|
10
|
+
import { useStableCallback } from '../hooks/useStableCallback';
|
|
11
|
+
const MessageList = props => {
|
|
17
12
|
const {
|
|
18
13
|
className,
|
|
19
14
|
roleSide,
|
|
@@ -22,97 +17,38 @@ export default function MessageList(props) {
|
|
|
22
17
|
wrapperStyle,
|
|
23
18
|
historyLimit
|
|
24
19
|
} = props;
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
} = useAgentMessage();
|
|
28
|
-
const [id] = useState(() => "ScrollView-".concat(generateId()));
|
|
29
|
-
const [scrollAnimation, setScrollAnimation] = useState(false);
|
|
30
|
-
// 最大整数位数,用于强制滚动到底部,收到连续 scrollToBottom 时,每 10 毫秒更新一次
|
|
31
|
-
const [scrollTop, setScrollTop] = useState(() => 1000000000000000 + Math.floor(Date.now() / 10));
|
|
32
|
-
const followNewMessageRef = useRef(true);
|
|
33
|
-
const sleep = useSleep();
|
|
20
|
+
const messages = useAgentMessage();
|
|
21
|
+
const onScroll = useStableCallback(props.onScroll);
|
|
34
22
|
const [showSelect] = useAgentSessionValue('UIRay.multiSelect.show');
|
|
35
|
-
const canIUse = useMemo(() => {
|
|
36
|
-
// @ts-ignore
|
|
37
|
-
const {
|
|
38
|
-
containerVersion
|
|
39
|
-
} = systemInfo;
|
|
40
|
-
return {
|
|
41
|
-
// 在 2.27.2 版本之前,pageScrollTo 在某些场景不生效
|
|
42
|
-
scroll: false
|
|
43
|
-
};
|
|
44
|
-
}, []);
|
|
45
|
-
const scroll = useDebouncedFn(animation => {
|
|
46
|
-
// @ts-ignore
|
|
47
|
-
ty.pageScrollTo({
|
|
48
|
-
scrollTop: 0,
|
|
49
|
-
duration: animation ? 100 : 1,
|
|
50
|
-
selector: "#".concat(id)
|
|
51
|
-
});
|
|
52
|
-
}, 100);
|
|
53
|
-
|
|
54
|
-
// 强制滚动到底部
|
|
55
|
-
useOnEvent('scrollToBottom', _ref => {
|
|
56
|
-
let {
|
|
57
|
-
animation,
|
|
58
|
-
follow
|
|
59
|
-
} = _ref;
|
|
60
|
-
// 如果发送的跟随新消息的滚动,判断当前是不是滚动到了底部,如果没有滚动到底部,不执行滚动
|
|
61
|
-
if (follow && !followNewMessageRef.current) {
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
if (canIUse.scroll) {
|
|
65
|
-
scroll(animation);
|
|
66
|
-
} else {
|
|
67
|
-
sleep(100).then(() => {
|
|
68
|
-
setScrollAnimation(!!animation);
|
|
69
|
-
const top = 1000000000000000 + Math.floor(Date.now() / 10);
|
|
70
|
-
if (top !== scrollTop) {
|
|
71
|
-
setScrollTop(top);
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
// 使用翻转列表,让滚动和新消息出现在第一条,这样可以避免滚动到底部时的闪烁
|
|
78
|
-
const reversed = useMemo(() => [...messages].reverse(), [messages]);
|
|
79
|
-
const scrollProps = canIUse.scroll ? {} : {
|
|
80
|
-
scrollWithAnimation: scrollAnimation,
|
|
81
|
-
scrollTop
|
|
82
|
-
};
|
|
83
23
|
return /*#__PURE__*/React.createElement(View, {
|
|
84
24
|
className: "t-agent-message-list ".concat(wrapperClassName || ''),
|
|
85
25
|
"data-testid": "t-agent-message-list",
|
|
86
|
-
style: wrapperStyle
|
|
87
|
-
|
|
26
|
+
style: wrapperStyle,
|
|
27
|
+
id: "message-list"
|
|
28
|
+
}, /*#__PURE__*/React.createElement(ScrollBottomView, {
|
|
88
29
|
className: "".concat(className || '', " t-agent-message-list-scroll"),
|
|
30
|
+
contentClassName: "t-agent-message-list-scroll-content",
|
|
89
31
|
style: style,
|
|
90
|
-
|
|
91
|
-
},
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
// 使用了 flex-direction: column-reverse,所以滚动到顶部时,scrollTop = 0
|
|
97
|
-
followNewMessageRef.current = event.detail.scrollTop > -10;
|
|
98
|
-
}
|
|
99
|
-
}), /*#__PURE__*/React.createElement(View, {
|
|
100
|
-
className: "t-agent-message-list-padding"
|
|
101
|
-
}), reversed.map((msg, index) => {
|
|
32
|
+
onScroll: onScroll
|
|
33
|
+
}, historyLimit && historyLimit.count < messages.length && /*#__PURE__*/React.createElement(View, {
|
|
34
|
+
className: "t-agent-message-list-history-tip"
|
|
35
|
+
}, historyLimit.tipText), /*#__PURE__*/React.createElement(View, {
|
|
36
|
+
className: "t-agent-message-list-padding-start"
|
|
37
|
+
}), props.renderTop, messages.map((msg, index) => {
|
|
102
38
|
let side = roleSide === null || roleSide === void 0 ? void 0 : roleSide[msg.role];
|
|
103
39
|
if (!side) {
|
|
104
40
|
side = msg.role === 'user' ? 'end' : 'start';
|
|
105
41
|
}
|
|
42
|
+
const isLatestMessage = index === messages.length - 1;
|
|
106
43
|
return /*#__PURE__*/React.createElement(MessageRender, {
|
|
107
44
|
showSelect: showSelect,
|
|
108
45
|
key: msg.id,
|
|
109
46
|
message: msg,
|
|
110
|
-
isLatestMessage:
|
|
47
|
+
isLatestMessage: isLatestMessage,
|
|
111
48
|
side: side
|
|
112
49
|
});
|
|
113
|
-
}),
|
|
114
|
-
className: "t-agent-message-list-
|
|
115
|
-
}, historyLimit.tipText), props.renderTop, /*#__PURE__*/React.createElement(View, {
|
|
116
|
-
className: "t-agent-message-list-padding-start"
|
|
50
|
+
}), props.renderBottom, /*#__PURE__*/React.createElement(View, {
|
|
51
|
+
className: "t-agent-message-list-padding"
|
|
117
52
|
})));
|
|
118
|
-
}
|
|
53
|
+
};
|
|
54
|
+
export default MessageList;
|
|
@@ -4,21 +4,32 @@
|
|
|
4
4
|
overflow-x: hidden;
|
|
5
5
|
position: relative;
|
|
6
6
|
background: var(--app-B1);
|
|
7
|
-
padding: 16rpx 32rpx 0;
|
|
8
7
|
}
|
|
9
8
|
|
|
10
9
|
.t-agent-message-list-scroll {
|
|
11
|
-
display: flex;
|
|
12
10
|
width: 100%;
|
|
13
11
|
height: 100%;
|
|
14
|
-
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.t-agent-message-list-scroll-content {
|
|
15
|
+
padding: 0 32rpx;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.t-agent-message-list-block {
|
|
19
|
+
border: 2rpx solid green;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.t-agent-message-list-padding-start {
|
|
23
|
+
height: 16rpx;
|
|
15
24
|
}
|
|
16
25
|
|
|
17
26
|
.t-agent-message-list-padding {
|
|
18
27
|
flex: 1
|
|
19
28
|
}
|
|
20
29
|
|
|
21
|
-
.t-agent-message-list-
|
|
30
|
+
.t-agent-message-list-hide {
|
|
31
|
+
opacity: 0;
|
|
32
|
+
}
|
|
22
33
|
|
|
23
34
|
.t-agent-message-list-history-tip {
|
|
24
35
|
width: 100%;
|
package/dist/TileRender/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import './index.less';
|
|
2
2
|
import React, { useCallback, useMemo } from 'react';
|
|
3
|
-
import { useChatAgent, useRenderOptions } from '../hooks';
|
|
3
|
+
import { useChatAgent, useNotifyHeightChanged, useRenderOptions } from '../hooks';
|
|
4
4
|
import { TilePropsContext } from '../contexts';
|
|
5
5
|
const TileRender = _ref => {
|
|
6
6
|
let {
|
|
@@ -11,6 +11,7 @@ const TileRender = _ref => {
|
|
|
11
11
|
} = _ref;
|
|
12
12
|
const agent = useChatAgent();
|
|
13
13
|
const emitTileEvent = useCallback(async payload => agent.emitTileEvent(tile.id, payload), [agent, tile.id]);
|
|
14
|
+
const notifyHeightChanged = useNotifyHeightChanged();
|
|
14
15
|
const {
|
|
15
16
|
renderTileAs
|
|
16
17
|
} = useRenderOptions();
|
|
@@ -22,9 +23,10 @@ const TileRender = _ref => {
|
|
|
22
23
|
side,
|
|
23
24
|
isLatestMessage,
|
|
24
25
|
emitEvent: emitTileEvent,
|
|
25
|
-
emitTileEvent
|
|
26
|
+
emitTileEvent,
|
|
27
|
+
notifyHeightChanged
|
|
26
28
|
};
|
|
27
|
-
}, [agent, tile, message, side, isLatestMessage, emitTileEvent]);
|
|
29
|
+
}, [agent, tile, message, side, isLatestMessage, emitTileEvent, notifyHeightChanged]);
|
|
28
30
|
const node = renderTileAs(props);
|
|
29
31
|
return /*#__PURE__*/React.createElement(TilePropsContext.Provider, {
|
|
30
32
|
value: props
|
package/dist/contexts.d.ts
CHANGED
|
@@ -2,14 +2,26 @@
|
|
|
2
2
|
import { ChatAgent, ChatMessageObject, UIPlugin } from '@ray-js/t-agent';
|
|
3
3
|
import { RenderOptions, TileProps } from './types';
|
|
4
4
|
import { ChatSession } from '@ray-js/t-agent';
|
|
5
|
-
export declare const MessageContext: import("react").Context<{
|
|
6
|
-
messages: ChatMessageObject[];
|
|
7
|
-
keyboardHeight: number;
|
|
8
|
-
}>;
|
|
9
|
-
export declare const RenderContext: import("react").Context<RenderOptions>;
|
|
10
5
|
export type UIChatSession = Pick<ChatSession, 'get' | 'getData' | 'set' | 'sessionId'>;
|
|
11
6
|
export type UIChatAgent = Pick<ChatAgent<UIPlugin>, 'pushInputBlocks' | 'plugins' | 'emitTileEvent' | 'removeMessage'> & {
|
|
12
7
|
session: UIChatSession;
|
|
13
8
|
};
|
|
14
|
-
export declare const ChatAgentContext: import("react").Context<UIChatAgent>;
|
|
15
9
|
export declare const TilePropsContext: import("react").Context<TileProps<any, any>>;
|
|
10
|
+
declare const SharedProvider: ({ value, children }: import("react").PropsWithChildren<{
|
|
11
|
+
value: {
|
|
12
|
+
agent: UIChatAgent;
|
|
13
|
+
messages: ChatMessageObject[];
|
|
14
|
+
keyboardHeight: number;
|
|
15
|
+
renderOptions: RenderOptions;
|
|
16
|
+
notifyHeightChanged: () => void;
|
|
17
|
+
tickValue: number;
|
|
18
|
+
};
|
|
19
|
+
}>) => import("react").JSX.Element, useSharedState: <K extends "agent" | "messages" | "keyboardHeight" | "renderOptions" | "notifyHeightChanged" | "tickValue">(key: K) => {
|
|
20
|
+
agent: UIChatAgent;
|
|
21
|
+
messages: ChatMessageObject[];
|
|
22
|
+
keyboardHeight: number;
|
|
23
|
+
renderOptions: RenderOptions;
|
|
24
|
+
notifyHeightChanged: () => void;
|
|
25
|
+
tickValue: number;
|
|
26
|
+
}[K];
|
|
27
|
+
export { SharedProvider, useSharedState };
|
package/dist/contexts.js
CHANGED
|
@@ -1,18 +1,6 @@
|
|
|
1
|
+
import "core-js/modules/web.dom-collections.iterator.js";
|
|
1
2
|
import { createContext } from 'react';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
export const RenderContext = /*#__PURE__*/createContext({
|
|
7
|
-
formatErrorMessageAs: message => message,
|
|
8
|
-
renderTileAs: () => null,
|
|
9
|
-
renderCustomBlockAs: () => null,
|
|
10
|
-
renderCardAs: () => null,
|
|
11
|
-
renderLongPressAs: () => null,
|
|
12
|
-
customBlockTypes: [],
|
|
13
|
-
customCardMap: {},
|
|
14
|
-
getStaticResourceBizType: () => '',
|
|
15
|
-
i18nTranslate: key => key
|
|
16
|
-
});
|
|
17
|
-
export const ChatAgentContext = /*#__PURE__*/createContext({});
|
|
18
|
-
export const TilePropsContext = /*#__PURE__*/createContext({});
|
|
3
|
+
import { createSharedStore } from './utils/createSharedStore';
|
|
4
|
+
export const TilePropsContext = /*#__PURE__*/createContext({});
|
|
5
|
+
const [SharedProvider, useSharedState] = createSharedStore();
|
|
6
|
+
export { SharedProvider, useSharedState };
|
package/dist/hooks/context.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
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
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
};
|
|
4
|
+
export declare const useTick: () => number;
|
|
5
|
+
export declare const useNotifyHeightChanged: () => () => void;
|
|
6
|
+
export declare const useAgentMessage: () => import("@ray-js/t-agent").ChatMessageObject[];
|
|
8
7
|
export declare const useRenderOptions: () => import("../types").RenderOptions;
|
|
8
|
+
export declare const useKeyboardHeight: () => number;
|
|
9
9
|
export declare const useOnEvent: (eventName: string, callback: (details: any) => void) => void;
|
|
10
10
|
export declare const useEmitEvent: () => <T extends keyof import("@ray-js/t-agent").UIEventMap>(eventName: T, detail: import("@ray-js/t-agent").UIEventMap[T]) => void;
|
|
11
11
|
export declare const useTileProps: () => import("../types").TileProps<any, any>;
|
package/dist/hooks/context.js
CHANGED
|
@@ -1,14 +1,23 @@
|
|
|
1
1
|
import "core-js/modules/web.dom-collections.iterator.js";
|
|
2
2
|
import { useEffect, useContext, useCallback, useRef, useState } from 'react';
|
|
3
|
-
import { TilePropsContext,
|
|
3
|
+
import { TilePropsContext, useSharedState } from '../contexts';
|
|
4
4
|
export const useChatAgent = () => {
|
|
5
|
-
return
|
|
5
|
+
return useSharedState('agent');
|
|
6
|
+
};
|
|
7
|
+
export const useTick = () => {
|
|
8
|
+
return useSharedState('tickValue');
|
|
9
|
+
};
|
|
10
|
+
export const useNotifyHeightChanged = () => {
|
|
11
|
+
return useSharedState('notifyHeightChanged');
|
|
6
12
|
};
|
|
7
13
|
export const useAgentMessage = () => {
|
|
8
|
-
return
|
|
14
|
+
return useSharedState('messages');
|
|
9
15
|
};
|
|
10
16
|
export const useRenderOptions = () => {
|
|
11
|
-
return
|
|
17
|
+
return useSharedState('renderOptions');
|
|
18
|
+
};
|
|
19
|
+
export const useKeyboardHeight = () => {
|
|
20
|
+
return useSharedState('keyboardHeight');
|
|
12
21
|
};
|
|
13
22
|
export const useOnEvent = (eventName, callback) => {
|
|
14
23
|
const callbackRef = useRef(callback);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useStableCallback: <T extends (...args: any[]) => any>(fn: T) => T;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import "core-js/modules/web.dom-collections.iterator.js";
|
|
2
|
+
import { useCallback, useRef } from 'react';
|
|
3
|
+
export const useStableCallback = fn => {
|
|
4
|
+
const ref = useRef(fn);
|
|
5
|
+
ref.current = fn;
|
|
6
|
+
const cb = useCallback(function () {
|
|
7
|
+
return ref.current(...arguments);
|
|
8
|
+
}, []);
|
|
9
|
+
if (!fn) {
|
|
10
|
+
return fn;
|
|
11
|
+
}
|
|
12
|
+
return cb;
|
|
13
|
+
};
|
|
@@ -108,13 +108,13 @@ const BubbleTile = props => {
|
|
|
108
108
|
}), /*#__PURE__*/React.createElement(View, {
|
|
109
109
|
className: "t-agent-bubble-tile-bubble ".concat(loading ? 't-agent-bubble-tile-bubble-loading' : '')
|
|
110
110
|
}, (() => {
|
|
111
|
-
return
|
|
111
|
+
return children.map(t => /*#__PURE__*/React.createElement(TileRender, {
|
|
112
112
|
side: side,
|
|
113
113
|
tile: t,
|
|
114
114
|
message: message,
|
|
115
115
|
key: t.id,
|
|
116
116
|
isLatestMessage: isLatestMessage
|
|
117
|
-
}))
|
|
117
|
+
}));
|
|
118
118
|
})(), /*#__PURE__*/React.createElement(LoadingIndicator, {
|
|
119
119
|
status: status
|
|
120
120
|
}), showAbortedMessage && /*#__PURE__*/React.createElement(View, {
|
|
@@ -126,7 +126,6 @@ const BubbleTile = props => {
|
|
|
126
126
|
nodeId: workflowNode
|
|
127
127
|
}));
|
|
128
128
|
};
|
|
129
|
-
export default /*#__PURE__*/React.memo(BubbleTile);
|
|
130
129
|
const ErrorNotice = /*#__PURE__*/memo(_ref => {
|
|
131
130
|
let {
|
|
132
131
|
bubbleStatus,
|
|
@@ -172,4 +171,5 @@ const LoadingIndicator = /*#__PURE__*/memo(_ref2 => {
|
|
|
172
171
|
}));
|
|
173
172
|
}
|
|
174
173
|
return null;
|
|
175
|
-
});
|
|
174
|
+
});
|
|
175
|
+
export default /*#__PURE__*/React.memo(BubbleTile);
|
|
@@ -7,7 +7,7 @@ import React, { useMemo, useState } from 'react';
|
|
|
7
7
|
import './index.less';
|
|
8
8
|
// import { ChangeInfoItem, DeviceInfoItem, SceneInfoItem } from '@ray-js/t-agent-plugin-assistant';
|
|
9
9
|
|
|
10
|
-
import { useTranslate } from '../../hooks';
|
|
10
|
+
import { useTileProps, useTranslate } from '../../hooks';
|
|
11
11
|
import Expand from './Expand';
|
|
12
12
|
import { formatMessage } from '../../utils';
|
|
13
13
|
const handleDesc = (detail, t) => {
|
|
@@ -197,6 +197,9 @@ export default function OperateCardTile(props) {
|
|
|
197
197
|
};
|
|
198
198
|
}, [deviceInfo, sceneInfo, changeInfo, t]);
|
|
199
199
|
const desc = useMemo(() => handleDesc(operations, t), [operations, t]);
|
|
200
|
+
const {
|
|
201
|
+
notifyHeightChanged
|
|
202
|
+
} = useTileProps();
|
|
200
203
|
if (!operations.device.length && !operations.scene.length && !operations.moreDevice.length && !operations.moreScene.length) {
|
|
201
204
|
return null;
|
|
202
205
|
}
|
|
@@ -208,6 +211,7 @@ export default function OperateCardTile(props) {
|
|
|
208
211
|
className: "t-agent-scene-control-tile-summary-detail",
|
|
209
212
|
onClick: () => {
|
|
210
213
|
setShowDetail(!showDetail);
|
|
214
|
+
notifyHeightChanged();
|
|
211
215
|
}
|
|
212
216
|
}, showDetail ? t('t-agent.operate-card-tile.hide.details') : t('t-agent.operate-card-tile.view.details'))), renderDetail && renderDetail({
|
|
213
217
|
operations,
|
package/dist/types.d.ts
CHANGED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import React, { PropsWithChildren } from 'react';
|
|
2
|
+
export declare function createSharedStore<T>(): readonly [({ value, children }: React.PropsWithChildren<{
|
|
3
|
+
value: T;
|
|
4
|
+
}>) => React.JSX.Element, <K extends keyof T>(key: K) => T[K], <K_1 extends keyof T>(key: K_1) => [T[K_1], (v: T[K_1]) => void]];
|