@agentscope-ai/chat 1.1.45-beta.1766388936317 → 1.1.45-beta.1766392979633
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/components/ChatAnywhere/Input/UploadPopover.tsx +42 -0
- package/components/ChatAnywhere/Input/index.tsx +23 -15
- package/lib/ChatAnywhere/Input/UploadPopover.d.ts +4 -0
- package/lib/ChatAnywhere/Input/UploadPopover.js +51 -0
- package/lib/ChatAnywhere/Input/index.js +29 -18
- package/package.json +1 -1
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { IconButton, Popover } from "@agentscope-ai/design";
|
|
2
|
+
import { PlusOutlined } from "@ant-design/icons";
|
|
3
|
+
import { useGetState } from "ahooks";
|
|
4
|
+
import { Flex } from "antd";
|
|
5
|
+
import React from "react";
|
|
6
|
+
import { useEffect, useState } from "react";
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
export default function UploadPopover({
|
|
11
|
+
nodes
|
|
12
|
+
}: {
|
|
13
|
+
nodes: React.ReactElement[];
|
|
14
|
+
}) {
|
|
15
|
+
const [visible, setVisible, getVisible] = useGetState(false);
|
|
16
|
+
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
const close = () => {
|
|
19
|
+
if (getVisible()) {
|
|
20
|
+
setVisible(false);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
document.addEventListener('click', close, true);
|
|
25
|
+
return () => {
|
|
26
|
+
document.removeEventListener('click', close, true);
|
|
27
|
+
}
|
|
28
|
+
}, []);
|
|
29
|
+
|
|
30
|
+
return <Popover
|
|
31
|
+
placement='bottomLeft'
|
|
32
|
+
open={visible}
|
|
33
|
+
onOpenChange={setVisible}
|
|
34
|
+
content={<Flex vertical>
|
|
35
|
+
{nodes}
|
|
36
|
+
</Flex>} trigger="click" styles={{ body: { padding: 4 } }}>
|
|
37
|
+
<IconButton
|
|
38
|
+
icon={<PlusOutlined />}
|
|
39
|
+
bordered={false}
|
|
40
|
+
/>
|
|
41
|
+
</Popover>
|
|
42
|
+
}
|
|
@@ -4,11 +4,11 @@ import { useProviderContext, ChatInput, uuid, Sender, Attachments } from '@agent
|
|
|
4
4
|
import cls from 'classnames';
|
|
5
5
|
import { useChatAnywhere } from '../hooks/ChatAnywhereProvider';
|
|
6
6
|
import { useInput } from '../hooks/useInput';
|
|
7
|
-
import {
|
|
7
|
+
import { GetProp, Space, Upload } from 'antd';
|
|
8
8
|
import Style from './style';
|
|
9
|
-
import { IconButton } from '@agentscope-ai/design';
|
|
9
|
+
import { IconButton, Button } from '@agentscope-ai/design';
|
|
10
10
|
import { AIGC } from '@agentscope-ai/chat';
|
|
11
|
-
import
|
|
11
|
+
import UploadPopover from './UploadPopover';
|
|
12
12
|
|
|
13
13
|
type AttachedFiles = GetProp<typeof Attachments, 'items'>;
|
|
14
14
|
|
|
@@ -91,6 +91,23 @@ export default forwardRef(function (_, ref) {
|
|
|
91
91
|
return [];
|
|
92
92
|
}
|
|
93
93
|
const nodes = onUpload.map((item, index) => {
|
|
94
|
+
|
|
95
|
+
let trigger;
|
|
96
|
+
|
|
97
|
+
if (item.trigger) {
|
|
98
|
+
trigger = item.trigger;
|
|
99
|
+
} else if (item.title || item.description) {
|
|
100
|
+
trigger = <Button type='text' icon={item.icon} >
|
|
101
|
+
{item.title && <span>{item.title}</span>}
|
|
102
|
+
{item.description && <span style={{ fontSize: '0.8em', opacity: 0.8 }}>{item.description}</span>}
|
|
103
|
+
</Button>
|
|
104
|
+
} else {
|
|
105
|
+
trigger = <IconButton
|
|
106
|
+
icon={item.icon}
|
|
107
|
+
bordered={false}
|
|
108
|
+
/>
|
|
109
|
+
}
|
|
110
|
+
|
|
94
111
|
return <Upload
|
|
95
112
|
{...item}
|
|
96
113
|
fileList={attachedFiles[index]}
|
|
@@ -107,23 +124,14 @@ export default forwardRef(function (_, ref) {
|
|
|
107
124
|
showUploadList={false}
|
|
108
125
|
>
|
|
109
126
|
{
|
|
110
|
-
|
|
111
|
-
icon={item.icon}
|
|
112
|
-
bordered={false}
|
|
113
|
-
/>
|
|
127
|
+
trigger
|
|
114
128
|
}
|
|
115
129
|
</Upload>
|
|
116
130
|
});
|
|
117
131
|
|
|
118
132
|
if (nodes.length === 1) return nodes;
|
|
119
|
-
return <
|
|
120
|
-
|
|
121
|
-
</Flex>} trigger="click">
|
|
122
|
-
<IconButton
|
|
123
|
-
icon={<PlusOutlined />}
|
|
124
|
-
bordered={false}
|
|
125
|
-
/>
|
|
126
|
-
</Popover>
|
|
133
|
+
return <UploadPopover nodes={nodes} />
|
|
134
|
+
|
|
127
135
|
|
|
128
136
|
|
|
129
137
|
}, [onInput.variant, onUpload, attachedFiles]);
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
3
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
4
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
5
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
6
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
7
|
+
import { IconButton, Popover } from "@agentscope-ai/design";
|
|
8
|
+
import { PlusOutlined } from "@agentscope-ai/icons-override-antd";
|
|
9
|
+
import { useGetState } from "ahooks";
|
|
10
|
+
import { Flex } from "antd";
|
|
11
|
+
import React from "react";
|
|
12
|
+
import { useEffect } from "react";
|
|
13
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
|
+
export default function UploadPopover(_ref) {
|
|
15
|
+
var nodes = _ref.nodes;
|
|
16
|
+
var _useGetState = useGetState(false),
|
|
17
|
+
_useGetState2 = _slicedToArray(_useGetState, 3),
|
|
18
|
+
visible = _useGetState2[0],
|
|
19
|
+
setVisible = _useGetState2[1],
|
|
20
|
+
getVisible = _useGetState2[2];
|
|
21
|
+
useEffect(function () {
|
|
22
|
+
var close = function close() {
|
|
23
|
+
if (getVisible()) {
|
|
24
|
+
setVisible(false);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
document.addEventListener('click', close, true);
|
|
28
|
+
return function () {
|
|
29
|
+
document.removeEventListener('click', close, true);
|
|
30
|
+
};
|
|
31
|
+
}, []);
|
|
32
|
+
return /*#__PURE__*/_jsx(Popover, {
|
|
33
|
+
placement: "bottomLeft",
|
|
34
|
+
open: visible,
|
|
35
|
+
onOpenChange: setVisible,
|
|
36
|
+
content: /*#__PURE__*/_jsx(Flex, {
|
|
37
|
+
vertical: true,
|
|
38
|
+
children: nodes
|
|
39
|
+
}),
|
|
40
|
+
trigger: "click",
|
|
41
|
+
styles: {
|
|
42
|
+
body: {
|
|
43
|
+
padding: 4
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
children: /*#__PURE__*/_jsx(IconButton, {
|
|
47
|
+
icon: /*#__PURE__*/_jsx(PlusOutlined, {}),
|
|
48
|
+
bordered: false
|
|
49
|
+
})
|
|
50
|
+
});
|
|
51
|
+
}
|
|
@@ -18,20 +18,19 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
|
|
|
18
18
|
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
19
19
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
20
20
|
import React, { forwardRef, useEffect, useMemo, useRef, useState } from 'react';
|
|
21
|
-
import { Flex, Popover } from 'antd';
|
|
22
21
|
import { useProviderContext, ChatInput, Sender, Attachments } from "../..";
|
|
23
22
|
import cls from 'classnames';
|
|
24
23
|
import { useChatAnywhere } from "../hooks/ChatAnywhereProvider";
|
|
25
24
|
import { useInput } from "../hooks/useInput";
|
|
26
25
|
import { Upload } from 'antd';
|
|
27
26
|
import Style from "./style";
|
|
28
|
-
import { IconButton } from '@agentscope-ai/design';
|
|
27
|
+
import { IconButton, Button } from '@agentscope-ai/design';
|
|
29
28
|
import { AIGC } from "../..";
|
|
30
|
-
import
|
|
29
|
+
import UploadPopover from "./UploadPopover";
|
|
31
30
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
31
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
32
32
|
import { createElement as _createElement } from "react";
|
|
33
33
|
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
34
|
-
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
35
34
|
export default /*#__PURE__*/forwardRef(function (_, ref) {
|
|
36
35
|
var _React$useState = React.useState(''),
|
|
37
36
|
_React$useState2 = _slicedToArray(_React$useState, 2),
|
|
@@ -130,6 +129,29 @@ export default /*#__PURE__*/forwardRef(function (_, ref) {
|
|
|
130
129
|
return [];
|
|
131
130
|
}
|
|
132
131
|
var nodes = onUpload.map(function (item, index) {
|
|
132
|
+
var trigger;
|
|
133
|
+
if (item.trigger) {
|
|
134
|
+
trigger = item.trigger;
|
|
135
|
+
} else if (item.title || item.description) {
|
|
136
|
+
trigger = /*#__PURE__*/_jsxs(Button, {
|
|
137
|
+
type: "text",
|
|
138
|
+
icon: item.icon,
|
|
139
|
+
children: [item.title && /*#__PURE__*/_jsx("span", {
|
|
140
|
+
children: item.title
|
|
141
|
+
}), item.description && /*#__PURE__*/_jsx("span", {
|
|
142
|
+
style: {
|
|
143
|
+
fontSize: '0.8em',
|
|
144
|
+
opacity: 0.8
|
|
145
|
+
},
|
|
146
|
+
children: item.description
|
|
147
|
+
})]
|
|
148
|
+
});
|
|
149
|
+
} else {
|
|
150
|
+
trigger = /*#__PURE__*/_jsx(IconButton, {
|
|
151
|
+
icon: item.icon,
|
|
152
|
+
bordered: false
|
|
153
|
+
});
|
|
154
|
+
}
|
|
133
155
|
return /*#__PURE__*/_createElement(Upload, _objectSpread(_objectSpread({}, item), {}, {
|
|
134
156
|
fileList: attachedFiles[index],
|
|
135
157
|
key: index,
|
|
@@ -142,22 +164,11 @@ export default /*#__PURE__*/forwardRef(function (_, ref) {
|
|
|
142
164
|
}
|
|
143
165
|
},
|
|
144
166
|
showUploadList: false
|
|
145
|
-
}),
|
|
146
|
-
icon: item.icon,
|
|
147
|
-
bordered: false
|
|
148
|
-
}));
|
|
167
|
+
}), trigger);
|
|
149
168
|
});
|
|
150
169
|
if (nodes.length === 1) return nodes;
|
|
151
|
-
return /*#__PURE__*/_jsx(
|
|
152
|
-
|
|
153
|
-
vertical: true,
|
|
154
|
-
children: nodes
|
|
155
|
-
}),
|
|
156
|
-
trigger: "click",
|
|
157
|
-
children: /*#__PURE__*/_jsx(IconButton, {
|
|
158
|
-
icon: /*#__PURE__*/_jsx(PlusOutlined, {}),
|
|
159
|
-
bordered: false
|
|
160
|
-
})
|
|
170
|
+
return /*#__PURE__*/_jsx(UploadPopover, {
|
|
171
|
+
nodes: nodes
|
|
161
172
|
});
|
|
162
173
|
}, [onInput.variant, onUpload, attachedFiles]);
|
|
163
174
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentscope-ai/chat",
|
|
3
|
-
"version": "1.1.45-beta.
|
|
3
|
+
"version": "1.1.45-beta.1766392979633",
|
|
4
4
|
"description": "a free and open-source chat framework for building excellent LLM-powered chat experiences",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"sideEffects": [
|