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