stream-chat-react 12.0.0-rc.6 → 12.0.0-rc.8

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 (27) hide show
  1. package/dist/components/ChannelList/ChannelList.js +1 -1
  2. package/dist/components/Chat/hooks/useCreateChatClient.d.ts +4 -2
  3. package/dist/components/Chat/hooks/useCreateChatClient.js +5 -4
  4. package/dist/components/Message/MessageStatus.js +3 -2
  5. package/dist/components/Message/renderText/rehypePlugins/mentionsMarkdownPlugin.d.ts +1 -1
  6. package/dist/components/Message/renderText/remarkPlugins/htmlToTextPlugin.d.ts +1 -1
  7. package/dist/components/Message/renderText/remarkPlugins/keepLineBreaksPlugin.d.ts +1 -1
  8. package/dist/components/Message/renderText/remarkPlugins/keepLineBreaksPlugin.js +1 -5
  9. package/dist/components/Message/renderText/renderText.d.ts +2 -2
  10. package/dist/components/Message/renderText/renderText.js +8 -6
  11. package/dist/components/UtilityComponents/ErrorBoundary.d.ts +16 -0
  12. package/dist/components/UtilityComponents/ErrorBoundary.js +19 -0
  13. package/dist/components/UtilityComponents/index.d.ts +1 -0
  14. package/dist/components/UtilityComponents/index.js +1 -0
  15. package/dist/index.browser.cjs +47663 -0
  16. package/dist/index.browser.cjs.map +7 -0
  17. package/dist/{index.cjs.js → index.node.cjs} +11660 -12438
  18. package/dist/{index.cjs.js.map → index.node.cjs.map} +4 -4
  19. package/dist/plugins/Emojis/index.browser.cjs +329 -0
  20. package/dist/plugins/Emojis/{index.cjs.js → index.node.cjs} +1 -1
  21. package/dist/plugins/Emojis/index.node.cjs.map +7 -0
  22. package/dist/plugins/encoders/mp3.browser.cjs +107 -0
  23. package/dist/plugins/encoders/{mp3.cjs.js → mp3.node.cjs} +1 -1
  24. package/dist/plugins/encoders/mp3.node.cjs.map +7 -0
  25. package/package.json +30 -12
  26. /package/dist/plugins/Emojis/{index.cjs.js.map → index.browser.cjs.map} +0 -0
  27. /package/dist/plugins/encoders/{mp3.cjs.js.map → mp3.browser.cjs.map} +0 -0
