stream-chat-react 13.0.0-rc.1 → 13.0.0-rc.2

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.
@@ -24,7 +24,7 @@ export const useChat = ({ client, defaultLanguage = 'en', i18nInstance, initialN
24
24
  useEffect(() => {
25
25
  if (!client)
26
26
  return;
27
- const version = "13.0.0-rc.1";
27
+ const version = "13.0.0-rc.2";
28
28
  const userAgent = client.getUserAgent();
29
29
  if (!userAgent.includes('stream-chat-react')) {
30
30
  // result looks like: 'stream-chat-react-2.3.2-stream-chat-javascript-client-browser-2.2.2'
@@ -1,13 +1,7 @@
1
1
  import type { PropsWithChildren } from 'react';
2
2
  import React from 'react';
3
+ import type { CommandResponse } from 'stream-chat';
3
4
  export type CommandItemProps = {
4
- entity: {
5
- /** Arguments of command */
6
- args?: string;
7
- /** Description of command */
8
- description?: string;
9
- /** Name of the command */
10
- name?: string;
11
- };
5
+ entity: CommandResponse;
12
6
  };
13
7
  export declare const CommandItem: (props: PropsWithChildren<CommandItemProps>) => React.JSX.Element;
@@ -1,16 +1,14 @@
1
1
  import React from 'react';
2
- import type { SuggestionItemProps } from './SuggestionListItem';
2
+ import type { SuggestionListItemComponentProps } from './SuggestionListItem';
3
+ type SuggestionTrigger = '/' | ':' | '@' | string;
3
4
  export type SuggestionListProps = Partial<{
4
- SuggestionItem: React.ComponentType<SuggestionItemProps>;
5
+ suggestionItemComponents: Record<SuggestionTrigger, React.ComponentType<SuggestionListItemComponentProps>>;
5
6
  className?: string;
6
7
  closeOnClickOutside?: boolean;
7
8
  containerClassName?: string;
8
9
  focusedItemIndex: number;
9
10
  setFocusedItemIndex: (index: number) => void;
10
11
  }>;
11
- export declare const defaultComponents: {
12
- '/': (props: React.PropsWithChildren<import("./CommandItem").CommandItemProps>) => React.JSX.Element;
13
- ':': (props: import("./EmoticonItem").EmoticonItemProps) => React.JSX.Element | null;
14
- '@': ({ Avatar, entity }: import("./UserItem").UserItemProps) => React.JSX.Element | null;
15
- };
16
- export declare const SuggestionList: ({ className, closeOnClickOutside, containerClassName, focusedItemIndex, setFocusedItemIndex, }: SuggestionListProps) => React.JSX.Element | null;
12
+ export declare const defaultComponents: Record<SuggestionTrigger, React.ComponentType<SuggestionListItemComponentProps>>;
13
+ export declare const SuggestionList: ({ className, closeOnClickOutside, containerClassName, focusedItemIndex, setFocusedItemIndex, suggestionItemComponents, }: SuggestionListProps) => React.JSX.Element | null;
14
+ export {};
@@ -15,19 +15,20 @@ const searchSourceStateSelector = (nextValue) => ({
15
15
  items: nextValue.items ?? [],
16
16
  });
17
17
  export const defaultComponents = {
18
- '/': CommandItem,
19
- ':': EmoticonItem,
20
- '@': UserItem,
18
+ '/': (props) => (React.createElement(CommandItem, { entity: props.entity })),
19
+ ':': (props) => (React.createElement(EmoticonItem, { entity: props.entity })),
20
+ '@': (props) => (React.createElement(UserItem, { entity: props.entity })),
21
21
  };
22
- export const SuggestionList = ({ className, closeOnClickOutside = true, containerClassName, focusedItemIndex, setFocusedItemIndex, }) => {
22
+ export const SuggestionList = ({ className, closeOnClickOutside = true, containerClassName, focusedItemIndex, setFocusedItemIndex, suggestionItemComponents = defaultComponents, }) => {
23
23
  const { AutocompleteSuggestionItem = DefaultSuggestionListItem } = useComponentContext();
24
24
  const messageComposer = useMessageComposer();
25
25
  const { textComposer } = messageComposer;
26
26
  const { suggestions } = useStateStore(textComposer.state, textComposerStateSelector);
27
27
  const { items } = useStateStore(suggestions?.searchSource.state, searchSourceStateSelector) ?? {};
28
28
  const [container, setContainer] = useState(null);
29
- // @ts-expect-error component type mismatch
30
- const component = suggestions?.trigger && defaultComponents[suggestions?.trigger];
29
+ const component = suggestions?.trigger
30
+ ? suggestionItemComponents[suggestions?.trigger]
31
+ : undefined;
31
32
  useEffect(() => {
32
33
  if (!closeOnClickOutside || !suggestions || !container)
33
34
  return;
@@ -1,15 +1,15 @@
1
1
  import React from 'react';
2
- import type { CommandResponse, TextComposerSuggestion, UserResponse } from 'stream-chat';
3
- import type { EmojiSearchIndexResult } from '../../MessageInput';
4
- export type SuggestionCommand = CommandResponse;
5
- export type SuggestionUser = UserResponse;
6
- export type SuggestionEmoji = EmojiSearchIndexResult;
7
- export type SuggestionItem = SuggestionUser | SuggestionCommand | SuggestionEmoji;
2
+ import type { TextComposerSuggestion } from 'stream-chat';
3
+ import type { UserItemProps } from './UserItem';
4
+ import type { CommandItemProps } from './CommandItem';
5
+ import type { EmoticonItemProps } from './EmoticonItem';
6
+ export type DefaultSuggestionListItemEntity = UserItemProps['entity'] | CommandItemProps['entity'] | EmoticonItemProps['entity'];
7
+ export type SuggestionListItemComponentProps = {
8
+ entity: DefaultSuggestionListItemEntity | unknown;
9
+ focused: boolean;
10
+ };
8
11
  export type SuggestionItemProps = {
9
- component: React.ComponentType<{
10
- entity: SuggestionItem;
11
- focused: boolean;
12
- }>;
12
+ component: React.ComponentType<SuggestionListItemComponentProps>;
13
13
  item: TextComposerSuggestion;
14
14
  focused: boolean;
15
15
  className?: string;
@@ -1,6 +1,5 @@
1
1
  import clsx from 'clsx';
2
- import { useLayoutEffect } from 'react';
3
- import React, { useCallback, useRef } from 'react';
2
+ import React, { useCallback, useLayoutEffect, useRef } from 'react';
4
3
  import { useMessageComposer } from '../../MessageInput';
5
4
  export const SuggestionListItem = React.forwardRef(function SuggestionListItem({ className, component: Component, focused, item, onMouseEnter }, innerRef) {
6
5
  const { textComposer } = useMessageComposer();