stream-chat-react 13.5.1 → 13.6.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/Channel/Channel.d.ts +1 -1
- package/dist/components/Channel/Channel.js +2 -0
- package/dist/components/Chat/Chat.d.ts +1 -1
- package/dist/components/Chat/Chat.js +3 -1
- package/dist/components/Chat/hooks/useChat.js +1 -1
- package/dist/components/Dialog/DialogManager.d.ts +3 -1
- package/dist/components/Dialog/DialogManager.js +3 -0
- package/dist/components/Dialog/DialogPortal.d.ts +1 -1
- package/dist/components/Dialog/DialogPortal.js +4 -2
- package/dist/components/Dialog/hooks/useDialog.d.ts +11 -3
- package/dist/components/Dialog/hooks/useDialog.js +10 -7
- package/dist/components/Gallery/Gallery.js +2 -2
- package/dist/components/Gallery/Image.js +11 -5
- package/dist/components/Message/utils.js +2 -2
- package/dist/components/MessageBounce/MessageBounceModal.js +3 -2
- package/dist/components/MessageInput/AttachmentSelector.js +2 -1
- package/dist/components/MessageInput/EditMessageForm.js +2 -2
- package/dist/components/Modal/GlobalModal.d.ts +4 -0
- package/dist/components/Modal/GlobalModal.js +57 -0
- package/dist/components/Modal/Modal.d.ts +3 -4
- package/dist/components/Modal/index.d.ts +1 -0
- package/dist/components/Modal/index.js +1 -0
- package/dist/components/Poll/PollActions/PollAction.js +8 -4
- package/dist/components/Poll/PollActions/PollActions.js +8 -6
- package/dist/components/Reactions/ReactionsListModal.d.ts +1 -1
- package/dist/components/Reactions/ReactionsListModal.js +3 -2
- package/dist/components/TextareaComposer/TextareaComposer.js +15 -24
- package/dist/context/ComponentContext.d.ts +3 -1
- package/dist/context/DialogManagerContext.d.ts +21 -4
- package/dist/context/DialogManagerContext.js +114 -5
- package/dist/css/v2/index.css +1 -1
- package/dist/css/v2/index.layout.css +1 -1
- package/dist/experimental/index.browser.cjs +94 -22
- package/dist/experimental/index.browser.cjs.map +4 -4
- package/dist/experimental/index.node.cjs +94 -22
- package/dist/experimental/index.node.cjs.map +4 -4
- package/dist/index.browser.cjs +1767 -1545
- package/dist/index.browser.cjs.map +4 -4
- package/dist/index.node.cjs +1774 -1545
- package/dist/index.node.cjs.map +4 -4
- package/dist/scss/v2/Modal/Modal-theme.scss +21 -6
- package/dist/scss/v2/Poll/Poll-layout.scss +20 -6
- package/dist/scss/v2/Poll/Poll-theme.scss +8 -8
- package/package.json +4 -4
|
@@ -1,11 +1,28 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import type { PropsWithChildren } from 'react';
|
|
1
|
+
import React, { type PropsWithChildren } from 'react';
|
|
3
2
|
import { DialogManager } from '../components/Dialog/DialogManager';
|
|
3
|
+
import type { PropsWithChildrenOnly } from '../types/types';
|
|
4
4
|
type DialogManagerProviderContextValue = {
|
|
5
5
|
dialogManager: DialogManager;
|
|
6
6
|
};
|
|
7
|
+
/**
|
|
8
|
+
* Marks the portal location
|
|
9
|
+
* @param children
|
|
10
|
+
* @param id
|
|
11
|
+
* @constructor
|
|
12
|
+
*/
|
|
7
13
|
export declare const DialogManagerProvider: ({ children, id, }: PropsWithChildren<{
|
|
8
14
|
id?: string;
|
|
9
|
-
}>) => React.JSX.Element;
|
|
10
|
-
export
|
|
15
|
+
}>) => React.JSX.Element | null;
|
|
16
|
+
export type UseDialogManagerParams = {
|
|
17
|
+
dialogId?: string;
|
|
18
|
+
dialogManagerId?: string;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Retrieves the nearest dialog manager or searches for the dialog manager by dialog manager id or dialog id.
|
|
22
|
+
* Dialog id will take precedence over dialog manager id if both are provided and dialog manager is found by dialog id.
|
|
23
|
+
*/
|
|
24
|
+
export declare const useDialogManager: ({ dialogId, dialogManagerId, }?: UseDialogManagerParams) => DialogManagerProviderContextValue;
|
|
25
|
+
export declare const modalDialogManagerId: "modal-dialog-manager";
|
|
26
|
+
export declare const ModalDialogManagerProvider: ({ children }: PropsWithChildrenOnly) => React.JSX.Element;
|
|
27
|
+
export declare const useModalDialogManager: () => DialogManager | undefined;
|
|
11
28
|
export {};
|
|
@@ -1,14 +1,123 @@
|
|
|
1
|
-
import React, { useContext, useState } from 'react';
|
|
1
|
+
import React, { useContext, useEffect, useMemo, useState, } from 'react';
|
|
2
|
+
import { StateStore } from 'stream-chat';
|
|
2
3
|
import { DialogManager } from '../components/Dialog/DialogManager';
|
|
3
4
|
import { DialogPortalDestination } from '../components/Dialog/DialogPortal';
|
|
5
|
+
const dialogManagersRegistry = new StateStore({});
|
|
6
|
+
const getDialogManager = (id) => dialogManagersRegistry.getLatestValue()[id];
|
|
7
|
+
const getOrCreateDialogManager = (id) => {
|
|
8
|
+
let manager = getDialogManager(id);
|
|
9
|
+
if (!manager) {
|
|
10
|
+
manager = new DialogManager({ id });
|
|
11
|
+
dialogManagersRegistry.partialNext({ [id]: manager });
|
|
12
|
+
}
|
|
13
|
+
return manager;
|
|
14
|
+
};
|
|
15
|
+
const removeDialogManager = (id) => {
|
|
16
|
+
if (!getDialogManager(id))
|
|
17
|
+
return;
|
|
18
|
+
dialogManagersRegistry.partialNext({ [id]: undefined });
|
|
19
|
+
};
|
|
4
20
|
const DialogManagerProviderContext = React.createContext(undefined);
|
|
21
|
+
/**
|
|
22
|
+
* Marks the portal location
|
|
23
|
+
* @param children
|
|
24
|
+
* @param id
|
|
25
|
+
* @constructor
|
|
26
|
+
*/
|
|
5
27
|
export const DialogManagerProvider = ({ children, id, }) => {
|
|
6
|
-
const [dialogManager] = useState(() =>
|
|
28
|
+
const [dialogManager, setDialogManager] = useState(() => {
|
|
29
|
+
if (id)
|
|
30
|
+
return getDialogManager(id) ?? null;
|
|
31
|
+
return new DialogManager(); // will not be included in the registry
|
|
32
|
+
});
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
if (!id)
|
|
35
|
+
return;
|
|
36
|
+
setDialogManager(getOrCreateDialogManager(id));
|
|
37
|
+
return () => {
|
|
38
|
+
removeDialogManager(id);
|
|
39
|
+
setDialogManager(null);
|
|
40
|
+
};
|
|
41
|
+
}, [id]);
|
|
42
|
+
// temporarily do not render until a new dialog manager is created
|
|
43
|
+
if (!dialogManager)
|
|
44
|
+
return null;
|
|
7
45
|
return (React.createElement(DialogManagerProviderContext.Provider, { value: { dialogManager } },
|
|
8
46
|
children,
|
|
9
47
|
React.createElement(DialogPortalDestination, null)));
|
|
10
48
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
49
|
+
const getManagerFromStore = ({ dialogId, dialogManagerId, newState, previousState, }) => {
|
|
50
|
+
let managerInNewState;
|
|
51
|
+
let managerInPrevState;
|
|
52
|
+
if (dialogManagerId) {
|
|
53
|
+
if (!dialogId) {
|
|
54
|
+
managerInNewState = newState[dialogManagerId];
|
|
55
|
+
managerInPrevState = previousState?.[dialogManagerId];
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
if (newState[dialogManagerId]?.get(dialogId)) {
|
|
59
|
+
managerInNewState = newState[dialogManagerId];
|
|
60
|
+
}
|
|
61
|
+
if (previousState?.[dialogManagerId]?.get(dialogId)) {
|
|
62
|
+
managerInPrevState = previousState[dialogManagerId];
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
else if (dialogId) {
|
|
67
|
+
managerInNewState = Object.values(newState).find((dialogMng) => dialogId && dialogMng?.get(dialogId));
|
|
68
|
+
managerInPrevState =
|
|
69
|
+
previousState &&
|
|
70
|
+
Object.values(previousState).find((dialogMng) => dialogId && dialogMng?.get(dialogId));
|
|
71
|
+
}
|
|
72
|
+
return { managerInNewState, managerInPrevState };
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* Retrieves the nearest dialog manager or searches for the dialog manager by dialog manager id or dialog id.
|
|
76
|
+
* Dialog id will take precedence over dialog manager id if both are provided and dialog manager is found by dialog id.
|
|
77
|
+
*/
|
|
78
|
+
export const useDialogManager = ({ dialogId, dialogManagerId, } = {}) => {
|
|
79
|
+
const nearestDialogManagerContext = useContext(DialogManagerProviderContext);
|
|
80
|
+
const [dialogManagerContext, setDialogManagerContext] = useState(() => {
|
|
81
|
+
const { managerInNewState } = getManagerFromStore({
|
|
82
|
+
dialogId,
|
|
83
|
+
dialogManagerId,
|
|
84
|
+
newState: dialogManagersRegistry.getLatestValue(),
|
|
85
|
+
previousState: undefined,
|
|
86
|
+
});
|
|
87
|
+
return managerInNewState
|
|
88
|
+
? { dialogManager: managerInNewState }
|
|
89
|
+
: nearestDialogManagerContext;
|
|
90
|
+
});
|
|
91
|
+
useEffect(() => {
|
|
92
|
+
if (!dialogId && !dialogManagerId)
|
|
93
|
+
return;
|
|
94
|
+
const unsubscribe = dialogManagersRegistry.subscribeWithSelector((state) => state, (newState, previousState) => {
|
|
95
|
+
const { managerInNewState, managerInPrevState } = getManagerFromStore({
|
|
96
|
+
dialogId,
|
|
97
|
+
dialogManagerId,
|
|
98
|
+
newState,
|
|
99
|
+
previousState,
|
|
100
|
+
});
|
|
101
|
+
if (!managerInPrevState || managerInNewState?.id !== managerInPrevState.id) {
|
|
102
|
+
setDialogManagerContext((prevState) => {
|
|
103
|
+
if (prevState?.dialogManager.id === managerInNewState?.id)
|
|
104
|
+
return prevState;
|
|
105
|
+
// fixme: need to handle the possibility that the dialogManager is undefined
|
|
106
|
+
return {
|
|
107
|
+
dialogManager: managerInNewState || nearestDialogManagerContext?.dialogManager,
|
|
108
|
+
};
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
return () => {
|
|
113
|
+
unsubscribe();
|
|
114
|
+
};
|
|
115
|
+
}, [dialogId, dialogManagerId, nearestDialogManagerContext?.dialogManager]);
|
|
116
|
+
if (!dialogManagerContext?.dialogManager) {
|
|
117
|
+
console.warn(`Dialog manager (manager id: ${dialogManagerId}, dialog id: ${dialogId}) is not available`);
|
|
118
|
+
}
|
|
119
|
+
return dialogManagerContext;
|
|
14
120
|
};
|
|
121
|
+
export const modalDialogManagerId = 'modal-dialog-manager';
|
|
122
|
+
export const ModalDialogManagerProvider = ({ children }) => (React.createElement(DialogManagerProvider, { id: modalDialogManagerId }, children));
|
|
123
|
+
export const useModalDialogManager = () => useMemo(() => getDialogManager(modalDialogManagerId), []);
|