@@ -117,7 +117,7 @@ const UnMemoizedChannelList = (props) => {
117
117
  channel: item,
118
118
  // forces the update of preview component on channel update
119
119
  channelUpdateCount,
120
- key: item.id,
120
+ key: item.cid,
121
121
  Preview,
122
122
  setActiveChannel,
123
123
  watchers,
@@ -1,9 +1,11 @@
1
- import { DefaultGenerics, ExtendableGenerics, OwnUserResponse, StreamChat, TokenOrProvider, UserResponse } from 'stream-chat';
1
+ import { StreamChat } from 'stream-chat';
2
+ import type { DefaultGenerics, ExtendableGenerics, OwnUserResponse, StreamChatOptions, TokenOrProvider, UserResponse } from 'stream-chat';
2
3
  /**
3
4
  * React hook to create, connect and return `StreamChat` client.
4
5
  */
5
- export declare const useCreateChatClient: <SCG extends ExtendableGenerics = DefaultGenerics>({ apiKey, tokenOrProvider, userData, }: {
6
+ export declare const useCreateChatClient: <SCG extends ExtendableGenerics = DefaultGenerics>({ apiKey, options, tokenOrProvider, userData, }: {
6
7
  apiKey: string;
7
8
  tokenOrProvider: TokenOrProvider;
8
9
  userData: OwnUserResponse<SCG> | UserResponse<SCG>;
10
+ options?: StreamChatOptions;
9
11
  }) => StreamChat<SCG> | null;
@@ -1,16 +1,17 @@
1
1
  import { useEffect, useState } from 'react';
2
- import { StreamChat, } from 'stream-chat';
2
+ import { StreamChat } from 'stream-chat';
3
3
  /**
4
4
  * React hook to create, connect and return `StreamChat` client.
5
5
  */
6
- export const useCreateChatClient = ({ apiKey, tokenOrProvider, userData, }) => {
6
+ export const useCreateChatClient = ({ apiKey, options, tokenOrProvider, userData, }) => {
7
7
  const [chatClient, setChatClient] = useState(null);
8
8
  const [cachedUserData, setCachedUserData] = useState(userData);
9
9
  if (userData.id !== cachedUserData.id) {
10
10
  setCachedUserData(userData);
11
11
  }
12
+ const [cachedOptions] = useState(options);
12
13
  useEffect(() => {
13
- const client = new StreamChat(apiKey);
14
+ const client = new StreamChat(apiKey, undefined, cachedOptions);
14
15
  let didUserConnectInterrupt = false;
15
16
  const connectionPromise = client.connectUser(cachedUserData, tokenOrProvider).then(() => {
16
17
  if (!didUserConnectInterrupt)
@@ -25,6 +26,6 @@ export const useCreateChatClient = ({ apiKey, tokenOrProvider, userData, }) => {
25
26
  console.log(`Connection for user "${cachedUserData.id}" has been closed`);
26
27
  });
27
28
  };
28
- }, [apiKey, cachedUserData, tokenOrProvider]);
29
+ }, [apiKey, cachedUserData, cachedOptions, tokenOrProvider]);
29
30
  return chatClient;
30
31
  };
@@ -26,9 +26,10 @@ const UnMemoizedMessageStatus = (props) => {
26
26
  const sending = message.status === 'sending';
27
27
  const delivered = message.status === 'received' && message.id === lastReceivedId && !threadList;
28
28
  const deliveredAndRead = !!(readBy?.length && !threadList && !justReadByMe);
29
- const [lastReadUser] = deliveredAndRead
29
+ const readersWithoutOwnUser = deliveredAndRead
30
30
  ? readBy.filter((item) => item.id !== client.user?.id)
31
31
  : [];
32
+ const [lastReadUser] = readersWithoutOwnUser;
32
33
  return (React.createElement("span", { className: rootClassName, "data-testid": clsx({
33
34
  'message-status-read-by': deliveredAndRead,
34
35
  'message-status-received': delivered && !deliveredAndRead,
@@ -47,6 +48,6 @@ const UnMemoizedMessageStatus = (props) => {
47
48
  (MessageReadStatus ? (React.createElement(MessageReadStatus, null)) : (React.createElement(React.Fragment, null,
48
49
  React.createElement(PopperTooltip, { offset: [0, 5], referenceElement: referenceElement, visible: tooltipVisible }, getReadByTooltipText(readBy, t, client, tooltipUserNameMapper)),
49
50
  React.createElement(Avatar, { className: 'str-chat__avatar--message-status', image: lastReadUser.image, name: lastReadUser.name || lastReadUser.id, user: lastReadUser }),
50
- readBy.length > 2 && (React.createElement("span", { className: `str-chat__message-${messageType}-status-number`, "data-testid": 'message-status-read-by-many' }, readBy.length - 1)))))));
51
+ readersWithoutOwnUser.length > 1 && (React.createElement("span", { className: `str-chat__message-${messageType}-status-number`, "data-testid": 'message-status-read-by-many' }, readersWithoutOwnUser.length)))))));
51
52
  };
52
53
  export const MessageStatus = React.memo(UnMemoizedMessageStatus);
@@ -1,4 +1,4 @@
1
1
  import type { Nodes } from 'hast-util-find-and-replace/lib';
2
2
  import type { UserResponse } from 'stream-chat';
3
- import type { DefaultStreamChatGenerics } from '../../../../types/types';
3
+ import type { DefaultStreamChatGenerics } from '../../../../types';
4
4
  export declare const mentionsMarkdownPlugin: <StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics>(mentioned_users: UserResponse<StreamChatGenerics>[]) => () => (tree: Nodes) => void;
@@ -1,2 +1,2 @@
1
- import type { Nodes } from 'react-markdown/lib';
1
+ import type { Nodes } from 'hast-util-find-and-replace/lib';
2
2
  export declare const htmlToTextPlugin: () => (tree: Nodes) => void;
@@ -1,2 +1,2 @@
1
- import type { Nodes } from 'react-markdown/lib';
1
+ import type { Nodes } from 'hast-util-find-and-replace/lib';
2
2
  export declare const keepLineBreaksPlugin: () => (tree: Nodes) => void;
@@ -1,11 +1,7 @@
1
1
  import { visit } from 'unist-util-visit';
2
2
  import { u } from 'unist-builder';
3
3
  const visitor = (node, index, parent) => {
4
- if (typeof index === 'undefined' || index === 0)
5
- return;
6
- if (typeof parent === 'undefined')
7
- return;
8
- if (!node.position)
4
+ if (!(index && parent && node.position))
9
5
  return;
10
6
  const prevSibling = parent.children.at(index - 1);
11
7
  if (!prevSibling?.position)
@@ -1,8 +1,8 @@
1
1
  import React, { ComponentType } from 'react';
2
2
  import { Options } from 'react-markdown';
3
- import { MentionProps } from './componentRenderers';
4
- import type { PluggableList } from 'react-markdown/lib';
3
+ import type { PluggableList } from 'react-markdown/lib/react-markdown';
5
4
  import type { UserResponse } from 'stream-chat';
5
+ import { MentionProps } from './componentRenderers';
6
6
  import type { DefaultStreamChatGenerics } from '../../../types/types';
7
7
  export type RenderTextPluginConfigurator = (defaultPlugins: PluggableList) => PluggableList;
8
8
  export declare const defaultAllowedTagNames: Array<keyof JSX.IntrinsicElements | 'emoji' | 'mention'>;
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import ReactMarkdown, { defaultUrlTransform } from 'react-markdown';
2
+ import ReactMarkdown, { uriTransformer } from 'react-markdown';
3
3
  import { find } from 'linkifyjs';
4
4
  import uniqBy from 'lodash.uniqby';
5
5
  import remarkGfm from 'remark-gfm';
@@ -7,6 +7,7 @@ import { Anchor, Emoji, Mention } from './componentRenderers';
7
7
  import { detectHttp, escapeRegExp, matchMarkdownLinks, messageCodeBlocks } from './regex';
8
8
  import { emojiMarkdownPlugin, mentionsMarkdownPlugin } from './rehypePlugins';
9
9
  import { htmlToTextPlugin, keepLineBreaksPlugin } from './remarkPlugins';
10
+ import { ErrorBoundary } from '../../UtilityComponents';
10
11
  export const defaultAllowedTagNames = [
11
12
  'html',
12
13
  'text',
@@ -42,7 +43,7 @@ function encodeDecode(url) {
42
43
  return url;
43
44
  }
44
45
  }
45
- const urlTransform = (uri) => (uri.startsWith('app://') ? uri : defaultUrlTransform(uri));
46
+ const urlTransform = (uri) => (uri.startsWith('app://') ? uri : uriTransformer(uri));
46
47
  const getPluginsForward = (plugins) => plugins;
47
48
  export const markDownRenderers = {
48
49
  a: Anchor,
@@ -106,8 +107,9 @@ export const renderText = (text, mentionedUsers, { allowedTagNames = defaultAllo
106
107
  if (mentionedUsers?.length) {
107
108
  rehypePlugins.push(mentionsMarkdownPlugin(mentionedUsers));
108
109
  }
109
- return (React.createElement(ReactMarkdown, { allowedElements: allowedTagNames, components: {
110
- ...markDownRenderers,
111
- ...customMarkDownRenderers,
112
- }, rehypePlugins: getRehypePlugins(rehypePlugins), remarkPlugins: getRemarkPlugins(remarkPlugins), skipHtml: true, unwrapDisallowed: true, urlTransform: urlTransform }, newText));
110
+ return (React.createElement(ErrorBoundary, { fallback: React.createElement(React.Fragment, null, text) },
111
+ React.createElement(ReactMarkdown, { allowedElements: allowedTagNames, components: {
112
+ ...markDownRenderers,
113
+ ...customMarkDownRenderers,
114
+ }, rehypePlugins: getRehypePlugins(rehypePlugins), remarkPlugins: getRemarkPlugins(remarkPlugins), skipHtml: true, transformLinkUri: urlTransform, unwrapDisallowed: true }, newText)));
113
115
  };
@@ -0,0 +1,16 @@
1
+ import { Component } from 'react';
2
+ import type { PropsWithChildren, ReactNode } from 'react';
3
+ type ErrorBoundaryProps = PropsWithChildren<{
4
+ fallback?: ReactNode;
5
+ }>;
6
+ export declare class ErrorBoundary extends Component<ErrorBoundaryProps, {
7
+ hasError: boolean;
8
+ }> {
9
+ constructor(props: ErrorBoundaryProps);
10
+ static getDerivedStateFromError(): {
11
+ hasError: boolean;
12
+ };
13
+ componentDidCatch(error: unknown, information: unknown): void;
14
+ render(): ReactNode;
15
+ }
16
+ export {};
@@ -0,0 +1,19 @@
1
+ import { Component } from 'react';
2
+ export class ErrorBoundary extends Component {
3
+ constructor(props) {
4
+ super(props);
5
+ this.state = { hasError: false };
6
+ }
7
+ static getDerivedStateFromError() {
8
+ return { hasError: true };
9
+ }
10
+ componentDidCatch(error, information) {
11
+ console.error(error, information);
12
+ }
13
+ render() {
14
+ if (this.state.hasError) {
15
+ return this.props.fallback;
16
+ }
17
+ return this.props.children;
18
+ }
19
+ }
@@ -1 +1,2 @@
1
1
  export * from './NullComponent';
2
+ export * from './ErrorBoundary';
@@ -1 +1,2 @@
1
1
  export * from './NullComponent';
2
+ export * from './ErrorBoundary';