@agentscope-ai/chat 1.1.45-beta.1766559291919 → 1.1.45-beta.1766631141555

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.
@@ -1,44 +1,65 @@
1
+ import React, { useMemo, useRef, useState } from "react";
1
2
  import { IconButton, Popover } from "@agentscope-ai/design";
2
3
  import { PlusOutlined } from "@ant-design/icons";
3
- import { useGetState } from "ahooks";
4
+ import { useProviderContext } from "@agentscope-ai/chat";
4
5
  import { Flex, Upload } from "antd";
5
- import React, { useMemo } from "react";
6
- import { useEffect, useState } from "react";
7
6
 
8
7
  export default function UploadPopover({
9
8
  uploadPropsList
10
9
  }: {
11
10
  uploadPropsList: any[];
12
11
  }) {
13
- const [visible, setVisible, getVisible] = useGetState(false);
12
+ const { getPrefixCls } = useProviderContext();
13
+ const prefixCls = getPrefixCls('chat-anywhere-sender');
14
+ const [visible, setVisible] = useState(false);
15
+ const uploadRefs = useRef<Array<HTMLDivElement | null>>([]);
14
16
 
15
- const nodes = useMemo(() => {
17
+ const popoverNodes = useMemo(() => {
16
18
  return uploadPropsList.map((item, index) => {
17
19
  return (
18
- <Upload
20
+ <div
19
21
  key={index}
20
- {...item}
21
- customRequest={(v) => {
22
- if (item.customRequest) {
23
- item.customRequest(v);
24
- }
22
+ onClick={() => {
23
+ // 触发对应Upload组件的children的click事件
24
+ uploadRefs.current[index]?.click();
25
25
  setVisible(false);
26
26
  }}
27
- />
27
+ >
28
+ {item.trigger}
29
+ </div>
30
+ );
31
+ })
32
+ }, [uploadPropsList]);
33
+
34
+ const nodes = useMemo(() => {
35
+ return uploadPropsList.map((item, index) => {
36
+ const { trigger, ...rest } = item;
37
+ return (
38
+ <Upload
39
+ key={index}
40
+ {...rest}
41
+ >
42
+ <div ref={(el) => (uploadRefs.current[index] = el)} />
43
+ </Upload>
28
44
  )
29
45
  });
30
46
  }, [uploadPropsList]);
31
47
 
32
- return <Popover
33
- placement='bottomLeft'
34
- open={visible}
35
- onOpenChange={setVisible}
36
- content={<Flex vertical>
37
- {nodes}
38
- </Flex>} trigger="click" styles={{ body: { padding: 4 } }}>
39
- <IconButton
40
- icon={<PlusOutlined />}
41
- bordered={false}
42
- />
43
- </Popover>
48
+ return (
49
+ <>
50
+ <Popover
51
+ placement='bottomLeft'
52
+ open={visible}
53
+ onOpenChange={setVisible}
54
+ content={<Flex vertical>
55
+ {popoverNodes}
56
+ </Flex>} trigger="click" styles={{ body: { padding: 4 } }}>
57
+ <IconButton
58
+ icon={<PlusOutlined />}
59
+ bordered={false}
60
+ />
61
+ </Popover>
62
+ <div className={`${prefixCls}-upload-hidden-nodes`}>{nodes}</div>
63
+ </>
64
+ )
44
65
  }
@@ -122,12 +122,12 @@ export default forwardRef(function (_, ref) {
122
122
  }
123
123
  },
124
124
  showUploadList: false,
125
- children: trigger,
125
+ trigger,
126
126
  }
127
127
  });
128
128
 
129
129
  if (uploadPropsList.length === 1) return (
130
- <Upload {...uploadPropsList[0]} />
130
+ <Upload {...uploadPropsList[0]}>{uploadPropsList[0].trigger}</Upload>
131
131
  );
132
132
  return <UploadPopover uploadPropsList={uploadPropsList} />
133
133
 
@@ -11,4 +11,14 @@ export default createGlobalStyle`
11
11
  }
12
12
  }
13
13
 
14
+ .${(p) => p.theme.prefixCls}-chat-anywhere-sender-upload-hidden-nodes {
15
+ position: absolute;
16
+ z-index: -999;
17
+ top: -100vh;
18
+ left: -100vw;
19
+ width: 0;
20
+ height: 0;
21
+ overflow: hidden;
22
+ }
23
+ }
14
24
  `;
@@ -1,57 +1,84 @@
1
1
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ var _excluded = ["trigger"];
2
3
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
4
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
5
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
5
6
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
6
7
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
8
+ function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
9
+ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
7
10
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
8
11
  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."); }
9
12
  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); }
10
13
  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; }
11
14
  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; } }
12
15
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
16
+ import React, { useMemo, useRef, useState } from "react";
13
17
  import { IconButton, Popover } from "@agentscope-ai/design";
14
18
  import { PlusOutlined } from "@agentscope-ai/icons-override-antd";
15
- import { useGetState } from "ahooks";
19
+ import { useProviderContext } from "../..";
16
20
  import { Flex, Upload } from "antd";
17
- import React, { useMemo } from "react";
18
21
  import { jsx as _jsx } from "react/jsx-runtime";
