Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Reduce bundle size by update import path #2475

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
29 changes: 28 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,34 @@
"asc",
{ "caseSensitive": false, "natural": true }
],
"valid-typeof": 2
"valid-typeof": 2,
"@typescript-eslint/no-restricted-imports": [
"error",
{
"paths": [
{
"name": "../../context",
"message": "Importing from top-level barrel files is not allowed. Import from specific files instead.",
"allowTypeImports": true
},
{
"name": "../../../context",
"message": "Importing from top-level barrel files is not allowed. Import from specific files instead.",
"allowTypeImports": true
},
{
"name": "../../components",
"message": "Importing from top-level barrel files is not allowed. Import from specific files instead.",
"allowTypeImports": true
},
{
"name": "../../../components",
"message": "Importing from top-level barrel files is not allowed. Import from specific files instead.",
"allowTypeImports": true
}
]
}
]
}
}
]
Expand Down
14 changes: 13 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@
},
"default": "./dist/index.js"
},
"./dist/*": {
"types": "./dist/*",
"node": {
"require": "./dist/*",
"import": "./dist/*"
},
"browser": {
"require": "./dist/*",
"import": "./dist/*"
},
"default": "./dist/*"
},
"./emojis": {
"types": "./dist/plugins/Emojis/index.d.ts",
"node": {
Expand Down Expand Up @@ -279,4 +291,4 @@
"not op_mini all"
],
"packageManager": "[email protected]+sha1.1959a18351b811cdeedbd484a8f86c3cc3bbaf72"
}
}
2 changes: 1 addition & 1 deletion src/components/Attachment/AttachmentActions.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import type { Action, Attachment } from 'stream-chat';

import { useTranslationContext } from '../../context';
import { useTranslationContext } from '../../context/TranslationContext';

import type { ActionHandlerReturnType } from '../Message/hooks/useActionHandler';
import type { DefaultStreamChatGenerics } from '../../types/types';
Expand Down
5 changes: 4 additions & 1 deletion src/components/Attachment/Audio.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import React from 'react';

import type { Attachment } from 'stream-chat';

import { DownloadButton, FileSizeIndicator, PlayButton, ProgressBar } from './components';
import { DownloadButton } from './components/DownloadButton';
import { FileSizeIndicator } from './components/FileSizeIndicator';
import { PlayButton } from './components/PlayButton';
import { ProgressBar } from './components/ProgressBar';
import { useAudioController } from './hooks/useAudioController';

import type { DefaultStreamChatGenerics } from '../../types/types';
Expand Down
3 changes: 2 additions & 1 deletion src/components/Attachment/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import ReactPlayer from 'react-player';
import { AudioProps } from './Audio';
import { ImageComponent } from '../Gallery';
import { SafeAnchor } from '../SafeAnchor';
import { PlayButton, ProgressBar } from './components';
import { PlayButton } from './components/PlayButton';
import { ProgressBar } from './components/ProgressBar';
import { useAudioController } from './hooks/useAudioController';
import { useChannelStateContext } from '../../context/ChannelStateContext';
import { useTranslationContext } from '../../context/TranslationContext';
Expand Down
3 changes: 2 additions & 1 deletion src/components/Attachment/FileAttachment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import React from 'react';
import { FileIcon } from '../ReactFileUtilities';
import type { Attachment } from 'stream-chat';

import { DownloadButton, FileSizeIndicator } from './components';
import { DownloadButton } from './components/DownloadButton';
import { FileSizeIndicator } from './components/FileSizeIndicator';

import type { DefaultStreamChatGenerics } from '../../types/types';

Expand Down
2 changes: 1 addition & 1 deletion src/components/Attachment/UnsupportedAttachment.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { FileIcon } from '../ReactFileUtilities';
import { useTranslationContext } from '../../context';
import { useTranslationContext } from '../../context/TranslationContext';
import type { Attachment } from 'stream-chat';
import type { DefaultStreamChatGenerics } from '../../types/types';

Expand Down
7 changes: 5 additions & 2 deletions src/components/Attachment/VoiceRecording.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import React from 'react';
import type { Attachment } from 'stream-chat';

import { FileSizeIndicator, PlaybackRateButton, PlayButton, WaveProgressBar } from './components';
import { FileSizeIndicator } from './components/FileSizeIndicator';
import { PlaybackRateButton } from './components/PlaybackRateButton';
import { WaveProgressBar } from './components/WaveProgressBar';
import { PlayButton } from './components/PlayButton';
import { useAudioController } from './hooks/useAudioController';
import { displayDuration } from './utils';
import { FileIcon } from '../ReactFileUtilities';
import { useTranslationContext } from '../../context';
import { useTranslationContext } from '../../context/TranslationContext';

