stream-chat-react 13.0.0 → 13.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/Chat/hooks/useChat.js +1 -1
- package/dist/components/MessageInput/hooks/useSubmitHandler.js +31 -1
- package/dist/components/Poll/PollActions/PollResults/PollResults.js +1 -1
- package/dist/components/Poll/PollCreationDialog/MultipleAnswersField.js +9 -2
- package/dist/components/TextareaComposer/TextareaComposer.js +3 -6
- package/dist/css/v2/index.css +1 -1
- package/dist/css/v2/index.layout.css +1 -1
- package/dist/i18n/Streami18n.d.ts +1 -0
- package/dist/i18n/de.json +1 -0
- package/dist/i18n/en.json +1 -0
- package/dist/i18n/es.json +1 -0
- package/dist/i18n/fr.json +1 -0
- package/dist/i18n/hi.json +1 -0
- package/dist/i18n/it.json +1 -0
- package/dist/i18n/ja.json +1 -0
- package/dist/i18n/ko.json +2 -1
- package/dist/i18n/nl.json +2 -1
- package/dist/i18n/pt.json +1 -0
- package/dist/i18n/ru.json +1 -0
- package/dist/i18n/tr.json +1 -0
- package/dist/index.browser.cjs +85 -42
- package/dist/index.browser.cjs.map +3 -3
- package/dist/index.node.cjs +85 -42
- package/dist/index.node.cjs.map +3 -3
- package/dist/scss/v2/MessageInput/MessageInput-layout.scss +5 -0
- package/package.json +3 -3
|
@@ -24,7 +24,7 @@ export const useChat = ({ client, defaultLanguage = 'en', i18nInstance, initialN
|
|
|
24
24
|
useEffect(() => {
|
|
25
25
|
if (!client)
|
|
26
26
|
return;
|
|
27
|
-
const version = "13.0.
|
|
27
|
+
const version = "13.0.1";
|
|
28
28
|
const userAgent = client.getUserAgent();
|
|
29
29
|
if (!userAgent.includes('stream-chat-react')) {
|
|
30
30
|
// result looks like: 'stream-chat-react-2.3.2-stream-chat-javascript-client-browser-2.2.2'
|
|
@@ -1,7 +1,24 @@
|
|
|
1
1
|
import { useCallback } from 'react';
|
|
2
|
+
import { MessageComposer } from 'stream-chat';
|
|
2
3
|
import { useMessageComposer } from './useMessageComposer';
|
|
3
4
|
import { useChannelActionContext } from '../../../context/ChannelActionContext';
|
|
4
5
|
import { useTranslationContext } from '../../../context/TranslationContext';
|
|
6
|
+
const takeStateSnapshot = (messageComposer) => {
|
|
7
|
+
const textComposerState = messageComposer.textComposer.state.getLatestValue();
|
|
8
|
+
const attachmentManagerState = messageComposer.attachmentManager.state.getLatestValue();
|
|
9
|
+
const linkPreviewsManagerState = messageComposer.linkPreviewsManager.state.getLatestValue();
|
|
10
|
+
const pollComposerState = messageComposer.pollComposer.state.getLatestValue();
|
|
11
|
+
const customDataManagerState = messageComposer.customDataManager.state.getLatestValue();
|
|
12
|
+
const state = messageComposer.state.getLatestValue();
|
|
13
|
+
return () => {
|
|
14
|
+
messageComposer.state.next(state);
|
|
15
|
+
messageComposer.textComposer.state.next(textComposerState);
|
|
16
|
+
messageComposer.attachmentManager.state.next(attachmentManagerState);
|
|
17
|
+
messageComposer.linkPreviewsManager.state.next(linkPreviewsManagerState);
|
|
18
|
+
messageComposer.pollComposer.state.next(pollComposerState);
|
|
19
|
+
messageComposer.customDataManager.state.next(customDataManagerState);
|
|
20
|
+
};
|
|
21
|
+
};
|
|
5
22
|
export const useSubmitHandler = (props) => {
|
|
6
23
|
const { clearEditingState, overrideSubmitHandler } = props;
|
|
7
24
|
const { addNotification, editMessage, sendMessage } = useChannelActionContext('useSubmitHandler');
|
|
@@ -23,7 +40,20 @@ export const useSubmitHandler = (props) => {
|
|
|
23
40
|
}
|
|
24
41
|
}
|
|
25
42
|
else {
|
|
43
|
+
const restoreComposerStateSnapshot = takeStateSnapshot(messageComposer);
|
|
26
44
|
try {
|
|
45
|
+
// FIXME: once MessageComposer has sendMessage method, then the following condition should be encapsulated by it
|
|
46
|
+
// keep attachments, text, quoted message (treat them as draft) ... if sending a poll
|
|
47
|
+
const sentPollMessage = !!message.poll_id;
|
|
48
|
+
if (sentPollMessage) {
|
|
49
|
+
messageComposer.state.partialNext({
|
|
50
|
+
id: MessageComposer.generateId(),
|
|
51
|
+
pollId: null,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
messageComposer.clear();
|
|
56
|
+
}
|
|
27
57
|
// todo: get rid of overrideSubmitHandler once MessageComposer supports submission flow
|
|
28
58
|
if (overrideSubmitHandler) {
|
|
29
59
|
await overrideSubmitHandler({
|
|
@@ -36,11 +66,11 @@ export const useSubmitHandler = (props) => {
|
|
|
36
66
|
else {
|
|
37
67
|
await sendMessage({ localMessage, message, options: sendOptions });
|
|
38
68
|
}
|
|
39
|
-
messageComposer.clear();
|
|
40
69
|
if (messageComposer.config.text.publishTypingEvents)
|
|
41
70
|
await messageComposer.channel.stopTyping();
|
|
42
71
|
}
|
|
43
72
|
catch (err) {
|
|
73
|
+
restoreComposerStateSnapshot();
|
|
44
74
|
addNotification(t('Send message request failed'), 'error');
|
|
45
75
|
}
|
|
46
76
|
}
|
|
@@ -7,7 +7,7 @@ import { useStateStore } from '../../../../store';
|
|
|
7
7
|
import { usePollContext, useTranslationContext } from '../../../../context';
|
|
8
8
|
const pollStateSelector = (nextValue) => ({
|
|
9
9
|
name: nextValue.name,
|
|
10
|
-
options: nextValue.options,
|
|
10
|
+
options: [...nextValue.options],
|
|
11
11
|
vote_counts_by_option: nextValue.vote_counts_by_option,
|
|
12
12
|
});
|
|
13
13
|
export const PollResults = ({ close }) => {
|
|
@@ -28,8 +28,15 @@ export const MultipleAnswersField = () => {
|
|
|
28
28
|
React.createElement("input", { id: 'max_votes_allowed', onBlur: () => {
|
|
29
29
|
pollComposer.handleFieldBlur('max_votes_allowed');
|
|
30
30
|
}, onChange: (e) => {
|
|
31
|
+
const nativeFieldValidation = !e.target.validity.valid
|
|
32
|
+
? {
|
|
33
|
+
max_votes_allowed: t('Only numbers are allowed'),
|
|
34
|
+
}
|
|
35
|
+
: undefined;
|
|
31
36
|
pollComposer.updateFields({
|
|
32
|
-
max_votes_allowed:
|
|
33
|
-
|
|
37
|
+
max_votes_allowed: !nativeFieldValidation
|
|
38
|
+
? e.target.value
|
|
39
|
+
: pollComposer.max_votes_allowed,
|
|
40
|
+
}, nativeFieldValidation);
|
|
34
41
|
}, placeholder: t('Maximum number of votes (from 2 to 10)'), type: 'number', value: max_votes_allowed }))))));
|
|
35
42
|
};
|
|
@@ -26,11 +26,11 @@ const configStateSelector = (state) => ({
|
|
|
26
26
|
* In the long term, the fix should happen by handling keypress, but changing this has unknown implications.
|
|
27
27
|
*/
|
|
28
28
|
const defaultShouldSubmit = (event) => event.key === 'Enter' && !event.shiftKey && !event.nativeEvent.isComposing;
|
|
29
|
-
export const TextareaComposer = ({ className, closeSuggestionsOnClickOutside, containerClassName, listClassName, maxRows: maxRowsProp
|
|
29
|
+
export const TextareaComposer = ({ className, closeSuggestionsOnClickOutside, containerClassName, listClassName, maxRows: maxRowsProp, minRows: minRowsProp, onBlur, onChange, onKeyDown, onScroll, onSelect, placeholder: placeholderProp, shouldSubmit: shouldSubmitProp, ...restTextareaProps }) => {
|
|
30
30
|
const { t } = useTranslationContext();
|
|
31
31
|
const { AutocompleteSuggestionList = DefaultSuggestionList } = useComponentContext();
|
|
32
32
|
const { additionalTextareaProps, cooldownRemaining, handleSubmit, maxRows: maxRowsContext, minRows: minRowsContext, onPaste, shouldSubmit: shouldSubmitContext, textareaRef, } = useMessageInputContext();
|
|
33
|
-
const maxRows = maxRowsProp ?? maxRowsContext;
|
|
33
|
+
const maxRows = maxRowsProp ?? maxRowsContext ?? 1;
|
|
34
34
|
const minRows = minRowsProp ?? minRowsContext;
|
|
35
35
|
const placeholder = placeholderProp ?? additionalTextareaProps?.placeholder;
|
|
36
36
|
const shouldSubmit = shouldSubmitProp ?? shouldSubmitContext ?? defaultShouldSubmit;
|
|
@@ -68,16 +68,13 @@ export const TextareaComposer = ({ className, closeSuggestionsOnClickOutside, co
|
|
|
68
68
|
onKeyDown(event);
|
|
69
69
|
return;
|
|
70
70
|
}
|
|
71
|
-
if (event.key === 'Enter') {
|
|
72
|
-
// allow next line only on Shift + Enter. Enter is reserved for submission.
|
|
73
|
-
event.preventDefault();
|
|
74
|
-
}
|
|
75
71
|
if (textComposer.suggestions &&
|
|
76
72
|
textComposer.suggestions.searchSource.items?.length) {
|
|
77
73
|
if (event.key === 'Escape')
|
|
78
74
|
return textComposer.closeSuggestions();
|
|
79
75
|
const loadedItems = textComposer.suggestions.searchSource.items;
|
|
80
76
|
if (event.key === 'Enter') {
|
|
77
|
+
event.preventDefault();
|
|
81
78
|
textComposer.handleSelect(loadedItems[focusedItemIndex]);
|
|
82
79
|
}
|
|
83
80
|
if (event.key === 'ArrowUp') {
|