@webinex/chatify 1.0.0-alpha06 → 1.0.0-alpha08

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import React, { PropsWithChildren, FC, Ref, RefObject, CSSProperties } from 'react';
1
+ /// <reference types="react" />
2
+ import React$1, { PropsWithChildren, FC, Ref, RefObject, CSSProperties } from 'react';
2
3
  import * as react_jsx_runtime from 'react/jsx-runtime';
3
4
  import { AxiosInstance } from 'axios';
4
5
 
@@ -8,29 +9,32 @@ interface Localizer {
8
9
  chatCreated: () => string;
9
10
  };
10
11
  message: {
11
- read: () => React.ReactNode;
12
- reading: () => React.ReactNode;
13
- sending: () => React.ReactNode;
12
+ read: () => React$1.ReactNode;
13
+ reading: () => React$1.ReactNode;
14
+ sending: () => React$1.ReactNode;
14
15
  };
15
16
  addChat: {
16
- title: () => React.ReactNode;
17
+ title: () => React$1.ReactNode;
17
18
  name: {
18
- label: () => React.ReactNode;
19
+ label: () => React$1.ReactNode;
19
20
  required: () => string;
20
21
  max250: () => string;
21
22
  };
22
23
  members: {
23
- label: () => React.ReactNode;
24
+ label: () => React$1.ReactNode;
24
25
  required: () => string;
25
26
  };
26
- submitBtn: () => React.ReactNode;
27
+ submitBtn: () => React$1.ReactNode;
28
+ };
29
+ input: {
30
+ placeholder: () => string;
27
31
  };
28
32
  }
29
- declare const LocalizerContext: React.Context<Localizer>;
33
+ declare const LocalizerContext: React$1.Context<Localizer>;
30
34
  declare function useLocalizer(): Localizer;
31
35
  declare const defaultLocalizer: Localizer;
32
36
 
