@webinex/chatify 2.0.0-alpha12 → 2.0.0-alpha14

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 (144) hide show
  1. package/dist/{Chatify-CwAfN1wu.js → Chatify-CP2jgo8d.js} +191 -118
  2. package/dist/Chatify-CP2jgo8d.js.map +1 -0
  3. package/dist/Chatify.css +28 -0
  4. package/dist/audit.js +3 -2
  5. package/dist/audit.js.map +1 -1
  6. package/dist/index.js +1 -1
  7. package/dist/types/audit/index.d.ts +17 -15
  8. package/dist/types/core/api/api.d.ts +146 -0
  9. package/dist/types/ui/Chat/ChatContext.d.ts +2 -0
  10. package/dist/types/ui/Chat/ChatPanel.d.ts +7 -0
  11. package/dist/types/ui/Chat/ChatView.d.ts +4 -2
  12. package/dist/types/ui/ChatGroup/ChatGroupContext.d.ts +4 -1
  13. package/dist/types/ui/ChatGroup/ChatGroupPanel.d.ts +21 -2
  14. package/dist/types/ui/Conversation/Conversation.d.ts +1 -0
  15. package/dist/types/ui/Conversation/ConversationContext.d.ts +1 -0
  16. package/dist/types/ui/Conversation/ConversationHeader.d.ts +4 -1
  17. package/dist/types/ui/localizer.d.ts +4 -1
  18. package/dist/types/ui/useCompact.d.ts +4 -0
  19. package/package.json +81 -81
  20. package/src/audit/AuditChatList.tsx +25 -25
  21. package/src/audit/AuditConversationPanel.tsx +49 -48
  22. package/src/audit/AuditPanel.tsx +76 -76
  23. package/src/audit/AuditPanelCustomizeValue.ts +11 -11
  24. package/src/audit/AuditSearch.tsx +89 -89
  25. package/src/audit/AuditSearchValue.tsx +42 -42
  26. package/src/audit/auditApi.tsx +113 -113
  27. package/src/audit/index.d.ts +18 -18
  28. package/src/audit/index.tsx +28 -28
  29. package/src/audit/styles.scss +72 -72
  30. package/src/core/api/api.ts +675 -669
  31. package/src/core/api/baseApi.ts +38 -38
  32. package/src/core/api/index.ts +1 -1
  33. package/src/core/client.ts +298 -298
  34. package/src/core/constants.ts +1 -1
  35. package/src/core/debounce.ts +90 -90
  36. package/src/core/index.ts +4 -4
  37. package/src/core/types.tsx +182 -182
  38. package/src/index.ts +2 -2
  39. package/src/styles/aside.scss +34 -26
  40. package/src/styles/chat-list.scss +138 -138
  41. package/src/styles/chat.scss +11 -11
  42. package/src/styles/conversation.scss +199 -200
  43. package/src/styles/index.scss +227 -220
  44. package/src/styles/input.scss +148 -148
  45. package/src/styles/keyframes.scss +14 -14
  46. package/src/styles/members.scss +30 -13
  47. package/src/styles/mixins.scss +38 -25
  48. package/src/styles/variables.scss +13 -13
  49. package/src/ui/Chat/ChatContext.tsx +32 -30
  50. package/src/ui/Chat/ChatEditableHeaderName.tsx +63 -63
  51. package/src/ui/Chat/ChatHeaderActions.tsx +19 -19
  52. package/src/ui/Chat/ChatPanel.tsx +46 -30
  53. package/src/ui/Chat/ChatView.tsx +122 -115
  54. package/src/ui/Chat/Members/ChatMembersButton.tsx +9 -9
  55. package/src/ui/Chat/Members/ChatMembersPanel.tsx +128 -112
  56. package/src/ui/Chat/Members/ChatMembersPreview.tsx +25 -25
  57. package/src/ui/Chat/Members/index.ts +13 -13
  58. package/src/ui/Chat/index.ts +6 -6
  59. package/src/ui/ChatGroup/AutoReply/AutoReplyButton.tsx +21 -21
  60. package/src/ui/ChatGroup/AutoReply/AutoReplyForm.tsx +50 -50
  61. package/src/ui/ChatGroup/AutoReply/AutoReplyPanel.tsx +94 -94
  62. package/src/ui/ChatGroup/AutoReply/AutoReplyPeriodInput.tsx +22 -22
  63. package/src/ui/ChatGroup/AutoReply/AutoReplyTextInput.tsx +22 -22
  64. package/src/ui/ChatGroup/AutoReply/index.ts +19 -19
  65. package/src/ui/ChatGroup/ChatGroupContext.tsx +63 -61
  66. package/src/ui/ChatGroup/ChatGroupPanel.tsx +110 -75
  67. package/src/ui/ChatGroup/Create/CreateChatButton.tsx +15 -15
  68. package/src/ui/ChatGroup/Create/CreateChatForm.tsx +36 -36
  69. package/src/ui/ChatGroup/Create/CreateChatMemberInput.tsx +65 -65
  70. package/src/ui/ChatGroup/Create/CreateChatNameInput.tsx +25 -25
  71. package/src/ui/ChatGroup/Create/CreateChatPanel.tsx +45 -45
  72. package/src/ui/ChatGroup/Create/index.ts +19 -19
  73. package/src/ui/ChatGroup/Layout/ChatGroupActions.tsx +15 -15
  74. package/src/ui/ChatGroup/Layout/ChatGroupAside.tsx +12 -12
  75. package/src/ui/ChatGroup/Layout/ChatGroupBody.tsx +17 -10
  76. package/src/ui/ChatGroup/Layout/ChatGroupFooter.tsx +3 -3
  77. package/src/ui/ChatGroup/Layout/ChatGroupHeader.tsx +5 -5
  78. package/src/ui/ChatGroup/Layout/ChatGroupMain.tsx +21 -19
  79. package/src/ui/ChatGroup/Layout/index.ts +22 -22
  80. package/src/ui/ChatGroup/List/ChatListPanel.tsx +28 -28
  81. package/src/ui/ChatGroup/List/index.ts +8 -8
  82. package/src/ui/ChatGroup/index.ts +6 -6
  83. package/src/ui/Chatify.tsx +15 -15
  84. package/src/ui/Conversation/Conversation.tsx +96 -92
  85. package/src/ui/Conversation/ConversationActions.tsx +12 -12
  86. package/src/ui/Conversation/ConversationBody.tsx +28 -28
  87. package/src/ui/Conversation/ConversationContext.ts +31 -30
  88. package/src/ui/Conversation/ConversationHeader.tsx +35 -19
  89. package/src/ui/Conversation/ConversationName.tsx +7 -7
  90. package/src/ui/Conversation/InputBox/InputBox.tsx +126 -126
  91. package/src/ui/Conversation/InputBox/InputBoxFile.tsx +38 -38
  92. package/src/ui/Conversation/InputBox/InputBoxFileList.tsx +21 -21
  93. package/src/ui/Conversation/InputBox/InputFilesBox.tsx +78 -78
  94. package/src/ui/Conversation/InputBox/InputSubmitButtonBox.tsx +26 -26
  95. package/src/ui/Conversation/InputBox/InputTextBox.tsx +63 -61
  96. package/src/ui/Conversation/InputBox/index.ts +23 -23
  97. package/src/ui/Conversation/Message/MessageAuthor.tsx +13 -13
  98. package/src/ui/Conversation/Message/MessageBox.tsx +20 -20
  99. package/src/ui/Conversation/Message/MessageContent.tsx +15 -15
  100. package/src/ui/Conversation/Message/MessageFile.tsx +54 -54
  101. package/src/ui/Conversation/Message/MessageFileList.tsx +14 -14
  102. package/src/ui/Conversation/Message/MessageInfoBox.tsx +28 -28
  103. package/src/ui/Conversation/Message/MessageRow.tsx +28 -28
  104. package/src/ui/Conversation/Message/MessageText.tsx +7 -7
  105. package/src/ui/Conversation/Message/index.ts +28 -28
  106. package/src/ui/Conversation/NextObserver/NextMessagesObserver.tsx +47 -47
  107. package/src/ui/Conversation/NextObserver/index.ts +1 -1
  108. package/src/ui/Conversation/ReadObserver/MessageReadObserver.tsx +49 -49
  109. package/src/ui/Conversation/ReadObserver/index.ts +1 -1
  110. package/src/ui/Conversation/SendingMessage/SendingMessageBox.tsx +16 -16
  111. package/src/ui/Conversation/SendingMessage/SendingMessageContent.tsx +13 -13
  112. package/src/ui/Conversation/SendingMessage/SendingMessageInfoBox.tsx +13 -13
  113. package/src/ui/Conversation/SendingMessage/SendingMessageText.tsx +7 -7
  114. package/src/ui/Conversation/SendingMessage/index.ts +16 -16
  115. package/src/ui/Conversation/SystemMessage/SystemMessageBox.tsx +20 -20
  116. package/src/ui/Conversation/SystemMessage/SystemMessageRow.tsx +28 -28
  117. package/src/ui/Conversation/SystemMessage/index.ts +10 -10
  118. package/src/ui/Conversation/index.ts +13 -13
  119. package/src/ui/Thread/ThreadActions.tsx +22 -22
  120. package/src/ui/Thread/ThreadContext.ts +13 -13
  121. package/src/ui/Thread/ThreadPanel.tsx +128 -127
  122. package/src/ui/Thread/index.tsx +3 -3
  123. package/src/ui/color.ts +20 -20
  124. package/src/ui/common/Avatar.tsx +20 -20
  125. package/src/ui/common/ChatList/ChatList.tsx +83 -84
  126. package/src/ui/common/ChatList/ChatListItemAvatar.tsx +22 -22
  127. package/src/ui/common/ChatList/ChatListItemBox.tsx +32 -32
  128. package/src/ui/common/ChatList/ChatListItemLastMessage.tsx +15 -15
  129. package/src/ui/common/ChatList/ChatListItemLastMessageAuthor.tsx +15 -15
  130. package/src/ui/common/ChatList/ChatListItemLastMessageContent.tsx +21 -21
  131. package/src/ui/common/ChatList/ChatListItemLastMessageSentAt.tsx +22 -22
  132. package/src/ui/common/ChatList/ChatListItemName.tsx +8 -8
  133. package/src/ui/common/ChatList/ChatListItemUnreadCount.tsx +12 -12
  134. package/src/ui/common/ChatList/ChatListValue.ts +9 -9
  135. package/src/ui/common/ChatList/index.ts +32 -32
  136. package/src/ui/common/Icon.tsx +48 -48
  137. package/src/ui/common/MessageSkeleton.tsx +20 -20
  138. package/src/ui/common/index.ts +14 -14
  139. package/src/ui/customize.tsx +51 -51
  140. package/src/ui/index.ts +11 -11
  141. package/src/ui/localizer.tsx +148 -137
  142. package/src/ui/useCompact.tsx +32 -0
  143. package/src/ui/useFormatter.tsx +17 -17
  144. package/dist/Chatify-CwAfN1wu.js.map +0 -1
