@webinex/chatify 2.0.1-alpha1 → 2.0.2-alpha2

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.
Files changed (232) hide show
  1. package/dist/css/chatify.css +111 -12
  2. package/dist/esm/index.js +2 -2
  3. package/dist/esm/index.js.map +1 -1
  4. package/dist/esm/types/core/api/api.d.ts +10784 -232
  5. package/dist/esm/types/core/api/baseApi.d.ts +1 -1
  6. package/dist/esm/types/ui/Conversation/Conversation.d.ts +2 -0
  7. package/dist/esm/types/ui/Conversation/ConversationContext.d.ts +2 -0
  8. package/dist/esm/types/ui/Conversation/InputBox/InputBoxFile.d.ts +8 -0
  9. package/dist/esm/types/ui/Conversation/InputBox/InputBoxFileList.d.ts +8 -0
  10. package/dist/esm/types/ui/Conversation/InputBox/InputFilesBox.d.ts +11 -1
  11. package/dist/esm/types/ui/Conversation/InputBox/InputSubmitButtonBox.d.ts +2 -0
  12. package/dist/esm/types/ui/Conversation/InputBox/InputTextBox.d.ts +1 -0
  13. package/dist/esm/types/ui/Conversation/InputBox/index.d.ts +8 -1
  14. package/dist/esm/types/ui/Conversation/Message/MessageFile.d.ts +6 -0
  15. package/dist/esm/types/ui/Conversation/Message/MessageFileList.d.ts +3 -0
  16. package/dist/esm/types/ui/Conversation/Message/index.d.ts +6 -0
  17. package/dist/esm/types/ui/common/Icon.d.ts +2 -0
  18. package/dist/esm/types/ui/customize.d.ts +2 -2
  19. package/dist/esm/types/ui/localizer.d.ts +5 -0
  20. package/dist/esm/types/ui/useFormatter.d.ts +3 -0
  21. package/dist/index.d.ts +10835 -239
  22. package/package.json +94 -93
  23. package/src/core/api/api.ts +643 -642
  24. package/src/core/api/baseApi.ts +38 -38
  25. package/src/core/api/index.ts +1 -1
  26. package/src/core/client.ts +280 -280
  27. package/src/core/constants.ts +1 -1
  28. package/src/core/debounce.ts +90 -90
  29. package/src/core/index.ts +4 -4
  30. package/src/core/types.tsx +152 -152
  31. package/src/index.ts +2 -2
  32. package/src/styles/aside.scss +162 -161
  33. package/src/styles/chat.scss +209 -208
  34. package/src/styles/index.scss +153 -110
  35. package/src/styles/input.scss +147 -74
  36. package/src/styles/keyframes.scss +14 -14
  37. package/src/styles/members.scss +13 -13
  38. package/src/styles/mixins.scss +25 -20
  39. package/src/styles/variables.scss +13 -10
  40. package/src/ui/Chat/ChatContext.tsx +30 -30
  41. package/src/ui/Chat/ChatEditableHeaderName.tsx +63 -63
  42. package/src/ui/Chat/ChatHeaderActions.tsx +19 -19
  43. package/src/ui/Chat/ChatPanel.tsx +30 -30
  44. package/src/ui/Chat/ChatView.tsx +115 -115
  45. package/src/ui/Chat/Members/ChatMembersButton.tsx +9 -9
  46. package/src/ui/Chat/Members/ChatMembersPanel.tsx +112 -112
  47. package/src/ui/Chat/Members/ChatMembersPreview.tsx +25 -25
  48. package/src/ui/Chat/Members/index.ts +13 -13
  49. package/src/ui/Chat/index.ts +6 -6
  50. package/src/ui/ChatGroup/ChatGroupContext.tsx +50 -50
  51. package/src/ui/ChatGroup/ChatGroupPanel.tsx +73 -73
  52. package/src/ui/ChatGroup/Create/CreateChatButton.tsx +15 -15
  53. package/src/ui/ChatGroup/Create/CreateChatForm.tsx +36 -36
  54. package/src/ui/ChatGroup/Create/CreateChatMemberInput.tsx +65 -65
  55. package/src/ui/ChatGroup/Create/CreateChatNameInput.tsx +25 -25
  56. package/src/ui/ChatGroup/Create/CreateChatPanel.tsx +45 -45
  57. package/src/ui/ChatGroup/Create/index.ts +19 -19
  58. package/src/ui/ChatGroup/Layout/ChatGroupAside.tsx +12 -12
  59. package/src/ui/ChatGroup/Layout/ChatGroupBody.tsx +10 -10
  60. package/src/ui/ChatGroup/Layout/ChatGroupFooter.tsx +3 -3
  61. package/src/ui/ChatGroup/Layout/ChatGroupHeader.tsx +5 -5
  62. package/src/ui/ChatGroup/Layout/ChatGroupMain.tsx +17 -17
  63. package/src/ui/ChatGroup/Layout/index.ts +19 -19
  64. package/src/ui/ChatGroup/List/ChatList.tsx +41 -41
  65. package/src/ui/ChatGroup/List/ChatListItemAvatar.tsx +22 -22
  66. package/src/ui/ChatGroup/List/ChatListItemBox.tsx +26 -26
  67. package/src/ui/ChatGroup/List/ChatListItemLastMessage.tsx +15 -15
  68. package/src/ui/ChatGroup/List/ChatListItemLastMessageAuthor.tsx +15 -15
  69. package/src/ui/ChatGroup/List/ChatListItemLastMessageContent.tsx +21 -21
  70. package/src/ui/ChatGroup/List/ChatListItemLastMessageSentAt.tsx +22 -22
  71. package/src/ui/ChatGroup/List/ChatListItemName.tsx +8 -8
  72. package/src/ui/ChatGroup/List/ChatListItemUnreadCount.tsx +12 -12
  73. package/src/ui/ChatGroup/List/index.ts +31 -31
  74. package/src/ui/ChatGroup/index.ts +5 -5
  75. package/src/ui/Chatify.tsx +9 -9
  76. package/src/ui/Conversation/Conversation.tsx +78 -76
  77. package/src/ui/Conversation/ConversationActions.tsx +5 -5
  78. package/src/ui/Conversation/ConversationBody.tsx +28 -28
  79. package/src/ui/Conversation/ConversationContext.ts +29 -27
  80. package/src/ui/Conversation/ConversationHeader.tsx +23 -23
  81. package/src/ui/Conversation/ConversationName.tsx +7 -7
  82. package/src/ui/Conversation/InputBox/InputBox.tsx +113 -40
  83. package/src/ui/Conversation/InputBox/InputBoxFile.tsx +38 -0
  84. package/src/ui/Conversation/InputBox/InputBoxFileList.tsx +21 -0
  85. package/src/ui/Conversation/InputBox/InputFilesBox.tsx +78 -9
  86. package/src/ui/Conversation/InputBox/InputSubmitButtonBox.tsx +26 -17
  87. package/src/ui/Conversation/InputBox/InputTextBox.tsx +55 -53
  88. package/src/ui/Conversation/InputBox/index.ts +23 -16
  89. package/src/ui/Conversation/Message/MessageAuthor.tsx +13 -13
  90. package/src/ui/Conversation/Message/MessageBox.tsx +20 -20
  91. package/src/ui/Conversation/Message/MessageContent.tsx +15 -11
  92. package/src/ui/Conversation/Message/MessageFile.tsx +52 -0
  93. package/src/ui/Conversation/Message/MessageFileList.tsx +14 -0
  94. package/src/ui/Conversation/Message/MessageInfoBox.tsx +28 -28
  95. package/src/ui/Conversation/Message/MessageRow.tsx +28 -28
  96. package/src/ui/Conversation/Message/MessageText.tsx +7 -7
  97. package/src/ui/Conversation/Message/index.ts +28 -22
  98. package/src/ui/Conversation/NextObserver/NextMessagesObserver.tsx +47 -47
  99. package/src/ui/Conversation/NextObserver/index.ts +1 -1
  100. package/src/ui/Conversation/ReadObserver/MessageReadObserver.tsx +49 -49
  101. package/src/ui/Conversation/ReadObserver/index.ts +1 -1
  102. package/src/ui/Conversation/SendingMessage/SendingMessageBox.tsx +16 -16
  103. package/src/ui/Conversation/SendingMessage/SendingMessageContent.tsx +13 -13
  104. package/src/ui/Conversation/SendingMessage/SendingMessageInfoBox.tsx +13 -13
  105. package/src/ui/Conversation/SendingMessage/SendingMessageText.tsx +7 -7
  106. package/src/ui/Conversation/SendingMessage/index.ts +16 -16
  107. package/src/ui/Conversation/SystemMessage/SystemMessageBox.tsx +20 -20
  108. package/src/ui/Conversation/SystemMessage/SystemMessageRow.tsx +28 -28
  109. package/src/ui/Conversation/SystemMessage/index.ts +10 -10
  110. package/src/ui/Conversation/index.ts +13 -13
  111. package/src/ui/Thread/ThreadActions.tsx +22 -22
  112. package/src/ui/Thread/ThreadContext.ts +13 -13
  113. package/src/ui/Thread/ThreadPanel.tsx +127 -127
  114. package/src/ui/Thread/index.tsx +3 -3
  115. package/src/ui/color.ts +20 -20
  116. package/src/ui/common/Avatar.tsx +20 -20
  117. package/src/ui/common/Icon.tsx +44 -40
  118. package/src/ui/common/MessageSkeleton.tsx +20 -20
  119. package/src/ui/common/index.ts +13 -13
  120. package/src/ui/customize.tsx +51 -53
  121. package/src/ui/index.ts +11 -11
  122. package/src/ui/localizer.tsx +96 -81
  123. package/src/ui/useFormatter.tsx +17 -0
  124. package/dist/esm/types/core/api/accountApi.d.ts +0 -5
  125. package/dist/esm/types/core/api/chatApi.d.ts +0 -16
  126. package/dist/esm/types/core/api/chatListApi.d.ts +0 -5
  127. package/dist/esm/types/core/api/chatMemberApi.d.ts +0 -6
  128. package/dist/esm/types/core/api/chatMessageApi.d.ts +0 -3
  129. package/dist/esm/types/core/api/threadApi.d.ts +0 -1
  130. package/dist/esm/types/core/api/threadMessageApi.d.ts +0 -6
  131. package/src/core/api/accountApi.ts +0 -11
  132. package/src/core/api/chatApi.ts +0 -87
  133. package/src/core/api/chatListApi.ts +0 -134
  134. package/src/core/api/chatMemberApi.ts +0 -20
  135. package/src/core/api/chatMessageApi.ts +0 -12
  136. package/src/core/api/threadApi.ts +0 -8
  137. package/src/core/api/threadMessageApi.ts +0 -20
  138. package/src/types/core/api/accountApi.d.ts +0 -5
  139. package/src/types/core/api/api.d.ts +0 -2380
  140. package/src/types/core/api/baseApi.d.ts +0 -15
  141. package/src/types/core/api/chatApi.d.ts +0 -16
  142. package/src/types/core/api/chatListApi.d.ts +0 -5
  143. package/src/types/core/api/chatMemberApi.d.ts +0 -6
  144. package/src/types/core/api/chatMessageApi.d.ts +0 -3
  145. package/src/types/core/api/index.d.ts +0 -1
  146. package/src/types/core/api/threadApi.d.ts +0 -1
  147. package/src/types/core/api/threadMessageApi.d.ts +0 -6
  148. package/src/types/core/client.d.ts +0 -83
  149. package/src/types/core/constants.d.ts +0 -1
  150. package/src/types/core/debounce.d.ts +0 -27
  151. package/src/types/core/index.d.ts +0 -4
  152. package/src/types/core/types.d.ts +0 -105
  153. package/src/types/index.d.ts +0 -2
  154. package/src/types/ui/Chat/ChatContext.d.ts +0 -10
  155. package/src/types/ui/Chat/ChatEditableHeaderName.d.ts +0 -2
  156. package/src/types/ui/Chat/ChatHeaderActions.d.ts +0 -2
  157. package/src/types/ui/Chat/ChatPanel.d.ts +0 -13
  158. package/src/types/ui/Chat/ChatView.d.ts +0 -17
  159. package/src/types/ui/Chat/Members/ChatMembersButton.d.ts +0 -2
  160. package/src/types/ui/Chat/Members/ChatMembersPanel.d.ts +0 -2
  161. package/src/types/ui/Chat/Members/ChatMembersPreview.d.ts +0 -2
  162. package/src/types/ui/Chat/Members/index.d.ts +0 -11
  163. package/src/types/ui/Chat/index.d.ts +0 -6
  164. package/src/types/ui/ChatGroup/ChatGroupContext.d.ts +0 -12
  165. package/src/types/ui/ChatGroup/ChatGroupPanel.d.ts +0 -15
  166. package/src/types/ui/ChatGroup/Create/CreateChatButton.d.ts +0 -2
  167. package/src/types/ui/ChatGroup/Create/CreateChatForm.d.ts +0 -11
  168. package/src/types/ui/ChatGroup/Create/CreateChatMemberInput.d.ts +0 -5
  169. package/src/types/ui/ChatGroup/Create/CreateChatNameInput.d.ts +0 -5
  170. package/src/types/ui/ChatGroup/Create/CreateChatPanel.d.ts +0 -2
  171. package/src/types/ui/ChatGroup/Create/index.d.ts +0 -17
  172. package/src/types/ui/ChatGroup/Layout/ChatGroupAside.d.ts +0 -2
  173. package/src/types/ui/ChatGroup/Layout/ChatGroupBody.d.ts +0 -2
  174. package/src/types/ui/ChatGroup/Layout/ChatGroupFooter.d.ts +0 -2
  175. package/src/types/ui/ChatGroup/Layout/ChatGroupHeader.d.ts +0 -2
  176. package/src/types/ui/ChatGroup/Layout/ChatGroupMain.d.ts +0 -2
  177. package/src/types/ui/ChatGroup/Layout/index.d.ts +0 -17
  178. package/src/types/ui/ChatGroup/List/ChatList.d.ts +0 -2
  179. package/src/types/ui/ChatGroup/List/ChatListItemAvatar.d.ts +0 -3
  180. package/src/types/ui/ChatGroup/List/ChatListItemBox.d.ts +0 -6
  181. package/src/types/ui/ChatGroup/List/ChatListItemLastMessage.d.ts +0 -3
  182. package/src/types/ui/ChatGroup/List/ChatListItemLastMessageAuthor.d.ts +0 -3
  183. package/src/types/ui/ChatGroup/List/ChatListItemLastMessageContent.d.ts +0 -3
  184. package/src/types/ui/ChatGroup/List/ChatListItemLastMessageSentAt.d.ts +0 -3
  185. package/src/types/ui/ChatGroup/List/ChatListItemName.d.ts +0 -3
  186. package/src/types/ui/ChatGroup/List/ChatListItemUnreadCount.d.ts +0 -3
  187. package/src/types/ui/ChatGroup/List/index.d.ts +0 -29
  188. package/src/types/ui/ChatGroup/index.d.ts +0 -5
  189. package/src/types/ui/Chatify.d.ts +0 -8
  190. package/src/types/ui/Conversation/Conversation.d.ts +0 -21
  191. package/src/types/ui/Conversation/ConversationActions.d.ts +0 -2
  192. package/src/types/ui/Conversation/ConversationBody.d.ts +0 -2
  193. package/src/types/ui/Conversation/ConversationContext.d.ts +0 -20
  194. package/src/types/ui/Conversation/ConversationHeader.d.ts +0 -2
  195. package/src/types/ui/Conversation/ConversationName.d.ts +0 -2
  196. package/src/types/ui/Conversation/InputBox/InputBox.d.ts +0 -2
  197. package/src/types/ui/Conversation/InputBox/InputFilesBox.d.ts +0 -2
  198. package/src/types/ui/Conversation/InputBox/InputSubmitButtonBox.d.ts +0 -5
  199. package/src/types/ui/Conversation/InputBox/InputTextBox.d.ts +0 -8
  200. package/src/types/ui/Conversation/InputBox/index.d.ts +0 -14
  201. package/src/types/ui/Conversation/Message/MessageAuthor.d.ts +0 -3
  202. package/src/types/ui/Conversation/Message/MessageBox.d.ts +0 -6
  203. package/src/types/ui/Conversation/Message/MessageContent.d.ts +0 -3
  204. package/src/types/ui/Conversation/Message/MessageInfoBox.d.ts +0 -3
  205. package/src/types/ui/Conversation/Message/MessageRow.d.ts +0 -6
  206. package/src/types/ui/Conversation/Message/MessageText.d.ts +0 -3
  207. package/src/types/ui/Conversation/Message/index.d.ts +0 -20
  208. package/src/types/ui/Conversation/NextObserver/NextMessagesObserver.d.ts +0 -5
  209. package/src/types/ui/Conversation/NextObserver/index.d.ts +0 -1
  210. package/src/types/ui/Conversation/ReadObserver/MessageReadObserver.d.ts +0 -6
  211. package/src/types/ui/Conversation/ReadObserver/index.d.ts +0 -1
  212. package/src/types/ui/Conversation/SendingMessage/SendingMessageBox.d.ts +0 -7
  213. package/src/types/ui/Conversation/SendingMessage/SendingMessageContent.d.ts +0 -3
  214. package/src/types/ui/Conversation/SendingMessage/SendingMessageInfoBox.d.ts +0 -3
  215. package/src/types/ui/Conversation/SendingMessage/SendingMessageText.d.ts +0 -3
  216. package/src/types/ui/Conversation/SendingMessage/index.d.ts +0 -14
  217. package/src/types/ui/Conversation/SystemMessage/SystemMessageBox.d.ts +0 -6
  218. package/src/types/ui/Conversation/SystemMessage/SystemMessageRow.d.ts +0 -9
  219. package/src/types/ui/Conversation/SystemMessage/index.d.ts +0 -8
  220. package/src/types/ui/Conversation/index.d.ts +0 -12
  221. package/src/types/ui/Thread/ThreadActions.d.ts +0 -2
  222. package/src/types/ui/Thread/ThreadContext.d.ts +0 -8
  223. package/src/types/ui/Thread/ThreadPanel.d.ts +0 -14
  224. package/src/types/ui/Thread/index.d.ts +0 -3
  225. package/src/types/ui/color.d.ts +0 -6
  226. package/src/types/ui/common/Avatar.d.ts +0 -6
  227. package/src/types/ui/common/Icon.d.ts +0 -20
  228. package/src/types/ui/common/MessageSkeleton.d.ts +0 -5
  229. package/src/types/ui/common/index.d.ts +0 -11
  230. package/src/types/ui/customize.d.ts +0 -9
  231. package/src/types/ui/index.d.ts +0 -11
  232. package/src/types/ui/localizer.d.ts +0 -35