22
+ import { Fragment as _Fragment } from "react/jsx-runtime";
23
+ import { jsxs as _jsxs } from "react/jsx-runtime";
19
24
  export default function UploadPopover(_ref) {
20
25
  var uploadPropsList = _ref.uploadPropsList;
21
- var _useGetState = useGetState(false),
22
- _useGetState2 = _slicedToArray(_useGetState, 3),
23
- visible = _useGetState2[0],
24
- setVisible = _useGetState2[1],
25
- getVisible = _useGetState2[2];
26
+ var _useProviderContext = useProviderContext(),
27
+ getPrefixCls = _useProviderContext.getPrefixCls;
28
+ var prefixCls = getPrefixCls('chat-anywhere-sender');
29
+ var _useState = useState(false),
30
+ _useState2 = _slicedToArray(_useState, 2),
31
+ visible = _useState2[0],
32
+ setVisible = _useState2[1];
33
+ var uploadRefs = useRef([]);
34
+ var popoverNodes = useMemo(function () {
35
+ return uploadPropsList.map(function (item, index) {
36
+ return /*#__PURE__*/_jsx("div", {
37
+ onClick: function onClick() {
38
+ var _uploadRefs$current$i;
39
+ // 触发对应Upload组件的children的click事件
40
+ (_uploadRefs$current$i = uploadRefs.current[index]) === null || _uploadRefs$current$i === void 0 || _uploadRefs$current$i.click();
41
+ setVisible(false);
42
+ },
43
+ children: item.trigger
44
+ }, index);
45
+ });
46
+ }, [uploadPropsList]);
26
47
  var nodes = useMemo(function () {
27
48
  return uploadPropsList.map(function (item, index) {
28
- return /*#__PURE__*/_jsx(Upload, _objectSpread(_objectSpread({}, item), {}, {
29
- customRequest: function customRequest(v) {
30
- if (item.customRequest) {
31
- item.customRequest(v);
49
+ var trigger = item.trigger,
50
+ rest = _objectWithoutProperties(item, _excluded);
51
+ return /*#__PURE__*/_jsx(Upload, _objectSpread(_objectSpread({}, rest), {}, {
52
+ children: /*#__PURE__*/_jsx("div", {
53
+ ref: function ref(el) {
54
+ return uploadRefs.current[index] = el;
32
55
  }
33
- setVisible(false);
34
- }
56
+ })
35
57
  }), index);
36
58
  });
37
59
  }, [uploadPropsList]);
38
- return /*#__PURE__*/_jsx(Popover, {
39
- placement: "bottomLeft",
40
- open: visible,
41
- onOpenChange: setVisible,
42
- content: /*#__PURE__*/_jsx(Flex, {
43
- vertical: true,
60
+ return /*#__PURE__*/_jsxs(_Fragment, {
61
+ children: [/*#__PURE__*/_jsx(Popover, {
62
+ placement: "bottomLeft",
63
+ open: visible,
64
+ onOpenChange: setVisible,
65
+ content: /*#__PURE__*/_jsx(Flex, {
66
+ vertical: true,
67
+ children: popoverNodes
68
+ }),
69
+ trigger: "click",
70
+ styles: {
71
+ body: {
72
+ padding: 4
73
+ }
74
+ },
75
+ children: /*#__PURE__*/_jsx(IconButton, {
76
+ icon: /*#__PURE__*/_jsx(PlusOutlined, {}),
77
+ bordered: false
78
+ })
79
+ }), /*#__PURE__*/_jsx("div", {
80
+ className: "".concat(prefixCls, "-upload-hidden-nodes"),
44
81
  children: nodes
45
- }),
46
- trigger: "click",
47
- styles: {
48
- body: {
49
- padding: 4
50
- }
51
- },
52
- children: /*#__PURE__*/_jsx(IconButton, {
53
- icon: /*#__PURE__*/_jsx(PlusOutlined, {}),
54
- bordered: false
55
- })
82
+ })]
56
83
  });
57
84
  }
@@ -163,10 +163,12 @@ export default /*#__PURE__*/forwardRef(function (_, ref) {
163
163
  }
164
164
  },
165
165
  showUploadList: false,
166
- children: trigger
166
+ trigger: trigger
167
167
  });
168
168
  });
169
- if (uploadPropsList.length === 1) return /*#__PURE__*/_jsx(Upload, _objectSpread({}, uploadPropsList[0]));
169
+ if (uploadPropsList.length === 1) return /*#__PURE__*/_jsx(Upload, _objectSpread(_objectSpread({}, uploadPropsList[0]), {}, {
170
+ children: uploadPropsList[0].trigger
171
+ }));
170
172
  return /*#__PURE__*/_jsx(UploadPopover, {
171
173
  uploadPropsList: uploadPropsList
172
174
  });
@@ -1,6 +1,8 @@
1
1
  var _templateObject;
2
2
  function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
3
3
  import { createGlobalStyle } from 'antd-style';
4
- export default createGlobalStyle(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n.", "-chat-anywhere-sender-wrapper {\n position: relative;\n\n &-header {\n display: flex;\n gap: 8px;\n margin-bottom: 12px;\n }\n}\n\n"])), function (p) {
4
+ export default createGlobalStyle(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n.", "-chat-anywhere-sender-wrapper {\n position: relative;\n\n &-header {\n display: flex;\n gap: 8px;\n margin-bottom: 12px;\n }\n}\n\n.", "-chat-anywhere-sender-upload-hidden-nodes {\n position: absolute;\n z-index: -999;\n top: -100vh;\n left: -100vw;\n width: 0;\n height: 0;\n overflow: hidden;\n }\n}\n"])), function (p) {
5
+ return p.theme.prefixCls;
6
+ }, function (p) {
5
7
  return p.theme.prefixCls;
6
8
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentscope-ai/chat",
3
- "version": "1.1.45-beta.1766559291919",
3
+ "version": "1.1.45-beta.1766631141555",
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": [
@@ -58,6 +58,7 @@
58
58
  ]
59
59
  },
60
60
  "dependencies": {
61
+ "dayjs": "^1.11.7",
61
62
  "@agentscope-ai/design": "^1.0.0",
62
63
  "@agentscope-ai/icons": "^1.0.32",
63
64
  "@agentscope-ai/icons-override-antd": "^6.0.0",