@@ -1,13 +1,13 @@
1
- export * from './InputBox';
2
- export * from './Message';
3
- export * from './NextObserver';
4
- export * from './ReadObserver';
5
- export * from './SendingMessage';
6
- export * from './SystemMessage';
7
-
8
- export * from './ConversationActions';
9
- export * from './ConversationBody';
10
- export * from './ConversationHeader';
11
- export * from './ConversationName';
12
- export * from './ConversationContext';
13
- export * from './Conversation';
1
+ export * from './InputBox';
2
+ export * from './Message';
3
+ export * from './NextObserver';
4
+ export * from './ReadObserver';
5
+ export * from './SendingMessage';
6
+ export * from './SystemMessage';
7
+
8
+ export * from './ConversationActions';
9
+ export * from './ConversationBody';
10
+ export * from './ConversationHeader';
11
+ export * from './ConversationName';
12
+ export * from './ConversationContext';
13
+ export * from './Conversation';
@@ -1,22 +1,22 @@
1
- import { Button, Tooltip } from 'antd';
2
- import { customize } from '../customize';
3
- import { useThreadContext } from './ThreadContext';
4
- import { Icon } from '../common/Icon';
5
-
6
- export const ThreadActions = customize('ThreadActions', () => {
7
- const { watch, onWatch } = useThreadContext();
8
-
9
- if (!watch) {
10
- return (
11
- <Tooltip title="Watch thread">
12
- <Button type="link" icon={<Icon type="watch" />} onClick={() => onWatch(true)} />
13
- </Tooltip>
14
- );
15
- }
16
-
17
- return (
18
- <Tooltip title="Unwatch thread">
19
- <Button type="link" icon={<Icon type="unwatch" />} onClick={() => onWatch(false)} />
20
- </Tooltip>
21
- );
22
- });
1
+ import { Button, Tooltip } from 'antd';
2
+ import { customize } from '../customize';
3
+ import { useThreadContext } from './ThreadContext';
4
+ import { Icon } from '../common/Icon';
5
+
6
+ export const ThreadActions = customize('ThreadActions', () => {
7
+ const { watch, onWatch } = useThreadContext();
8
+
9
+ if (!watch) {
10
+ return (
11
+ <Tooltip title="Watch thread">
12
+ <Button type="link" icon={<Icon type="watch" />} onClick={() => onWatch(true)} />
13
+ </Tooltip>
14
+ );
15
+ }
16
+
17
+ return (
18
+ <Tooltip title="Unwatch thread">
19
+ <Button type="link" icon={<Icon type="unwatch" />} onClick={() => onWatch(false)} />
20
+ </Tooltip>
21
+ );
22
+ });
@@ -1,13 +1,13 @@
1
- import React from 'react';
2
-
3
- export interface ThreadContextValue {
4
- id: string;
5
- watch: boolean;
6
- onWatch: (value: boolean) => void;
7
- }
8
-
9
- export const ThreadContext = React.createContext<ThreadContextValue>(null!);
10
-
11
- export function useThreadContext() {
12
- return React.useContext(ThreadContext);
13
- }
1
+ import React from 'react';
2
+
3
+ export interface ThreadContextValue {
4
+ id: string;
5
+ watch: boolean;
6
+ onWatch: (value: boolean) => void;
7
+ }
8
+
9
+ export const ThreadContext = React.createContext<ThreadContextValue>(null!);
10
+
11
+ export function useThreadContext() {
12
+ return React.useContext(ThreadContext);
13
+ }
@@ -1,127 +1,128 @@
1
- import { useCallback, useEffect, useMemo } from 'react';
2
- import { MessageBody, chatifyApi, parseThreadMessageId } from '../../core';
3
- import { Conversation, ConversationCustomizeValue, ConversationProps } from '../Conversation';
4
- import { ThreadContext, ThreadContextValue } from './ThreadContext';
5
- import { Localizer, LocalizerContext, defaultLocalizer } from '../localizer';
6
- import { CustomizeContext } from '../customize';
7
- import { ThreadActions } from './ThreadActions';
8
- import { CommonCustomizeValue } from '../common';
9
-
10
- export interface ThreadCustomizeValue extends ConversationCustomizeValue, CommonCustomizeValue {
11
- ThreadActions?: typeof ThreadActions.Component | null;
12
- }
13
-
14
- export interface ThreadPanelProps {
15
- threadId: string;
16
- className?: string;
17
- customize?: ThreadCustomizeValue;
18
- localizer?: Localizer;
19
- }
20
-
21
- function usePanelState(props: ThreadPanelProps) {
22
- const { threadId } = props;
23
- const { data: thread } = chatifyApi.useGetThreadQuery({ id: threadId });
24
- const { data: messageList } = chatifyApi.useGetThreadMessageListQuery({ threadId });
25
- const { id, name, archive, lastReadMessageId, watch } = thread ?? {};
26
- const { messages, hasMore } = messageList ?? {};
27
-
28
- const [read] = chatifyApi.useReadThreadMessageMutation();
29
- const onRead = useCallback((id: string) => read({ id }), [read]);
30
-
31
- const [fetchNext, { isLoading: isFetchNextLoading }] = chatifyApi.useFetchNextThreadMessageListMutation();
32
- const onNext = useCallback(() => fetchNext({ threadId }), [fetchNext, threadId]);
33
-
34
- const [send] = chatifyApi.useSendThreadMessageMutation();
35
- const onSend = useCallback(
36
- (message: MessageBody) => send({ body: message, threadId }).unwrap(),
37
- [threadId, send],
38
- );
39
-
40
- const { data: readQueue } = chatifyApi.useGetThreadMessageReadQueueQuery();
41
-
42
- const conversation = useMemo(() => {
43
- if (!id) {
44
- return null;
45
- }
46
-
47
- const result: ConversationProps = {
48
- value: { id: id!, name: name!, active: !archive, lastReadMessageId: lastReadMessageId ?? null },
49
- messages,
50
- hasMore,
51
- onNext,
52
- nextLoading: isFetchNextLoading,
53
- onRead,
54
- onSend,
55
- noReadTracking: !watch,
56
- isReading: (id: string) =>
57
- readQueue!.some(
58
- (unit) => parseThreadMessageId(unit.value)[0] === parseThreadMessageId(id)[0] && id <= unit.value,
59
- ),
60
- };
61
-
62
- return result;
63
- }, [
64
- onNext,
65
- onRead,
66
- onSend,
67
- isFetchNextLoading,
68
- id,
69
- name,
70
- archive,
71
- messages,
72
- hasMore,
73
- lastReadMessageId,
74
- readQueue,
75
- watch,
76
- ]);
77
-
78
- const [watchThread] = chatifyApi.useWatchThreadMutation();
79
-
80
- const threadContext = useMemo<ThreadContextValue | null>(
81
- () =>
82
- thread
83
- ? {
84
- id: thread.id,
85
- watch: thread.watch,
86
- onWatch: (value) => watchThread({ id: thread.id, watch: value }).unwrap(),
87
- }
88
- : null,
89
- [thread, watchThread],
90
- );
91
-
92
- return [conversation, threadContext] as const;
93
- }
94
-
95
- const DEFAULT_CUSTOMIZE: ThreadCustomizeValue = {
96
- ConversationActions: () => <ThreadActions />,
97
- };
98
-
99
- export function ThreadPanel(props: ThreadPanelProps) {
100
- const { threadId, customize, localizer = defaultLocalizer, className = '' } = props;
101
- const [conversation, threadContext] = usePanelState(props);
102
- const customizeMergeValue = useMemo(() => ({ ...DEFAULT_CUSTOMIZE, ...customize }), [customize]);
103
-
104
- useEffect(() => {
105
- chatifyApi.settings.client.connectToThread(threadId);
106
-
107
- return () => {
108
- chatifyApi.settings.client.disconnectFromThread(threadId);
109
- };
110
- }, [threadId]);
111
-
112
- if (!conversation || !threadContext) {
113
- return null;
114
- }
115
-
116
- return (
117
- <LocalizerContext.Provider value={localizer}>
118
- <ThreadContext.Provider value={threadContext}>
119
- <CustomizeContext.Provider value={customizeMergeValue as any}>
120
- <div className={`wxchtf-chatify wxchtf-thread ${className}`}>
121
- {conversation && <Conversation {...conversation} />}
122
- </div>
123
- </CustomizeContext.Provider>
124
- </ThreadContext.Provider>
125
- </LocalizerContext.Provider>
126
- );
127
- }
1
+ import { useCallback, useEffect, useMemo } from 'react';
2
+ import { MessageBody, chatifyApi, parseThreadMessageId } from '../../core';
3
+ import { Conversation, ConversationCustomizeValue, ConversationProps } from '../Conversation';
4
+ import { ThreadContext, ThreadContextValue } from './ThreadContext';
5
+ import { Localizer, LocalizerContext, defaultLocalizer } from '../localizer';
6
+ import { CustomizeContext } from '../customize';
7
+ import { ThreadActions } from './ThreadActions';
8
+ import { CommonCustomizeValue } from '../common';
9
+
10
+ export interface ThreadCustomizeValue extends ConversationCustomizeValue, CommonCustomizeValue {
11
+ ThreadActions?: typeof ThreadActions.Component | null;
12
+ }
13
+
14
+ export interface ThreadPanelProps {
15
+ threadId: string;
16
+ className?: string;
17
+ customize?: ThreadCustomizeValue;
18
+ localizer?: Localizer;
19
+ }
20
+
21
+ function usePanelState(props: ThreadPanelProps) {
22
+ const { threadId } = props;
23
+ const { data: thread } = chatifyApi.useGetThreadQuery({ id: threadId });
24
+ const { data: messageList } = chatifyApi.useGetThreadMessageListQuery({ threadId });
25
+ const { id, name, archive, lastReadMessageId, watch } = thread ?? {};
26
+ const { messages, hasMore } = messageList ?? {};
27
+
28
+ const [read] = chatifyApi.useReadThreadMessageMutation();
29
+ const onRead = useCallback((id: string) => read({ id }), [read]);
30
+
31
+ const [fetchNext, { isLoading: isFetchNextLoading }] = chatifyApi.useFetchNextThreadMessageListMutation();
32
+ const onNext = useCallback(() => fetchNext({ threadId }), [fetchNext, threadId]);
33
+
34
+ const [send] = chatifyApi.useSendThreadMessageMutation();
35
+ const onSend = useCallback(
36
+ (message: MessageBody) => send({ body: message, threadId }).unwrap(),
37
+ [threadId, send],
38
+ );
39
+
40
+ const { data: readQueue } = chatifyApi.useGetThreadMessageReadQueueQuery();
41
+
42
+ const conversation = useMemo(() => {
43
+ if (!id) {
44
+ return null;
45
+ }
46
+
47
+ const result: ConversationProps = {
48
+ value: { id: id!, name: name!, active: !archive, lastReadMessageId: lastReadMessageId ?? null },
49
+ messages,
50
+ hasMore,
51
+ onNext,
52
+ nextLoading: isFetchNextLoading,
53
+ onRead,
54
+ onSend,
55
+ noReadTracking: !watch,
56
+ compact: false,
57
+ isReading: (id: string) =>
58
+ readQueue!.some(
59
+ (unit) => parseThreadMessageId(unit.value)[0] === parseThreadMessageId(id)[0] && id <= unit.value,
60
+ ),
61
+ };
62
+
63
+ return result;
64
+ }, [
65
+ onNext,
66
+ onRead,
67
+ onSend,
68
+ isFetchNextLoading,
69
+ id,
70
+ name,
71
+ archive,
72
+ messages,
73
+ hasMore,
74
+ lastReadMessageId,
75
+ readQueue,
76
+ watch,
77
+ ]);
78
+
79
+ const [watchThread] = chatifyApi.useWatchThreadMutation();
80
+
81
+ const threadContext = useMemo<ThreadContextValue | null>(
82
+ () =>
83
+ thread
84
+ ? {
85
+ id: thread.id,
86
+ watch: thread.watch,
87
+ onWatch: (value) => watchThread({ id: thread.id, watch: value }).unwrap(),
88
+ }
89
+ : null,
90
+ [thread, watchThread],
91
+ );
92
+
93
+ return [conversation, threadContext] as const;
94
+ }
95
+
96
+ const DEFAULT_CUSTOMIZE: ThreadCustomizeValue = {
97
+ ConversationActions: () => <ThreadActions />,
98
+ };
99
+
100
+ export function ThreadPanel(props: ThreadPanelProps) {
101
+ const { threadId, customize, localizer = defaultLocalizer, className = '' } = props;
102
+ const [conversation, threadContext] = usePanelState(props);
103
+ const customizeMergeValue = useMemo(() => ({ ...DEFAULT_CUSTOMIZE, ...customize }), [customize]);
104
+
105
+ useEffect(() => {
106
+ chatifyApi.settings.client.connectToThread(threadId);
107
+
108
+ return () => {
109
+ chatifyApi.settings.client.disconnectFromThread(threadId);
110
+ };
111
+ }, [threadId]);
112
+
113
+ if (!conversation || !threadContext) {
114
+ return null;
115
+ }
116
+
117
+ return (
118
+ <LocalizerContext.Provider value={localizer}>
119
+ <ThreadContext.Provider value={threadContext}>
120
+ <CustomizeContext.Provider value={customizeMergeValue as any}>
121
+ <div className={`wxchtf-chatify wxchtf-thread ${className}`}>
122
+ {conversation && <Conversation {...conversation} />}
123
+ </div>
124
+ </CustomizeContext.Provider>
125
+ </ThreadContext.Provider>
126
+ </LocalizerContext.Provider>
127
+ );
128
+ }
@@ -1,3 +1,3 @@
1
- export * from './ThreadActions';
2
- export * from './ThreadPanel';
3
- export * from './ThreadContext';
1
+ export * from './ThreadActions';
2
+ export * from './ThreadPanel';
3
+ export * from './ThreadContext';
package/src/ui/color.ts CHANGED
@@ -1,20 +1,20 @@
1
- interface ColorOptions {
2
- saturation?: number;
3
- lightness?: number;
4
- }
5
-
6
- const DEFAULT_COLOR_OPTIONS: ColorOptions = {
7
- saturation: 100,
8
- lightness: 75,
9
- };
10
-
11
- export function color(value: string, options: ColorOptions = {}) {
12
- options = Object.assign({}, DEFAULT_COLOR_OPTIONS, options);
13
-
14
- let hash = 0;
15
- for (let i = 0; i < value.length; i++) {
16
- hash = value.charCodeAt(i) + ((hash << 5) - hash);
17
- hash = hash & hash;
18
- }
19
- return `hsl(${hash % 360}, ${options.saturation}%, ${options.lightness}%)`;
20
- }
1
+ interface ColorOptions {
2
+ saturation?: number;
3
+ lightness?: number;
4
+ }
5
+
6
+ const DEFAULT_COLOR_OPTIONS: ColorOptions = {
7
+ saturation: 100,
8
+ lightness: 75,
9
+ };
10
+
11
+ export function color(value: string, options: ColorOptions = {}) {
12
+ options = Object.assign({}, DEFAULT_COLOR_OPTIONS, options);
13
+
14
+ let hash = 0;
15
+ for (let i = 0; i < value.length; i++) {
16
+ hash = value.charCodeAt(i) + ((hash << 5) - hash);
17
+ hash = hash & hash;
18
+ }
19
+ return `hsl(${hash % 360}, ${options.saturation}%, ${options.lightness}%)`;
20
+ }
@@ -1,20 +1,20 @@
1
- import { FC, ForwardedRef, forwardRef } from 'react';
2
- import { Account } from '../../core';
3
- import { Avatar as AntdAvatar } from 'antd';
4
- import { customize } from '../customize';
5
-
6
- export interface AvatarProps {
7
- account: Account;
8
- }
9
-
10
- const _Avatar: FC<AvatarProps> = forwardRef(
11
- (props: AvatarProps, forwardRef: ForwardedRef<HTMLSpanElement>) => {
12
- const { account } = props;
13
-
14
- return <AntdAvatar ref={forwardRef} src={account.avatar} />;
15
- },
16
- );
17
-
18
- _Avatar.displayName = 'Avatar';
19
-
20
- export const Avatar = customize('Avatar', _Avatar);
1
+ import { FC, ForwardedRef, forwardRef } from 'react';
2
+ import { Account } from '../../core';
3
+ import { Avatar as AntdAvatar } from 'antd';
4
+ import { customize } from '../customize';
5
+
6
+ export interface AvatarProps {
7
+ account: Account;
8
+ }
9
+
10
+ const _Avatar: FC<AvatarProps> = forwardRef(
11
+ (props: AvatarProps, forwardRef: ForwardedRef<HTMLSpanElement>) => {
12
+ const { account } = props;
13
+
14
+ return <AntdAvatar ref={forwardRef} src={account.avatar} />;
15
+ },
16
+ );
17
+
18
+ _Avatar.displayName = 'Avatar';
19
+
20
+ export const Avatar = customize('Avatar', _Avatar);
@@ -1,84 +1,83 @@
1
- import { Menu, MenuProps } from 'antd';
2
- import { useMemo } from 'react';
3
- import { ChatListItemBox } from './ChatListItemBox';
4
- import { customize } from '../../customize';
5
- import { ChatListValue } from './ChatListValue';
6
- import { useLocalizer } from '../../localizer';
7
- import { messageSequencePart } from '../../../core';
8
-
9
- export interface ChatListProps {
10
- className?: string;
11
- items: ChatListValue[];
12
- selected: string | null;
13
- onSelect?: (id: string) => void;
14
-
15
- /**
16
- * If true, do not show read status.
17
- */
18
- noRead?: boolean;
19
-
20
- /**
21
- * If set, shows a message at the bottom indicating that only the top N chats are shown.
22
- */
23
- top?: number;
24
- }
25
-
26
- function useOnSelect(props: ChatListProps) {
27
- const { onSelect } = props;
28
-
29
- return useMemo(
30
- () =>
31
- onSelect
32
- ? (info: Parameters<NonNullable<MenuProps['onSelect']>>[0]) => onSelect(info.key as string)
33
- : undefined,
34
- [onSelect],
35
- );
36
- }
37
-
38
- function useMenuItems(props: ChatListProps) {
39
- //28b2a1a6-c052-4761-ad2d-95ce36d59f06-000000001
40
- const { items, noRead, top } = props;
41
- const localizer = useLocalizer();
42
-
43
- return useMemo<MenuProps['items']>(() => {
44
- const result = items
45
- ?.slice()
46
- .sort(
47
- (a, b) => -messageSequencePart(a.lastMessage.id).localeCompare(messageSequencePart(b.lastMessage.id)),
48
- )
49
- .map((x) => ({ key: x.id, label: <ChatListItemBox chat={x} noRead={noRead} /> }));
50
-
51
- if (top != null) {
52
- return [
53
- ...result,
54
- {
55
- type: 'item',
56
- key: 'top',
57
- disabled: true,
58
- label: (
59
- <div style={{ textAlign: 'center', cursor: 'text', fontStyle: 'italic' }}>
60
- {localizer.chatList.topShown(top)}
61
- </div>
62
- ),
63
- },
64
- ];
65
- }
66
-
67
- return result;
68
- }, [items, noRead, top, localizer]);
69
- }
70
-
71
- export const ChatList = customize('ChatList', (props: ChatListProps) => {
72
- const { selected: selectedChatId } = props;
73
- const selected = useMemo(() => (selectedChatId ? [selectedChatId] : []), [selectedChatId]);
74
- const onSelect = useOnSelect(props);
75
- const items = useMenuItems(props);
76
-
77
- return (
78
- <>
79
- {items && (
80
- <Menu className="wxchtf-chat-list" selectedKeys={selected} onSelect={onSelect} items={items} />
81
- )}
82
- </>
83
- );
84
- });
1
+ import { Menu, MenuProps } from 'antd';
2
+ import { useMemo } from 'react';
3
+ import { ChatListItemBox } from './ChatListItemBox';
4
+ import { customize } from '../../customize';
5
+ import { ChatListValue } from './ChatListValue';
6
+ import { useLocalizer } from '../../localizer';
7
+ import { messageSequencePart } from '../../../core';
8
+
9
+ export interface ChatListProps {
10
+ className?: string;
11
+ items: ChatListValue[];
12
+ selected: string | null;
13
+ onSelect?: (id: string) => void;
14
+
15
+ /**
16
+ * If true, do not show read status.
17
+ */
18
+ noRead?: boolean;
19
+
20
+ /**
21
+ * If set, shows a message at the bottom indicating that only the top N chats are shown.
22
+ */
23
+ top?: number;
24
+ }
25
+
26
+ function useOnSelect(props: ChatListProps) {
27
+ const { onSelect } = props;
28
+
29
+ return useMemo(
30
+ () =>
31
+ onSelect
32
+ ? (info: Parameters<NonNullable<MenuProps['onSelect']>>[0]) => onSelect(info.key as string)
33
+ : undefined,
34
+ [onSelect],
35
+ );
36
+ }
37
+
38
+ function useMenuItems(props: ChatListProps) {
39
+ const { items, noRead, top } = props;
40
+ const localizer = useLocalizer();
41
+
42
+ return useMemo<MenuProps['items']>(() => {
43
+ const result = items
44
+ ?.slice()
45
+ .sort(
46
+ (a, b) => -messageSequencePart(a.lastMessage.id).localeCompare(messageSequencePart(b.lastMessage.id)),
47
+ )
48
+ .map((x) => ({ key: x.id, label: <ChatListItemBox chat={x} noRead={noRead} /> }));
49
+
50
+ if (top != null) {
51
+ return [
52
+ ...result,
53
+ {
54
+ type: 'item',
55
+ key: 'top',
56
+ disabled: true,
57
+ label: (
58
+ <div style={{ textAlign: 'center', cursor: 'text', fontStyle: 'italic' }}>
59
+ {localizer.chatList.topShown(top)}
60
+ </div>
61
+ ),
62
+ },
63
+ ];
64
+ }
65
+
66
+ return result;
67
+ }, [items, noRead, top, localizer]);
68
+ }
69
+
70
+ export const ChatList = customize('ChatList', (props: ChatListProps) => {
71
+ const { selected: selectedChatId } = props;
72
+ const selected = useMemo(() => (selectedChatId ? [selectedChatId] : []), [selectedChatId]);
73
+ const onSelect = useOnSelect(props);
74
+ const items = useMenuItems(props);
75
+
76
+ return (
77
+ <>
78
+ {items && (
79
+ <Menu className="wxchtf-chat-list" selectedKeys={selected} onSelect={onSelect} items={items} />
80
+ )}
81
+ </>
82
+ );
83
+ });
@@ -1,22 +1,22 @@
1
- import { color } from '../../color';
2
- import { Icon } from '../../common/Icon';
3
- import { customize } from '../../customize';
4
- import type { ChatListItemBoxProps } from './ChatListItemBox';
5
-
6
- export const ChatListItemAvatar = customize('ChatListItemAvatar', (props: ChatListItemBoxProps) => {
7
- const { id } = props.chat;
8
-
9
- return (
10
- <div
11
- className="wxchtf-chat-avatar"
12
- style={
13
- {
14
- '--background-color': color(id, { lightness: 90 }),
15
- '--color': color(id, { saturation: 60, lightness: 65 }),
16
- } as any
17
- }
18
- >
19
- <Icon type="chat" />
20
- </div>
21
- );
22
- });
1
+ import { color } from '../../color';
2
+ import { Icon } from '../../common/Icon';
3
+ import { customize } from '../../customize';
4
+ import type { ChatListItemBoxProps } from './ChatListItemBox';
5
+
6
+ export const ChatListItemAvatar = customize('ChatListItemAvatar', (props: ChatListItemBoxProps) => {
7
+ const { id } = props.chat;
8
+
9
+ return (
10
+ <div
11
+ className="wxchtf-chat-avatar"
12
+ style={
13
+ {
14
+ '--background-color': color(id, { lightness: 90 }),
15
+ '--color': color(id, { saturation: 60, lightness: 65 }),
16
+ } as any
17
+ }
18
+ >
19
+ <Icon type="chat" />
20
+ </div>
21
+ );
22
+ });