@agentscope-ai/chat 1.1.4
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/README.md +88 -0
- package/dist/_util/hooks/use-proxy-imperative-handle.d.ts +4 -0
- package/dist/_util/hooks/use-proxy-imperative-handle.js +18 -0
- package/dist/_util/type.d.ts +1 -0
- package/dist/_util/type.js +1 -0
- package/dist/_util/warning.d.ts +30 -0
- package/dist/_util/warning.js +63 -0
- package/dist/accordion/Accordion.d.ts +22 -0
- package/dist/accordion/Accordion.js +93 -0
- package/dist/accordion/BodyContent.d.ts +8 -0
- package/dist/accordion/BodyContent.js +18 -0
- package/dist/accordion/DeepThink.d.ts +7 -0
- package/dist/accordion/DeepThink.js +35 -0
- package/dist/accordion/index.d.ts +2 -0
- package/dist/accordion/index.js +1 -0
- package/dist/accordion/index.less +170 -0
- package/dist/attachments/DropArea.d.ts +8 -0
- package/dist/attachments/DropArea.js +87 -0
- package/dist/attachments/FileList/AudioIcon.d.ts +2 -0
- package/dist/attachments/FileList/AudioIcon.js +19 -0
- package/dist/attachments/FileList/FileListCard.d.ts +12 -0
- package/dist/attachments/FileList/FileListCard.js +229 -0
- package/dist/attachments/FileList/Progress.d.ts +6 -0
- package/dist/attachments/FileList/Progress.js +21 -0
- package/dist/attachments/FileList/VideoIcon.d.ts +2 -0
- package/dist/attachments/FileList/VideoIcon.js +19 -0
- package/dist/attachments/FileList/index.d.ts +16 -0
- package/dist/attachments/FileList/index.js +132 -0
- package/dist/attachments/PlaceholderUploader.d.ts +17 -0
- package/dist/attachments/PlaceholderUploader.js +79 -0
- package/dist/attachments/SilentUploader.d.ts +9 -0
- package/dist/attachments/SilentUploader.js +23 -0
- package/dist/attachments/context.d.ts +5 -0
- package/dist/attachments/context.js +2 -0
- package/dist/attachments/index.d.ts +33 -0
- package/dist/attachments/index.js +166 -0
- package/dist/attachments/style/fileCard.d.ts +4 -0
- package/dist/attachments/style/fileCard.js +124 -0
- package/dist/attachments/style/index.d.ts +10 -0
- package/dist/attachments/style/index.js +211 -0
- package/dist/attachments/util.d.ts +2 -0
- package/dist/attachments/util.js +53 -0
- package/dist/bubble/Avatar.d.ts +10 -0
- package/dist/bubble/Avatar.js +22 -0
- package/dist/bubble/Bubble.d.ts +11 -0
- package/dist/bubble/Bubble.js +102 -0
- package/dist/bubble/BubbleList.d.ts +15 -0
- package/dist/bubble/BubbleList.js +44 -0
- package/dist/bubble/Cards.d.ts +21 -0
- package/dist/bubble/Cards.js +47 -0
- package/dist/bubble/ScrollToBottom.d.ts +7 -0
- package/dist/bubble/ScrollToBottom.js +45 -0
- package/dist/bubble/Spin.d.ts +2 -0
- package/dist/bubble/Spin.js +18 -0
- package/dist/bubble/hooks/useDisplayData.d.ts +0 -0
- package/dist/bubble/hooks/useDisplayData.js +0 -0
- package/dist/bubble/hooks/useListData.d.ts +0 -0
- package/dist/bubble/hooks/useListData.js +0 -0
- package/dist/bubble/index.d.ts +8 -0
- package/dist/bubble/index.js +4 -0
- package/dist/bubble/interface.d.ts +26 -0
- package/dist/bubble/interface.js +1 -0
- package/dist/bubble/loading.d.ts +6 -0
- package/dist/bubble/loading.js +17 -0
- package/dist/bubble/style/avatar.less +40 -0
- package/dist/bubble/style/content.d.ts +4 -0
- package/dist/bubble/style/content.js +43 -0
- package/dist/bubble/style/index.d.ts +9 -0
- package/dist/bubble/style/index.js +53 -0
- package/dist/bubble/style/list.less +15 -0
- package/dist/bubble/style/scrollToBottom.less +174 -0
- package/dist/chat-anywhere/Chat/Ref.d.ts +3 -0
- package/dist/chat-anywhere/Chat/Ref.js +19 -0
- package/dist/chat-anywhere/Chat/index.d.ts +4 -0
- package/dist/chat-anywhere/Chat/index.js +65 -0
- package/dist/chat-anywhere/Chat/index.less +54 -0
- package/dist/chat-anywhere/Header/index.d.ts +3 -0
- package/dist/chat-anywhere/Header/index.js +32 -0
- package/dist/chat-anywhere/Header/index.less +24 -0
- package/dist/chat-anywhere/Input/index.d.ts +3 -0
- package/dist/chat-anywhere/Input/index.js +170 -0
- package/dist/chat-anywhere/Input/index.less +12 -0
- package/dist/chat-anywhere/Layout/index.d.ts +10 -0
- package/dist/chat-anywhere/Layout/index.js +73 -0
- package/dist/chat-anywhere/Layout/index.less +61 -0
- package/dist/chat-anywhere/SessionList/index.d.ts +5 -0
- package/dist/chat-anywhere/SessionList/index.js +115 -0
- package/dist/chat-anywhere/SessionList/index.less +52 -0
- package/dist/chat-anywhere/hooks/ChatAnywhereProvider.d.ts +43 -0
- package/dist/chat-anywhere/hooks/ChatAnywhereProvider.js +90 -0
- package/dist/chat-anywhere/hooks/types.d.ts +57 -0
- package/dist/chat-anywhere/hooks/types.js +1 -0
- package/dist/chat-anywhere/hooks/useInput.d.ts +7 -0
- package/dist/chat-anywhere/hooks/useInput.js +21 -0
- package/dist/chat-anywhere/hooks/useMessages.d.ts +11 -0
- package/dist/chat-anywhere/hooks/useMessages.js +56 -0
- package/dist/chat-anywhere/hooks/useSessionList.d.ts +24 -0
- package/dist/chat-anywhere/hooks/useSessionList.js +120 -0
- package/dist/chat-anywhere/index.d.ts +9 -0
- package/dist/chat-anywhere/index.js +58 -0
- package/dist/conversations/GroupTitle.d.ts +10 -0
- package/dist/conversations/GroupTitle.js +15 -0
- package/dist/conversations/Item.d.ts +14 -0
- package/dist/conversations/Item.js +96 -0
- package/dist/conversations/hooks/useGroupable.d.ts +9 -0
- package/dist/conversations/hooks/useGroupable.js +72 -0
- package/dist/conversations/index.d.ts +62 -0
- package/dist/conversations/index.js +124 -0
- package/dist/conversations/interface.d.ts +60 -0
- package/dist/conversations/interface.js +1 -0
- package/dist/conversations/style/index.d.ts +9 -0
- package/dist/conversations/style/index.js +80 -0
- package/dist/default-cards/Count/index.d.ts +3 -0
- package/dist/default-cards/Count/index.js +16 -0
- package/dist/default-cards/Count/index.less +19 -0
- package/dist/default-cards/DeepThink/index.d.ts +11 -0
- package/dist/default-cards/DeepThink/index.js +11 -0
- package/dist/default-cards/DeepThink/index.less +0 -0
- package/dist/default-cards/Files/index.d.ts +2 -0
- package/dist/default-cards/Files/index.js +18 -0
- package/dist/default-cards/Footer/index.d.ts +19 -0
- package/dist/default-cards/Footer/index.js +50 -0
- package/dist/default-cards/Footer/index.less +41 -0
- package/dist/default-cards/Images/index.d.ts +3 -0
- package/dist/default-cards/Images/index.js +33 -0
- package/dist/default-cards/Images/index.less +17 -0
- package/dist/default-cards/Interrupted/index.d.ts +11 -0
- package/dist/default-cards/Interrupted/index.js +40 -0
- package/dist/default-cards/Interrupted/index.less +57 -0
- package/dist/default-cards/Text/index.d.ts +2 -0
- package/dist/default-cards/Text/index.js +12 -0
- package/dist/default-cards/index.d.ts +6 -0
- package/dist/default-cards/index.js +6 -0
- package/dist/disclaimer/index.d.ts +11 -0
- package/dist/disclaimer/index.js +26 -0
- package/dist/docs/1896.async.js +457 -0
- package/dist/docs/2710.async.js +62 -0
- package/dist/docs/2863.async.js +400 -0
- package/dist/docs/3057.async.js +46 -0
- package/dist/docs/3364.async.js +25 -0
- package/dist/docs/404.html +15 -0
- package/dist/docs/4820.async.js +1381 -0
- package/dist/docs/5623.async.js +60 -0
- package/dist/docs/5757.async.js +1 -0
- package/dist/docs/5804.async.js +271 -0
- package/dist/docs/6198.async.js +18 -0
- package/dist/docs/6671.async.js +137 -0
- package/dist/docs/7195.async.js +1 -0
- package/dist/docs/7485.async.js +29 -0
- package/dist/docs/7931.async.js +19 -0
- package/dist/docs/7997.async.js +5 -0
- package/dist/docs/8156.async.js +110 -0
- package/dist/docs/8368.async.js +2 -0
- package/dist/docs/8480.async.js +1449 -0
- package/dist/docs/8618.async.js +246 -0
- package/dist/docs/9016.async.js +32 -0
- package/dist/docs/9016.chunk.css +1 -0
- package/dist/docs/9335.async.js +11 -0
- package/dist/docs/accordion__demos.async.js +9 -0
- package/dist/docs/attachments__demos.async.js +1 -0
- package/dist/docs/bubble__demos.async.js +50 -0
- package/dist/docs/components/accordion/index.html +15 -0
- package/dist/docs/components/accordion-cn/index.html +15 -0
- package/dist/docs/components/attachments/index.html +15 -0
- package/dist/docs/components/attachments-cn/index.html +15 -0
- package/dist/docs/components/bubble/index.html +15 -0
- package/dist/docs/components/bubble-cn/index.html +15 -0
- package/dist/docs/components/bubble-list/index.html +15 -0
- package/dist/docs/components/bubble-list-cn/index.html +15 -0
- package/dist/docs/components/conversations/index.html +15 -0
- package/dist/docs/components/conversations-cn/index.html +15 -0
- package/dist/docs/components/disclaimer/index.html +15 -0
- package/dist/docs/components/disclaimer-cn/index.html +15 -0
- package/dist/docs/components/footer/index.html +15 -0
- package/dist/docs/components/footer-cn/index.html +15 -0
- package/dist/docs/components/markdown/index.html +15 -0
- package/dist/docs/components/markdown-cn/index.html +15 -0
- package/dist/docs/components/sender/index.html +15 -0
- package/dist/docs/components/sender-cn/index.html +15 -0
- package/dist/docs/components/status/index.html +15 -0
- package/dist/docs/components/status-cn/index.html +15 -0
- package/dist/docs/components/welcome/index.html +15 -0
- package/dist/docs/components/welcome-cn/index.html +15 -0
- package/dist/docs/components__accordion__index.en-US.md.async.js +6 -0
- package/dist/docs/components__accordion__index.en-US.md.chunk.css +1 -0
- package/dist/docs/components__accordion__index.zh-CN.md.async.js +6 -0
- package/dist/docs/components__accordion__index.zh-CN.md.chunk.css +1 -0
- package/dist/docs/components__attachments__index.en-US.md.async.js +1 -0
- package/dist/docs/components__attachments__index.en-US.md.chunk.css +1 -0
- package/dist/docs/components__attachments__index.zh-CN.md.async.js +1 -0
- package/dist/docs/components__attachments__index.zh-CN.md.chunk.css +1 -0
- package/dist/docs/components__bubble-list__index.en-US.md.async.js +2 -0
- package/dist/docs/components__bubble-list__index.en-US.md.chunk.css +1 -0
- package/dist/docs/components__bubble-list__index.zh-CN.md.async.js +2 -0
- package/dist/docs/components__bubble-list__index.zh-CN.md.chunk.css +1 -0
- package/dist/docs/components__bubble__index.en-US.md.async.js +1 -0
- package/dist/docs/components__bubble__index.en-US.md.chunk.css +1 -0
- package/dist/docs/components__bubble__index.zh-CN.md.async.js +1 -0
- package/dist/docs/components__bubble__index.zh-CN.md.chunk.css +1 -0
- package/dist/docs/components__conversations__index.en-US.md.async.js +2 -0
- package/dist/docs/components__conversations__index.en-US.md.chunk.css +1 -0
- package/dist/docs/components__conversations__index.zh-CN.md.async.js +1 -0
- package/dist/docs/components__conversations__index.zh-CN.md.chunk.css +1 -0
- package/dist/docs/components__disclaimer__index.en-US.md.async.js +1 -0
- package/dist/docs/components__disclaimer__index.en-US.md.chunk.css +1 -0
- package/dist/docs/components__disclaimer__index.zh-CN.md.async.js +1 -0
- package/dist/docs/components__disclaimer__index.zh-CN.md.chunk.css +1 -0
- package/dist/docs/components__footer__index.en-US.md.async.js +1 -0
- package/dist/docs/components__footer__index.en-US.md.chunk.css +1 -0
- package/dist/docs/components__footer__index.zh-CN.md.async.js +2 -0
- package/dist/docs/components__footer__index.zh-CN.md.chunk.css +1 -0
- package/dist/docs/components__markdown__index.en-US.md.async.js +1 -0
- package/dist/docs/components__markdown__index.en-US.md.chunk.css +1 -0
- package/dist/docs/components__markdown__index.zh-CN.md.async.js +1 -0
- package/dist/docs/components__markdown__index.zh-CN.md.chunk.css +1 -0
- package/dist/docs/components__sender__index.en-US.md.async.js +1 -0
- package/dist/docs/components__sender__index.en-US.md.chunk.css +1 -0
- package/dist/docs/components__sender__index.zh-CN.md.async.js +1 -0
- package/dist/docs/components__sender__index.zh-CN.md.chunk.css +1 -0
- package/dist/docs/components__status__index.en-US.md.async.js +1 -0
- package/dist/docs/components__status__index.en-US.md.chunk.css +1 -0
- package/dist/docs/components__status__index.zh-CN.md.async.js +2 -0
- package/dist/docs/components__status__index.zh-CN.md.chunk.css +1 -0
- package/dist/docs/components__welcome__index.en-US.md.async.js +2 -0
- package/dist/docs/components__welcome__index.en-US.md.chunk.css +1 -0
- package/dist/docs/components__welcome__index.zh-CN.md.async.js +2 -0
- package/dist/docs/components__welcome__index.zh-CN.md.chunk.css +1 -0
- package/dist/docs/conversations__demos.async.js +1 -0
- package/dist/docs/demos.async.js +47 -0
- package/dist/docs/demos.chunk.css +1 -0
- package/dist/docs/disclaimer__demos.async.js +1 -0
- package/dist/docs/docs/development/ag-ui/index.html +15 -0
- package/dist/docs/docs/development/ag-ui-cn/index.html +15 -0
- package/dist/docs/docs/development/backend/index.html +15 -0
- package/dist/docs/docs/development/backend-cn/index.html +15 -0
- package/dist/docs/docs/development/cards/index.html +15 -0
- package/dist/docs/docs/development/cards-cn/index.html +15 -0
- package/dist/docs/docs/development/chatanywhere/index.html +15 -0
- package/dist/docs/docs/development/chatanywhere-api/index.html +15 -0
- package/dist/docs/docs/development/chatanywhere-api-cn/index.html +15 -0
- package/dist/docs/docs/development/chatanywhere-cn/index.html +15 -0
- package/dist/docs/docs/development/custom/index.html +15 -0
- package/dist/docs/docs/development/custom-cn/index.html +15 -0
- package/dist/docs/docs/development/overview/index.html +15 -0
- package/dist/docs/docs/development/overview-cn/index.html +15 -0
- package/dist/docs/docs/development/qwen/index.html +15 -0
- package/dist/docs/docs/development/qwen-cn/index.html +15 -0
- package/dist/docs/docs/templates/copilot/index.html +15 -0
- package/dist/docs/docs/templates/copilot-cn/index.html +15 -0
- package/dist/docs/docs/templates/native/index.html +15 -0
- package/dist/docs/docs/templates/native-cn/index.html +15 -0
- package/dist/docs/docs/templates/voice/index.html +15 -0
- package/dist/docs/docs/templates/voice-cn/index.html +15 -0
- package/dist/docs/docs__development__ag-ui.en-US.md.async.js +210 -0
- package/dist/docs/docs__development__ag-ui.en-US.md.chunk.css +1 -0
- package/dist/docs/docs__development__ag-ui.zh-CN.md.async.js +210 -0
- package/dist/docs/docs__development__ag-ui.zh-CN.md.chunk.css +1 -0
- package/dist/docs/docs__development__backend.en-US.md.async.js +12 -0
- package/dist/docs/docs__development__backend.en-US.md.chunk.css +1 -0
- package/dist/docs/docs__development__backend.zh-CN.md.async.js +12 -0
- package/dist/docs/docs__development__backend.zh-CN.md.chunk.css +1 -0
- package/dist/docs/docs__development__cards.en-US.md.async.js +27 -0
- package/dist/docs/docs__development__cards.en-US.md.chunk.css +1 -0
- package/dist/docs/docs__development__cards.zh-CN.md.async.js +27 -0
- package/dist/docs/docs__development__cards.zh-CN.md.chunk.css +1 -0
- package/dist/docs/docs__development__chatanywhere-api.en-US.md.async.js +69 -0
- package/dist/docs/docs__development__chatanywhere-api.en-US.md.chunk.css +1 -0
- package/dist/docs/docs__development__chatanywhere-api.zh-CN.md.async.js +69 -0
- package/dist/docs/docs__development__chatanywhere-api.zh-CN.md.chunk.css +1 -0
- package/dist/docs/docs__development__chatanywhere.en-US.md.async.js +77 -0
- package/dist/docs/docs__development__chatanywhere.en-US.md.chunk.css +1 -0
- package/dist/docs/docs__development__chatanywhere.zh-CN.md.async.js +77 -0
- package/dist/docs/docs__development__chatanywhere.zh-CN.md.chunk.css +1 -0
- package/dist/docs/docs__development__custom.en-US.md.async.js +22 -0
- package/dist/docs/docs__development__custom.en-US.md.chunk.css +1 -0
- package/dist/docs/docs__development__custom.zh-CN.md.async.js +22 -0
- package/dist/docs/docs__development__custom.zh-CN.md.chunk.css +1 -0
- package/dist/docs/docs__development__overview.en-US.md.async.js +21 -0
- package/dist/docs/docs__development__overview.en-US.md.chunk.css +1 -0
- package/dist/docs/docs__development__overview.zh-CN.md.async.js +21 -0
- package/dist/docs/docs__development__overview.zh-CN.md.chunk.css +1 -0
- package/dist/docs/docs__development__qwen.en-US.md.async.js +25 -0
- package/dist/docs/docs__development__qwen.en-US.md.chunk.css +1 -0
- package/dist/docs/docs__development__qwen.zh-CN.md.async.js +25 -0
- package/dist/docs/docs__development__qwen.zh-CN.md.chunk.css +1 -0
- package/dist/docs/docs__templates__copilot.en-US.md.async.js +1 -0
- package/dist/docs/docs__templates__copilot.en-US.md.chunk.css +1 -0
- package/dist/docs/docs__templates__copilot.zh-CN.md.async.js +1 -0
- package/dist/docs/docs__templates__copilot.zh-CN.md.chunk.css +1 -0
- package/dist/docs/docs__templates__native.en-US.md.async.js +1 -0
- package/dist/docs/docs__templates__native.en-US.md.chunk.css +1 -0
- package/dist/docs/docs__templates__native.zh-CN.md.async.js +1 -0
- package/dist/docs/docs__templates__native.zh-CN.md.chunk.css +1 -0
- package/dist/docs/docs__templates__voice.en-US.md.async.js +20 -0
- package/dist/docs/docs__templates__voice.en-US.md.chunk.css +1 -0
- package/dist/docs/docs__templates__voice.zh-CN.md.async.js +1 -0
- package/dist/docs/docs__templates__voice.zh-CN.md.chunk.css +1 -0
- package/dist/docs/dumi__pages__index__index.en-US.async.js +1 -0
- package/dist/docs/dumi__pages__index__index.en-US.chunk.css +1 -0
- package/dist/docs/dumi__pages__index__index.zh-CN.async.js +1 -0
- package/dist/docs/dumi__pages__index__index.zh-CN.chunk.css +1 -0
- package/dist/docs/dumi__theme__layouts__DocLayout__index.async.js +1 -0
- package/dist/docs/dumi__theme__layouts__DocLayout__index.chunk.css +1 -0
- package/dist/docs/dumi__theme__layouts__GlobalLayout__index.async.js +18 -0
- package/dist/docs/dumi__theme__layouts__GlobalLayout__index.chunk.css +1 -0
- package/dist/docs/dumi__tmp-production__dumi__theme__ContextWrapper.async.js +1 -0
- package/dist/docs/index/index.html +15 -0
- package/dist/docs/index-cn/index.html +15 -0
- package/dist/docs/markdown__demos.async.js +164 -0
- package/dist/docs/meta__components__en-US.async.js +9 -0
- package/dist/docs/meta__components__zh-CN.async.js +10 -0
- package/dist/docs/meta__docs__en-US.async.js +475 -0
- package/dist/docs/meta__docs__en-US.chunk.css +1 -0
- package/dist/docs/meta__docs__zh-CN.async.js +456 -0
- package/dist/docs/meta__docs__zh-CN.chunk.css +1 -0
- package/dist/docs/nm__dumi__dist__client__pages__404.async.js +1 -0
- package/dist/docs/nm__dumi__dist__client__pages__Demo__index.async.js +1 -0
- package/dist/docs/nm__dumi__dist__client__pages__Demo__index.chunk.css +1 -0
- package/dist/docs/preload_helper.js +1 -0
- package/dist/docs/sender__demos.async.js +1 -0
- package/dist/docs/umi.css +1 -0
- package/dist/docs/umi.js +107 -0
- package/dist/docs/welcome__demos.async.js +1 -0
- package/dist/docs/~demos/:id/index.html +15 -0
- package/dist/docs/~demos/accordion-demo-inline/index.html +15 -0
- package/dist/docs/~demos/accordion-demo-mutisteps/index.html +15 -0
- package/dist/docs/~demos/accordion-demo-thinking/index.html +15 -0
- package/dist/docs/~demos/attachments-demo-files/index.html +15 -0
- package/dist/docs/~demos/bubble-demo-basic/index.html +15 -0
- package/dist/docs/~demos/bubble-demo-havestopped/index.html +15 -0
- package/dist/docs/~demos/bubble-demo-userwithfile/index.html +15 -0
- package/dist/docs/~demos/bubble-demo-userwithimage/index.html +15 -0
- package/dist/docs/~demos/bubble-demo-userwithnormal/index.html +15 -0
- package/dist/docs/~demos/bubble-demo-withavatar/index.html +15 -0
- package/dist/docs/~demos/bubble-demo-withcode/index.html +15 -0
- package/dist/docs/~demos/bubble-demo-witherror/index.html +15 -0
- package/dist/docs/~demos/bubble-demo-witherrordetail/index.html +15 -0
- package/dist/docs/~demos/bubble-demo-withimage/index.html +15 -0
- package/dist/docs/~demos/bubble-demo-withusage/index.html +15 -0
- package/dist/docs/~demos/bubble-demo-withwaitingmessage/index.html +15 -0
- package/dist/docs/~demos/components-bubble-list-demo-basic/index.html +15 -0
- package/dist/docs/~demos/components-footer-demo-basic/index.html +15 -0
- package/dist/docs/~demos/components-footer-demo-withusage/index.html +15 -0
- package/dist/docs/~demos/components-status-demo-basic/index.html +15 -0
- package/dist/docs/~demos/conversations-demo-basic/index.html +15 -0
- package/dist/docs/~demos/disclaimer-demo-demo/index.html +15 -0
- package/dist/docs/~demos/disclaimer-demo-withlink/index.html +15 -0
- package/dist/docs/~demos/docs-development-ag-ui-demo-with-copilotkit/index.html +15 -0
- package/dist/docs/~demos/docs-development-cards-demo-file/index.html +15 -0
- package/dist/docs/~demos/docs-development-cards-demo-footer/index.html +15 -0
- package/dist/docs/~demos/docs-development-cards-demo-image/index.html +15 -0
- package/dist/docs/~demos/docs-development-cards-demo-text/index.html +15 -0
- package/dist/docs/~demos/docs-development-custom-demo-custom/index.html +15 -0
- package/dist/docs/~demos/docs-templates-copilot-demo-copilot/index.html +15 -0
- package/dist/docs/~demos/docs-templates-native-demo-basic/index.html +15 -0
- package/dist/docs/~demos/docs-templates-voice-demo-demo/index.html +15 -0
- package/dist/docs/~demos/markdown-demo-citations/index.html +15 -0
- package/dist/docs/~demos/markdown-demo-cursor/index.html +15 -0
- package/dist/docs/~demos/markdown-demo-mathjax/index.html +15 -0
- package/dist/docs/~demos/markdown-demo-md/index.html +15 -0
- package/dist/docs/~demos/sender-demo-basic/index.html +15 -0
- package/dist/docs/~demos/sender-demo-disabled/index.html +15 -0
- package/dist/docs/~demos/sender-demo-loading/index.html +15 -0
- package/dist/docs/~demos/sender-demo-moreprefixaction/index.html +15 -0
- package/dist/docs/~demos/sender-demo-withfile/index.html +15 -0
- package/dist/docs/~demos/welcome-demo-demo0/index.html +15 -0
- package/dist/docs/~demos/welcome-demo-demo1/index.html +15 -0
- package/dist/docs/~demos/welcome-demo-demo2/index.html +15 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.js +20 -0
- package/dist/index.less +1 -0
- package/dist/markdown/Citation.d.ts +16 -0
- package/dist/markdown/Citation.js +55 -0
- package/dist/markdown/CodeBlock.d.ts +6 -0
- package/dist/markdown/CodeBlock.js +88 -0
- package/dist/markdown/ImageOrVideo.d.ts +2 -0
- package/dist/markdown/ImageOrVideo.js +81 -0
- package/dist/markdown/Link.d.ts +3 -0
- package/dist/markdown/Link.js +28 -0
- package/dist/markdown/Markdown.d.ts +4 -0
- package/dist/markdown/Markdown.js +121 -0
- package/dist/markdown/cursor/Blur.d.ts +3 -0
- package/dist/markdown/cursor/Blur.js +7 -0
- package/dist/markdown/cursor/Dot.d.ts +3 -0
- package/dist/markdown/cursor/Dot.js +16 -0
- package/dist/markdown/cursor/Underline.d.ts +3 -0
- package/dist/markdown/cursor/Underline.js +7 -0
- package/dist/markdown/cursor/index.less +124 -0
- package/dist/markdown/hooks/index.d.ts +1 -0
- package/dist/markdown/hooks/index.js +49 -0
- package/dist/markdown/hooks/useTypedEffect.d.ts +6 -0
- package/dist/markdown/hooks/useTypedEffect.js +56 -0
- package/dist/markdown/index.d.ts +16 -0
- package/dist/markdown/index.js +37 -0
- package/dist/markdown/index.less +204 -0
- package/dist/markdown/plugins/footnote.d.ts +2 -0
- package/dist/markdown/plugins/footnote.js +89 -0
- package/dist/markdown/plugins/katexDir.d.ts +1 -0
- package/dist/markdown/plugins/katexDir.js +15 -0
- package/dist/markdown/rehype/fadeIn.d.ts +2 -0
- package/dist/markdown/rehype/fadeIn.js +43 -0
- package/dist/markdown/type.d.ts +46 -0
- package/dist/markdown/type.js +1 -0
- package/dist/markdown/utils.d.ts +22 -0
- package/dist/markdown/utils.js +125 -0
- package/dist/provider/CustomCardsProvider.d.ts +15 -0
- package/dist/provider/CustomCardsProvider.js +18 -0
- package/dist/provider/GlobalProvider.d.ts +5 -0
- package/dist/provider/GlobalProvider.js +11 -0
- package/dist/provider/index.d.ts +8 -0
- package/dist/provider/index.js +20 -0
- package/dist/provider/types.d.ts +8 -0
- package/dist/provider/types.js +1 -0
- package/dist/sender/SenderHeader.d.ts +19 -0
- package/dist/sender/SenderHeader.js +79 -0
- package/dist/sender/StopLoading.d.ts +5 -0
- package/dist/sender/StopLoading.js +20 -0
- package/dist/sender/components/ActionButton.d.ts +22 -0
- package/dist/sender/components/ActionButton.js +39 -0
- package/dist/sender/components/ClearButton.d.ts +4 -0
- package/dist/sender/components/ClearButton.js +13 -0
- package/dist/sender/components/LoadingButton.d.ts +4 -0
- package/dist/sender/components/LoadingButton.js +22 -0
- package/dist/sender/components/SendButton.d.ts +4 -0
- package/dist/sender/components/SendButton.js +14 -0
- package/dist/sender/components/SpeechButton/RecordingIcon.d.ts +5 -0
- package/dist/sender/components/SpeechButton/RecordingIcon.js +49 -0
- package/dist/sender/components/SpeechButton/index.d.ts +4 -0
- package/dist/sender/components/SpeechButton/index.js +30 -0
- package/dist/sender/index.d.ts +61 -0
- package/dist/sender/index.js +307 -0
- package/dist/sender/style/header.d.ts +4 -0
- package/dist/sender/style/header.js +46 -0
- package/dist/sender/style/index.d.ts +10 -0
- package/dist/sender/style/index.js +123 -0
- package/dist/sender/useSpeech.d.ts +6 -0
- package/dist/sender/useSpeech.js +114 -0
- package/dist/stream/index.d.ts +34 -0
- package/dist/stream/index.en-US.md.bk +50 -0
- package/dist/stream/index.js +197 -0
- package/dist/stream/index.zh-CN.md.bk +51 -0
- package/dist/theme/components.d.ts +10 -0
- package/dist/theme/components.js +1 -0
- package/dist/theme/cssinjs-utils.d.ts +14 -0
- package/dist/theme/cssinjs-utils.js +1 -0
- package/dist/theme/genStyleUtils.d.ts +28 -0
- package/dist/theme/genStyleUtils.js +49 -0
- package/dist/theme/useToken.d.ts +18 -0
- package/dist/theme/useToken.js +110 -0
- package/dist/version/index.d.ts +2 -0
- package/dist/version/index.js +2 -0
- package/dist/voice-chat/Recorder/index.d.ts +26 -0
- package/dist/voice-chat/Recorder/index.js +168 -0
- package/dist/voice-chat/VoiceChatProvider/context.d.ts +22 -0
- package/dist/voice-chat/VoiceChatProvider/context.js +3 -0
- package/dist/voice-chat/VoiceChatProvider/hooks/useChatState.d.ts +1 -0
- package/dist/voice-chat/VoiceChatProvider/hooks/useChatState.js +5 -0
- package/dist/voice-chat/VoiceChatProvider/hooks/useMessages.d.ts +8 -0
- package/dist/voice-chat/VoiceChatProvider/hooks/useMessages.js +31 -0
- package/dist/voice-chat/VoiceChatProvider/hooks/useRecorder.d.ts +5 -0
- package/dist/voice-chat/VoiceChatProvider/hooks/useRecorder.js +48 -0
- package/dist/voice-chat/VoiceChatProvider/hooks/useVoiceChat.d.ts +4 -0
- package/dist/voice-chat/VoiceChatProvider/hooks/useVoiceChat.js +10 -0
- package/dist/voice-chat/VoiceChatProvider/index.d.ts +9 -0
- package/dist/voice-chat/VoiceChatProvider/index.js +55 -0
- package/dist/voice-chat/VoiceChatService/index.d.ts +34 -0
- package/dist/voice-chat/VoiceChatService/index.js +209 -0
- package/dist/voice-chat/index.d.ts +2 -0
- package/dist/voice-chat/index.js +2 -0
- package/dist/voice-chat/types/index.d.ts +12 -0
- package/dist/voice-chat/types/index.js +4 -0
- package/dist/welcome/icon.d.ts +2 -0
- package/dist/welcome/icon.js +38 -0
- package/dist/welcome/index.d.ts +9 -0
- package/dist/welcome/index.js +57 -0
- package/package.json +117 -0
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { GetProp, Upload, UploadFile } from 'antd';
|
|
3
|
+
export interface TSession {
|
|
4
|
+
key: string;
|
|
5
|
+
messages: TMessage[][];
|
|
6
|
+
label: string;
|
|
7
|
+
}
|
|
8
|
+
export interface TMessage {
|
|
9
|
+
id: string;
|
|
10
|
+
content?: string;
|
|
11
|
+
cards?: {
|
|
12
|
+
id?: string;
|
|
13
|
+
code: string;
|
|
14
|
+
component?: React.FC;
|
|
15
|
+
data?: string | any;
|
|
16
|
+
}[];
|
|
17
|
+
role: 'user' | 'assistant' | 'system';
|
|
18
|
+
msgStatus?: 'finished' | 'interrupted' | 'generating' | 'error';
|
|
19
|
+
}
|
|
20
|
+
export interface IChatAnywhereConfig {
|
|
21
|
+
cardConfig?: {
|
|
22
|
+
[key: string]: React.FC<any>;
|
|
23
|
+
};
|
|
24
|
+
uiConfig?: {
|
|
25
|
+
narrowScreen?: boolean;
|
|
26
|
+
background?: string;
|
|
27
|
+
header?: React.ReactElement;
|
|
28
|
+
quickInput?: React.ReactElement | React.ReactElement[];
|
|
29
|
+
logo?: React.ReactElement;
|
|
30
|
+
welcome?: React.ReactElement;
|
|
31
|
+
disclaimer?: React.ReactElement | string;
|
|
32
|
+
};
|
|
33
|
+
onInput: {
|
|
34
|
+
morePrefixActions?: React.ReactElement | React.ReactElement[];
|
|
35
|
+
hide?: boolean;
|
|
36
|
+
header?: React.ReactElement | React.ReactElement[];
|
|
37
|
+
onSubmit(data: {
|
|
38
|
+
query: string;
|
|
39
|
+
fileList?: UploadFile[][];
|
|
40
|
+
}): void;
|
|
41
|
+
maxLength?: number;
|
|
42
|
+
beforeSubmit?: () => Promise<Boolean>;
|
|
43
|
+
zoomable?: boolean;
|
|
44
|
+
};
|
|
45
|
+
onStop(): void;
|
|
46
|
+
onRegenerate?(msg: Partial<TMessage>): void;
|
|
47
|
+
onSessionKeyChange?(key: string): void;
|
|
48
|
+
onUpload?: {
|
|
49
|
+
renderType?: 'simple' | 'default';
|
|
50
|
+
maxCount?: GetProp<typeof Upload, 'maxCount'>;
|
|
51
|
+
beforeUpload?: GetProp<typeof Upload, 'beforeUpload'>;
|
|
52
|
+
customRequest: GetProp<typeof Upload, 'customRequest'>;
|
|
53
|
+
multiple?: boolean;
|
|
54
|
+
accept?: string;
|
|
55
|
+
icon?: string | React.ReactElement;
|
|
56
|
+
}[];
|
|
57
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { useChatAnywhere } from "./ChatAnywhereProvider";
|
|
2
|
+
export function useInput() {
|
|
3
|
+
var _useChatAnywhere = useChatAnywhere(function (v) {
|
|
4
|
+
return {
|
|
5
|
+
loading: v.loading,
|
|
6
|
+
disabled: v.disabled,
|
|
7
|
+
setLoading: v.setLoading,
|
|
8
|
+
setDisabled: v.setDisabled
|
|
9
|
+
};
|
|
10
|
+
}),
|
|
11
|
+
loading = _useChatAnywhere.loading,
|
|
12
|
+
disabled = _useChatAnywhere.disabled,
|
|
13
|
+
setLoading = _useChatAnywhere.setLoading,
|
|
14
|
+
setDisabled = _useChatAnywhere.setDisabled;
|
|
15
|
+
return {
|
|
16
|
+
loading: loading,
|
|
17
|
+
disabled: disabled,
|
|
18
|
+
setLoading: setLoading,
|
|
19
|
+
setDisabled: setDisabled
|
|
20
|
+
};
|
|
21
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { TMessage } from './types';
|
|
3
|
+
export declare function useMessages(): {
|
|
4
|
+
messages: TMessage[];
|
|
5
|
+
getMessage: (id: string) => TMessage;
|
|
6
|
+
setMessages: React.Dispatch<React.SetStateAction<TMessage[]>>;
|
|
7
|
+
getMessages: () => TMessage[];
|
|
8
|
+
updateMessage: (message: TMessage) => void;
|
|
9
|
+
removeMessage: (message: Partial<TMessage>) => void;
|
|
10
|
+
removeAllMessages: () => void;
|
|
11
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
2
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread 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 _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
5
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
6
|
+
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; }
|
|
7
|
+
import React from 'react';
|
|
8
|
+
import { useChatAnywhere } from "./ChatAnywhereProvider";
|
|
9
|
+
export function useMessages() {
|
|
10
|
+
var _useChatAnywhere = useChatAnywhere(function (v) {
|
|
11
|
+
return {
|
|
12
|
+
messages: v.messages,
|
|
13
|
+
setMessages: v.setMessages,
|
|
14
|
+
getMessages: v.getMessages
|
|
15
|
+
};
|
|
16
|
+
}),
|
|
17
|
+
messages = _useChatAnywhere.messages,
|
|
18
|
+
setMessages = _useChatAnywhere.setMessages,
|
|
19
|
+
getMessages = _useChatAnywhere.getMessages;
|
|
20
|
+
var updateMessage = React.useCallback(function (message) {
|
|
21
|
+
setMessages(function (prev) {
|
|
22
|
+
var index = prev.findIndex(function (item) {
|
|
23
|
+
return item.id === message.id;
|
|
24
|
+
});
|
|
25
|
+
if (index > -1) {
|
|
26
|
+
return [].concat(_toConsumableArray(prev.slice(0, index)), [message], _toConsumableArray(prev.slice(index + 1)));
|
|
27
|
+
} else {
|
|
28
|
+
return [].concat(_toConsumableArray(prev), [message]);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}, []);
|
|
32
|
+
var removeMessage = React.useCallback(function (message) {
|
|
33
|
+
setMessages(function (prev) {
|
|
34
|
+
return prev.filter(function (item) {
|
|
35
|
+
return item.id !== message.id;
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
}, []);
|
|
39
|
+
var removeAllMessages = React.useCallback(function () {
|
|
40
|
+
setMessages([]);
|
|
41
|
+
}, []);
|
|
42
|
+
var getMessage = React.useCallback(function (id) {
|
|
43
|
+
return getMessages().find(function (item) {
|
|
44
|
+
return item.id === id;
|
|
45
|
+
});
|
|
46
|
+
}, []);
|
|
47
|
+
return {
|
|
48
|
+
messages: messages,
|
|
49
|
+
getMessage: getMessage,
|
|
50
|
+
setMessages: setMessages,
|
|
51
|
+
getMessages: getMessages,
|
|
52
|
+
updateMessage: updateMessage,
|
|
53
|
+
removeMessage: removeMessage,
|
|
54
|
+
removeAllMessages: removeAllMessages
|
|
55
|
+
};
|
|
56
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { TMessage, TSession } from './types';
|
|
3
|
+
export declare function useSessionList(): {
|
|
4
|
+
currentRegenerateIndex: number;
|
|
5
|
+
setCurrentRegenerateIndex: React.Dispatch<React.SetStateAction<number>>;
|
|
6
|
+
getCurrentRegenerateIndex: () => number;
|
|
7
|
+
sessionList: TSession[];
|
|
8
|
+
setSessionList: React.Dispatch<React.SetStateAction<TSession[]>>;
|
|
9
|
+
getSessionList: () => TSession[];
|
|
10
|
+
currentSessionKey: string;
|
|
11
|
+
setCurrentSessionKey: React.Dispatch<React.SetStateAction<string>>;
|
|
12
|
+
sessionListShow: boolean;
|
|
13
|
+
setSessionListShow: React.Dispatch<React.SetStateAction<boolean>>;
|
|
14
|
+
createSession: () => string;
|
|
15
|
+
deleteSession: (key: string) => void;
|
|
16
|
+
updateSessionMessages: (messages: TMessage[]) => void;
|
|
17
|
+
getMessagesBySession: (currentSessionKey: any, currentRegenerateIndex: any) => TMessage[];
|
|
18
|
+
getSession: () => {
|
|
19
|
+
sessionList: TSession[];
|
|
20
|
+
currentSessionKey: string;
|
|
21
|
+
currentRegenerateIndex: number;
|
|
22
|
+
};
|
|
23
|
+
updateSession: (data: any) => void;
|
|
24
|
+
};
|
|
@@ -0,0 +1,120 @@
|
|
|
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
|
+
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
|
+
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
|
+
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
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
6
|
+
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); }
|
|
7
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
8
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
9
|
+
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
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
11
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
12
|
+
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; }
|
|
13
|
+
import React from 'react';
|
|
14
|
+
import { useChatAnywhere } from "./ChatAnywhereProvider";
|
|
15
|
+
import { v4 as uuid } from 'uuid';
|
|
16
|
+
import ReactDOM from 'react-dom';
|
|
17
|
+
export function useSessionList() {
|
|
18
|
+
var _useChatAnywhere = useChatAnywhere(function (v) {
|
|
19
|
+
return {
|
|
20
|
+
getCurrentSessionKey: v.getCurrentSessionKey,
|
|
21
|
+
currentRegenerateIndex: v.currentRegenerateIndex,
|
|
22
|
+
setCurrentRegenerateIndex: v.setCurrentRegenerateIndex,
|
|
23
|
+
getCurrentRegenerateIndex: v.getCurrentRegenerateIndex,
|
|
24
|
+
sessionListShow: v.sessionListShow,
|
|
25
|
+
setSessionListShow: v.setSessionListShow,
|
|
26
|
+
sessionList: v.sessionList,
|
|
27
|
+
setSessionList: v.setSessionList,
|
|
28
|
+
currentSessionKey: v.currentSessionKey,
|
|
29
|
+
setCurrentSessionKey: v.setCurrentSessionKey,
|
|
30
|
+
getSessionList: v.getSessionList
|
|
31
|
+
};
|
|
32
|
+
}),
|
|
33
|
+
getCurrentSessionKey = _useChatAnywhere.getCurrentSessionKey,
|
|
34
|
+
sessionList = _useChatAnywhere.sessionList,
|
|
35
|
+
setSessionList = _useChatAnywhere.setSessionList,
|
|
36
|
+
currentSessionKey = _useChatAnywhere.currentSessionKey,
|
|
37
|
+
setCurrentSessionKey = _useChatAnywhere.setCurrentSessionKey,
|
|
38
|
+
sessionListShow = _useChatAnywhere.sessionListShow,
|
|
39
|
+
setSessionListShow = _useChatAnywhere.setSessionListShow,
|
|
40
|
+
currentRegenerateIndex = _useChatAnywhere.currentRegenerateIndex,
|
|
41
|
+
setCurrentRegenerateIndex = _useChatAnywhere.setCurrentRegenerateIndex,
|
|
42
|
+
getCurrentRegenerateIndex = _useChatAnywhere.getCurrentRegenerateIndex,
|
|
43
|
+
getSessionList = _useChatAnywhere.getSessionList;
|
|
44
|
+
var createSession = React.useCallback(function () {
|
|
45
|
+
var newKey = uuid();
|
|
46
|
+
var newSession = {
|
|
47
|
+
label: Date.now().toString(),
|
|
48
|
+
key: newKey,
|
|
49
|
+
messages: [[]]
|
|
50
|
+
};
|
|
51
|
+
ReactDOM.flushSync(function () {
|
|
52
|
+
setSessionList(function (sessionList) {
|
|
53
|
+
var newSessionList = [].concat(_toConsumableArray(sessionList), [newSession]);
|
|
54
|
+
return newSessionList;
|
|
55
|
+
});
|
|
56
|
+
setCurrentSessionKey(newKey);
|
|
57
|
+
});
|
|
58
|
+
return newKey;
|
|
59
|
+
}, []);
|
|
60
|
+
var deleteSession = React.useCallback(function (key) {
|
|
61
|
+
setSessionList(function (sessionList) {
|
|
62
|
+
var newSessionList = sessionList.filter(function (item) {
|
|
63
|
+
return item.key !== key;
|
|
64
|
+
});
|
|
65
|
+
return newSessionList;
|
|
66
|
+
});
|
|
67
|
+
}, []);
|
|
68
|
+
var updateSessionMessages = React.useCallback(function (messages) {
|
|
69
|
+
var currentSessionKey = getCurrentSessionKey();
|
|
70
|
+
var currentRegenerateIndex = getCurrentRegenerateIndex();
|
|
71
|
+
setSessionList(function (sessionList) {
|
|
72
|
+
return sessionList.map(function (session) {
|
|
73
|
+
if (session.key === currentSessionKey) {
|
|
74
|
+
session.messages[currentRegenerateIndex] = messages;
|
|
75
|
+
return _objectSpread({}, session);
|
|
76
|
+
}
|
|
77
|
+
return session;
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
}, []);
|
|
81
|
+
var getMessagesBySession = React.useCallback(function (currentSessionKey, currentRegenerateIndex) {
|
|
82
|
+
var _getSessionList$find;
|
|
83
|
+
return (_getSessionList$find = getSessionList().find(function (session) {
|
|
84
|
+
return session.key === currentSessionKey;
|
|
85
|
+
})) === null || _getSessionList$find === void 0 ? void 0 : _getSessionList$find.messages[currentRegenerateIndex];
|
|
86
|
+
}, []);
|
|
87
|
+
var getSession = React.useCallback(function () {
|
|
88
|
+
return {
|
|
89
|
+
sessionList: getSessionList(),
|
|
90
|
+
currentSessionKey: getCurrentSessionKey(),
|
|
91
|
+
currentRegenerateIndex: getCurrentRegenerateIndex()
|
|
92
|
+
};
|
|
93
|
+
}, []);
|
|
94
|
+
var updateSession = React.useCallback(function (data) {
|
|
95
|
+
var sessionList = data.sessionList,
|
|
96
|
+
currentSessionKey = data.currentSessionKey,
|
|
97
|
+
currentRegenerateIndex = data.currentRegenerateIndex;
|
|
98
|
+
setSessionList(sessionList);
|
|
99
|
+
setCurrentSessionKey(currentSessionKey);
|
|
100
|
+
setCurrentRegenerateIndex(currentRegenerateIndex);
|
|
101
|
+
}, []);
|
|
102
|
+
return {
|
|
103
|
+
currentRegenerateIndex: currentRegenerateIndex,
|
|
104
|
+
setCurrentRegenerateIndex: setCurrentRegenerateIndex,
|
|
105
|
+
getCurrentRegenerateIndex: getCurrentRegenerateIndex,
|
|
106
|
+
sessionList: sessionList,
|
|
107
|
+
setSessionList: setSessionList,
|
|
108
|
+
getSessionList: getSessionList,
|
|
109
|
+
currentSessionKey: currentSessionKey,
|
|
110
|
+
setCurrentSessionKey: setCurrentSessionKey,
|
|
111
|
+
sessionListShow: sessionListShow,
|
|
112
|
+
setSessionListShow: setSessionListShow,
|
|
113
|
+
createSession: createSession,
|
|
114
|
+
deleteSession: deleteSession,
|
|
115
|
+
updateSessionMessages: updateSessionMessages,
|
|
116
|
+
getMessagesBySession: getMessagesBySession,
|
|
117
|
+
getSession: getSession,
|
|
118
|
+
updateSession: updateSession
|
|
119
|
+
};
|
|
120
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { v4 as uuid } from 'uuid';
|
|
3
|
+
import { ChatAnywhereRef, useChatAnywhere } from './hooks/ChatAnywhereProvider';
|
|
4
|
+
import { IChatAnywhereConfig } from './hooks/types';
|
|
5
|
+
export type { ChatAnywhereRef };
|
|
6
|
+
export { uuid, useChatAnywhere };
|
|
7
|
+
export type { TMessage, TSession } from './hooks/types';
|
|
8
|
+
declare const _default: React.ForwardRefExoticComponent<IChatAnywhereConfig & React.RefAttributes<unknown>>;
|
|
9
|
+
export default _default;
|
|
@@ -0,0 +1,58 @@
|
|
|
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 = ["cardConfig"];
|
|
3
|
+
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
4
|
+
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; }
|
|
5
|
+
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; }
|
|
6
|
+
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; }
|
|
7
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
8
|
+
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); }
|
|
9
|
+
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; }
|
|
10
|
+
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; }
|
|
11
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
12
|
+
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."); }
|
|
13
|
+
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); }
|
|
14
|
+
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; }
|
|
15
|
+
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; } }
|
|
16
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
17
|
+
import React, { forwardRef, useRef, useState } from 'react';
|
|
18
|
+
import Layout from "./Layout";
|
|
19
|
+
import SessionList from "./SessionList";
|
|
20
|
+
import Chat from "./Chat";
|
|
21
|
+
import Header from "./Header";
|
|
22
|
+
import { v4 as uuid } from 'uuid';
|
|
23
|
+
import { CustomCardsProvider } from "./..";
|
|
24
|
+
import { ChatAnywhereProvider, useChatAnywhere } from "./hooks/ChatAnywhereProvider";
|
|
25
|
+
import ContextRef from "./Chat/Ref";
|
|
26
|
+
export { uuid, useChatAnywhere };
|
|
27
|
+
export default /*#__PURE__*/forwardRef(function (chatanywhereConfig, ref) {
|
|
28
|
+
var _useState = useState(0),
|
|
29
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
30
|
+
key = _useState2[0],
|
|
31
|
+
setKey = _useState2[1];
|
|
32
|
+
var cardConfig = chatanywhereConfig.cardConfig,
|
|
33
|
+
rest = _objectWithoutProperties(chatanywhereConfig, _excluded);
|
|
34
|
+
var chatRef = useRef(null);
|
|
35
|
+
var contextRef = useRef(null);
|
|
36
|
+
React.useImperativeHandle(ref, function () {
|
|
37
|
+
return _objectSpread(_objectSpread(_objectSpread({}, chatRef.current), contextRef.current), {}, {
|
|
38
|
+
reload: function reload() {
|
|
39
|
+
setKey(function (key) {
|
|
40
|
+
return key + 1;
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
return /*#__PURE__*/React.createElement(ChatAnywhereProvider, _extends({}, rest, {
|
|
46
|
+
key: key
|
|
47
|
+
}), /*#__PURE__*/React.createElement(CustomCardsProvider, {
|
|
48
|
+
cardConfig: cardConfig
|
|
49
|
+
}, /*#__PURE__*/React.createElement(Layout, {
|
|
50
|
+
top: rest.uiConfig.header ? /*#__PURE__*/React.createElement(Header, null) : null,
|
|
51
|
+
left: rest.onSessionKeyChange ? /*#__PURE__*/React.createElement(SessionList, null) : null,
|
|
52
|
+
right: /*#__PURE__*/React.createElement(Chat, {
|
|
53
|
+
ref: chatRef
|
|
54
|
+
})
|
|
55
|
+
}), /*#__PURE__*/React.createElement(ContextRef, {
|
|
56
|
+
ref: contextRef
|
|
57
|
+
})));
|
|
58
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ConfigProviderProps, GetProp } from 'antd';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
export interface GroupTitleProps {
|
|
4
|
+
children?: React.ReactNode;
|
|
5
|
+
}
|
|
6
|
+
export declare const GroupTitleContext: React.Context<{
|
|
7
|
+
prefixCls?: GetProp<ConfigProviderProps, 'prefixCls'>;
|
|
8
|
+
}>;
|
|
9
|
+
declare const GroupTitle: React.FC<GroupTitleProps>;
|
|
10
|
+
export default GroupTitle;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Typography } from 'antd';
|
|
2
|
+
import classnames from 'classnames';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
// User should not care about internal state.
|
|
5
|
+
// Which should pass by context instead.
|
|
6
|
+
export var GroupTitleContext = /*#__PURE__*/React.createContext(null);
|
|
7
|
+
var GroupTitle = function GroupTitle(_ref) {
|
|
8
|
+
var children = _ref.children;
|
|
9
|
+
var _React$useContext = React.useContext(GroupTitleContext),
|
|
10
|
+
prefixCls = _React$useContext.prefixCls;
|
|
11
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
12
|
+
className: classnames("".concat(prefixCls, "-group-title"))
|
|
13
|
+
}, children && /*#__PURE__*/React.createElement(Typography.Text, null, children));
|
|
14
|
+
};
|
|
15
|
+
export default GroupTitle;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { MenuProps } from 'antd';
|
|
3
|
+
import type { DirectionType } from 'antd/es/config-provider';
|
|
4
|
+
import type { Conversation } from './interface';
|
|
5
|
+
export interface ConversationsItemProps extends Omit<React.HTMLAttributes<HTMLLIElement>, 'onClick'> {
|
|
6
|
+
info: Conversation;
|
|
7
|
+
prefixCls?: string;
|
|
8
|
+
direction?: DirectionType;
|
|
9
|
+
menu?: MenuProps;
|
|
10
|
+
active?: boolean;
|
|
11
|
+
onClick?: (info: Conversation) => void;
|
|
12
|
+
}
|
|
13
|
+
declare const ConversationsItem: React.FC<ConversationsItemProps>;
|
|
14
|
+
export default ConversationsItem;
|
|
@@ -0,0 +1,96 @@
|
|
|
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 = ["prefixCls", "info", "className", "direction", "onClick", "active", "menu"];
|
|
3
|
+
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
4
|
+
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
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
6
|
+
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); }
|
|
7
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
8
|
+
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
|
+
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
|
+
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
|
+
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
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
13
|
+
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; }
|
|
14
|
+
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; }
|
|
15
|
+
import { EllipsisOutlined } from '@ant-design/icons';
|
|
16
|
+
import { Dropdown, Tooltip, Typography } from 'antd';
|
|
17
|
+
import classnames from 'classnames';
|
|
18
|
+
import React from 'react';
|
|
19
|
+
import pickAttrs from 'rc-util/lib/pickAttrs';
|
|
20
|
+
var stopPropagation = function stopPropagation(e) {
|
|
21
|
+
e.stopPropagation();
|
|
22
|
+
};
|
|
23
|
+
var ConversationsItem = function ConversationsItem(props) {
|
|
24
|
+
var prefixCls = props.prefixCls,
|
|
25
|
+
info = props.info,
|
|
26
|
+
className = props.className,
|
|
27
|
+
direction = props.direction,
|
|
28
|
+
onClick = props.onClick,
|
|
29
|
+
active = props.active,
|
|
30
|
+
menu = props.menu,
|
|
31
|
+
restProps = _objectWithoutProperties(props, _excluded);
|
|
32
|
+
var domProps = pickAttrs(restProps, {
|
|
33
|
+
aria: true,
|
|
34
|
+
data: true,
|
|
35
|
+
attr: true
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
// ============================= MISC =============================
|
|
39
|
+
var disabled = info.disabled;
|
|
40
|
+
|
|
41
|
+
// =========================== Ellipsis ===========================
|
|
42
|
+
var _React$useState = React.useState(false),
|
|
43
|
+
_React$useState2 = _slicedToArray(_React$useState, 2),
|
|
44
|
+
inEllipsis = _React$useState2[0],
|
|
45
|
+
onEllipsis = _React$useState2[1];
|
|
46
|
+
|
|
47
|
+
// =========================== Tooltip ============================
|
|
48
|
+
var _React$useState3 = React.useState(false),
|
|
49
|
+
_React$useState4 = _slicedToArray(_React$useState3, 2),
|
|
50
|
+
opened = _React$useState4[0],
|
|
51
|
+
setOpened = _React$useState4[1];
|
|
52
|
+
|
|
53
|
+
// ============================ Style =============================
|
|
54
|
+
var mergedCls = classnames(className, "".concat(prefixCls, "-item"), _defineProperty({}, "".concat(prefixCls, "-item-active"), active && !disabled), _defineProperty({}, "".concat(prefixCls, "-item-disabled"), disabled));
|
|
55
|
+
|
|
56
|
+
// ============================ Events ============================
|
|
57
|
+
var onInternalClick = function onInternalClick() {
|
|
58
|
+
if (!disabled && onClick) {
|
|
59
|
+
onClick(info);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
var onOpenChange = function onOpenChange(open) {
|
|
63
|
+
if (open) {
|
|
64
|
+
setOpened(!open);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
// ============================ Render ============================
|
|
69
|
+
return /*#__PURE__*/React.createElement(Tooltip, {
|
|
70
|
+
title: info.label,
|
|
71
|
+
open: inEllipsis && opened,
|
|
72
|
+
onOpenChange: setOpened,
|
|
73
|
+
placement: direction === 'rtl' ? 'left' : 'right'
|
|
74
|
+
}, /*#__PURE__*/React.createElement("li", _extends({}, domProps, {
|
|
75
|
+
className: mergedCls,
|
|
76
|
+
onClick: onInternalClick
|
|
77
|
+
}), info.icon && /*#__PURE__*/React.createElement("div", {
|
|
78
|
+
className: "".concat(prefixCls, "-icon")
|
|
79
|
+
}, info.icon), /*#__PURE__*/React.createElement(Typography.Text, {
|
|
80
|
+
className: "".concat(prefixCls, "-label"),
|
|
81
|
+
ellipsis: {
|
|
82
|
+
onEllipsis: onEllipsis
|
|
83
|
+
}
|
|
84
|
+
}, info.label), menu && !disabled && /*#__PURE__*/React.createElement(Dropdown, {
|
|
85
|
+
menu: menu,
|
|
86
|
+
placement: direction === 'rtl' ? 'bottomLeft' : 'bottomRight',
|
|
87
|
+
trigger: ['click'],
|
|
88
|
+
disabled: disabled,
|
|
89
|
+
onOpenChange: onOpenChange
|
|
90
|
+
}, /*#__PURE__*/React.createElement(EllipsisOutlined, {
|
|
91
|
+
onClick: stopPropagation,
|
|
92
|
+
disabled: disabled,
|
|
93
|
+
className: "".concat(prefixCls, "-menu-icon")
|
|
94
|
+
}))));
|
|
95
|
+
};
|
|
96
|
+
export default ConversationsItem;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Conversation, Groupable } from '../interface';
|
|
2
|
+
import type { ConversationsProps } from '..';
|
|
3
|
+
type GroupList = {
|
|
4
|
+
data: Conversation[];
|
|
5
|
+
name?: string;
|
|
6
|
+
title?: Groupable['title'];
|
|
7
|
+
}[];
|
|
8
|
+
declare const useGroupable: (groupable?: ConversationsProps['groupable'], items?: Conversation[]) => [groupList: GroupList, enableGroup: boolean];
|
|
9
|
+
export default useGroupable;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
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; }
|
|
2
|
+
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; }
|
|
3
|
+
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; }
|
|
4
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
5
|
+
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); }
|
|
6
|
+
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); }
|
|
7
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
8
|
+
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
|
+
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
|
+
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
|
+
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
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
13
|
+
import React from 'react';
|
|
14
|
+
/**
|
|
15
|
+
* 🔥 Only for handling ungrouped data. Do not use it for any other purpose! 🔥
|
|
16
|
+
*/
|
|
17
|
+
var __UNGROUPED = '__ungrouped';
|
|
18
|
+
var useGroupable = function useGroupable(groupable) {
|
|
19
|
+
var items = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
20
|
+
var _React$useMemo = React.useMemo(function () {
|
|
21
|
+
if (!groupable) {
|
|
22
|
+
return [false, undefined, undefined];
|
|
23
|
+
}
|
|
24
|
+
var baseConfig = {
|
|
25
|
+
sort: undefined,
|
|
26
|
+
title: undefined
|
|
27
|
+
};
|
|
28
|
+
if (_typeof(groupable) === 'object') {
|
|
29
|
+
baseConfig = _objectSpread(_objectSpread({}, baseConfig), groupable);
|
|
30
|
+
}
|
|
31
|
+
return [true, baseConfig.sort, baseConfig.title];
|
|
32
|
+
}, [groupable]),
|
|
33
|
+
_React$useMemo2 = _slicedToArray(_React$useMemo, 3),
|
|
34
|
+
enableGroup = _React$useMemo2[0],
|
|
35
|
+
sort = _React$useMemo2[1],
|
|
36
|
+
title = _React$useMemo2[2];
|
|
37
|
+
return React.useMemo(function () {
|
|
38
|
+
// 未开启分组模式直接返回
|
|
39
|
+
if (!enableGroup) {
|
|
40
|
+
var _groupList = [{
|
|
41
|
+
name: __UNGROUPED,
|
|
42
|
+
data: items,
|
|
43
|
+
title: undefined
|
|
44
|
+
}];
|
|
45
|
+
return [_groupList, enableGroup];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// 1. 将 data 做数据分组,填充 groupMap
|
|
49
|
+
var groupMap = items.reduce(function (acc, item) {
|
|
50
|
+
var group = item.group || __UNGROUPED;
|
|
51
|
+
if (!acc[group]) {
|
|
52
|
+
acc[group] = [];
|
|
53
|
+
}
|
|
54
|
+
acc[group].push(item);
|
|
55
|
+
return acc;
|
|
56
|
+
}, {});
|
|
57
|
+
|
|
58
|
+
// 2. 存在 sort 时对 groupKeys 排序
|
|
59
|
+
var groupKeys = sort ? Object.keys(groupMap).sort(sort) : Object.keys(groupMap);
|
|
60
|
+
|
|
61
|
+
// 3. groupMap 转 groupList
|
|
62
|
+
var groupList = groupKeys.map(function (group) {
|
|
63
|
+
return {
|
|
64
|
+
name: group === __UNGROUPED ? undefined : group,
|
|
65
|
+
title: title,
|
|
66
|
+
data: groupMap[group]
|
|
67
|
+
};
|
|
68
|
+
});
|
|
69
|
+
return [groupList, enableGroup];
|
|
70
|
+
}, [items, groupable]);
|
|
71
|
+
};
|
|
72
|
+
export default useGroupable;
|