import type { DefaultStreamChatGenerics } from '../../types';

Expand Down
3 changes: 2 additions & 1 deletion src/components/Attachment/hooks/useAudioController.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import throttle from 'lodash.throttle';
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import { useChannelActionContext, useTranslationContext } from '../../../context';
import { useTranslationContext } from '../../../context/TranslationContext';
import { useChannelActionContext } from '../../../context/ChannelActionContext';

const isSeekable = (audioElement: HTMLAudioElement) =>
!(audioElement.duration === Infinity || isNaN(audioElement.duration));
Expand Down
2 changes: 1 addition & 1 deletion src/components/ChannelHeader/icons.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';

import { useTranslationContext } from '../../context';
import { useTranslationContext } from '../../context/TranslationContext';

export const MenuIcon = ({ title }: { title?: string }) => {
const { t } = useTranslationContext('MenuIcon');
Expand Down
2 changes: 1 addition & 1 deletion src/components/ChannelList/ChannelList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { LoadingChannels } from '../Loading/LoadingChannels';
import { LoadMorePaginator, LoadMorePaginatorProps } from '../LoadMore/LoadMorePaginator';
import { NullComponent } from '../UtilityComponents';

import { ChannelListContextProvider } from '../../context';
import { ChannelListContextProvider } from '../../context/ChannelListContext';
import { useChatContext } from '../../context/ChatContext';

import type { Channel, ChannelFilters, ChannelOptions, ChannelSort, Event } from 'stream-chat';
Expand Down
2 changes: 1 addition & 1 deletion src/components/ChannelList/ChannelListMessenger.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { PropsWithChildren } from 'react';

import { LoadingChannels } from '../Loading/LoadingChannels';
import { NullComponent } from '../UtilityComponents';
import { useTranslationContext } from '../../context';
import { useTranslationContext } from '../../context/TranslationContext';

import type { APIErrorResponse, Channel, ErrorFromResponse } from 'stream-chat';
import type { DefaultStreamChatGenerics } from '../../types/types';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { Channel } from 'stream-chat';
import { getDisplayImage, getDisplayTitle } from '../utils';
import type { DefaultStreamChatGenerics } from '../../../types/types';

import { useChatContext } from '../../../context';
import { useChatContext } from '../../../context/ChatContext';

export type ChannelPreviewInfoParams<StreamChatGenerics extends DefaultStreamChatGenerics> = {
channel: Channel<StreamChatGenerics>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useCallback, useEffect, useState } from 'react';
import type { Channel, Event } from 'stream-chat';

import { useChatContext } from '../../../context';
import { useChatContext } from '../../../context/ChatContext';

import type { DefaultStreamChatGenerics } from '../../../types/types';
import type { StreamMessage } from '../../../context';
Expand Down
2 changes: 1 addition & 1 deletion src/components/ChannelSearch/SearchResults.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ChannelPreview } from '../ChannelPreview';
import { ChannelOrUserResponse, isChannel } from './utils';
import { Avatar } from '../Avatar';

import { useTranslationContext } from '../../context';
import { useTranslationContext } from '../../context/TranslationContext';

import type { DefaultStreamChatGenerics } from '../../types/types';

Expand Down
2 changes: 1 addition & 1 deletion src/components/Gallery/Image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { sanitizeUrl } from '@braintree/sanitize-url';
import { BaseImage as DefaultBaseImage } from './BaseImage';
import { Modal } from '../Modal';
import { ModalGallery as DefaultModalGallery } from './ModalGallery';
import { useComponentContext } from '../../context';
import { useComponentContext } from '../../context/ComponentContext';

import type { Attachment } from 'stream-chat';
import type { DefaultStreamChatGenerics, Dimensions } from '../../types/types';
Expand Down
2 changes: 1 addition & 1 deletion src/components/Gallery/ModalGallery.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useMemo } from 'react';
import ImageGallery, { ReactImageGalleryItem } from 'react-image-gallery';
import { BaseImage } from './BaseImage';
import { useTranslationContext } from '../../context';
import { useTranslationContext } from '../../context/TranslationContext';