@@ -1,23 +1,23 @@
1
- import { Col, Row } from 'antd';
2
- import { customize, useCustomize } from '../customize';
3
- import { ConversationName } from './ConversationName';
4
- import { ConversationActions } from './ConversationActions';
5
-
6
- export const ConversationHeader = customize('ConversationHeader', () => {
7
- const Actions = useCustomize(ConversationActions);
8
-
9
- return (
10
- <div className="wxchtf-conversation-header">
11
- <Row justify="space-between" align="middle">
12
- <Col>
13
- <ConversationName />
14
- </Col>
15
- {Actions && (
16
- <Col className="wxchtf-conversation-actions">
17
- <Actions />
18
- </Col>
19
- )}
20
- </Row>
21
- </div>
22
- );
23
- });
1
+ import { Col, Row } from 'antd';
2
+ import { customize, useCustomize } from '../customize';
3
+ import { ConversationName } from './ConversationName';
4
+ import { ConversationActions } from './ConversationActions';
5
+
6
+ export const ConversationHeader = customize('ConversationHeader', () => {
7
+ const Actions = useCustomize(ConversationActions);
8
+
9
+ return (
10
+ <div className="wxchtf-conversation-header">
11
+ <Row justify="space-between" align="middle">
12
+ <Col>
13
+ <ConversationName />
14
+ </Col>
15
+ {Actions && (
16
+ <Col className="wxchtf-conversation-actions">
17
+ <Actions />
18
+ </Col>
19
+ )}
20
+ </Row>
21
+ </div>
22
+ );
23
+ });
@@ -1,7 +1,7 @@
1
- import { customize } from '../customize';
2
- import { useConversation } from './ConversationContext';
3
-
4
- export const ConversationName = customize('ConversationName', () => {
5
- const { name } = useConversation();
6
- return <span className="wxchtf-conversation-name">{name}</span>;
7
- });
1
+ import { customize } from '../customize';
2
+ import { useConversation } from './ConversationContext';
3
+
4
+ export const ConversationName = customize('ConversationName', () => {
5
+ const { name } = useConversation();
6
+ return <span className="wxchtf-conversation-name">{name}</span>;
7
+ });
@@ -1,40 +1,113 @@
1
- import { useCallback, useLayoutEffect, useRef, useState } from 'react';
2
- import { InputFilesBox } from './InputFilesBox';
3
- import { InputTextBox } from './InputTextBox';
4
- import { customize } from '../../customize';
5
- import { InputSubmitButtonBox } from './InputSubmitButtonBox';
6
- import { useConversation } from '../ConversationContext';
7
-
8
- function useFormState() {
9
- const { onSend } = useConversation();
10
- const [text, setText] = useState('');
11
-
12
- const onSubmit = useCallback(() => {
13
- if (text.length === 0) {
14
- return;
15
- }
16
-
17
- setText('');
18
- Promise.resolve(onSend({ text, files: [] })).catch(() => setText(text));
19
- // eslint-disable-next-line react-hooks/exhaustive-deps
20
- }, [text, onSend]);
21
-
22
- return [onSubmit, { text, setText }] as const;
23
- }
24
-
25
- export const InputBox = customize('InputBox', () => {
26
- const [onSend, { text, setText }] = useFormState();
27
- const inputRef = useRef<HTMLTextAreaElement>(null);
28
-
29
- useLayoutEffect(() => inputRef.current?.focus(), []);
30
-
31
- return (
32
- <div className="wxchtf-input-form">
33
- <div className="wxchtf-input-box">
34
- <InputFilesBox />
35
- <InputTextBox value={text} onSend={onSend} onChange={setText} inputRef={inputRef} />
36
- <InputSubmitButtonBox onSubmit={onSend} />
37
- </div>
38
- </div>
39
- );
40
- });
1
+ import { useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react';
2
+ import { InputFilesBox } from './InputFilesBox';
3
+ import { File } from '../../../core';
4
+ import { InputTextBox } from './InputTextBox';
5
+ import { customize, useCustomizeContext } from '../../customize';
6
+ import { InputSubmitButtonBox } from './InputSubmitButtonBox';
7
+ import { useConversation } from '../ConversationContext';
8
+ import { ConversationCustomizeValue } from '../Conversation';
9
+ import { InputBoxFileList } from './InputBoxFileList';
10
+
11
+ function useFormState() {
12
+ const { onSend } = useConversation();
13
+ const [text, setText] = useState('');
14
+ const [sending, setSending] = useState(false);
15
+ const { onUpload, files, loading, setFiles, showFileBox, onDeleteFile } = useFlippoInputFileBox();
16
+
17
+ const onSubmit = useCallback(() => {
18
+ if (text.length === 0 || loading) {
19
+ return;
20
+ }
21
+
22
+ setSending(true);
23
+ Promise.resolve(onSend({ text, files }))
24
+ .finally(() => setSending(false))
25
+ .then(() => {
26
+ setFiles([]);
27
+ setText('');
28
+ });
29
+ // eslint-disable-next-line react-hooks/exhaustive-deps
30
+ }, [text, onSend, files, setFiles, loading]);
31
+
32
+ return [onSubmit, { text, setText, files, onUpload, loading, showFileBox, onDeleteFile, sending }] as const;
33
+ }
34
+
35
+ function useFlippoInputFileBox() {
36
+ const [loading, setLoading] = useState(false);
37
+ const [files, setFiles] = useState<File[]>([]);
38
+ const { flippo } = useCustomizeContext<ConversationCustomizeValue>();
39
+
40
+ const onUpload = useCallback(
41
+ (files: globalThis.File[]) => {
42
+ if (!flippo) return;
43
+
44
+ setLoading(true);
45
+ Promise.all(files.map((file) => flippo.store(file)))
46
+ .then((references) =>
47
+ setFiles((prev) => [
48
+ ...prev,
49
+ ...references.map((reference, index) => ({
50
+ name: files[index].name,
51
+ ref: reference,
52
+ bytes: files[index].size,
53
+ })),
54
+ ]),
55
+ )
56
+ .finally(() => setLoading(false));
57
+ },
58
+ [flippo],
59
+ );
60
+
61
+ const onDeleteFile = useCallback((file: File) => {
62
+ setFiles((prev) => prev.filter((f) => f !== file));
63
+ }, []);
64
+
65
+ return { onUpload, files, loading, setFiles, showFileBox: !!flippo, onDeleteFile };
66
+ }
67
+
68
+ export const InputBox = customize('InputBox', () => {
69
+ const [onSend, { text, setText, files, loading, onUpload, showFileBox, onDeleteFile, sending }] =
70
+ useFormState();
71
+ const inputRef = useRef<HTMLTextAreaElement>(null);
72
+ const [showFileList, setShowFileList] = useState(false);
73
+ const toggleShowFileList = useCallback(() => setShowFileList((prev) => !prev), []);
74
+
75
+ useLayoutEffect(() => inputRef.current?.focus(), []);
76
+
77
+ useEffect(() => {
78
+ if (files.length === 0 && showFileList) {
79
+ setShowFileList(false);
80
+ }
81
+ }, [files, showFileList]);
82
+
83
+ return (
84
+ <div className="wxchtf-input-form">
85
+ <div className="wxchtf-input-box">
86
+ {showFileList && (
87
+ <div className="wxchtf-file-list-box">
88
+ <InputBoxFileList files={files} onDelete={onDeleteFile} disabled={sending} />
89
+ </div>
90
+ )}
91
+ <div className="wxchtf-input-box-row">
92
+ {showFileBox && (
93
+ <InputFilesBox
94
+ onAddedClick={toggleShowFileList}
95
+ onUpload={onUpload}
96
+ value={files}
97
+ loading={loading}
98
+ disabled={sending}
99
+ />
100
+ )}
101
+ <InputTextBox
102
+ value={text}
103
+ onSend={onSend}
104
+ onChange={setText}
105
+ disabled={sending}
106
+ inputRef={inputRef}
107
+ />
108
+ <InputSubmitButtonBox onSubmit={onSend} disabled={loading} loading={sending} />
109
+ </div>
110
+ </div>
111
+ </div>
112
+ );
113
+ });
@@ -0,0 +1,38 @@
1
+ import { Button } from 'antd';
2
+ import { File } from '../../../core';
3
+ import { Icon } from '../../common';
4
+ import { useCallback } from 'react';
5
+ import { useFormatter } from '../../useFormatter';
6
+ import { customize } from '../../customize';
7
+
8
+ export interface InputBoxFileProps {
9
+ file: File;
10
+ disabled?: boolean;
11
+ onDelete: (file: File) => void;
12
+ }
13
+
14
+ export const InputBoxFile = customize('InputBoxFile', (props: InputBoxFileProps) => {
15
+ const { file, disabled, onDelete } = props;
16
+ const formatter = useFormatter();
17
+ const onDeleteClick = useCallback(() => onDelete(file), [file, onDelete]);
18
+
19
+ return (
20
+ <div className="wxchtf-file">
21
+ <div className="wxchtf-file-info">
22
+ <div className="wxchtf-file-name" title={file.name}>
23
+ {file.name}
24
+ </div>
25
+ <div className="wxchtf-file-size">{formatter.size(file.bytes)}</div>
26
+ </div>
27
+ <div className="wxchtf-file-actions">
28
+ <Button
29
+ disabled={disabled}
30
+ className="wxchtf-delete"
31
+ type="link"
32
+ icon={<Icon type="delete-file" />}
33
+ onClick={onDeleteClick}
34
+ />
35
+ </div>
36
+ </div>
37
+ );
38
+ });
@@ -0,0 +1,21 @@
1
+ import { File } from '../../../core';
2
+ import { customize } from '../../customize';
3
+ import { InputBoxFile } from './InputBoxFile';
4
+
5
+ export interface InputBoxFileListProps {
6
+ files: File[];
7
+ disabled?: boolean;
8
+ onDelete: (file: File) => void;
9
+ }
10
+
11
+ export const InputBoxFileList = customize('InputBoxFileList', (props: InputBoxFileListProps) => {
12
+ const { files, onDelete, disabled } = props;
13
+
14
+ return (
15
+ <div className="wxchtf-file-list">
16
+ {files.map((file) => (
17
+ <InputBoxFile key={file.ref} file={file} onDelete={onDelete} disabled={disabled} />
18
+ ))}
19
+ </div>
20
+ );
21
+ });
@@ -1,9 +1,78 @@
1
- import { Button } from 'antd';
2
- import { customize } from '../../customize';
3
- import { Icon } from '../../common/Icon';
4
-
5
- export const InputFilesBox = customize('InputFilesBox', () => (
6
- <div className="wxchtf-add-files-box">
7
- <Button type="link" icon={<Icon type="attach" />} className="wxchtf-add-files-btn" />
8
- </div>
9
- ));
1
+ import { Button } from 'antd';
2
+ import { customize } from '../../customize';
3
+ import { Icon } from '../../common/Icon';
4
+ import { File } from '../../../core';
5
+ import { useCallback, useEffect, useRef } from 'react';
6
+
7
+ export interface InputFilesBoxProps {
8
+ value: File[];
9
+ accept?: string;
10
+ loading?: boolean;
11
+ disabled?: boolean;
12
+ onAddedClick?: () => void;
13
+ onUpload: (value: globalThis.File[]) => void;
14
+ }
15
+
16
+ export const InputFileButton = customize('InputFileButton', (props: InputFilesBoxProps) => {
17
+ const { onUpload, onAddedClick, accept, loading, value, disabled } = props;
18
+ const inputRef = useRef<HTMLInputElement | null>(null);
19
+ const onClick = useCallback(() => inputRef.current?.click(), []);
20
+ const countButtonRef = useRef<HTMLButtonElement | null>(null);
21
+
22
+ useEffect(() => {
23
+ countButtonRef.current?.classList.add('active');
24
+ }, [value]);
25
+
26
+ const onCountButtonAnimationEnd = useCallback(() => {
27
+ countButtonRef.current?.classList.remove('active');
28
+ }, []);
29
+
30
+ const onInputChange = useCallback(
31
+ (e: React.ChangeEvent<HTMLInputElement>) => {
32
+ const files = e.target.files;
33
+ files && files.length > 0 && onUpload(Array.from(files));
34
+ },
35
+ [onUpload],
36
+ );
37
+
38
+ return (
39
+ <>
40
+ <Button
41
+ loading={loading}
42
+ onClick={onClick}
43
+ type="link"
44
+ disabled={disabled}
45
+ icon={<Icon type="attach" />}
46
+ className="wxchtf-add-files-btn"
47
+ />
48
+ {value.length > 0 && (
49
+ <Button
50
+ ref={countButtonRef}
51
+ className="wxchtf-add-files-added-btn"
52
+ onAnimationIteration={onCountButtonAnimationEnd}
53
+ onClick={onAddedClick}
54
+ type="link"
55
+ disabled={disabled}
56
+ icon={<>+{value.length}</>}
57
+ />
58
+ )}
59
+ <input
60
+ value=""
61
+ accept={accept}
62
+ onChange={onInputChange}
63
+ ref={inputRef}
64
+ type="file"
65
+ multiple
66
+ style={{ display: 'none' }}
67
+ />
68
+ </>
69
+ );
70
+ });
71
+
72
+ export const InputFilesBox = customize('InputFilesBox', (props: InputFilesBoxProps) => {
73
+ return (
74
+ <div className="wxchtf-add-files-box">
75
+ <InputFileButton {...props} />
76
+ </div>
77
+ );
78
+ });
@@ -1,17 +1,26 @@
1
- import { Button } from 'antd';
2
- import { customize } from '../../customize';
3
- import { Icon } from '../../common/Icon';
4
-
5
- export interface InputSubmitButtonBoxProps {
6
- onSubmit: () => void;
7
- }
8
-
9
- export const InputSubmitButtonBox = customize('InputSubmitButtonBox', (props: InputSubmitButtonBoxProps) => {
10
- const { onSubmit } = props;
11
-
12
- return (
13
- <div className="wxchtf-submit-btn-box">
14
- <Button onClick={onSubmit} type="link" icon={<Icon type="send" />} className="wxchtf-submit-btn" />
15
- </div>
16
- );
17
- });
1
+ import { Button } from 'antd';
2
+ import { customize } from '../../customize';
3
+ import { Icon } from '../../common/Icon';
4
+
5
+ export interface InputSubmitButtonBoxProps {
6
+ onSubmit: () => void;
7
+ disabled?: boolean;
8
+ loading?: boolean;
9
+ }
10
+
11
+ export const InputSubmitButtonBox = customize('InputSubmitButtonBox', (props: InputSubmitButtonBoxProps) => {
12
+ const { onSubmit, disabled, loading } = props;
13
+
14
+ return (
15
+ <div className="wxchtf-submit-btn-box">
16
+ <Button
17
+ onClick={onSubmit}
18
+ type="link"
19
+ icon={<Icon type="send" />}
20
+ className="wxchtf-submit-btn"
21
+ disabled={disabled}
22
+ loading={loading}
23
+ />
24
+ </div>
25
+ );
26
+ });
@@ -1,53 +1,55 @@
1
- import { Input } from 'antd';
2
- import { customize } from '../../customize';
3
- import isHotkey from 'is-hotkey';
4
- import { RefObject, memo, useCallback } from 'react';
5
- import { useLocalizer } from '../../localizer';
6
- import { TextAreaProps } from 'antd/es/input';
7
-
8
- export interface TextInputBoxProps {
9
- value: string;
10
- onChange: (value: string) => void;
11
- onSend: (value: string) => void;
12
- inputRef?: RefObject<HTMLTextAreaElement>;
13
- }
14
-
15
- const isSend = isHotkey('ctrl+enter');
16
-
17
- const AUTO_SIZE: TextAreaProps['autoSize'] = { maxRows: 5, minRows: 1 };
18
-
19
- export const InputTextBox = customize(
20
- 'InputTextBox',
21
- memo((props: TextInputBoxProps) => {
22
- const { value, onChange, onSend, inputRef } = props;
23
- const localizer = useLocalizer();
24
-
25
- const onInputChange = useCallback(
26
- (e: React.ChangeEvent<HTMLTextAreaElement>) => onChange(e.target.value),
27
- [onChange],
28
- );
29
-
30
- const onKeyDown = useCallback(
31
- (e: React.KeyboardEvent<HTMLTextAreaElement>) => {
32
- if (isSend(e)) {
33
- onSend(value);
34
- }
35
- },
36
- [onSend, value],
37
- );
38
-
39
- return (
40
- <div className="wxchtf-text-input-box">
41
- <Input.TextArea
42
- ref={inputRef}
43
- value={value}
44
- onChange={onInputChange}
45
- autoSize={AUTO_SIZE}
46
- className="wxchtf-text-input-textarea"
47
- placeholder={localizer.input.placeholder()}
48
- onKeyDown={onKeyDown}
49
- />
50
- </div>
51
- );
52
- }),
53
- );
1
+ import { Input } from 'antd';
2
+ import { customize } from '../../customize';
3
+ import isHotkey from 'is-hotkey';
4
+ import { RefObject, memo, useCallback } from 'react';
5
+ import { useLocalizer } from '../../localizer';
6
+ import { TextAreaProps } from 'antd/es/input';
7
+
8
+ export interface TextInputBoxProps {
9
+ value: string;
10
+ onChange: (value: string) => void;
11
+ onSend: (value: string) => void;
12
+ disabled?: boolean;
13
+ inputRef?: RefObject<HTMLTextAreaElement>;
14
+ }
15
+
16
+ const isSend = isHotkey('ctrl+enter');
17
+
18
+ const AUTO_SIZE: TextAreaProps['autoSize'] = { maxRows: 5, minRows: 1 };
19
+
20
+ export const InputTextBox = customize(
21
+ 'InputTextBox',
22
+ memo((props: TextInputBoxProps) => {
23
+ const { value, onChange, onSend, disabled, inputRef } = props;
24
+ const localizer = useLocalizer();
25
+
26
+ const onInputChange = useCallback(
27
+ (e: React.ChangeEvent<HTMLTextAreaElement>) => onChange(e.target.value),
28
+ [onChange],
29
+ );
30
+
31
+ const onKeyDown = useCallback(
32
+ (e: React.KeyboardEvent<HTMLTextAreaElement>) => {
33
+ if (isSend(e)) {
34
+ onSend(value);
35
+ }
36
+ },
37
+ [onSend, value],
38
+ );
39
+
40
+ return (
41
+ <div className="wxchtf-text-input-box">
42
+ <Input.TextArea
43
+ ref={inputRef}
44
+ value={value}
45
+ onChange={onInputChange}
46
+ autoSize={AUTO_SIZE}
47
+ className="wxchtf-text-input-textarea"
48
+ placeholder={localizer.input.placeholder()}
49
+ onKeyDown={onKeyDown}
50
+ disabled={disabled}
51
+ />
52
+ </div>
53
+ );
54
+ }),
55
+ );
@@ -1,16 +1,23 @@
1
- import { InputBox } from './InputBox';
2
- import { InputFilesBox } from './InputFilesBox';
3
- import { InputSubmitButtonBox } from './InputSubmitButtonBox';
4
- import { InputTextBox } from './InputTextBox';
5
-
6
- export * from './InputBox';
7
- export * from './InputFilesBox';
8
- export * from './InputSubmitButtonBox';
9
- export * from './InputTextBox';
10
-
11
- export interface InputBoxCustomizeValue {
12
- InputBox?: typeof InputBox.Component | null;
13
- InputTextBox?: typeof InputTextBox.Component | null;
14
- InputFilesBox?: typeof InputFilesBox.Component | null;
15
- InputSubmitButtonBox?: typeof InputSubmitButtonBox.Component | null;
16
- }
1
+ import { InputBox } from './InputBox';
2
+ import { InputBoxFile } from './InputBoxFile';
3
+ import { InputBoxFileList } from './InputBoxFileList';
4
+ import { InputFileButton, InputFilesBox } from './InputFilesBox';
5
+ import { InputSubmitButtonBox } from './InputSubmitButtonBox';
6
+ import { InputTextBox } from './InputTextBox';
7
+
8
+ export * from './InputBox';
9
+ export * from './InputFilesBox';
10
+ export * from './InputSubmitButtonBox';
11
+ export * from './InputTextBox';
12
+ export * from './InputBoxFileList';
13
+ export * from './InputBoxFile';
14
+
15
+ export interface InputBoxCustomizeValue {
16
+ InputBox?: typeof InputBox.Component | null;
17
+ InputTextBox?: typeof InputTextBox.Component | null;
18
+ InputFilesBox?: typeof InputFilesBox.Component | null;
19
+ InputSubmitButtonBox?: typeof InputSubmitButtonBox.Component | null;
20
+ InputBoxFileList?: typeof InputBoxFileList.Component | null;
21
+ InputBoxFile?: typeof InputBoxFile.Component | null;
22
+ InputFileButton?: typeof InputFileButton.Component | null;
23
+ }
@@ -1,13 +1,13 @@
1
- import { customize } from '../../customize';
2
- import { Avatar } from '../../common/Avatar';
3
- import type { MessageBoxProps } from './MessageBox';
4
-
5
- export const MessageAuthor = customize('MessageAuthor', (props: MessageBoxProps) => {
6
- const { sentBy } = props.message;
7
-
8
- return (
9
- <div className="wxchtf-message-author">
10
- <Avatar account={sentBy} />
11
- </div>
12
- );
13
- });
1
+ import { customize } from '../../customize';
2
+ import { Avatar } from '../../common/Avatar';
3
+ import type { MessageBoxProps } from './MessageBox';
4
+
5
+ export const MessageAuthor = customize('MessageAuthor', (props: MessageBoxProps) => {
6
+ const { sentBy } = props.message;
7
+
8
+ return (
9
+ <div className="wxchtf-message-author">
10
+ <Avatar account={sentBy} />
11
+ </div>
12
+ );
13
+ });
@@ -1,20 +1,20 @@
1
- import { useRef } from 'react';
2
- import { customize } from '../../customize';
3
- import { MessageReadObserver } from '../ReadObserver';
4
- import { MessageRow } from './MessageRow';
5
- import { MessageBase } from '../../../core';
6
-
7
- export interface MessageBoxProps {
8
- message: MessageBase;
9
- }
10
-
11
- export const MessageBox = customize('MessageBox', (props: MessageBoxProps) => {
12
- const ref = useRef<HTMLDivElement | null>(null);
13
-
14
- return (
15
- <>
16
- <MessageReadObserver messageRef={ref} {...props} />
17
- <MessageRow containerRef={ref} {...props} />
18
- </>
19
- );
20
- });
1
+ import { useRef } from 'react';
2
+ import { customize } from '../../customize';
3
+ import { MessageReadObserver } from '../ReadObserver';
4
+ import { MessageRow } from './MessageRow';
5
+ import { MessageBase } from '../../../core';
6
+
7
+ export interface MessageBoxProps {
8
+ message: MessageBase;
9
+ }
10
+
11
+ export const MessageBox = customize('MessageBox', (props: MessageBoxProps) => {
12
+ const ref = useRef<HTMLDivElement | null>(null);
13
+
14
+ return (
15
+ <>
16
+ <MessageReadObserver messageRef={ref} {...props} />
17
+ <MessageRow containerRef={ref} {...props} />
18
+ </>
19
+ );
20
+ });
@@ -1,11 +1,15 @@
1
- import { customize } from '../../customize';
2
- import { MessageText } from './MessageText';
3
- import type { MessageBoxProps } from './MessageBox';
4
-
5
- export const MessageContent = customize('MessageContent', (props: MessageBoxProps) => {
6
- return (
7
- <div className="wxchtf-message-content">
8
- <MessageText {...props} />
9
- </div>
10
- );
11
- });
1
+ import { customize } from '../../customize';
2
+ import { MessageText } from './MessageText';
3
+ import type { MessageBoxProps } from './MessageBox';
4
+ import { MessageFileList } from './MessageFileList';
5
+
6
+ export const MessageContent = customize('MessageContent', (props: MessageBoxProps) => {
7
+ const { files } = props.message;
8
+
9
+ return (
10
+ <div className="wxchtf-message-content">
11
+ <MessageText {...props} />
12
+ {files.length > 0 && <MessageFileList {...props} />}
13
+ </div>
14
+ );
15
+ });