33
- type Customizable<TComponent extends React.ComponentType<any>, TKey extends string> = TComponent & {
37
+ type Customizable<TComponent extends React$1.ComponentType<any>, TKey extends string> = TComponent & {
34
38
  Component: TComponent;
35
39
  key: TKey;
36
40
  };
@@ -45,7 +49,7 @@ interface Account {
45
49
  name: string;
46
50
  avatar: string;
47
51
  }
48
- interface Message$1 {
52
+ interface Message {
49
53
  id: string;
50
54
  chatId: string;
51
55
  text: string;
@@ -63,7 +67,7 @@ interface Chat {
63
67
  interface ChatListItem {
64
68
  id: string;
65
69
  name: string;
66
- message: Message$1;
70
+ message: Message;
67
71
  unreadCount: number;
68
72
  }
69
73
  interface SendMessageRequest {
@@ -127,7 +131,7 @@ declare class ChatifyClient {
127
131
  chatId: string;
128
132
  skip?: number;
129
133
  take?: number;
130
- }) => Promise<Message$1[]>;
134
+ }) => Promise<Message[]>;
131
135
  send: (request: SendMessageRequest) => Promise<void>;
132
136
  read: (request: ReadRequest) => Promise<void>;
133
137
  removeMember: (request: RemoveMemberRequest) => Promise<void>;
@@ -192,7 +196,7 @@ declare const ACTIONS: {
192
196
  chatId: string;
193
197
  }) => State;
194
198
  message_received: (state: State, { message, requestId }: {
195
- message: Message$1;
199
+ message: Message;
196
200
  requestId: string;
197
201
  }) => State;
198
202
  chat_created: (state: State, { chat }: {
@@ -233,10 +237,10 @@ type Action = {
233
237
 
234
238
  type Reducer = ReturnType<typeof useReducer>;
235
239
  type Subscriber = (state: State) => void;
236
- declare function useReducer(): readonly [React.MutableRefObject<State>, (action: Action) => void, (subscriber: Subscriber) => () => void];
240
+ declare function useReducer(): readonly [React$1.MutableRefObject<State>, (action: Action) => void, (subscriber: Subscriber) => () => void];
237
241
  declare function ReducerProvider({ children }: PropsWithChildren<{}>): react_jsx_runtime.JSX.Element;
238
242
  declare function useDispatch(): (action: Action) => void;
239
- declare function useStateRef(): React.MutableRefObject<State>;
243
+ declare function useStateRef(): React$1.MutableRefObject<State>;
240
244
  declare function useSelect<TResult>(select: (state: State) => TResult, deps: any[]): TResult;
241
245
 
242
246
  declare function useChat(args: {
@@ -251,7 +255,7 @@ declare function useLoadMore({ chatId }: {
251
255
 
252
256
  type MessageState = ({
253
257
  type: 'message';
254
- } & Message$1) | {
258
+ } & Message) | {
255
259
  type: 'more';
256
260
  } | {
257
261
  type: 'sending';
@@ -320,23 +324,30 @@ declare const SendingMessageInfoBox: Customizable<FC<SendingMessageProps>, strin
320
324
  declare const SendingMessageBody: Customizable<FC<SendingMessageProps>, string>;
321
325
  declare const SendingMessage: Customizable<FC<SendingMessageProps>, string>;
322
326
 
323
- interface MessageProps {
324
- message: Message$1;
327
+ interface MessageBoxProps {
328
+ message: Message;
325
329
  }
326
- interface MessageBoxProps extends MessageProps {
330
+ interface MessageRowProps extends MessageBoxProps {
327
331
  containerRef?: Ref<HTMLDivElement>;
328
332
  }
329
- declare const MessageAuthor: Customizable<FC<MessageProps>, string>;
330
- declare const MessageText: Customizable<FC<MessageProps>, string>;
331
- declare const MessageInfoBox: Customizable<FC<MessageProps>, string>;
332
- declare const MessageBody: Customizable<FC<MessageProps>, string>;
333
+ declare const MessageAuthor: Customizable<FC<MessageBoxProps>, string>;
334
+ declare const MessageText: Customizable<FC<MessageBoxProps>, string>;
335
+ declare const MessageInfoBox: Customizable<FC<MessageBoxProps>, string>;
336
+ declare const MessageBody: Customizable<FC<MessageBoxProps>, string>;
337
+ declare const MessageRow: Customizable<FC<MessageRowProps>, string>;
333
338
  declare const MessageBox: Customizable<FC<MessageBoxProps>, string>;
334
- declare const Message: Customizable<FC<MessageProps>, string>;
335
- interface MessageReadObserverProps extends MessageProps {
339
+ interface MessageReadObserverProps extends MessageBoxProps {
336
340
  messageRef: RefObject<HTMLDivElement | null>;
337
341
  }
338
342
  declare const MessageReadObserver: Customizable<FC<MessageReadObserverProps>, string>;
339
343
 
344
+ type IconType = 'attach' | 'send';
345
+ interface IconProps {
346
+ type: IconType;
347
+ }
348
+ declare const ICONS: Record<IconType, React.ComponentType>;
349
+ declare const Icon: Customizable<FC<IconProps>, string>;
350
+
340
351
  interface ChatifyCustomizeValue {
341
352
  Avatar?: typeof Avatar.Component | null;
342
353
  Header?: typeof Header.Component | null;
@@ -355,13 +366,14 @@ interface ChatifyCustomizeValue {
355
366
  SendingMessageBody?: typeof SendingMessageBody.Component | null;
356
367
  SendingMessageInfoBox?: typeof SendingMessageInfoBox.Component | null;
357
368
  SendingMessageText?: typeof SendingMessageText.Component | null;
358
- Message?: typeof Message.Component | null;
359
- MessageReadObserver?: typeof MessageReadObserver.Component | null;
360
369
  MessageBox?: typeof MessageBox.Component | null;
370
+ MessageReadObserver?: typeof MessageReadObserver.Component | null;
371
+ MessageRow?: typeof MessageRow.Component | null;
361
372
  MessageBody?: typeof MessageBody.Component | null;
362
373
  MessageInfoBox?: typeof MessageInfoBox.Component | null;
363
374
  MessageText?: typeof MessageText.Component | null;
364
375
  MessageAuthor?: typeof MessageAuthor.Component | null;
376
+ Icon?: typeof Icon.Component | null;
365
377
  }
366
378
  interface ChatifyProps {
367
379
  className?: string;
@@ -376,6 +388,13 @@ interface ChatHeaderProps {
376
388
  }
377
389
  declare function ChatHeader(props: ChatHeaderProps): react_jsx_runtime.JSX.Element;
378
390
 
391
+ interface SystemMessageProps {
392
+ text: string;
393
+ sentAt: string;
394
+ }
395
+ declare function formatSystemMessage(localizer: Localizer, text: string): React.ReactNode;
396
+ declare function SystemMessage(props: SystemMessageProps): react_jsx_runtime.JSX.Element;
397
+
379
398
  declare function useClient(): ChatifyClient;
380
399
  declare function useMe(): string;
381
400
  interface ChatifyContextValue {
@@ -386,4 +405,4 @@ declare function ChatifyContext({ value, children }: PropsWithChildren<{
386
405
  value: ChatifyContextValue;
387
406
  }>): react_jsx_runtime.JSX.Element;
388
407
 
389
- export { ACTIONS, Account, Action, AddChatButton, AddChatRequest, AddMemberRequest, Avatar, AvatarProps, Chat, ChatHeader, ChatHeaderMembers, ChatHeaderMembersProps, ChatHeaderProps, ChatListItem, ChatListItemBox, ChatListItemBoxProps, ChatListItemLastMessage, ChatListItemLastMessageAuthor, ChatListItemLastMessageContent, ChatListItemName, ChatListItemUnreadCount, Chatify, ChatifyClient, ChatifyClientConfig, ChatifyContext, ChatifyContextValue, ChatifyCustomizeValue, ChatifyProps, ChatifySignalRConfig, File, Header, Localizer, LocalizerContext, Message$1 as Message, MessageContent, MessageState, ReadEvent, ReadRequest, Reducer, ReducerProvider, RemoveMemberRequest, SendMessageRequest, defaultLocalizer, useAccounts, useAddChat, useAddMember, useChat, useChatList, useClient, useDispatch, useLoadMore, useLocalizer, useMe, useMessages, useReadMonitor, useReducer, useRemoveMember, useSelect, useSignalRMonitor, useStateRef };
408
+ export { ACTIONS, Account, Action, AddChatButton, AddChatRequest, AddMemberRequest, Avatar, AvatarProps, Chat, ChatHeader, ChatHeaderMembers, ChatHeaderMembersProps, ChatHeaderProps, ChatListItem, ChatListItemBox, ChatListItemBoxProps, ChatListItemLastMessage, ChatListItemLastMessageAuthor, ChatListItemLastMessageContent, ChatListItemName, ChatListItemUnreadCount, Chatify, ChatifyClient, ChatifyClientConfig, ChatifyContext, ChatifyContextValue, ChatifyCustomizeValue, ChatifyProps, ChatifySignalRConfig, File, Header, ICONS, Icon, IconProps, IconType, Localizer, LocalizerContext, Message, MessageAuthor, MessageBody, MessageBox, MessageBoxProps, MessageContent, MessageInfoBox, MessageReadObserver, MessageReadObserverProps, MessageRow, MessageRowProps, MessageState, MessageText, ReadEvent, ReadRequest, Reducer, ReducerProvider, RemoveMemberRequest, SendMessageRequest, SystemMessage, SystemMessageProps, defaultLocalizer, formatSystemMessage, useAccounts, useAddChat, useAddMember, useChat, useChatList, useClient, useDispatch, useLoadMore, useLocalizer, useMe, useMessages, useReadMonitor, useReducer, useRemoveMember, useSelect, useSignalRMonitor, useStateRef };
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@webinex/chatify",
3
3
  "description": "Webinex Wispo",
4
4
  "private": false,
5
- "version": "1.0.0-alpha06",
5
+ "version": "1.0.0-alpha08",
6
6
  "author": "Webinex Dev",
7
7
  "license": "Apache-2.0",
8
8
  "main": "dist/cjs/index.js",
@@ -1,4 +1,4 @@
1
- import { Message } from './Message';
1
+ import { MessageBox } from './Message';
2
2
  import { useMessages } from '../core';
3
3
  import { LoadMore } from './LoadMore';
4
4
  import { SendingMessage } from './SendingMessage';
@@ -23,7 +23,7 @@ export function ChatBody(props: ChatBodyProps) {
23
23
 
24
24
  switch (x.type) {
25
25
  case 'message': {
26
- return <Message message={x} key={x.id} />;
26
+ return <MessageBox message={x} key={x.id} />;
27
27
  }
28
28
 
29
29
  case 'sending': {
@@ -26,14 +26,15 @@ import {
26
26
  SendingMessageText,
27
27
  } from './SendingMessage';
28
28
  import {
29
- Message,
30
29
  MessageAuthor,
31
30
  MessageBody,
32
31
  MessageBox,
33
32
  MessageInfoBox,
34
33
  MessageReadObserver,
34
+ MessageRow,
35
35
  MessageText,
36
36
  } from './Message';
37
+ import { Icon } from './Icon';
37
38
 
38
39
  export interface ChatifyCustomizeValue {
39
40
  Avatar?: typeof Avatar.Component | null;
@@ -53,13 +54,14 @@ export interface ChatifyCustomizeValue {
53
54
  SendingMessageBody?: typeof SendingMessageBody.Component | null;
54
55
  SendingMessageInfoBox?: typeof SendingMessageInfoBox.Component | null;
55
56
  SendingMessageText?: typeof SendingMessageText.Component | null;
56
- Message?: typeof Message.Component | null;
57
- MessageReadObserver?: typeof MessageReadObserver.Component | null;
58
57
  MessageBox?: typeof MessageBox.Component | null;
58
+ MessageReadObserver?: typeof MessageReadObserver.Component | null;
59
+ MessageRow?: typeof MessageRow.Component | null;
59
60
  MessageBody?: typeof MessageBody.Component | null;
60
61
  MessageInfoBox?: typeof MessageInfoBox.Component | null;
61
62
  MessageText?: typeof MessageText.Component | null;
62
63
  MessageAuthor?: typeof MessageAuthor.Component | null;
64
+ Icon?: typeof Icon.Component | null;
63
65
  }
64
66
 
65
67
  export interface ChatifyProps {
@@ -0,0 +1,21 @@
1
+ import { FC } from 'react';
2
+ import { customize } from '../util';
3
+ import SendOutlined from '@ant-design/icons/SendOutlined';
4
+ import FileAddOutlined from '@ant-design/icons/FileAddOutlined';
5
+
6
+ export type IconType = 'attach' | 'send';
7
+
8
+ export interface IconProps {
9
+ type: IconType;
10
+ }
11
+
12
+ export const ICONS: Record<IconType, React.ComponentType> = {
13
+ attach: FileAddOutlined,
14
+ send: SendOutlined,
15
+ };
16
+
17
+ export const Icon = customize<FC<IconProps>, string>('Icon', (props) => {
18
+ const { type } = props;
19
+ const IconComponent = ICONS[type];
20
+ return IconComponent ? <IconComponent /> : null;
21
+ });
@@ -1,16 +1,19 @@
1
1
  import { Button, Input } from 'antd';
2
- import SendOutlined from '@ant-design/icons/SendOutlined';
3
- import FileAddOutlined from '@ant-design/icons/FileAddOutlined';
4
2
  import { useCallback, useState } from 'react';
5
3
  import isHotkey from 'is-hotkey';
6
4
  import { useAddMessage } from '../core/useAddMessage';
7
5
  import { uniqId } from '../util';
8
6
  import { useSelect } from '../core';
7
+ import { useLocalizer } from './localizer';
8
+ import { Icon } from './Icon';
9
+
10
+ const isSend = isHotkey('ctrl+enter');
9
11
 
10
12
  export function InputForm() {
11
13
  const chatId = useSelect((x) => x.ui.chatId!, []);
12
14
  const [add] = useAddMessage({ chatId });
13
15
  const [text, setText] = useState('');
16
+ const localizer = useLocalizer();
14
17
 
15
18
  const onSend = useCallback(() => {
16
19
  setText('');
@@ -23,7 +26,7 @@ export function InputForm() {
23
26
  <div className="wxchtf-input-form">
24
27
  <div className="wxchtf-input-box">
25
28
  <div className="wxchtf-add-files-box">
26
- <Button type="link" icon={<FileAddOutlined />} className="wxchtf-add-files-btn" />
29
+ <Button type="link" icon={<Icon type="attach" />} className="wxchtf-add-files-btn" />
27
30
  </div>
28
31
  <div className="wxchtf-text-input-box">
29
32
  <Input.TextArea
@@ -31,16 +34,16 @@ export function InputForm() {
31
34
  onChange={(e) => setText(e.target.value)}
32
35
  autoSize={{ maxRows: 5 }}
33
36
  className="wxchtf-text-input-textarea"
34
- placeholder="Start typing (Ctrl/⌘Cmd + Enter to send) ..."
37
+ placeholder={localizer.input.placeholder()}
35
38
  onKeyDown={(event) => {
36
- if (isHotkey('ctrl+enter')(event)) {
39
+ if (isSend(event)) {
37
40
  onSend();
38
41
  }
39
42
  }}
40
43
  />
41
44
  </div>
42
45
  <div className="wxchtf-submit-btn-box">
43
- <Button onClick={onSend} type="link" icon={<SendOutlined />} className="wxchtf-submit-btn" />
46
+ <Button onClick={onSend} type="link" icon={<Icon type="send" />} className="wxchtf-submit-btn" />
44
47
  </div>
45
48
  </div>
46
49
  </div>
@@ -1,19 +1,19 @@
1
1
  import { useMe } from '../ChatifyContext';
2
2
  import { FC, Ref, RefObject, useEffect, useMemo, useRef } from 'react';
3
- import { useDispatch, useSelect, Message as MessageModel } from '../core';
3
+ import { Message, useDispatch, useSelect } from '../core';
4
4
  import { customize } from '../util';
5
5
  import { useLocalizer } from './localizer';
6
6
  import { Avatar } from './Avatar';
7
7
 
8
- export interface MessageProps {
9
- message: MessageModel;
8
+ export interface MessageBoxProps {
9
+ message: Message;
10
10
  }
11
11
 
12
- export interface MessageBoxProps extends MessageProps {
12
+ export interface MessageRowProps extends MessageBoxProps {
13
13
  containerRef?: Ref<HTMLDivElement>;
14
14
  }
15
15
 
16
- export const MessageAuthor = customize<FC<MessageProps>, string>('MessageAuthor', (props) => {
16
+ export const MessageAuthor = customize<FC<MessageBoxProps>, string>('MessageAuthor', (props) => {
17
17
  const { sentBy } = props.message;
18
18
 
19
19
  return (
@@ -23,12 +23,12 @@ export const MessageAuthor = customize<FC<MessageProps>, string>('MessageAuthor'
23
23
  );
24
24
  });
25
25
 
26
- export const MessageText = customize<FC<MessageProps>, string>('MessageText', (props) => {
26
+ export const MessageText = customize<FC<MessageBoxProps>, string>('MessageText', (props) => {
27
27
  const { text } = props.message;
28
28
  return <div className="wxchtf-message-text">{text}</div>;
29
29
  });
30
30
 
31
- export const MessageInfoBox = customize<FC<MessageProps>, string>('MessageInfoBox', (props) => {
31
+ export const MessageInfoBox = customize<FC<MessageBoxProps>, string>('MessageInfoBox', (props) => {
32
32
  const { message } = props;
33
33
  const { id, sentBy, sentAt, read } = message;
34
34
  const me = useMe();
@@ -48,7 +48,7 @@ export const MessageInfoBox = customize<FC<MessageProps>, string>('MessageInfoBo
48
48
  );
49
49
  });
50
50
 
51
- export const MessageBody = customize<FC<MessageProps>, string>('MessageBody', (props) => {
51
+ export const MessageBody = customize<FC<MessageBoxProps>, string>('MessageBody', (props) => {
52
52
  return (
53
53
  <div className="wxchtf-message-body">
54
54
  <MessageText {...props} />
@@ -57,7 +57,7 @@ export const MessageBody = customize<FC<MessageProps>, string>('MessageBody', (p
57
57
  );
58
58
  });
59
59
 
60
- export const MessageBox = customize<FC<MessageBoxProps>, string>('MessageBox', (props) => {
60
+ export const MessageRow = customize<FC<MessageRowProps>, string>('MessageRow', (props) => {
61
61
  const { message, containerRef } = props;
62
62
  const { sentBy } = message;
63
63
  const me = useMe();
@@ -71,20 +71,21 @@ export const MessageBox = customize<FC<MessageBoxProps>, string>('MessageBox', (
71
71
  );
72
72
  });
73
73
 
74
- export const Message = customize<FC<MessageProps>, string>('Message', (props) => {
74
+ export const MessageBox = customize<FC<MessageBoxProps>, string>('MessageBox', (props) => {
75
75
  const ref = useRef<HTMLDivElement | null>(null);
76
76
 
77
77
  return (
78
78
  <>
79
79
  <MessageReadObserver messageRef={ref} {...props} />
80
- <MessageBox containerRef={ref} {...props} />
80
+ <MessageRow containerRef={ref} {...props} />
81
81
  </>
82
82
  );
83
83
  });
84
84
 
85
- export interface MessageReadObserverProps extends MessageProps {
85
+ export interface MessageReadObserverProps extends MessageBoxProps {
86
86
  messageRef: RefObject<HTMLDivElement | null>;
87
87
  }
88
+
88
89
  export const MessageReadObserver = customize<FC<MessageReadObserverProps>, string>(
89
90
  'MessageReadObserver',
90
91
  (props) => {
package/src/ui/index.ts CHANGED
@@ -6,3 +6,6 @@ export * from './Header';
6
6
  export * from './ChatHeader';
7
7
  export * from './ChatHeaderMembers';
8
8
  export * from './ChatListItem';
9
+ export * from './Message';
10
+ export * from './SystemMessage';
11
+ export * from './Icon';
@@ -24,6 +24,10 @@ export interface Localizer {
24
24
  };
25
25
  submitBtn: () => React.ReactNode;
26
26
  };
27
+
28
+ input: {
29
+ placeholder: () => string;
30
+ };
27
31
  }
28
32
 
29
33
  export const LocalizerContext = React.createContext<Localizer>(null!);
@@ -55,4 +59,8 @@ export const defaultLocalizer: Localizer = {
55
59
  system: {
56
60
  chatCreated: () => 'Chat created',
57
61
  },
62
+
63
+ input: {
64
+ placeholder: () => 'Start typing (Ctrl/⌘Cmd + Enter to send) ...',
65
+ },
58
66
  };
@@ -69,10 +69,6 @@
69
69
  width: 100%;
70
70
  align-items: flex-end;
71
71
 
72
- &.--sending {
73
- animation: fadeInFromNone 0.5s ease-out;
74
- }
75
-
76
72
  &.--my {
77
73
  direction: rtl;
78
74
  justify-content: flex-start;