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

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 (36) hide show
  1. package/dist/components/Channel/Channel.d.ts +1 -1
  2. package/dist/components/Channel/Channel.js +2 -0
  3. package/dist/components/Chat/hooks/useChat.js +1 -1
  4. package/dist/components/MessageInput/EditMessageForm.js +1 -1
  5. package/dist/components/MessageInput/MessageInput.d.ts +1 -3
  6. package/dist/components/MessageInput/MessageInputFlat.js +2 -2
  7. package/dist/components/MessageInput/hooks/useCreateMessageInputContext.js +1 -3
  8. package/dist/components/MessageInput/hooks/useMessageInputControls.d.ts +0 -1
  9. package/dist/components/MessageInput/hooks/useMessageInputControls.js +3 -4
  10. package/dist/components/MessageInput/hooks/usePasteHandler.d.ts +1 -1
  11. package/dist/components/MessageInput/hooks/usePasteHandler.js +4 -4
  12. package/dist/components/MessageInput/hooks/{useMessageInputText.d.ts → useTextareaRef.d.ts} +1 -2
  13. package/dist/components/MessageInput/hooks/useTextareaRef.js +14 -0
  14. package/dist/components/TextareaComposer/SuggestionList/CommandItem.d.ts +2 -8
  15. package/dist/components/TextareaComposer/SuggestionList/SuggestionList.d.ts +6 -8
  16. package/dist/components/TextareaComposer/SuggestionList/SuggestionList.js +7 -6
  17. package/dist/components/TextareaComposer/SuggestionList/SuggestionListItem.d.ts +10 -10
  18. package/dist/components/TextareaComposer/SuggestionList/SuggestionListItem.js +1 -2
  19. package/dist/components/TextareaComposer/TextareaComposer.d.ts +3 -5
  20. package/dist/components/TextareaComposer/TextareaComposer.js +13 -8
  21. package/dist/context/ComponentContext.d.ts +3 -3
  22. package/dist/experimental/index.browser.cjs.map +2 -2
  23. package/dist/experimental/index.node.cjs.map +2 -2
  24. package/dist/index.browser.cjs +75 -93
  25. package/dist/index.browser.cjs.map +4 -4
  26. package/dist/index.node.cjs +75 -93
  27. package/dist/index.node.cjs.map +4 -4
  28. package/dist/plugins/Emojis/EmojiPicker.js +9 -4
  29. package/dist/plugins/Emojis/index.browser.cjs +208 -96
  30. package/dist/plugins/Emojis/index.browser.cjs.map +4 -4
  31. package/dist/plugins/Emojis/index.node.cjs +208 -96
  32. package/dist/plugins/Emojis/index.node.cjs.map +4 -4
  33. package/dist/plugins/Emojis/middleware/textComposerEmojiMiddleware.d.ts +4 -48
  34. package/dist/plugins/Emojis/middleware/textComposerEmojiMiddleware.js +52 -58
  35. package/package.json +3 -3
  36. package/dist/components/MessageInput/hooks/useMessageInputText.js +0 -44
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../../src/plugins/Emojis/index.ts", "../../../src/plugins/Emojis/EmojiPicker.tsx", "../../../src/context/TranslationContext.tsx", "../../../src/i18n/utils.ts", "../../../src/context/MessageInputContext.tsx", "../../../src/plugins/Emojis/icons.tsx", "../../../src/plugins/Emojis/middleware/textComposerEmojiMiddleware.ts"],
4
- "sourcesContent": ["export * from './EmojiPicker';\nexport * from './middleware';\nexport { EmojiPickerIcon } from './icons';\n", "import React, { useEffect, useState } from 'react';\nimport { usePopper } from 'react-popper';\nimport Picker from '@emoji-mart/react';\n\nimport type { Options } from '@popperjs/core';\n\nimport { useMessageInputContext, useTranslationContext } from '../../context';\nimport { EmojiPickerIcon } from './icons';\n\nconst isShadowRoot = (node: Node): node is ShadowRoot => !!(node as ShadowRoot).host;\n\nexport type EmojiPickerProps = {\n ButtonIconComponent?: React.ComponentType;\n buttonClassName?: string;\n pickerContainerClassName?: string;\n wrapperClassName?: string;\n closeOnEmojiSelect?: boolean;\n /**\n * Untyped [properties](https://github.com/missive/emoji-mart/tree/v5.5.2#options--props) to be\n * passed down to the [emoji-mart `Picker`](https://github.com/missive/emoji-mart/tree/v5.5.2#-picker) component\n */\n pickerProps?: Partial<{ theme: 'auto' | 'light' | 'dark' } & Record<string, unknown>>;\n /**\n * [React Popper options](https://popper.js.org/docs/v2/constructors/#options) to be\n * passed down to the [react-popper `usePopper`](https://popper.js.org/react-popper/v2/hook/) hook\n */\n popperOptions?: Partial<Options>;\n};\n\nconst classNames: EmojiPickerProps = {\n buttonClassName: 'str-chat__emoji-picker-button',\n pickerContainerClassName: 'str-chat__message-textarea-emoji-picker-container',\n wrapperClassName: 'str-chat__message-textarea-emoji-picker',\n};\n\nexport const EmojiPicker = (props: EmojiPickerProps) => {\n const { t } = useTranslationContext('EmojiPicker');\n const { insertText, textareaRef } = useMessageInputContext('EmojiPicker');\n const [displayPicker, setDisplayPicker] = useState(false);\n const [referenceElement, setReferenceElement] = useState<HTMLButtonElement | null>(\n null,\n );\n const [popperElement, setPopperElement] = useState<HTMLDivElement | null>(null);\n const { attributes, styles } = usePopper(referenceElement, popperElement, {\n placement: 'top-end',\n ...props.popperOptions,\n });\n\n const { buttonClassName, pickerContainerClassName, wrapperClassName } = classNames;\n\n const { ButtonIconComponent = EmojiPickerIcon } = props;\n\n useEffect(() => {\n if (!popperElement || !referenceElement) return;\n\n const handlePointerDown = (e: PointerEvent) => {\n const target = e.target as HTMLElement;\n\n const rootNode = target.getRootNode();\n\n if (\n popperElement.contains(isShadowRoot(rootNode) ? rootNode.host : target) ||\n referenceElement.contains(target)\n ) {\n return;\n }\n\n setDisplayPicker(false);\n };\n\n window.addEventListener('pointerdown', handlePointerDown);\n return () => window.removeEventListener('pointerdown', handlePointerDown);\n }, [referenceElement, popperElement]);\n\n return (\n <div className={props.wrapperClassName ?? wrapperClassName}>\n {displayPicker && (\n <div\n className={props.pickerContainerClassName ?? pickerContainerClassName}\n style={styles.popper}\n {...attributes.popper}\n ref={setPopperElement}\n >\n <Picker\n data={async () => (await import('@emoji-mart/data')).default}\n onEmojiSelect={(e: { native: string }) => {\n insertText(e.native);\n textareaRef.current?.focus();\n if (props.closeOnEmojiSelect) {\n setDisplayPicker(false);\n }\n }}\n {...props.pickerProps}\n />\n </div>\n )}\n <button\n aria-expanded={displayPicker}\n aria-label={t('aria/Emoji picker')}\n className={props.buttonClassName ?? buttonClassName}\n onClick={() => setDisplayPicker((cv) => !cv)}\n ref={setReferenceElement}\n type='button'\n >\n {ButtonIconComponent && <ButtonIconComponent />}\n </button>\n </div>\n );\n};\n", "import React, { useContext } from 'react';\nimport Dayjs from 'dayjs';\nimport calendar from 'dayjs/plugin/calendar';\nimport localizedFormat from 'dayjs/plugin/localizedFormat';\nimport type { PropsWithChildren } from 'react';\nimport type { TFunction } from 'i18next';\nimport type { TranslationLanguages } from 'stream-chat';\n\nimport { getDisplayName } from './utils/getDisplayName';\nimport { defaultDateTimeParser, defaultTranslatorFunction } from '../i18n/utils';\nimport type { UnknownType } from '../types/types';\nimport type { TDateTimeParser } from '../i18n/types';\n\nDayjs.extend(calendar);\nDayjs.extend(localizedFormat);\n\nexport type TranslationContextValue = {\n t: TFunction;\n tDateTimeParser: TDateTimeParser;\n userLanguage: TranslationLanguages;\n};\n\nexport const TranslationContext = React.createContext<TranslationContextValue>({\n t: defaultTranslatorFunction,\n tDateTimeParser: defaultDateTimeParser,\n userLanguage: 'en',\n});\n\nexport const TranslationProvider = ({\n children,\n value,\n}: PropsWithChildren<{ value: TranslationContextValue }>) => (\n <TranslationContext.Provider value={value}>{children}</TranslationContext.Provider>\n);\n\nexport const useTranslationContext = (componentName?: string) => {\n const contextValue = useContext(TranslationContext);\n\n if (!contextValue) {\n console.warn(\n `The useTranslationContext hook was called outside of the TranslationContext provider. Make sure this hook is called within a child of the Chat component. The errored call is located in the ${componentName} component.`,\n );\n\n return {} as TranslationContextValue;\n }\n\n return contextValue;\n};\n\nexport const withTranslationContext = <P extends UnknownType>(\n Component: React.ComponentType<P>,\n) => {\n const WithTranslationContextComponent = (\n props: Omit<P, keyof TranslationContextValue>,\n ) => {\n const translationContext = useTranslationContext();\n\n return <Component {...(props as P)} {...translationContext} />;\n };\n\n WithTranslationContextComponent.displayName = `WithTranslationContext${getDisplayName(\n Component,\n )}`;\n\n return WithTranslationContextComponent;\n};\n", "import Dayjs from 'dayjs';\n\nimport type { TFunction } from 'i18next';\nimport type { Moment } from 'moment-timezone';\nimport type {\n DateFormatterOptions,\n PredefinedFormatters,\n SupportedTranslations,\n TDateTimeParserInput,\n TDateTimeParserOutput,\n TimestampFormatterOptions,\n} from './types';\n\nexport const notValidDateWarning =\n 'MessageTimestamp was called without a message, or message has invalid created_at date.';\nexport const noParsingFunctionWarning =\n 'MessageTimestamp was called but there is no datetime parsing function available';\n\nexport const isNumberOrString = (\n output: TDateTimeParserOutput,\n): output is number | string => typeof output === 'string' || typeof output === 'number';\n\nexport const isDayOrMoment = (\n output: TDateTimeParserOutput,\n): output is Dayjs.Dayjs | Moment => !!(output as Dayjs.Dayjs | Moment)?.isSame;\n\nexport const isDate = (output: unknown): output is Date =>\n output !== null &&\n typeof output === 'object' &&\n typeof (output as Date).getTime === 'function';\n\nexport function getDateString({\n calendar,\n calendarFormats,\n format,\n formatDate,\n messageCreatedAt,\n t,\n tDateTimeParser,\n timestampTranslationKey,\n}: DateFormatterOptions): string | number | null {\n if (\n !messageCreatedAt ||\n (typeof messageCreatedAt === 'string' && !Date.parse(messageCreatedAt))\n ) {\n console.warn(notValidDateWarning);\n return null;\n }\n\n if (typeof formatDate === 'function') {\n return formatDate(new Date(messageCreatedAt));\n }\n\n if (t && timestampTranslationKey) {\n const options: TimestampFormatterOptions = {};\n if (typeof calendar !== 'undefined' && calendar !== null) options.calendar = calendar;\n if (typeof calendarFormats !== 'undefined' && calendarFormats !== null)\n options.calendarFormats = calendarFormats;\n if (typeof format !== 'undefined' && format !== null) options.format = format;\n\n const translatedTimestamp = t(timestampTranslationKey, {\n ...options,\n timestamp: new Date(messageCreatedAt),\n });\n const translationKeyFound = timestampTranslationKey !== translatedTimestamp;\n if (translationKeyFound) return translatedTimestamp;\n }\n\n if (!tDateTimeParser) {\n console.warn(noParsingFunctionWarning);\n return null;\n }\n\n const parsedTime = tDateTimeParser(messageCreatedAt);\n\n if (isDayOrMoment(parsedTime)) {\n /**\n * parsedTime.calendar is guaranteed on the type but is only\n * available when a user calls dayjs.extend(calendar)\n */\n return calendar && parsedTime.calendar\n ? parsedTime.calendar(undefined, calendarFormats || undefined)\n : parsedTime.format(format || undefined);\n }\n\n if (isDate(parsedTime)) {\n return parsedTime.toDateString();\n }\n\n if (isNumberOrString(parsedTime)) {\n return parsedTime;\n }\n\n return null;\n}\n\nexport const predefinedFormatters: PredefinedFormatters = {\n timestampFormatter:\n (streamI18n) =>\n (\n value,\n _,\n {\n calendarFormats,\n ...options\n }: Pick<TimestampFormatterOptions, 'calendar' | 'format'> & {\n calendarFormats?: Record<string, string> | string;\n },\n ) => {\n let parsedCalendarFormats;\n try {\n if (!options.calendar) {\n parsedCalendarFormats = {};\n } else if (typeof calendarFormats === 'string') {\n parsedCalendarFormats = JSON.parse(calendarFormats);\n } else if (typeof calendarFormats === 'object') {\n parsedCalendarFormats = calendarFormats;\n }\n } catch (e) {\n console.error('[TIMESTAMP FORMATTER]', e);\n }\n\n const result = getDateString({\n ...options,\n calendarFormats: parsedCalendarFormats,\n messageCreatedAt: value,\n tDateTimeParser: streamI18n.tDateTimeParser,\n });\n if (!result || typeof result === 'number') {\n return JSON.stringify(value);\n }\n return result;\n },\n};\n\nexport const defaultTranslatorFunction: TFunction = <tResult = string>(key: tResult) =>\n key;\n\nexport const defaultDateTimeParser = (input?: TDateTimeParserInput) => Dayjs(input);\n\nexport const isLanguageSupported = (\n language: string,\n): language is SupportedTranslations => {\n const translations = [\n 'de',\n 'en',\n 'es',\n 'fr',\n 'hi',\n 'it',\n 'ja',\n 'ko',\n 'nl',\n 'pt',\n 'ru',\n 'tr',\n ];\n return translations.some((translation) => language === translation);\n};\n", "import React, { createContext, useContext } from 'react';\nimport type { PropsWithChildren } from 'react';\n\nimport type { CooldownTimerState, MessageInputProps } from '../components/MessageInput';\nimport type { MessageInputHookProps } from '../components/MessageInput/hooks/useMessageInputControls';\n\nexport type MessageInputContextValue = MessageInputHookProps &\n Omit<MessageInputProps, 'Input'> &\n CooldownTimerState;\n\nexport const MessageInputContext = createContext<MessageInputHookProps | undefined>(\n undefined,\n);\n\nexport const MessageInputContextProvider = ({\n children,\n value,\n}: PropsWithChildren<{\n value: MessageInputContextValue;\n}>) => (\n <MessageInputContext.Provider value={value as unknown as MessageInputContextValue}>\n {children}\n </MessageInputContext.Provider>\n);\n\nexport const useMessageInputContext = (\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n componentName?: string,\n) => {\n const contextValue = useContext(MessageInputContext);\n\n if (!contextValue) {\n return {} as MessageInputContextValue;\n }\n\n return contextValue as unknown as MessageInputContextValue;\n};\n", "import React from 'react';\n\nexport const EmojiPickerIcon = () => (\n <svg\n preserveAspectRatio='xMinYMin'\n viewBox='0 0 28 28'\n width='100%'\n xmlns='http://www.w3.org/2000/svg'\n >\n <g clipRule='evenodd' fillRule='evenodd'>\n <path d='M14 4.4C8.6 4.4 4.4 8.6 4.4 14c0 5.4 4.2 9.6 9.6 9.6c5.4 0 9.6-4.2 9.6-9.6c0-5.4-4.2-9.6-9.6-9.6zM2 14c0-6.6 5.4-12 12-12s12 5.4 12 12s-5.4 12-12 12s-12-5.4-12-12zM12.8 11c0 1-.8 1.8-1.8 1.8s-1.8-.8-1.8-1.8s.8-1.8 1.8-1.8s1.8.8 1.8 1.8zM18.8 11c0 1-.8 1.8-1.8 1.8s-1.8-.8-1.8-1.8s.8-1.8 1.8-1.8s1.8.8 1.8 1.8zM8.6 15.4c.6-.4 1.2-.2 1.6.2c.6.8 1.6 1.8 3 2c1.2.4 2.8.2 4.8-2c.4-.4 1.2-.6 1.6 0c.4.4.6 1.2 0 1.6c-2.2 2.6-4.8 3.4-7 3c-2-.4-3.6-1.8-4.4-3c-.4-.6-.2-1.2.4-1.8z'></path>\n </g>\n </svg>\n);\n", "import mergeWith from 'lodash.mergewith';\nimport type {\n SearchSourceOptions,\n SearchSourceType,\n TextComposerMiddlewareOptions,\n TextComposerMiddlewareParams,\n TextComposerSuggestion,\n} from 'stream-chat';\nimport {\n BaseSearchSource,\n getTokenizedSuggestionDisplayName,\n getTriggerCharWithToken,\n insertItemWithTrigger,\n replaceWordWithEntity,\n} from 'stream-chat';\nimport type {\n EmojiSearchIndex,\n EmojiSearchIndexResult,\n} from '../../../components/MessageInput';\n\nclass EmojiSearchSource<\n T extends TextComposerSuggestion<EmojiSearchIndexResult>,\n> extends BaseSearchSource<T> {\n readonly type: SearchSourceType = 'emoji';\n private emojiSearchIndex: EmojiSearchIndex;\n\n constructor(emojiSearchIndex: EmojiSearchIndex, options?: SearchSourceOptions) {\n super(options);\n this.emojiSearchIndex = emojiSearchIndex;\n }\n\n async query(searchQuery: string) {\n if (searchQuery.length === 0) {\n return { items: [] as T[], next: null };\n }\n const emojis = (await this.emojiSearchIndex.search(searchQuery)) ?? [];\n\n // emojiIndex.search sometimes returns undefined values, so filter those out first\n return {\n items: emojis\n .filter(Boolean)\n .slice(0, 7)\n .map(({ emoticons = [], id, name, native, skins = [] }) => {\n const [firstSkin] = skins;\n\n return {\n emoticons,\n id,\n name,\n native: native ?? firstSkin.native,\n };\n }) as T[],\n next: null, // todo: generate cursor\n };\n }\n\n protected filterQueryResults(items: T[]): T[] | Promise<T[]> {\n return items.map((item) => ({\n ...item,\n ...getTokenizedSuggestionDisplayName({\n displayName: item.id,\n searchToken: this.searchQuery,\n }),\n }));\n }\n}\n\nconst DEFAULT_OPTIONS: TextComposerMiddlewareOptions = { minChars: 1, trigger: ':' };\n\n/**\n * TextComposer middleware for mentions\n * Usage:\n *\n * const textComposer = new TextComposer(options);\n *\n * textComposer.use(new createTextComposerEmojiMiddleware(emojiSearchIndex, {\n * minChars: 2\n * }));\n *\n * @param emojiSearchIndex\n * @param {{\n * minChars: number;\n * trigger: string;\n * }} options\n * @returns\n */\nexport const createTextComposerEmojiMiddleware = <\n T extends EmojiSearchIndexResult = EmojiSearchIndexResult,\n>(\n emojiSearchIndex: EmojiSearchIndex,\n options?: Partial<TextComposerMiddlewareOptions>,\n) => {\n const finalOptions = mergeWith(DEFAULT_OPTIONS, options ?? {});\n const emojiSearchSource = new EmojiSearchSource(emojiSearchIndex);\n emojiSearchSource.activate();\n\n return {\n id: 'stream-io/emoji-middleware',\n onChange: async ({ input, nextHandler }: TextComposerMiddlewareParams<T>) => {\n const { state } = input;\n if (!state.selection) return nextHandler(input);\n\n const triggerWithToken = getTriggerCharWithToken({\n acceptTrailingSpaces: false,\n text: state.text.slice(0, state.selection.end),\n trigger: finalOptions.trigger,\n });\n\n const triggerWasRemoved =\n !triggerWithToken || triggerWithToken.length < finalOptions.minChars;\n\n if (triggerWasRemoved) {\n const hasSuggestionsForTrigger =\n input.state.suggestions?.trigger === finalOptions.trigger;\n const newInput = { ...input };\n if (hasSuggestionsForTrigger && newInput.state.suggestions) {\n delete newInput.state.suggestions;\n }\n return nextHandler(newInput);\n }\n\n const newSearchTriggerred =\n triggerWithToken && triggerWithToken === finalOptions.trigger;\n\n if (newSearchTriggerred) {\n emojiSearchSource.resetStateAndActivate();\n }\n\n const textWithReplacedWord = await replaceWordWithEntity({\n caretPosition: state.selection.end,\n getEntityString: async (word: string) => {\n const { items } = await emojiSearchSource.query(word);\n\n const emoji = items\n .filter(Boolean)\n .slice(0, 10)\n .find(({ emoticons }) => !!emoticons?.includes(word));\n\n if (!emoji) return null;\n\n const [firstSkin] = emoji.skins ?? [];\n\n return emoji.native ?? firstSkin.native;\n },\n text: state.text,\n });\n\n if (textWithReplacedWord !== state.text) {\n return {\n state: {\n ...state,\n suggestions: undefined, // to prevent the TextComposerMiddlewareExecutor to run the first page query\n text: textWithReplacedWord,\n },\n stop: true, // Stop other middleware from processing '@' character\n };\n }\n\n return {\n state: {\n ...state,\n suggestions: {\n query: triggerWithToken.slice(1),\n searchSource: emojiSearchSource,\n trigger: finalOptions.trigger,\n },\n },\n stop: true, // Stop other middleware from processing '@' character\n };\n },\n onSuggestionItemSelect: ({\n input,\n nextHandler,\n selectedSuggestion,\n }: TextComposerMiddlewareParams<T>) => {\n const { state } = input;\n if (!selectedSuggestion || state.suggestions?.trigger !== finalOptions.trigger)\n return nextHandler(input);\n\n emojiSearchSource.resetStateAndActivate();\n return Promise.resolve({\n state: {\n ...state,\n ...insertItemWithTrigger({\n insertText: `${'native' in selectedSuggestion ? selectedSuggestion.native : ''} `,\n selection: state.selection,\n text: state.text,\n trigger: finalOptions.trigger,\n }),\n suggestions: undefined, // Clear suggestions after selection\n },\n });\n },\n };\n};\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAA,gBAA2C;AAC3C,0BAA0B;AAC1B,IAAAA,gBAAmB;;;ACFnB,mBAAkC;AAClC,IAAAC,gBAAkB;AAClB,sBAAqB;AACrB,6BAA4B;;;ACH5B,mBAAkB;AAuIX,IAAM,4BAAuC,CAAmB,QACrE;AAEK,IAAM,wBAAwB,CAAC,cAAiC,aAAAC,SAAM,KAAK;;;AD7HlF,cAAAC,QAAM,OAAO,gBAAAC,OAAQ;AACrB,cAAAD,QAAM,OAAO,uBAAAE,OAAe;AAQrB,IAAM,qBAAqB,aAAAC,QAAM,cAAuC;AAAA,EAC7E,GAAG;AAAA,EACH,iBAAiB;AAAA,EACjB,cAAc;AAChB,CAAC;AASM,IAAM,wBAAwB,CAAC,kBAA2B;AAC/D,QAAM,mBAAe,yBAAW,kBAAkB;AAElD,MAAI,CAAC,cAAc;AACjB,YAAQ;AAAA,MACN,gMAAgM,aAAa;AAAA,IAC/M;AAEA,WAAO,CAAC;AAAA,EACV;AAEA,SAAO;AACT;;;AE/CA,IAAAC,gBAAiD;AAU1C,IAAM,0BAAsB;AAAA,EACjC;AACF;AAaO,IAAM,yBAAyB,CAEpC,kBACG;AACH,QAAM,mBAAe,0BAAW,mBAAmB;AAEnD,MAAI,CAAC,cAAc;AACjB,WAAO,CAAC;AAAA,EACV;AAEA,SAAO;AACT;;;ACpCA,IAAAC,gBAAkB;AAEX,IAAM,kBAAkB,MAC7B,8BAAAC,QAAA;AAAA,EAAC;AAAA;AAAA,IACC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Q,QAAQ;AAAA,QACrB,OAAO;AAAA,UACL,GAAG;AAAA,UACH,OAAG,0CAAsB;AAAA,YACvB,YAAY,GAAG,YAAY,qBAAqB,mBAAmB,SAAS,EAAE;AAAA,YAC9E,WAAW,MAAM;AAAA,YACjB,MAAM,MAAM;AAAA,YACZ,SAAS,aAAa;AAAA,UACxB,CAAC;AAAA,UACD,aAAa;AAAA;AAAA,QACf;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AACF;",
6
- "names": ["import_react", "import_dayjs", "Dayjs", "Dayjs", "calendar", "localizedFormat", "React", "import_react", "import_react", "React", "React", "Picker", "mergeWith"]
3
+ "sources": ["../../../src/plugins/Emojis/index.ts", "../../../src/plugins/Emojis/EmojiPicker.tsx", "../../../src/plugins/Emojis/icons.tsx", "../../../src/context/ChannelStateContext.tsx", "../../../src/context/ChatContext.tsx", "../../../src/context/MessageContext.tsx", "../../../src/context/TranslationContext.tsx", "../../../src/i18n/utils.ts", "../../../src/components/MessageInput/hooks/useMessageComposer.ts", "../../../src/components/Threads/ThreadContext.tsx", "../../../src/components/Thread/Thread.tsx", "../../../src/context/MessageInputContext.tsx", "../../../src/plugins/Emojis/middleware/textComposerEmojiMiddleware.ts"],
4
+ "sourcesContent": ["export * from './EmojiPicker';\nexport * from './middleware';\nexport { EmojiPickerIcon } from './icons';\n", "import React, { useEffect, useState } from 'react';\nimport { usePopper } from 'react-popper';\nimport Picker from '@emoji-mart/react';\n\nimport type { Options } from '@popperjs/core';\n\nimport { EmojiPickerIcon } from './icons';\nimport { useMessageInputContext, useTranslationContext } from '../../context';\nimport { useMessageComposer } from '../../components';\n\nconst isShadowRoot = (node: Node): node is ShadowRoot => !!(node as ShadowRoot).host;\n\nexport type EmojiPickerProps = {\n ButtonIconComponent?: React.ComponentType;\n buttonClassName?: string;\n pickerContainerClassName?: string;\n wrapperClassName?: string;\n closeOnEmojiSelect?: boolean;\n /**\n * Untyped [properties](https://github.com/missive/emoji-mart/tree/v5.5.2#options--props) to be\n * passed down to the [emoji-mart `Picker`](https://github.com/missive/emoji-mart/tree/v5.5.2#-picker) component\n */\n pickerProps?: Partial<{ theme: 'auto' | 'light' | 'dark' } & Record<string, unknown>>;\n /**\n * [React Popper options](https://popper.js.org/docs/v2/constructors/#options) to be\n * passed down to the [react-popper `usePopper`](https://popper.js.org/react-popper/v2/hook/) hook\n */\n popperOptions?: Partial<Options>;\n};\n\nconst classNames: EmojiPickerProps = {\n buttonClassName: 'str-chat__emoji-picker-button',\n pickerContainerClassName: 'str-chat__message-textarea-emoji-picker-container',\n wrapperClassName: 'str-chat__message-textarea-emoji-picker',\n};\n\nexport const EmojiPicker = (props: EmojiPickerProps) => {\n const { t } = useTranslationContext('EmojiPicker');\n const { textareaRef } = useMessageInputContext('EmojiPicker');\n const { textComposer } = useMessageComposer();\n const [displayPicker, setDisplayPicker] = useState(false);\n const [referenceElement, setReferenceElement] = useState<HTMLButtonElement | null>(\n null,\n );\n const [popperElement, setPopperElement] = useState<HTMLDivElement | null>(null);\n const { attributes, styles } = usePopper(referenceElement, popperElement, {\n placement: 'top-end',\n ...props.popperOptions,\n });\n\n const { buttonClassName, pickerContainerClassName, wrapperClassName } = classNames;\n\n const { ButtonIconComponent = EmojiPickerIcon } = props;\n\n useEffect(() => {\n if (!popperElement || !referenceElement) return;\n\n const handlePointerDown = (e: PointerEvent) => {\n const target = e.target as HTMLElement;\n\n const rootNode = target.getRootNode();\n\n if (\n popperElement.contains(isShadowRoot(rootNode) ? rootNode.host : target) ||\n referenceElement.contains(target)\n ) {\n return;\n }\n\n setDisplayPicker(false);\n };\n\n window.addEventListener('pointerdown', handlePointerDown);\n return () => window.removeEventListener('pointerdown', handlePointerDown);\n }, [referenceElement, popperElement]);\n\n return (\n <div className={props.wrapperClassName ?? wrapperClassName}>\n {displayPicker && (\n <div\n className={props.pickerContainerClassName ?? pickerContainerClassName}\n style={styles.popper}\n {...attributes.popper}\n ref={setPopperElement}\n >\n <Picker\n data={async () => (await import('@emoji-mart/data')).default}\n onEmojiSelect={(e: { native: string }) => {\n const textarea = textareaRef.current;\n if (!textarea) return;\n textComposer.insertText({ text: e.native });\n textarea.focus();\n if (props.closeOnEmojiSelect) {\n setDisplayPicker(false);\n }\n }}\n {...props.pickerProps}\n />\n </div>\n )}\n <button\n aria-expanded={displayPicker}\n aria-label={t('aria/Emoji picker')}\n className={props.buttonClassName ?? buttonClassName}\n onClick={() => setDisplayPicker((cv) => !cv)}\n ref={setReferenceElement}\n type='button'\n >\n {ButtonIconComponent && <ButtonIconComponent />}\n </button>\n </div>\n );\n};\n", "import React from 'react';\n\nexport const EmojiPickerIcon = () => (\n <svg\n preserveAspectRatio='xMinYMin'\n viewBox='0 0 28 28'\n width='100%'\n xmlns='http://www.w3.org/2000/svg'\n >\n <g clipRule='evenodd' fillRule='evenodd'>\n <path d='M14 4.4C8.6 4.4 4.4 8.6 4.4 14c0 5.4 4.2 9.6 9.6 9.6c5.4 0 9.6-4.2 9.6-9.6c0-5.4-4.2-9.6-9.6-9.6zM2 14c0-6.6 5.4-12 12-12s12 5.4 12 12s-5.4 12-12 12s-12-5.4-12-12zM12.8 11c0 1-.8 1.8-1.8 1.8s-1.8-.8-1.8-1.8s.8-1.8 1.8-1.8s1.8.8 1.8 1.8zM18.8 11c0 1-.8 1.8-1.8 1.8s-1.8-.8-1.8-1.8s.8-1.8 1.8-1.8s1.8.8 1.8 1.8zM8.6 15.4c.6-.4 1.2-.2 1.6.2c.6.8 1.6 1.8 3 2c1.2.4 2.8.2 4.8-2c.4-.4 1.2-.6 1.6 0c.4.4.6 1.2 0 1.6c-2.2 2.6-4.8 3.4-7 3c-2-.4-3.6-1.8-4.4-3c-.4-.6-.2-1.2.4-1.8z'></path>\n </g>\n </svg>\n);\n", "import type { PropsWithChildren } from 'react';\nimport React, { useContext } from 'react';\nimport type {\n Channel,\n ChannelConfigWithInfo,\n LocalMessage,\n Mute,\n ChannelState as StreamChannelState,\n} from 'stream-chat';\n\nimport type {\n ChannelUnreadUiState,\n GiphyVersions,\n ImageAttachmentSizeHandler,\n UnknownType,\n VideoAttachmentSizeHandler,\n} from '../types/types';\n\nexport type ChannelNotifications = Array<{\n id: string;\n text: string;\n type: 'success' | 'error';\n}>;\n\nexport type ChannelState = {\n suppressAutoscroll: boolean;\n error?: Error | null;\n hasMore?: boolean;\n hasMoreNewer?: boolean;\n highlightedMessageId?: string;\n loading?: boolean;\n loadingMore?: boolean;\n loadingMoreNewer?: boolean;\n members?: StreamChannelState['members'];\n messages?: LocalMessage[];\n pinnedMessages?: LocalMessage[];\n read?: StreamChannelState['read'];\n thread?: LocalMessage | null;\n threadHasMore?: boolean;\n threadLoadingMore?: boolean;\n threadMessages?: LocalMessage[];\n threadSuppressAutoscroll?: boolean;\n typing?: StreamChannelState['typing'];\n watcherCount?: number;\n watchers?: StreamChannelState['watchers'];\n};\n\nexport type ChannelStateContextValue = Omit<ChannelState, 'typing'> & {\n channel: Channel;\n channelCapabilities: Record<string, boolean>;\n channelConfig: ChannelConfigWithInfo | undefined;\n imageAttachmentSizeHandler: ImageAttachmentSizeHandler;\n notifications: ChannelNotifications;\n shouldGenerateVideoThumbnail: boolean;\n videoAttachmentSizeHandler: VideoAttachmentSizeHandler;\n channelUnreadUiState?: ChannelUnreadUiState;\n giphyVersion?: GiphyVersions;\n mutes?: Array<Mute>;\n watcher_count?: number;\n};\n\nexport const ChannelStateContext = React.createContext<\n ChannelStateContextValue | undefined\n>(undefined);\n\nexport const ChannelStateProvider = ({\n children,\n value,\n}: PropsWithChildren<{\n value: ChannelStateContextValue;\n}>) => (\n <ChannelStateContext.Provider value={value as unknown as ChannelStateContextValue}>\n {children}\n </ChannelStateContext.Provider>\n);\n\nexport const useChannelStateContext = (componentName?: string) => {\n const contextValue = useContext(ChannelStateContext);\n\n if (!contextValue) {\n console.warn(\n `The useChannelStateContext hook was called outside of the ChannelStateContext provider. Make sure this hook is called within a child of the Channel component. The errored call is located in the ${componentName} component.`,\n );\n\n return {} as ChannelStateContextValue;\n }\n\n return contextValue as unknown as ChannelStateContextValue;\n};\n\n/**\n * Typescript currently does not support partial inference, so if ChannelStateContext\n * typing is desired while using the HOC withChannelStateContext, the Props for the\n * wrapped component must be provided as the first generic.\n */\nexport const withChannelStateContext = <P extends UnknownType>(\n Component: React.ComponentType<P>,\n) => {\n const WithChannelStateContextComponent = (\n props: Omit<P, keyof ChannelStateContextValue>,\n ) => {\n const channelStateContext = useChannelStateContext();\n\n return <Component {...(props as P)} {...channelStateContext} />;\n };\n\n WithChannelStateContextComponent.displayName = (\n Component.displayName ||\n Component.name ||\n 'Component'\n ).replace('Base', '');\n\n return WithChannelStateContextComponent;\n};\n", "import React, { useContext } from 'react';\nimport type { PropsWithChildren } from 'react';\nimport type {\n AppSettingsAPIResponse,\n Channel,\n Mute,\n SearchController,\n} from 'stream-chat';\n\nimport { getDisplayName } from './utils/getDisplayName';\nimport type { ChatProps } from '../components/Chat/Chat';\nimport type { UnknownType } from '../types/types';\nimport type { ChannelsQueryState } from '../components/Chat/hooks/useChannelsQueryState';\n\ntype CSSClasses =\n | 'chat'\n | 'chatContainer'\n | 'channel'\n | 'channelList'\n | 'message'\n | 'messageList'\n | 'thread'\n | 'threadList'\n | 'virtualMessage'\n | 'virtualizedMessageList';\n\nexport type CustomClasses = Partial<Record<CSSClasses, string>>;\n\ntype ChannelConfId = string; // e.g.: \"messaging:general\"\n\nexport type ChatContextValue = {\n /**\n * Indicates, whether a channels query has been triggered within ChannelList by its channels pagination controller.\n */\n channelsQueryState: ChannelsQueryState;\n closeMobileNav: () => void;\n getAppSettings: () => Promise<AppSettingsAPIResponse> | null;\n latestMessageDatesByChannels: Record<ChannelConfId, Date>;\n mutes: Array<Mute>;\n openMobileNav: () => void;\n /** Instance of SearchController class that allows to control all the search operations. */\n searchController: SearchController;\n /**\n * Sets active channel to be rendered within Channel component.\n * @param newChannel\n * @param watchers\n * @param event\n */\n setActiveChannel: (\n newChannel?: Channel,\n watchers?: { limit?: number; offset?: number },\n event?: React.BaseSyntheticEvent,\n ) => void;\n useImageFlagEmojisOnWindows: boolean;\n /**\n * Active channel used to render the contents of the Channel component.\n */\n channel?: Channel;\n /**\n * Object through which custom classes can be set for main container components of the SDK.\n */\n customClasses?: CustomClasses;\n navOpen?: boolean;\n} & Partial<Pick<ChatProps, 'isMessageAIGenerated'>> &\n Required<Pick<ChatProps, 'theme' | 'client'>>;\n\nexport const ChatContext = React.createContext<ChatContextValue | undefined>(undefined);\n\nexport const ChatProvider = ({\n children,\n value,\n}: PropsWithChildren<{\n value: ChatContextValue;\n}>) => (\n <ChatContext.Provider value={value as unknown as ChatContextValue}>\n {children}\n </ChatContext.Provider>\n);\n\nexport const useChatContext = (componentName?: string) => {\n const contextValue = useContext(ChatContext);\n\n if (!contextValue) {\n console.warn(\n `The useChatContext hook was called outside of the ChatContext provider. Make sure this hook is called within a child of the Chat component. The errored call is located in the ${componentName} component.`,\n );\n\n return {} as ChatContextValue;\n }\n\n return contextValue as unknown as ChatContextValue;\n};\n\n/**\n * Typescript currently does not support partial inference so if ChatContext\n * typing is desired while using the HOC withChatContext the Props for the\n * wrapped component must be provided as the first generic.\n */\nexport const withChatContext = <P extends UnknownType>(\n Component: React.ComponentType<P>,\n) => {\n const WithChatContextComponent = (props: Omit<P, keyof ChatContextValue>) => {\n const chatContext = useChatContext();\n\n return <Component {...(props as P)} {...chatContext} />;\n };\n WithChatContextComponent.displayName = `WithChatContext${getDisplayName(Component)}`;\n return WithChatContextComponent;\n};\n", "import type { PropsWithChildren, ReactNode } from 'react';\nimport React, { useContext } from 'react';\n\nimport type {\n LocalMessage,\n Mute,\n ReactionResponse,\n ReactionSort,\n UserResponse,\n} from 'stream-chat';\n\nimport type { ChannelActionContextValue } from './ChannelActionContext';\n\nimport type { ActionHandlerReturnType } from '../components/Message/hooks/useActionHandler';\nimport type { PinPermissions } from '../components/Message/hooks/usePinHandler';\nimport type { ReactEventHandler } from '../components/Message/types';\nimport type { MessageActionsArray } from '../components/Message/utils';\nimport type { MessageInputProps } from '../components/MessageInput/MessageInput';\nimport type { GroupStyle } from '../components/MessageList/utils';\nimport type {\n ReactionDetailsComparator,\n ReactionsComparator,\n ReactionType,\n} from '../components/Reactions/types';\n\nimport type { RenderTextOptions } from '../components/Message/renderText';\nimport type { UnknownType } from '../types/types';\n\nexport type CustomMessageActions = {\n [key: string]: (\n message: LocalMessage,\n event: React.BaseSyntheticEvent,\n ) => Promise<void> | void;\n};\n\nexport type MessageContextValue = {\n /** If actions such as edit, delete, flag, mute are enabled on Message */\n actionsEnabled: boolean;\n /** Function to exit edit state */\n clearEditingState: (event?: React.BaseSyntheticEvent) => void;\n /** If the Message is in edit state */\n editing: boolean;\n /**\n * Returns all allowed actions on message by current user e.g., ['edit', 'delete', 'flag', 'mute', 'pin', 'quote', 'react', 'reply'].\n * Please check [Message](https://github.com/GetStream/stream-chat-react/blob/master/src/components/Message.tsx) component for default implementation.\n */\n getMessageActions: () => MessageActionsArray<string>;\n /** Function to send an action in a Channel */\n handleAction: ActionHandlerReturnType;\n /** Function to delete a message in a Channel */\n handleDelete: ReactEventHandler;\n /** Function to edit a message in a Channel */\n handleEdit: ReactEventHandler;\n /** Function to fetch the message reactions */\n handleFetchReactions: (\n reactionType?: ReactionType,\n sort?: ReactionSort,\n ) => Promise<Array<ReactionResponse>>;\n /** Function to flag a message in a Channel */\n handleFlag: ReactEventHandler;\n /** Function to mark message and the messages that follow it as unread in a Channel */\n handleMarkUnread: ReactEventHandler;\n /** Function to mute a user in a Channel */\n handleMute: ReactEventHandler;\n /** Function to open a Thread on a Message */\n handleOpenThread: ReactEventHandler;\n /** Function to pin a Message in a Channel */\n handlePin: ReactEventHandler;\n /** Function to post a reaction on a Message */\n handleReaction: (\n reactionType: string,\n event: React.BaseSyntheticEvent,\n ) => Promise<void>;\n /** Function to retry sending a Message */\n handleRetry: ChannelActionContextValue['retrySendMessage'];\n /** Function that returns whether the Message belongs to the current user */\n isMyMessage: () => boolean;\n /** The message object */\n message: LocalMessage;\n /** Indicates whether a message has not been read yet or has been marked unread */\n messageIsUnread: boolean;\n /** Handler function for a click event on an @mention in Message */\n onMentionsClickMessage: ReactEventHandler;\n /** Handler function for a hover event on an @mention in Message */\n onMentionsHoverMessage: ReactEventHandler;\n /** Handler function for a click event on the user that posted the Message */\n onUserClick: ReactEventHandler;\n /** Handler function for a hover event on the user that posted the Message */\n onUserHover: ReactEventHandler;\n /** Function to toggle the edit state on a Message */\n setEditingState: ReactEventHandler;\n /** Additional props for underlying MessageInput component, [available props](https://getstream.io/chat/docs/sdk/react/message-input-components/message_input/#props) */\n additionalMessageInputProps?: MessageInputProps;\n /** Call this function to keep message list scrolled to the bottom when the scroll height increases, e.g. an element appears below the last message (only used in the `VirtualizedMessageList`) */\n autoscrollToBottom?: () => void;\n /** Message component configuration prop. If true, picking a reaction from the `ReactionSelector` component will close the selector */\n closeReactionSelectorOnClick?: boolean;\n /** Object containing custom message actions and function handlers */\n customMessageActions?: CustomMessageActions;\n /** If true, the message is the last one in a group sent by a specific user (only used in the `VirtualizedMessageList`) */\n endOfGroup?: boolean;\n /** If true, the message is the first one in a group sent by a specific user (only used in the `VirtualizedMessageList`) */\n firstOfGroup?: boolean;\n /** Override the default formatting of the date. This is a function that has access to the original date object, returns a string */\n formatDate?: (date: Date) => string;\n /** If true, group messages sent by each user (only used in the `VirtualizedMessageList`) */\n groupedByUser?: boolean;\n /** A list of styles to apply to this message, ie. top, bottom, single */\n groupStyles?: GroupStyle[];\n /** Whether to highlight and focus the message on load */\n highlighted?: boolean;\n /** Whether the threaded message is the first in the thread list */\n initialMessage?: boolean;\n /**\n * A factory function that determines whether a message is AI generated or not.\n */\n isMessageAIGenerated?: (message: LocalMessage) => boolean;\n /** Latest message id on current channel */\n lastReceivedId?: string | null;\n /** DOMRect object for parent MessageList component */\n messageListRect?: DOMRect;\n /** Array of muted users coming from [ChannelStateContext](https://getstream.io/chat/docs/sdk/react/contexts/channel_state_context/#mutes) */\n mutes?: Mute[];\n /** @deprecated in favor of `channelCapabilities - The user roles allowed to pin Messages in various channel types */\n pinPermissions?: PinPermissions;\n /** Sort options to provide to a reactions query */\n reactionDetailsSort?: ReactionSort;\n /** A list of users that have read this Message */\n readBy?: UserResponse[];\n /** Custom function to render message text content, defaults to the renderText function: [utils](https://github.com/GetStream/stream-chat-react/blob/master/src/utils.tsx) */\n renderText?: (\n text?: string,\n mentioned_users?: UserResponse[],\n options?: RenderTextOptions,\n ) => ReactNode;\n /** Comparator function to sort the list of reacted users\n * @deprecated use `reactionDetailsSort` instead\n */\n sortReactionDetails?: ReactionDetailsComparator;\n /** Comparator function to sort reactions, defaults to chronological order */\n sortReactions?: ReactionsComparator;\n /** Whether or not the Message is in a Thread */\n threadList?: boolean;\n /** render HTML instead of markdown. Posting HTML is only allowed server-side */\n unsafeHTML?: boolean;\n};\n\nexport const MessageContext = React.createContext<MessageContextValue | undefined>(\n undefined,\n);\n\nexport const MessageProvider = ({\n children,\n value,\n}: PropsWithChildren<{\n value: MessageContextValue;\n}>) => (\n <MessageContext.Provider value={value as unknown as MessageContextValue}>\n {children}\n </MessageContext.Provider>\n);\n\nexport const useMessageContext = (\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n _componentName?: string,\n) => {\n const contextValue = useContext(MessageContext);\n\n if (!contextValue) {\n return {} as MessageContextValue;\n }\n\n return contextValue as unknown as MessageContextValue;\n};\n\n/**\n * Typescript currently does not support partial inference, so if MessageContext\n * typing is desired while using the HOC withMessageContext, the Props for the\n * wrapped component must be provided as the first generic.\n */\nexport const withMessageContext = <P extends UnknownType>(\n Component: React.ComponentType<P>,\n) => {\n const WithMessageContextComponent = (props: Omit<P, keyof MessageContextValue>) => {\n const messageContext = useMessageContext();\n\n return <Component {...(props as P)} {...messageContext} />;\n };\n\n WithMessageContextComponent.displayName = (\n Component.displayName ||\n Component.name ||\n 'Component'\n ).replace('Base', '');\n\n return WithMessageContextComponent;\n};\n", "import React, { useContext } from 'react';\nimport Dayjs from 'dayjs';\nimport calendar from 'dayjs/plugin/calendar';\nimport localizedFormat from 'dayjs/plugin/localizedFormat';\nimport type { PropsWithChildren } from 'react';\nimport type { TFunction } from 'i18next';\nimport type { TranslationLanguages } from 'stream-chat';\n\nimport { getDisplayName } from './utils/getDisplayName';\nimport { defaultDateTimeParser, defaultTranslatorFunction } from '../i18n/utils';\nimport type { UnknownType } from '../types/types';\nimport type { TDateTimeParser } from '../i18n/types';\n\nDayjs.extend(calendar);\nDayjs.extend(localizedFormat);\n\nexport type TranslationContextValue = {\n t: TFunction;\n tDateTimeParser: TDateTimeParser;\n userLanguage: TranslationLanguages;\n};\n\nexport const TranslationContext = React.createContext<TranslationContextValue>({\n t: defaultTranslatorFunction,\n tDateTimeParser: defaultDateTimeParser,\n userLanguage: 'en',\n});\n\nexport const TranslationProvider = ({\n children,\n value,\n}: PropsWithChildren<{ value: TranslationContextValue }>) => (\n <TranslationContext.Provider value={value}>{children}</TranslationContext.Provider>\n);\n\nexport const useTranslationContext = (componentName?: string) => {\n const contextValue = useContext(TranslationContext);\n\n if (!contextValue) {\n console.warn(\n `The useTranslationContext hook was called outside of the TranslationContext provider. Make sure this hook is called within a child of the Chat component. The errored call is located in the ${componentName} component.`,\n );\n\n return {} as TranslationContextValue;\n }\n\n return contextValue;\n};\n\nexport const withTranslationContext = <P extends UnknownType>(\n Component: React.ComponentType<P>,\n) => {\n const WithTranslationContextComponent = (\n props: Omit<P, keyof TranslationContextValue>,\n ) => {\n const translationContext = useTranslationContext();\n\n return <Component {...(props as P)} {...translationContext} />;\n };\n\n WithTranslationContextComponent.displayName = `WithTranslationContext${getDisplayName(\n Component,\n )}`;\n\n return WithTranslationContextComponent;\n};\n", "import Dayjs from 'dayjs';\n\nimport type { TFunction } from 'i18next';\nimport type { Moment } from 'moment-timezone';\nimport type {\n DateFormatterOptions,\n PredefinedFormatters,\n SupportedTranslations,\n TDateTimeParserInput,\n TDateTimeParserOutput,\n TimestampFormatterOptions,\n} from './types';\n\nexport const notValidDateWarning =\n 'MessageTimestamp was called without a message, or message has invalid created_at date.';\nexport const noParsingFunctionWarning =\n 'MessageTimestamp was called but there is no datetime parsing function available';\n\nexport const isNumberOrString = (\n output: TDateTimeParserOutput,\n): output is number | string => typeof output === 'string' || typeof output === 'number';\n\nexport const isDayOrMoment = (\n output: TDateTimeParserOutput,\n): output is Dayjs.Dayjs | Moment => !!(output as Dayjs.Dayjs | Moment)?.isSame;\n\nexport const isDate = (output: unknown): output is Date =>\n output !== null &&\n typeof output === 'object' &&\n typeof (output as Date).getTime === 'function';\n\nexport function getDateString({\n calendar,\n calendarFormats,\n format,\n formatDate,\n messageCreatedAt,\n t,\n tDateTimeParser,\n timestampTranslationKey,\n}: DateFormatterOptions): string | number | null {\n if (\n !messageCreatedAt ||\n (typeof messageCreatedAt === 'string' && !Date.parse(messageCreatedAt))\n ) {\n console.warn(notValidDateWarning);\n return null;\n }\n\n if (typeof formatDate === 'function') {\n return formatDate(new Date(messageCreatedAt));\n }\n\n if (t && timestampTranslationKey) {\n const options: TimestampFormatterOptions = {};\n if (typeof calendar !== 'undefined' && calendar !== null) options.calendar = calendar;\n if (typeof calendarFormats !== 'undefined' && calendarFormats !== null)\n options.calendarFormats = calendarFormats;\n if (typeof format !== 'undefined' && format !== null) options.format = format;\n\n const translatedTimestamp = t(timestampTranslationKey, {\n ...options,\n timestamp: new Date(messageCreatedAt),\n });\n const translationKeyFound = timestampTranslationKey !== translatedTimestamp;\n if (translationKeyFound) return translatedTimestamp;\n }\n\n if (!tDateTimeParser) {\n console.warn(noParsingFunctionWarning);\n return null;\n }\n\n const parsedTime = tDateTimeParser(messageCreatedAt);\n\n if (isDayOrMoment(parsedTime)) {\n /**\n * parsedTime.calendar is guaranteed on the type but is only\n * available when a user calls dayjs.extend(calendar)\n */\n return calendar && parsedTime.calendar\n ? parsedTime.calendar(undefined, calendarFormats || undefined)\n : parsedTime.format(format || undefined);\n }\n\n if (isDate(parsedTime)) {\n return parsedTime.toDateString();\n }\n\n if (isNumberOrString(parsedTime)) {\n return parsedTime;\n }\n\n return null;\n}\n\nexport const predefinedFormatters: PredefinedFormatters = {\n timestampFormatter:\n (streamI18n) =>\n (\n value,\n _,\n {\n calendarFormats,\n ...options\n }: Pick<TimestampFormatterOptions, 'calendar' | 'format'> & {\n calendarFormats?: Record<string, string> | string;\n },\n ) => {\n let parsedCalendarFormats;\n try {\n if (!options.calendar) {\n parsedCalendarFormats = {};\n } else if (typeof calendarFormats === 'string') {\n parsedCalendarFormats = JSON.parse(calendarFormats);\n } else if (typeof calendarFormats === 'object') {\n parsedCalendarFormats = calendarFormats;\n }\n } catch (e) {\n console.error('[TIMESTAMP FORMATTER]', e);\n }\n\n const result = getDateString({\n ...options,\n calendarFormats: parsedCalendarFormats,\n messageCreatedAt: value,\n tDateTimeParser: streamI18n.tDateTimeParser,\n });\n if (!result || typeof result === 'number') {\n return JSON.stringify(value);\n }\n return result;\n },\n};\n\nexport const defaultTranslatorFunction: TFunction = <tResult = string>(key: tResult) =>\n key;\n\nexport const defaultDateTimeParser = (input?: TDateTimeParserInput) => Dayjs(input);\n\nexport const isLanguageSupported = (\n language: string,\n): language is SupportedTranslations => {\n const translations = [\n 'de',\n 'en',\n 'es',\n 'fr',\n 'hi',\n 'it',\n 'ja',\n 'ko',\n 'nl',\n 'pt',\n 'ru',\n 'tr',\n ];\n return translations.some((translation) => language === translation);\n};\n", "import { useEffect, useMemo } from 'react';\nimport { FixedSizeQueueCache, MessageComposer } from 'stream-chat';\nimport { useThreadContext } from '../../Threads';\nimport {\n useChannelStateContext,\n useChatContext,\n useMessageContext,\n} from '../../../context';\nimport { useLegacyThreadContext } from '../../Thread';\n\nconst queueCache = new FixedSizeQueueCache<string, MessageComposer>(64);\n\nexport const useMessageComposer = () => {\n const { client } = useChatContext();\n const { channel } = useChannelStateContext();\n const { editing, message: editedMessage } = useMessageContext();\n // legacy thread will receive new composer\n const { legacyThread: parentMessage } = useLegacyThreadContext();\n const threadInstance = useThreadContext();\n\n const cachedEditedMessage = useMemo(() => {\n if (!editedMessage) return undefined;\n\n return editedMessage;\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [editedMessage?.id]);\n\n const cachedParentMessage = useMemo(() => {\n if (!parentMessage) return undefined;\n\n return parentMessage;\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [parentMessage?.id]);\n\n // composer hierarchy\n // edited message (always new) -> thread instance (own) -> thread message (always new) -> channel (own)\n // editedMessage ?? thread ?? parentMessage ?? channel;\n const messageComposer = useMemo(() => {\n if (editing && cachedEditedMessage) {\n const tag = MessageComposer.constructTag(cachedEditedMessage);\n\n const cachedComposer = queueCache.get(tag);\n if (cachedComposer) return cachedComposer;\n\n return new MessageComposer({\n client,\n composition: cachedEditedMessage,\n compositionContext: cachedEditedMessage,\n });\n } else if (threadInstance) {\n return threadInstance.messageComposer;\n } else if (cachedParentMessage) {\n const compositionContext = {\n ...cachedParentMessage,\n legacyThreadId: cachedParentMessage.id,\n };\n\n const tag = MessageComposer.constructTag(compositionContext);\n\n const cachedComposer = queueCache.get(tag);\n if (cachedComposer) return cachedComposer;\n\n return new MessageComposer({\n client,\n compositionContext,\n });\n } else {\n return channel.messageComposer;\n }\n }, [\n cachedEditedMessage,\n cachedParentMessage,\n channel,\n client,\n editing,\n threadInstance,\n ]);\n\n if (\n (['legacy_thread', 'message'] as MessageComposer['contextType'][]).includes(\n messageComposer.contextType,\n ) &&\n !queueCache.peek(messageComposer.tag)\n ) {\n queueCache.add(messageComposer.tag, messageComposer);\n }\n\n useEffect(() => {\n const unsubscribe = messageComposer.registerSubscriptions();\n return () => {\n unsubscribe();\n };\n }, [messageComposer]);\n\n return messageComposer;\n};\n", "import React, { createContext, useContext } from 'react';\n\nimport { Channel } from '../../components';\n\nimport type { PropsWithChildren } from 'react';\nimport type { Thread } from 'stream-chat';\n\nexport type ThreadContextValue = Thread | undefined;\n\nexport const ThreadContext = createContext<ThreadContextValue>(undefined);\n\nexport const useThreadContext = () => useContext(ThreadContext);\n\nexport const ThreadProvider = ({\n children,\n thread,\n}: PropsWithChildren<{ thread?: Thread }>) => (\n <ThreadContext.Provider value={thread}>\n <Channel channel={thread?.channel}>{children}</Channel>\n </ThreadContext.Provider>\n);\n", "import React, { useContext, useEffect } from 'react';\nimport clsx from 'clsx';\n\nimport { MESSAGE_ACTIONS } from '../Message';\nimport type { MessageInputProps } from '../MessageInput';\nimport { MessageInput, MessageInputFlat } from '../MessageInput';\nimport type { MessageListProps, VirtualizedMessageListProps } from '../MessageList';\nimport { MessageList, VirtualizedMessageList } from '../MessageList';\nimport { ThreadHeader as DefaultThreadHeader } from './ThreadHeader';\nimport { ThreadHead as DefaultThreadHead } from '../Thread/ThreadHead';\n\nimport {\n useChannelActionContext,\n useChannelStateContext,\n useChatContext,\n useComponentContext,\n} from '../../context';\nimport { useThreadContext } from '../Threads';\nimport { useStateStore } from '../../store';\n\nimport type { MessageProps, MessageUIComponentProps } from '../Message/types';\nimport type { MessageActionsArray } from '../Message/utils';\nimport type { LocalMessage, ThreadState } from 'stream-chat';\n\nexport type ThreadProps = {\n /** Additional props for `MessageInput` component: [available props](https://getstream.io/chat/docs/sdk/react/message-input-components/message_input/#props) */\n additionalMessageInputProps?: MessageInputProps;\n /** Additional props for `MessageList` component: [available props](https://getstream.io/chat/docs/sdk/react/core-components/message_list/#props) */\n additionalMessageListProps?: MessageListProps;\n /** Additional props for `Message` component of the parent message: [available props](https://getstream.io/chat/docs/sdk/react/message-components/message/#props) */\n additionalParentMessageProps?: Partial<MessageProps>;\n /** Additional props for `VirtualizedMessageList` component: [available props](https://getstream.io/chat/docs/sdk/react/core-components/virtualized_list/#props) */\n additionalVirtualizedMessageListProps?: VirtualizedMessageListProps;\n /** If true, focuses the `MessageInput` component on opening a thread */\n autoFocus?: boolean;\n /** Injects date separator components into `Thread`, defaults to `false`. To be passed to the underlying `MessageList` or `VirtualizedMessageList` components */\n enableDateSeparator?: boolean;\n /** Custom thread input UI component used to override the default `Input` value stored in `ComponentContext` or the [MessageInputSmall](https://github.com/GetStream/stream-chat-react/blob/master/src/components/MessageInput/MessageInputSmall.tsx) default */\n Input?: React.ComponentType;\n /** Custom thread message UI component used to override the default `Message` value stored in `ComponentContext` */\n Message?: React.ComponentType<MessageUIComponentProps>;\n /** Array of allowed message actions (ex: ['edit', 'delete', 'flag', 'mute', 'pin', 'quote', 'react', 'reply']). To disable all actions, provide an empty array. */\n messageActions?: MessageActionsArray;\n /** If true, render the `VirtualizedMessageList` instead of the standard `MessageList` component */\n virtualized?: boolean;\n};\n\nconst LegacyThreadContext = React.createContext<{\n legacyThread: LocalMessage | undefined;\n}>({ legacyThread: undefined });\n\nexport const useLegacyThreadContext = () => useContext(LegacyThreadContext);\n\n/**\n * The Thread component renders a parent Message with a list of replies\n */\nexport const Thread = (props: ThreadProps) => {\n const { channel, channelConfig, thread } = useChannelStateContext('Thread');\n const threadInstance = useThreadContext();\n\n if (!thread && !threadInstance) return null;\n if (channelConfig?.replies === false) return null;\n\n // the wrapper ensures a key variable is set and the component recreates on thread switch\n return (\n // FIXME: TS is having trouble here as at least one of the two would always be defined\n <ThreadInner\n {...props}\n key={`thread-${(thread ?? threadInstance)?.id}-${channel?.cid}`}\n />\n );\n};\n\nconst selector = (nextValue: ThreadState) => ({\n isLoadingNext: nextValue.pagination.isLoadingNext,\n isLoadingPrev: nextValue.pagination.isLoadingPrev,\n parentMessage: nextValue.parentMessage,\n replies: nextValue.replies,\n});\n\nconst ThreadInner = (props: ThreadProps & { key: string }) => {\n const {\n additionalMessageInputProps,\n additionalMessageListProps,\n additionalParentMessageProps,\n additionalVirtualizedMessageListProps,\n autoFocus = true,\n enableDateSeparator = false,\n Input: PropInput,\n Message: PropMessage,\n messageActions = Object.keys(MESSAGE_ACTIONS),\n virtualized,\n } = props;\n\n const threadInstance = useThreadContext();\n\n const {\n thread,\n threadHasMore,\n threadLoadingMore,\n threadMessages = [],\n threadSuppressAutoscroll,\n } = useChannelStateContext('Thread');\n const { closeThread, loadMoreThread } = useChannelActionContext('Thread');\n const { customClasses } = useChatContext('Thread');\n const {\n Message: ContextMessage,\n ThreadHead = DefaultThreadHead,\n ThreadHeader = DefaultThreadHeader,\n ThreadInput: ContextInput,\n VirtualMessage,\n } = useComponentContext('Thread');\n\n const { isLoadingNext, isLoadingPrev, parentMessage, replies } =\n useStateStore(threadInstance?.state, selector) ?? {};\n\n const ThreadInput =\n PropInput ?? additionalMessageInputProps?.Input ?? ContextInput ?? MessageInputFlat;\n\n const ThreadMessage = PropMessage || additionalMessageListProps?.Message;\n const FallbackMessage = virtualized && VirtualMessage ? VirtualMessage : ContextMessage;\n const MessageUIComponent = ThreadMessage || FallbackMessage;\n\n const ThreadMessageList = virtualized ? VirtualizedMessageList : MessageList;\n\n useEffect(() => {\n if (threadInstance) return;\n\n if ((thread?.reply_count ?? 0) > 0) {\n // FIXME: integrators can customize channel query options but cannot customize channel.getReplies() options\n loadMoreThread();\n }\n }, [thread, loadMoreThread, threadInstance]);\n\n const threadProps: Pick<\n VirtualizedMessageListProps,\n | 'hasMoreNewer'\n | 'loadMoreNewer'\n | 'loadingMoreNewer'\n | 'hasMore'\n | 'loadMore'\n | 'loadingMore'\n | 'messages'\n > = threadInstance\n ? {\n loadingMore: isLoadingPrev,\n loadingMoreNewer: isLoadingNext,\n loadMore: threadInstance.loadPrevPage,\n loadMoreNewer: threadInstance.loadNextPage,\n messages: replies,\n }\n : {\n hasMore: threadHasMore,\n loadingMore: threadLoadingMore,\n loadMore: loadMoreThread,\n messages: threadMessages,\n };\n\n const messageAsThread = thread ?? parentMessage;\n\n if (!messageAsThread) return null;\n\n const threadClass =\n customClasses?.thread ||\n clsx('str-chat__thread-container str-chat__thread', {\n 'str-chat__thread--virtualized': virtualized,\n });\n\n const head = (\n <ThreadHead\n key={messageAsThread.id}\n message={messageAsThread}\n Message={MessageUIComponent}\n {...additionalParentMessageProps}\n />\n );\n\n return (\n // Thread component needs a context which we can use for message composer\n <LegacyThreadContext.Provider\n value={{\n legacyThread: thread ?? undefined,\n }}\n >\n <div className={threadClass}>\n <ThreadHeader closeThread={closeThread} thread={messageAsThread} />\n <ThreadMessageList\n disableDateSeparator={!enableDateSeparator}\n head={head}\n Message={MessageUIComponent}\n messageActions={messageActions}\n suppressAutoscroll={threadSuppressAutoscroll}\n threadList\n {...threadProps}\n {...(virtualized\n ? additionalVirtualizedMessageListProps\n : additionalMessageListProps)}\n />\n <MessageInput\n focus={autoFocus}\n Input={ThreadInput}\n isThreadInput\n parent={thread ?? parentMessage}\n {...additionalMessageInputProps}\n />\n </div>\n </LegacyThreadContext.Provider>\n );\n};\n", "import React, { createContext, useContext } from 'react';\nimport type { PropsWithChildren } from 'react';\n\nimport type { CooldownTimerState, MessageInputProps } from '../components/MessageInput';\nimport type { MessageInputHookProps } from '../components/MessageInput/hooks/useMessageInputControls';\n\nexport type MessageInputContextValue = MessageInputHookProps &\n Omit<MessageInputProps, 'Input'> &\n CooldownTimerState;\n\nexport const MessageInputContext = createContext<MessageInputHookProps | undefined>(\n undefined,\n);\n\nexport const MessageInputContextProvider = ({\n children,\n value,\n}: PropsWithChildren<{\n value: MessageInputContextValue;\n}>) => (\n <MessageInputContext.Provider value={value as unknown as MessageInputContextValue}>\n {children}\n </MessageInputContext.Provider>\n);\n\nexport const useMessageInputContext = (\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n componentName?: string,\n) => {\n const contextValue = useContext(MessageInputContext);\n\n if (!contextValue) {\n return {} as MessageInputContextValue;\n }\n\n return contextValue as unknown as MessageInputContextValue;\n};\n", "import mergeWith from 'lodash.mergewith';\nimport type {\n Middleware,\n SearchSourceOptions,\n SearchSourceType,\n TextComposerMiddlewareExecutorState,\n TextComposerMiddlewareOptions,\n TextComposerSuggestion,\n} from 'stream-chat';\nimport {\n BaseSearchSource,\n getTokenizedSuggestionDisplayName,\n getTriggerCharWithToken,\n insertItemWithTrigger,\n replaceWordWithEntity,\n} from 'stream-chat';\nimport type {\n EmojiSearchIndex,\n EmojiSearchIndexResult,\n} from '../../../components/MessageInput';\n\nexport type EmojiSuggestion<T extends EmojiSearchIndexResult = EmojiSearchIndexResult> =\n TextComposerSuggestion<T>;\n\nclass EmojiSearchSource<\n T extends TextComposerSuggestion<EmojiSearchIndexResult>,\n> extends BaseSearchSource<T> {\n readonly type: SearchSourceType = 'emoji';\n private emojiSearchIndex: EmojiSearchIndex;\n\n constructor(emojiSearchIndex: EmojiSearchIndex, options?: SearchSourceOptions) {\n super(options);\n this.emojiSearchIndex = emojiSearchIndex;\n }\n\n async query(searchQuery: string) {\n if (searchQuery.length === 0) {\n return { items: [] as T[], next: null };\n }\n const emojis = (await this.emojiSearchIndex.search(searchQuery)) ?? [];\n\n // emojiIndex.search sometimes returns undefined values, so filter those out first\n return {\n items: emojis\n .filter(Boolean)\n .slice(0, 7)\n .map(({ emoticons = [], id, name, native, skins = [] }) => {\n const [firstSkin] = skins;\n\n return {\n emoticons,\n id,\n name,\n native: native ?? firstSkin.native,\n };\n }) as T[],\n next: null, // todo: generate cursor\n };\n }\n\n protected filterQueryResults(items: T[]): T[] | Promise<T[]> {\n return items.map((item) => ({\n ...item,\n ...getTokenizedSuggestionDisplayName({\n displayName: item.id,\n searchToken: this.searchQuery,\n }),\n }));\n }\n}\n\nconst DEFAULT_OPTIONS: TextComposerMiddlewareOptions = { minChars: 1, trigger: ':' };\n\nexport type EmojiMiddleware<T extends EmojiSearchIndexResult = EmojiSearchIndexResult> =\n Middleware<\n TextComposerMiddlewareExecutorState<EmojiSuggestion<T>>,\n 'onChange' | 'onSuggestionItemSelect'\n >;\n\n/**\n * TextComposer middleware for mentions\n * Usage:\n *\n * const textComposer = new TextComposer(options);\n *\n * textComposer.use(new createTextComposerEmojiMiddleware(emojiSearchIndex, {\n * minChars: 2\n * }));\n *\n * @param emojiSearchIndex\n * @param {{\n * minChars: number;\n * trigger: string;\n * }} options\n * @returns\n */\nexport const createTextComposerEmojiMiddleware = (\n emojiSearchIndex: EmojiSearchIndex,\n options?: Partial<TextComposerMiddlewareOptions>,\n): EmojiMiddleware => {\n const finalOptions = mergeWith(DEFAULT_OPTIONS, options ?? {});\n const emojiSearchSource = new EmojiSearchSource(emojiSearchIndex);\n emojiSearchSource.activate();\n\n return {\n id: 'stream-io/emoji-middleware',\n // eslint-disable-next-line sort-keys\n handlers: {\n onChange: async ({ complete, forward, next, state }) => {\n if (!state.selection) return forward();\n\n const triggerWithToken = getTriggerCharWithToken({\n acceptTrailingSpaces: false,\n text: state.text.slice(0, state.selection.end),\n trigger: finalOptions.trigger,\n });\n\n const triggerWasRemoved =\n !triggerWithToken || triggerWithToken.length < finalOptions.minChars;\n\n if (triggerWasRemoved) {\n const hasSuggestionsForTrigger =\n state.suggestions?.trigger === finalOptions.trigger;\n const newState = { ...state };\n if (hasSuggestionsForTrigger && newState.suggestions) {\n delete newState.suggestions;\n }\n return next(newState);\n }\n\n const newSearchTriggerred =\n triggerWithToken && triggerWithToken === finalOptions.trigger;\n\n if (newSearchTriggerred) {\n emojiSearchSource.resetStateAndActivate();\n }\n\n const textWithReplacedWord = await replaceWordWithEntity({\n caretPosition: state.selection.end,\n getEntityString: async (word: string) => {\n const { items } = await emojiSearchSource.query(word);\n\n const emoji = items\n .filter(Boolean)\n .slice(0, 10)\n .find(({ emoticons }) => !!emoticons?.includes(word));\n\n if (!emoji) return null;\n\n const [firstSkin] = emoji.skins ?? [];\n\n return emoji.native ?? firstSkin.native;\n },\n text: state.text,\n });\n\n if (textWithReplacedWord !== state.text) {\n return complete({\n ...state,\n suggestions: undefined, // to prevent the TextComposerMiddlewareExecutor to run the first page query\n text: textWithReplacedWord,\n });\n }\n\n return complete({\n ...state,\n suggestions: {\n query: triggerWithToken.slice(1),\n searchSource: emojiSearchSource,\n trigger: finalOptions.trigger,\n },\n });\n },\n onSuggestionItemSelect: ({ complete, forward, state }) => {\n const { selectedSuggestion } = state.change ?? {};\n if (!selectedSuggestion || state.suggestions?.trigger !== finalOptions.trigger)\n return forward();\n\n emojiSearchSource.resetStateAndActivate();\n return complete({\n ...state,\n ...insertItemWithTrigger({\n insertText: `${'native' in selectedSuggestion ? selectedSuggestion.native : ''} `,\n selection: state.selection,\n text: state.text,\n trigger: finalOptions.trigger,\n }),\n suggestions: undefined, // Clear suggestions after selection\n });\n },\n },\n };\n};\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAA,iBAA2C;AAC3C,0BAA0B;AAC1B,IAAAA,iBAAmB;;;ACFnB,mBAAkB;AAEX,IAAM,kBAAkB,MAC7B,6BAAAC,QAAA;AAAA,EAAC;AAAA;AAAA,IACC,qBAAoB;AAAA,IACpB,SAAQ;AAAA,IACR,OAAM;AAAA,IACN,OAAM;AAAA;AAAA,EAEN,6BAAAA,QAAA,cAAC,OAAE,UAAS,WAAU,UAAS,aAC7B,6BAAAA,QAAA,cAAC,UAAK,GAAE,0dAAyd,CACne;AACF;;;ACXF,IAAAC,gBAAkC;AA4D3B,IAAM,sBAAsB,cAAAC,QAAM,cAEvC,MAAS;AAaJ,IAAM,yBAAyB,CAAC,kBAA2B;AAChE,QAAM,mBAAe,0BAAW,mBAAmB;AAEnD,MAAI,CAAC,cAAc;AACjB,YAAQ;AAAA,MACN,qMAAqM,aAAa;AAAA,IACpN;AAEA,WAAO,CAAC;AAAA,EACV;AAEA,SAAO;AACT;;;ACxFA,IAAAC,gBAAkC;AAkE3B,IAAM,cAAc,cAAAC,QAAM,cAA4C,MAAS;AAa/E,IAAM,iBAAiB,CAAC,kBAA2B;AACxD,QAAM,mBAAe,0BAAW,WAAW;AAE3C,MAAI,CAAC,cAAc;AACjB,YAAQ;AAAA,MACN,kLAAkL,aAAa;AAAA,IACjM;AAEA,WAAO,CAAC;AAAA,EACV;AAEA,SAAO;AACT;;;AC1FA,IAAAC,gBAAkC;AAkJ3B,IAAM,iBAAiB,cAAAC,QAAM;AAAA,EAClC;AACF;AAaO,IAAM,oBAAoB,CAE/B,mBACG;AACH,QAAM,mBAAe,0BAAW,cAAc;AAE9C,M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QAAQ;AAEjB,0BAAkB,sBAAsB;AACxC,eAAO,SAAS;AAAA,UACd,GAAG;AAAA,UACH,OAAG,2CAAsB;AAAA,YACvB,YAAY,GAAG,YAAY,qBAAqB,mBAAmB,SAAS,EAAE;AAAA,YAC9E,WAAW,MAAM;AAAA,YACjB,MAAM,MAAM;AAAA,YACZ,SAAS,aAAa;AAAA,UACxB,CAAC;AAAA,UACD,aAAa;AAAA;AAAA,QACf,CAAC;AAAA,MACH;AAAA,IACF;AAAA,EACF;AACF;",
6
+ "names": ["import_react", "React", "import_react", "React", "import_react", "React", "import_react", "React", "import_react", "import_dayjs", "Dayjs", "Dayjs", "calendar", "localizedFormat", "React", "import_react", "import_react", "import_react", "React", "import_react", "React", "Picker", "import_stream_chat", "mergeWith"]
7
7
  }
@@ -1,16 +1,7 @@
1
- import type { SearchSourceOptions, SearchSourceType, TextComposerMiddlewareOptions, TextComposerMiddlewareParams, TextComposerSuggestion } from 'stream-chat';
2
- import { BaseSearchSource } from 'stream-chat';
1
+ import type { Middleware, TextComposerMiddlewareExecutorState, TextComposerMiddlewareOptions, TextComposerSuggestion } from 'stream-chat';
3
2
  import type { EmojiSearchIndex, EmojiSearchIndexResult } from '../../../components/MessageInput';
4
- declare class EmojiSearchSource<T extends TextComposerSuggestion<EmojiSearchIndexResult>> extends BaseSearchSource<T> {
5
- readonly type: SearchSourceType;
6
- private emojiSearchIndex;
7
- constructor(emojiSearchIndex: EmojiSearchIndex, options?: SearchSourceOptions);
8
- query(searchQuery: string): Promise<{
9
- items: T[];
10
- next: null;
11
- }>;
12
- protected filterQueryResults(items: T[]): T[] | Promise<T[]>;
13
- }
3
+ export type EmojiSuggestion<T extends EmojiSearchIndexResult = EmojiSearchIndexResult> = TextComposerSuggestion<T>;
4
+ export type EmojiMiddleware<T extends EmojiSearchIndexResult = EmojiSearchIndexResult> = Middleware<TextComposerMiddlewareExecutorState<EmojiSuggestion<T>>, 'onChange' | 'onSuggestionItemSelect'>;
14
5
  /**
15
6
  * TextComposer middleware for mentions
16
7
  * Usage:
@@ -28,39 +19,4 @@ declare class EmojiSearchSource<T extends TextComposerSuggestion<EmojiSearchInde
28
19
  * }} options
29
20
  * @returns
30
21
  */
31
- export declare const createTextComposerEmojiMiddleware: <T extends EmojiSearchIndexResult = EmojiSearchIndexResult>(emojiSearchIndex: EmojiSearchIndex, options?: Partial<TextComposerMiddlewareOptions>) => {
32
- id: string;
33
- onChange: ({ input, nextHandler }: TextComposerMiddlewareParams<T>) => Promise<import("stream-chat").TextComposerMiddlewareValue | {
34
- state: {
35
- suggestions: undefined;
36
- text: string;
37
- mentionedUsers: import("stream-chat").UserResponse[];
38
- selection: import("stream-chat").TextSelection;
39
- };
40
- stop: boolean;
41
- } | {
42
- state: {
43
- suggestions: {
44
- query: string;
45
- searchSource: EmojiSearchSource<TextComposerSuggestion<EmojiSearchIndexResult>>;
46
- trigger: any;
47
- };
48
- mentionedUsers: import("stream-chat").UserResponse[];
49
- selection: import("stream-chat").TextSelection;
50
- text: string;
51
- };
52
- stop: boolean;
53
- }>;
54
- onSuggestionItemSelect: ({ input, nextHandler, selectedSuggestion, }: TextComposerMiddlewareParams<T>) => Promise<import("stream-chat").TextComposerMiddlewareValue> | Promise<{
55
- state: {
56
- suggestions: undefined;
57
- text: string;
58
- selection: {
59
- start: number;
60
- end: number;
61
- };
62
- mentionedUsers: import("stream-chat").UserResponse[];
63
- };
64
- }>;
65
- };
66
- export {};
22
+ export declare const createTextComposerEmojiMiddleware: (emojiSearchIndex: EmojiSearchIndex, options?: Partial<TextComposerMiddlewareOptions>) => EmojiMiddleware;
@@ -62,72 +62,66 @@ export const createTextComposerEmojiMiddleware = (emojiSearchIndex, options) =>
62
62
  emojiSearchSource.activate();
63
63
  return {
64
64
  id: 'stream-io/emoji-middleware',
65
- onChange: async ({ input, nextHandler }) => {
66
- const { state } = input;
67
- if (!state.selection)
68
- return nextHandler(input);
69
- const triggerWithToken = getTriggerCharWithToken({
70
- acceptTrailingSpaces: false,
71
- text: state.text.slice(0, state.selection.end),
72
- trigger: finalOptions.trigger,
73
- });
74
- const triggerWasRemoved = !triggerWithToken || triggerWithToken.length < finalOptions.minChars;
75
- if (triggerWasRemoved) {
76
- const hasSuggestionsForTrigger = input.state.suggestions?.trigger === finalOptions.trigger;
77
- const newInput = { ...input };
78
- if (hasSuggestionsForTrigger && newInput.state.suggestions) {
79
- delete newInput.state.suggestions;
65
+ // eslint-disable-next-line sort-keys
66
+ handlers: {
67
+ onChange: async ({ complete, forward, next, state }) => {
68
+ if (!state.selection)
69
+ return forward();
70
+ const triggerWithToken = getTriggerCharWithToken({
71
+ acceptTrailingSpaces: false,
72
+ text: state.text.slice(0, state.selection.end),
73
+ trigger: finalOptions.trigger,
74
+ });
75
+ const triggerWasRemoved = !triggerWithToken || triggerWithToken.length < finalOptions.minChars;
76
+ if (triggerWasRemoved) {
77
+ const hasSuggestionsForTrigger = state.suggestions?.trigger === finalOptions.trigger;
78
+ const newState = { ...state };
79
+ if (hasSuggestionsForTrigger && newState.suggestions) {
80
+ delete newState.suggestions;
81
+ }
82
+ return next(newState);
80
83
  }
81
- return nextHandler(newInput);
82
- }
83
- const newSearchTriggerred = triggerWithToken && triggerWithToken === finalOptions.trigger;
84
- if (newSearchTriggerred) {
85
- emojiSearchSource.resetStateAndActivate();
86
- }
87
- const textWithReplacedWord = await replaceWordWithEntity({
88
- caretPosition: state.selection.end,
89
- getEntityString: async (word) => {
90
- const { items } = await emojiSearchSource.query(word);
91
- const emoji = items
92
- .filter(Boolean)
93
- .slice(0, 10)
94
- .find(({ emoticons }) => !!emoticons?.includes(word));
95
- if (!emoji)
96
- return null;
97
- const [firstSkin] = emoji.skins ?? [];
98
- return emoji.native ?? firstSkin.native;
99
- },
100
- text: state.text,
101
- });
102
- if (textWithReplacedWord !== state.text) {
103
- return {
104
- state: {
84
+ const newSearchTriggerred = triggerWithToken && triggerWithToken === finalOptions.trigger;
85
+ if (newSearchTriggerred) {
86
+ emojiSearchSource.resetStateAndActivate();
87
+ }
88
+ const textWithReplacedWord = await replaceWordWithEntity({
89
+ caretPosition: state.selection.end,
90
+ getEntityString: async (word) => {
91
+ const { items } = await emojiSearchSource.query(word);
92
+ const emoji = items
93
+ .filter(Boolean)
94
+ .slice(0, 10)
95
+ .find(({ emoticons }) => !!emoticons?.includes(word));
96
+ if (!emoji)
97
+ return null;
98
+ const [firstSkin] = emoji.skins ?? [];
99
+ return emoji.native ?? firstSkin.native;
100
+ },
101
+ text: state.text,
102
+ });
103
+ if (textWithReplacedWord !== state.text) {
104
+ return complete({
105
105
  ...state,
106
106
  suggestions: undefined, // to prevent the TextComposerMiddlewareExecutor to run the first page query
107
107
  text: textWithReplacedWord,
108
- },
109
- stop: true, // Stop other middleware from processing '@' character
110
- };
111
- }
112
- return {
113
- state: {
108
+ });
109
+ }
110
+ return complete({
114
111
  ...state,
115
112
  suggestions: {
116
113
  query: triggerWithToken.slice(1),
117
114
  searchSource: emojiSearchSource,
118
115
  trigger: finalOptions.trigger,
119
116
  },
120
- },
121
- stop: true, // Stop other middleware from processing '@' character
122
- };
123
- },
124
- onSuggestionItemSelect: ({ input, nextHandler, selectedSuggestion, }) => {
125
- const { state } = input;
126
- if (!selectedSuggestion || state.suggestions?.trigger !== finalOptions.trigger)
127
- return nextHandler(input);
128
- emojiSearchSource.resetStateAndActivate();
129
- return Promise.resolve({
130
- state: {
117
+ });
118
+ },
119
+ onSuggestionItemSelect: ({ complete, forward, state }) => {
120
+ const { selectedSuggestion } = state.change ?? {};
121
+ if (!selectedSuggestion || state.suggestions?.trigger !== finalOptions.trigger)
122
+ return forward();
123
+ emojiSearchSource.resetStateAndActivate();
124
+ return complete({
131
125
  ...state,
132
126
  ...insertItemWithTrigger({
133
127
  insertText: `${'native' in selectedSuggestion ? selectedSuggestion.native : ''} `,
@@ -136,8 +130,8 @@ export const createTextComposerEmojiMiddleware = (emojiSearchIndex, options) =>
136
130
  trigger: finalOptions.trigger,
137
131
  }),
138
132
  suggestions: undefined, // Clear suggestions after selection
139
- },
140
- });
133
+ });
134
+ },
141
135
  },
142
136
  };
143
137
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "stream-chat-react",
3
- "version": "13.0.0-rc.1",
3
+ "version": "13.0.0",
4
4
  "description": "React components to create chat conversations or livestream style chat",
5
5
  "author": "GetStream",
6
6
  "homepage": "https://getstream.io/chat/",
@@ -145,7 +145,7 @@
145
145
  "emoji-mart": "^5.4.0",
146
146
  "react": "^19.0.0 || ^18.0.0 || ^17.0.0 || ^16.14.0",
147
147
  "react-dom": "^19.0.0 || ^18.0.0 || ^17.0.0 || ^16.14.0",
148
- "stream-chat": "^9.0.0-rc.13"
148
+ "stream-chat": "^9.0.0"
149
149
  },
150
150
  "peerDependenciesMeta": {
151
151
  "@breezystack/lamejs": {
@@ -239,7 +239,7 @@
239
239
  "react": "^19.0.0",
240
240
  "react-dom": "^19.0.0",
241
241
  "semantic-release": "^24.2.3",
242
- "stream-chat": "^9.0.0-rc.13",
242
+ "stream-chat": "^9.0.0",
243
243
  "ts-jest": "^29.2.5",
244
244
  "typescript": "^5.4.5",
245
245
  "typescript-eslint": "^8.17.0"
@@ -1,44 +0,0 @@
1
- import { useCallback, useEffect, useRef } from 'react';
2
- import { useMessageComposer } from './useMessageComposer';
3
- import { useStateStore } from '../../../store';
4
- const messageComposerStateSelector = (state) => ({
5
- text: state.text,
6
- });
7
- export const useMessageInputText = (props) => {
8
- const { focus } = props;
9
- const messageComposer = useMessageComposer();
10
- const textareaRef = useRef(undefined);
11
- const { text } = useStateStore(messageComposer.textComposer.state, messageComposerStateSelector);
12
- // Focus
13
- useEffect(() => {
14
- if (focus && textareaRef.current) {
15
- textareaRef.current.focus();
16
- }
17
- }, [focus]);
18
- // Text + cursor position
19
- const newCursorPosition = useRef(undefined);
20
- const insertText = useCallback((textToInsert) => {
21
- const selection = textareaRef?.current && {
22
- end: textareaRef.current.selectionEnd,
23
- start: textareaRef.current.selectionStart,
24
- };
25
- messageComposer.textComposer.insertText({
26
- selection,
27
- text: textToInsert,
28
- });
29
- if (selection)
30
- newCursorPosition.current = selection.start + textToInsert.length;
31
- }, [messageComposer, newCursorPosition, textareaRef]);
32
- useEffect(() => {
33
- const textareaElement = textareaRef.current;
34
- if (textareaElement && newCursorPosition.current !== undefined) {
35
- textareaElement.selectionStart = newCursorPosition.current;
36
- textareaElement.selectionEnd = newCursorPosition.current;
37
- newCursorPosition.current = undefined;
38
- }
39
- }, [text, newCursorPosition]);
40
- return {
41
- insertText,
42
- textareaRef,
43
- };
44
- };