import type { Attachment } from 'stream-chat';
import type { DefaultStreamChatGenerics } from '../../types/types';
Expand Down
2 changes: 1 addition & 1 deletion src/components/LoadMore/LoadMoreButton.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { PropsWithChildren, useEffect } from 'react';
import { LoadingIndicator } from '../Loading';
import { deprecationAndReplacementWarning } from '../../utils/deprecationWarning';
import { useTranslationContext } from '../../context';
import { useTranslationContext } from '../../context/TranslationContext';

export type LoadMoreButtonProps = {
/** onClick handler load more button. Pagination logic should be executed in this handler. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
PauseIcon,
SendIcon,
} from '../../MessageInput';
import { useMessageInputContext } from '../../../context';
import { useMessageInputContext } from '../../../context/MessageInputContext';

export const AudioRecorder = () => {
const {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useEffect, useState } from 'react';
import { useTimeElapsed } from '../../MessageInput/hooks/useTimeElapsed';
import { useMessageInputContext } from '../../../context';
import { useMessageInputContext } from '../../../context/MessageInputContext';
import { RecordingTimer } from './RecordingTimer';

type WaveformProps = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { useTranslationContext } from '../../context';
import { useTranslationContext } from '../../context/TranslationContext';

import { RecordingPermission } from './classes/BrowserPermission';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import {
getRecordedMediaTypeFromMimeType,
RecordedMediaType,
} from '../../ReactFileUtilities';
import { TranslationContextValue } from '../../../context';
import { defaultTranslatorFunction } from '../../../i18n';
import { TranslationContextValue } from '../../../context/TranslationContext';
import { defaultTranslatorFunction } from '../../../i18n/utils';
import { isSafari } from '../../../utils/browsers';
import { mergeDeepUndefined } from '../../../utils/mergeDeep';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
RecordingAttachmentType,
} from '../MediaRecorderController';
import { AmplitudeRecorderState, DEFAULT_AMPLITUDE_RECORDER_CONFIG } from '../AmplitudeRecorder';
import { defaultTranslatorFunction } from '../../../../i18n';
import { defaultTranslatorFunction } from '../../../../i18n/utils';
import * as audioSampling from '../../../Attachment/audioSampling';
import * as reactFileUtils from '../../../ReactFileUtilities/utils';
import { generateVoiceRecordingAttachment } from '../../../../mock-builders';
Expand Down
3 changes: 2 additions & 1 deletion src/components/MediaRecorder/hooks/useMediaRecorder.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useCallback, useEffect, useMemo, useState } from 'react';
import { MessageInputContextValue, useTranslationContext } from '../../../context';
import { useTranslationContext } from '../../../context/TranslationContext';
import type { MessageInputContextValue } from '../../../context/MessageInputContext';
import {
CustomAudioRecordingConfig,
MediaRecorderController,
Expand Down
13 changes: 5 additions & 8 deletions src/components/Message/Message.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,11 @@ import {
} from './hooks';
import { areMessagePropsEqual, getMessageActions, MESSAGE_ACTIONS } from './utils';

import {
MessageContextValue,
MessageProvider,
useChannelActionContext,
useChannelStateContext,
useChatContext,
useComponentContext,
} from '../../context';
import { useComponentContext } from '../../context/ComponentContext';
import { useChatContext } from '../../context/ChatContext';
import { useChannelStateContext } from '../../context/ChannelStateContext';
import { useChannelActionContext } from '../../context/ChannelActionContext';
import { MessageContextValue, MessageProvider } from '../../context/MessageContext';

import type { MessageProps } from './types';
import type { DefaultStreamChatGenerics } from '../../types/types';
Expand Down
4 changes: 3 additions & 1 deletion src/components/Message/MessageEditedTimestamp.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import React from 'react';

import clsx from 'clsx';
import { useComponentContext, useMessageContext, useTranslationContext } from '../../context';
import { useComponentContext } from '../../context/ComponentContext';
import { useMessageContext } from '../../context/MessageContext';
import { useTranslationContext } from '../../context/TranslationContext';
import { Timestamp as DefaultTimestamp } from './Timestamp';
import { isMessageEdited } from './utils';

Expand Down
3 changes: 2 additions & 1 deletion src/components/Message/MessageErrorText.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';

import { StreamMessage, useTranslationContext } from '../../context';
import type { StreamMessage } from '../../context';
import { useTranslationContext } from '../../context/TranslationContext';
import { DefaultStreamChatGenerics } from '../../types/types';
import { isMessageBounced } from './utils';

Expand Down
2 changes: 1 addition & 1 deletion src/components/Message/MessageOptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { MessageActions } from '../MessageActions';
import { MessageContextValue, useMessageContext } from '../../context/MessageContext';

import type { DefaultStreamChatGenerics, IconProps } from '../../types/types';
import { useTranslationContext } from '../../context';
import { useTranslationContext } from '../../context/TranslationContext';

export type MessageOptionsProps<
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics
Expand Down
2 changes: 1 addition & 1 deletion src/components/Message/MessageSimple.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import { MessageContextValue, useMessageContext } from '../../context/MessageCon
import type { MessageUIComponentProps } from './types';

import type { DefaultStreamChatGenerics } from '../../types/types';
import { useTranslationContext } from '../../context';
import { useTranslationContext } from '../../context/TranslationContext';
import { MessageEditedTimestamp } from './MessageEditedTimestamp';

type MessageSimpleWithContextProps<
Expand Down
4 changes: 3 additions & 1 deletion src/components/Message/MessageText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import React, { useMemo } from 'react';
import { QuotedMessage as DefaultQuotedMessage } from './QuotedMessage';
import { isOnlyEmojis, messageHasAttachments } from './utils';

import { useComponentContext, useMessageContext, useTranslationContext } from '../../context';
import { useComponentContext } from '../../context/ComponentContext';
import { useMessageContext } from '../../context/MessageContext';
import { useTranslationContext } from '../../context/TranslationContext';
import { renderText as defaultRenderText } from './renderText';
import { MessageErrorText } from './MessageErrorText';

Expand Down
2 changes: 1 addition & 1 deletion src/components/Message/MessageTimestamp.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { useMessageContext } from '../../context/MessageContext';
import { Timestamp as DefaultTimestamp } from './Timestamp';
import { useComponentContext } from '../../context';
import { useComponentContext } from '../../context/ComponentContext';

import type { StreamMessage } from '../../context/ChannelStateContext';
import type { DefaultStreamChatGenerics } from '../../types/types';
Expand Down
5 changes: 2 additions & 3 deletions src/components/Message/__tests__/MessageTimestamp.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { notValidDateWarning } from '../../../i18n/utils';
import { Chat } from '../../Chat';
import { getTestClient } from '../../../mock-builders';
import { Streami18n } from '../../../i18n';

Dayjs.extend(calendar);

const calendarFormats = {
Expand Down Expand Up @@ -124,7 +123,7 @@ describe('<MessageTimestamp />', () => {
}),
},
});
expect(container).toHaveTextContent('2019-04-03T14:42:47+00:00');
expect(container).toHaveTextContent('2019-04-03T14:42:47Z');
});

it('should render with custom format provided via i18n service', async () => {
Expand Down Expand Up @@ -172,7 +171,7 @@ describe('<MessageTimestamp />', () => {
},
props: { calendarFormats },
});
expect(container).toHaveTextContent('2019-04-03T14:42:47+00:00');
expect(container).toHaveTextContent('2019-04-03T14:42:47Z');
});

it('should reflect the custom calendarFormats if calendar is enabled', async () => {
Expand Down
3 changes: 2 additions & 1 deletion src/components/Message/hooks/useMarkUnreadHandler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { validateAndGetMessage } from '../utils';
import { useChannelStateContext, useTranslationContext } from '../../../context';
import { useChannelStateContext } from '../../../context/ChannelStateContext';
import { useTranslationContext } from '../../../context/TranslationContext';

import type { StreamMessage } from '../../../context';
import type { ReactEventHandler } from '../types';
Expand Down
4 changes: 3 additions & 1 deletion src/components/Message/hooks/useReactionsFetcher.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { StreamMessage, useChatContext, useTranslationContext } from '../../../context';
import { useChatContext } from '../../../context/ChatContext';
import { useTranslationContext } from '../../../context/TranslationContext';
import type { StreamMessage } from '../../../context';
import { DefaultStreamChatGenerics } from '../../../types/types';
import { ReactionResponse, ReactionSort, StreamChat } from 'stream-chat';
import { ReactionType } from '../../Reactions/types';
Expand Down
2 changes: 1 addition & 1 deletion src/components/MessageActions/MessageActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { MessageContextValue, useMessageContext } from '../../context/MessageCon

import type { DefaultStreamChatGenerics, IconProps } from '../../types/types';
import { useMessageActionsBoxPopper } from './hooks';
import { useTranslationContext } from '../../context';
import { useTranslationContext } from '../../context/TranslationContext';

type MessageContextPropsToPick =
| 'getMessageActions'
Expand Down
Loading