mr-chat-bird 1.0.15 → 1.0.17
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/README.md +1 -1
- package/dist/index.css +27 -0
- package/dist/index.d.mts +4 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +100 -30
- package/dist/index.mjs +99 -29
- package/package.json +1 -1
- package/dist/AddReaction-DCDVOMZB.svg +0 -1
- package/dist/TextFormat-R4ZVDKE2.svg +0 -1
- package/dist/index.css.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/index.mjs.map +0 -1
package/README.md
CHANGED
package/dist/index.css
CHANGED
|
@@ -29,6 +29,8 @@
|
|
|
29
29
|
}
|
|
30
30
|
.mrchat-richTextEditorContainer .ProseMirror {
|
|
31
31
|
padding: 12px 16px 4px;
|
|
32
|
+
overflow-wrap: anywhere;
|
|
33
|
+
word-break: break-word;
|
|
32
34
|
}
|
|
33
35
|
.mrchat-mainActionContainer {
|
|
34
36
|
height: 24px;
|
|
@@ -57,6 +59,12 @@
|
|
|
57
59
|
position: absolute;
|
|
58
60
|
right: 6px;
|
|
59
61
|
}
|
|
62
|
+
.mrchat-sm-mainSendMsgIcon {
|
|
63
|
+
display: none;
|
|
64
|
+
position: absolute;
|
|
65
|
+
right: 4px;
|
|
66
|
+
bottom: 1.5px;
|
|
67
|
+
}
|
|
60
68
|
.mrchat-customToolActionItem {
|
|
61
69
|
background-color: var(--mantine-color-body);
|
|
62
70
|
border-color: var(--mantine-color-default-border);
|
|
@@ -78,6 +86,25 @@
|
|
|
78
86
|
display: none;
|
|
79
87
|
}
|
|
80
88
|
}
|
|
89
|
+
@media (max-width: 475px) {
|
|
90
|
+
.mrchat-mainActionContainer {
|
|
91
|
+
display: none;
|
|
92
|
+
}
|
|
93
|
+
.mrchat-richTextEditorContainer .mantine-RichTextEditor-Typography,
|
|
94
|
+
.mrchat-richTextEditorContainer .mantine-RichTextEditor-content {
|
|
95
|
+
min-height: 30px;
|
|
96
|
+
border-radius: 12px;
|
|
97
|
+
}
|
|
98
|
+
.mrchat-richTextEditorContainer {
|
|
99
|
+
border-radius: 12px;
|
|
100
|
+
}
|
|
101
|
+
.mrchat-richTextEditorContainer .ProseMirror {
|
|
102
|
+
padding: 8px 12px 4px;
|
|
103
|
+
}
|
|
104
|
+
.mrchat-sm-mainSendMsgIcon {
|
|
105
|
+
display: block;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
81
108
|
:where([data-mantine-color-scheme=dark]) .mantine-RichTextEditor-control {
|
|
82
109
|
background-color: var(--mantine-color-body);
|
|
83
110
|
}
|
package/dist/index.d.mts
CHANGED
|
@@ -13,7 +13,10 @@ type ChatUserListProps = {
|
|
|
13
13
|
primaryColor?: string;
|
|
14
14
|
darkColor?: string;
|
|
15
15
|
};
|
|
16
|
+
type MrChatProps = ChatUserListProps & {
|
|
17
|
+
authorization: string;
|
|
18
|
+
};
|
|
16
19
|
|
|
17
|
-
declare function MrChat({ colorScheme, primaryColor, darkColor, ...props }:
|
|
20
|
+
declare function MrChat({ colorScheme, primaryColor, darkColor, authorization, ...props }: MrChatProps): React.JSX.Element;
|
|
18
21
|
|
|
19
22
|
export { MrChat };
|
package/dist/index.d.ts
CHANGED
|
@@ -13,7 +13,10 @@ type ChatUserListProps = {
|
|
|
13
13
|
primaryColor?: string;
|
|
14
14
|
darkColor?: string;
|
|
15
15
|
};
|
|
16
|
+
type MrChatProps = ChatUserListProps & {
|
|
17
|
+
authorization: string;
|
|
18
|
+
};
|
|
16
19
|
|
|
17
|
-
declare function MrChat({ colorScheme, primaryColor, darkColor, ...props }:
|
|
20
|
+
declare function MrChat({ colorScheme, primaryColor, darkColor, authorization, ...props }: MrChatProps): React.JSX.Element;
|
|
18
21
|
|
|
19
22
|
export { MrChat };
|
package/dist/index.js
CHANGED
|
@@ -38,7 +38,7 @@ module.exports = __toCommonJS(index_exports);
|
|
|
38
38
|
var import_styles = require("@mantine/core/styles.css");
|
|
39
39
|
var import_styles2 = require("@mantine/tiptap/styles.css");
|
|
40
40
|
var import_styles3 = require("@mantine/notifications/styles.css");
|
|
41
|
-
var
|
|
41
|
+
var import_react12 = __toESM(require("react"));
|
|
42
42
|
var import_core9 = require("@mantine/core");
|
|
43
43
|
var import_notifications2 = require("@mantine/notifications");
|
|
44
44
|
|
|
@@ -162,9 +162,15 @@ var import_toolkit = require("@reduxjs/toolkit");
|
|
|
162
162
|
// src/utils/environment.ts
|
|
163
163
|
var environment = {
|
|
164
164
|
BASE_URL: "http://localhost:4000",
|
|
165
|
-
SOCKET_URL: "http://localhost:4000"
|
|
166
|
-
|
|
165
|
+
SOCKET_URL: "http://localhost:4000"
|
|
166
|
+
// BASE_URL: 'http://62.171.185.159:4000',
|
|
167
|
+
// SOCKET_URL: "http://62.171.185.159:4000",
|
|
167
168
|
};
|
|
169
|
+
var authorization = "";
|
|
170
|
+
var setEnvironmentAuthorization = (value) => {
|
|
171
|
+
authorization = value || "";
|
|
172
|
+
};
|
|
173
|
+
var getEnvironmentAuthorization = () => authorization;
|
|
168
174
|
|
|
169
175
|
// src/lib/axios.ts
|
|
170
176
|
var import_axios = __toESM(require("axios"));
|
|
@@ -172,9 +178,13 @@ var axiosInstance = import_axios.default.create({
|
|
|
172
178
|
baseURL: environment.BASE_URL,
|
|
173
179
|
headers: {
|
|
174
180
|
"Content-Type": "application/json",
|
|
175
|
-
Authorization:
|
|
181
|
+
Authorization: getEnvironmentAuthorization()
|
|
176
182
|
}
|
|
177
183
|
});
|
|
184
|
+
axiosInstance.interceptors.request.use((config) => {
|
|
185
|
+
config.headers?.set?.("Authorization", getEnvironmentAuthorization());
|
|
186
|
+
return config;
|
|
187
|
+
});
|
|
178
188
|
var axios_default = axiosInstance;
|
|
179
189
|
|
|
180
190
|
// src/store/slices/ChatSlice.ts
|
|
@@ -338,6 +348,10 @@ var deleteMessagesByChatId = (payload) => async (dispatch) => {
|
|
|
338
348
|
return err;
|
|
339
349
|
});
|
|
340
350
|
};
|
|
351
|
+
var resetAllMessages = () => async (dispatch) => {
|
|
352
|
+
dispatch(setMessagedUserList(null));
|
|
353
|
+
dispatch(resetMessageList());
|
|
354
|
+
};
|
|
341
355
|
var {
|
|
342
356
|
setMessagedUserList,
|
|
343
357
|
setMessageList,
|
|
@@ -379,7 +393,7 @@ var getSocket = (userId) => {
|
|
|
379
393
|
autoConnect: false,
|
|
380
394
|
transports: ["websocket"],
|
|
381
395
|
auth: {
|
|
382
|
-
apiKey:
|
|
396
|
+
apiKey: getEnvironmentAuthorization(),
|
|
383
397
|
userId
|
|
384
398
|
}
|
|
385
399
|
});
|
|
@@ -4792,7 +4806,8 @@ function EmojiPickerPopover({
|
|
|
4792
4806
|
action,
|
|
4793
4807
|
size = 320,
|
|
4794
4808
|
offset = 8,
|
|
4795
|
-
position = "bottom-start"
|
|
4809
|
+
position = "bottom-start",
|
|
4810
|
+
colorScheme = "light"
|
|
4796
4811
|
}) {
|
|
4797
4812
|
const [opened, setOpened] = (0, import_react3.useState)(false);
|
|
4798
4813
|
return /* @__PURE__ */ import_react3.default.createElement(
|
|
@@ -4823,7 +4838,7 @@ function EmojiPickerPopover({
|
|
|
4823
4838
|
EmojiPicker,
|
|
4824
4839
|
{
|
|
4825
4840
|
previewPosition: "none",
|
|
4826
|
-
theme:
|
|
4841
|
+
theme: colorScheme,
|
|
4827
4842
|
data: import_data.default,
|
|
4828
4843
|
onEmojiSelect: (emoji) => {
|
|
4829
4844
|
onSelect(emoji.native);
|
|
@@ -4873,11 +4888,36 @@ function CustomRichTextEditor({
|
|
|
4873
4888
|
content = "",
|
|
4874
4889
|
maxLength = 3e3,
|
|
4875
4890
|
onChange,
|
|
4876
|
-
onSubmit
|
|
4891
|
+
onSubmit,
|
|
4892
|
+
colorScheme = "light"
|
|
4877
4893
|
}) {
|
|
4878
4894
|
const [charCount, setCharCount] = (0, import_react4.useState)(0);
|
|
4895
|
+
const [hasContent, setHasContent] = (0, import_react4.useState)(false);
|
|
4879
4896
|
const [showWarning, setShowWarning] = (0, import_react4.useState)(false);
|
|
4880
4897
|
const [showToolbar, setShowToolbar] = (0, import_react4.useState)(false);
|
|
4898
|
+
const handleSubmitMsg = () => {
|
|
4899
|
+
if (!editor) return;
|
|
4900
|
+
const message = editor.getHTML();
|
|
4901
|
+
if (!editor.getText().trim()) return;
|
|
4902
|
+
onSubmit?.(message);
|
|
4903
|
+
editor.commands.clearContent();
|
|
4904
|
+
editor.commands.focus();
|
|
4905
|
+
setCharCount(0);
|
|
4906
|
+
setHasContent(false);
|
|
4907
|
+
};
|
|
4908
|
+
const handleEditorKeyDown = (_view, event) => {
|
|
4909
|
+
if (event.key === "Enter" && !event.shiftKey) {
|
|
4910
|
+
event.preventDefault();
|
|
4911
|
+
handleSubmitMsg();
|
|
4912
|
+
return true;
|
|
4913
|
+
}
|
|
4914
|
+
if (event.key === "Enter" && event.shiftKey) {
|
|
4915
|
+
event.preventDefault();
|
|
4916
|
+
editor?.commands.setHardBreak();
|
|
4917
|
+
return true;
|
|
4918
|
+
}
|
|
4919
|
+
return false;
|
|
4920
|
+
};
|
|
4881
4921
|
const editor = (0, import_react5.useEditor)({
|
|
4882
4922
|
extensions: [
|
|
4883
4923
|
import_starter_kit.default,
|
|
@@ -4890,9 +4930,14 @@ function CustomRichTextEditor({
|
|
|
4890
4930
|
import_extension_text_align.default.configure({ types: ["heading", "paragraph"] })
|
|
4891
4931
|
],
|
|
4892
4932
|
content,
|
|
4933
|
+
editorProps: {
|
|
4934
|
+
handleKeyDown: handleEditorKeyDown
|
|
4935
|
+
},
|
|
4893
4936
|
onUpdate: ({ editor: editor2 }) => {
|
|
4894
4937
|
const text = editor2.getText();
|
|
4938
|
+
const nextHasContent = text.trim().length > 0;
|
|
4895
4939
|
setCharCount(text.length);
|
|
4940
|
+
setHasContent(nextHasContent);
|
|
4896
4941
|
if (maxLength && text.length >= maxLength) {
|
|
4897
4942
|
setShowWarning(true);
|
|
4898
4943
|
} else {
|
|
@@ -4902,15 +4947,6 @@ function CustomRichTextEditor({
|
|
|
4902
4947
|
},
|
|
4903
4948
|
immediatelyRender: false
|
|
4904
4949
|
});
|
|
4905
|
-
const handleSubmitMsg = () => {
|
|
4906
|
-
if (!editor) return;
|
|
4907
|
-
const message = editor.getHTML();
|
|
4908
|
-
if (!editor.getText().trim()) return;
|
|
4909
|
-
onSubmit?.(message);
|
|
4910
|
-
editor.commands.clearContent();
|
|
4911
|
-
editor.commands.focus();
|
|
4912
|
-
setCharCount(0);
|
|
4913
|
-
};
|
|
4914
4950
|
return /* @__PURE__ */ import_react4.default.createElement(import_react4.default.Fragment, null, /* @__PURE__ */ import_react4.default.createElement(
|
|
4915
4951
|
import_tiptap.RichTextEditor,
|
|
4916
4952
|
{
|
|
@@ -4922,6 +4958,7 @@ function CustomRichTextEditor({
|
|
|
4922
4958
|
/* @__PURE__ */ import_react4.default.createElement(import_tiptap.RichTextEditor.Toolbar, { sticky: true, stickyOffset: "var(--docs-header-height)" }, /* @__PURE__ */ import_react4.default.createElement("div", { className: "mrchat-mainActionContainer" }, /* @__PURE__ */ import_react4.default.createElement(
|
|
4923
4959
|
EmojiPickerPopover,
|
|
4924
4960
|
{
|
|
4961
|
+
colorScheme,
|
|
4925
4962
|
onSelect: (emoji) => {
|
|
4926
4963
|
editor?.chain().focus().insertContent({
|
|
4927
4964
|
type: "emoji",
|
|
@@ -4958,10 +4995,22 @@ function CustomRichTextEditor({
|
|
|
4958
4995
|
variant: "filled",
|
|
4959
4996
|
"aria-label": "send",
|
|
4960
4997
|
className: "mrchat-mainSendMsgIcon",
|
|
4961
|
-
onClick:
|
|
4998
|
+
onClick: handleSubmitMsg,
|
|
4999
|
+
disabled: !hasContent
|
|
5000
|
+
},
|
|
5001
|
+
/* @__PURE__ */ import_react4.default.createElement(import_icons_react.IconSend, { size: 18 })
|
|
5002
|
+
)), /* @__PURE__ */ import_react4.default.createElement(
|
|
5003
|
+
import_core5.ActionIcon,
|
|
5004
|
+
{
|
|
5005
|
+
radius: "lg",
|
|
5006
|
+
variant: "filled",
|
|
5007
|
+
"aria-label": "send",
|
|
5008
|
+
className: "mrchat-sm-mainSendMsgIcon",
|
|
5009
|
+
onClick: handleSubmitMsg,
|
|
5010
|
+
disabled: !hasContent
|
|
4962
5011
|
},
|
|
4963
5012
|
/* @__PURE__ */ import_react4.default.createElement(import_icons_react.IconSend, { size: 18 })
|
|
4964
|
-
)
|
|
5013
|
+
), showToolbar && /* @__PURE__ */ import_react4.default.createElement(import_react4.default.Fragment, null, /* @__PURE__ */ import_react4.default.createElement(import_tiptap.RichTextEditor.ControlsGroup, null, /* @__PURE__ */ import_react4.default.createElement(import_tiptap.RichTextEditor.Bold, null), /* @__PURE__ */ import_react4.default.createElement(import_tiptap.RichTextEditor.Italic, null), /* @__PURE__ */ import_react4.default.createElement(import_tiptap.RichTextEditor.Underline, null), /* @__PURE__ */ import_react4.default.createElement(import_tiptap.RichTextEditor.Strikethrough, null), /* @__PURE__ */ import_react4.default.createElement(import_tiptap.RichTextEditor.Code, null), /* @__PURE__ */ import_react4.default.createElement(import_tiptap.RichTextEditor.Highlight, null)), /* @__PURE__ */ import_react4.default.createElement(
|
|
4965
5014
|
import_tiptap.RichTextEditor.ControlsGroup,
|
|
4966
5015
|
{
|
|
4967
5016
|
className: "mrchat-secondRichTextEditorToolBar"
|
|
@@ -5059,7 +5108,7 @@ function ChatScrollContainer({
|
|
|
5059
5108
|
const handleScroll = () => {
|
|
5060
5109
|
const el = containerRef.current;
|
|
5061
5110
|
if (!el) return;
|
|
5062
|
-
if (el.scrollTop <
|
|
5111
|
+
if (el.scrollTop < 50 && hasMore && !isFetchingRef.current) {
|
|
5063
5112
|
loadOlderMessages();
|
|
5064
5113
|
}
|
|
5065
5114
|
};
|
|
@@ -5075,7 +5124,7 @@ function ChatScrollContainer({
|
|
|
5075
5124
|
const heightDiff = newScrollHeight - prevScrollHeight;
|
|
5076
5125
|
el.scrollTop = prevScrollTop + heightDiff;
|
|
5077
5126
|
isFetchingRef.current = false;
|
|
5078
|
-
},
|
|
5127
|
+
}, 50);
|
|
5079
5128
|
};
|
|
5080
5129
|
return /* @__PURE__ */ import_react6.default.createElement(
|
|
5081
5130
|
"div",
|
|
@@ -5149,7 +5198,8 @@ function ChatUserMessage({
|
|
|
5149
5198
|
receiverDetails,
|
|
5150
5199
|
onChatInitialized,
|
|
5151
5200
|
onBack,
|
|
5152
|
-
showBackButton
|
|
5201
|
+
showBackButton,
|
|
5202
|
+
colorScheme
|
|
5153
5203
|
}) {
|
|
5154
5204
|
const dispatch = (0, import_react_redux2.useDispatch)();
|
|
5155
5205
|
const messageList = (0, import_react_redux2.useSelector)(
|
|
@@ -5186,7 +5236,7 @@ function ChatUserMessage({
|
|
|
5186
5236
|
}
|
|
5187
5237
|
}, [chatId]);
|
|
5188
5238
|
(0, import_react8.useEffect)(() => {
|
|
5189
|
-
if (!senderDetails?.userId) return;
|
|
5239
|
+
if (!senderDetails?.userId || !getEnvironmentAuthorization()) return;
|
|
5190
5240
|
const socket2 = getSocket(senderDetails?.userId || "");
|
|
5191
5241
|
if (!socket2) return;
|
|
5192
5242
|
const handleNewMessage = (data2) => {
|
|
@@ -5368,7 +5418,7 @@ function ChatUserMessage({
|
|
|
5368
5418
|
));
|
|
5369
5419
|
}
|
|
5370
5420
|
}
|
|
5371
|
-
)), (chatId || enableChat) && /* @__PURE__ */ import_react8.default.createElement("div", { className: "mrchat-inputBar" }, /* @__PURE__ */ import_react8.default.createElement(CustomRichTextEditor, { onSubmit: handleSendMessage })), /* @__PURE__ */ import_react8.default.createElement(
|
|
5421
|
+
)), (chatId || enableChat) && /* @__PURE__ */ import_react8.default.createElement("div", { className: "mrchat-inputBar" }, /* @__PURE__ */ import_react8.default.createElement(CustomRichTextEditor, { onSubmit: handleSendMessage, colorScheme })), /* @__PURE__ */ import_react8.default.createElement(
|
|
5372
5422
|
UserProfileDrawer,
|
|
5373
5423
|
{
|
|
5374
5424
|
opened: showUserInfo,
|
|
@@ -5448,7 +5498,8 @@ var getChatDisplayTime = (timestamp) => {
|
|
|
5448
5498
|
// src/components/ChatUserList/ChatUserList.tsx
|
|
5449
5499
|
function ChatUserList({
|
|
5450
5500
|
currentUser,
|
|
5451
|
-
onSearchUsers
|
|
5501
|
+
onSearchUsers,
|
|
5502
|
+
colorScheme
|
|
5452
5503
|
}) {
|
|
5453
5504
|
const [opened, { open, close }] = (0, import_hooks.useDisclosure)(false);
|
|
5454
5505
|
const dispatch = (0, import_react_redux3.useDispatch)();
|
|
@@ -5824,21 +5875,40 @@ function ChatUserList({
|
|
|
5824
5875
|
displayName: receiverDetails?.displayName,
|
|
5825
5876
|
avatar: receiverDetails?.avatar
|
|
5826
5877
|
});
|
|
5827
|
-
}
|
|
5878
|
+
},
|
|
5879
|
+
colorScheme
|
|
5828
5880
|
}
|
|
5829
5881
|
)
|
|
5830
5882
|
)));
|
|
5831
5883
|
}
|
|
5832
5884
|
|
|
5885
|
+
// src/store/reset.tsx
|
|
5886
|
+
var import_react11 = require("react");
|
|
5887
|
+
var import_react_redux4 = require("react-redux");
|
|
5888
|
+
function ResetHandler() {
|
|
5889
|
+
const dispatch = (0, import_react_redux4.useDispatch)();
|
|
5890
|
+
(0, import_react11.useEffect)(() => {
|
|
5891
|
+
return () => {
|
|
5892
|
+
dispatch(resetAllMessages());
|
|
5893
|
+
};
|
|
5894
|
+
}, [dispatch]);
|
|
5895
|
+
return null;
|
|
5896
|
+
}
|
|
5897
|
+
|
|
5833
5898
|
// src/components/MrChat/index.tsx
|
|
5834
5899
|
function MrChat({
|
|
5835
5900
|
colorScheme,
|
|
5836
5901
|
primaryColor = "customBrand",
|
|
5837
5902
|
darkColor,
|
|
5903
|
+
authorization: authorization2,
|
|
5838
5904
|
...props
|
|
5839
5905
|
}) {
|
|
5840
5906
|
const theme = createAppTheme(primaryColor);
|
|
5841
|
-
(0,
|
|
5907
|
+
(0, import_react12.useLayoutEffect)(() => {
|
|
5908
|
+
if (typeof window === "undefined") return;
|
|
5909
|
+
setEnvironmentAuthorization(authorization2 || "");
|
|
5910
|
+
}, [authorization2]);
|
|
5911
|
+
(0, import_react12.useEffect)(() => {
|
|
5842
5912
|
if (typeof document === "undefined" || !darkColor) return;
|
|
5843
5913
|
const previousBodyBackground = document.body.style.backgroundColor;
|
|
5844
5914
|
document.body.style.backgroundColor = colorScheme === "dark" ? darkColor : "";
|
|
@@ -5851,15 +5921,15 @@ function MrChat({
|
|
|
5851
5921
|
document.documentElement.style.removeProperty("--mantine-color-body");
|
|
5852
5922
|
};
|
|
5853
5923
|
}, [colorScheme, darkColor]);
|
|
5854
|
-
return /* @__PURE__ */
|
|
5924
|
+
return /* @__PURE__ */ import_react12.default.createElement(ReduxProvider, null, /* @__PURE__ */ import_react12.default.createElement(SocketProvider, null, /* @__PURE__ */ import_react12.default.createElement(ResetHandler, null), /* @__PURE__ */ import_react12.default.createElement(
|
|
5855
5925
|
import_core9.MantineProvider,
|
|
5856
5926
|
{
|
|
5857
5927
|
defaultColorScheme: colorScheme ?? "light",
|
|
5858
5928
|
forceColorScheme: colorScheme,
|
|
5859
5929
|
theme
|
|
5860
5930
|
},
|
|
5861
|
-
/* @__PURE__ */
|
|
5862
|
-
/* @__PURE__ */
|
|
5931
|
+
/* @__PURE__ */ import_react12.default.createElement(import_notifications2.Notifications, null),
|
|
5932
|
+
/* @__PURE__ */ import_react12.default.createElement(ChatUserList, { colorScheme, ...props })
|
|
5863
5933
|
)));
|
|
5864
5934
|
}
|
|
5865
5935
|
// Annotate the CommonJS export names for ESM import in node:
|
package/dist/index.mjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import "@mantine/core/styles.css";
|
|
3
3
|
import "@mantine/tiptap/styles.css";
|
|
4
4
|
import "@mantine/notifications/styles.css";
|
|
5
|
-
import React10, { useEffect as
|
|
5
|
+
import React10, { useEffect as useEffect7, useLayoutEffect } from "react";
|
|
6
6
|
import { MantineProvider } from "@mantine/core";
|
|
7
7
|
import { Notifications } from "@mantine/notifications";
|
|
8
8
|
|
|
@@ -126,9 +126,15 @@ import { createSlice } from "@reduxjs/toolkit";
|
|
|
126
126
|
// src/utils/environment.ts
|
|
127
127
|
var environment = {
|
|
128
128
|
BASE_URL: "http://localhost:4000",
|
|
129
|
-
SOCKET_URL: "http://localhost:4000"
|
|
130
|
-
|
|
129
|
+
SOCKET_URL: "http://localhost:4000"
|
|
130
|
+
// BASE_URL: 'http://62.171.185.159:4000',
|
|
131
|
+
// SOCKET_URL: "http://62.171.185.159:4000",
|
|
131
132
|
};
|
|
133
|
+
var authorization = "";
|
|
134
|
+
var setEnvironmentAuthorization = (value) => {
|
|
135
|
+
authorization = value || "";
|
|
136
|
+
};
|
|
137
|
+
var getEnvironmentAuthorization = () => authorization;
|
|
132
138
|
|
|
133
139
|
// src/lib/axios.ts
|
|
134
140
|
import axios from "axios";
|
|
@@ -136,9 +142,13 @@ var axiosInstance = axios.create({
|
|
|
136
142
|
baseURL: environment.BASE_URL,
|
|
137
143
|
headers: {
|
|
138
144
|
"Content-Type": "application/json",
|
|
139
|
-
Authorization:
|
|
145
|
+
Authorization: getEnvironmentAuthorization()
|
|
140
146
|
}
|
|
141
147
|
});
|
|
148
|
+
axiosInstance.interceptors.request.use((config) => {
|
|
149
|
+
config.headers?.set?.("Authorization", getEnvironmentAuthorization());
|
|
150
|
+
return config;
|
|
151
|
+
});
|
|
142
152
|
var axios_default = axiosInstance;
|
|
143
153
|
|
|
144
154
|
// src/store/slices/ChatSlice.ts
|
|
@@ -302,6 +312,10 @@ var deleteMessagesByChatId = (payload) => async (dispatch) => {
|
|
|
302
312
|
return err;
|
|
303
313
|
});
|
|
304
314
|
};
|
|
315
|
+
var resetAllMessages = () => async (dispatch) => {
|
|
316
|
+
dispatch(setMessagedUserList(null));
|
|
317
|
+
dispatch(resetMessageList());
|
|
318
|
+
};
|
|
305
319
|
var {
|
|
306
320
|
setMessagedUserList,
|
|
307
321
|
setMessageList,
|
|
@@ -343,7 +357,7 @@ var getSocket = (userId) => {
|
|
|
343
357
|
autoConnect: false,
|
|
344
358
|
transports: ["websocket"],
|
|
345
359
|
auth: {
|
|
346
|
-
apiKey:
|
|
360
|
+
apiKey: getEnvironmentAuthorization(),
|
|
347
361
|
userId
|
|
348
362
|
}
|
|
349
363
|
});
|
|
@@ -4785,7 +4799,8 @@ function EmojiPickerPopover({
|
|
|
4785
4799
|
action,
|
|
4786
4800
|
size = 320,
|
|
4787
4801
|
offset = 8,
|
|
4788
|
-
position = "bottom-start"
|
|
4802
|
+
position = "bottom-start",
|
|
4803
|
+
colorScheme = "light"
|
|
4789
4804
|
}) {
|
|
4790
4805
|
const [opened, setOpened] = useState(false);
|
|
4791
4806
|
return /* @__PURE__ */ React3.createElement(
|
|
@@ -4816,7 +4831,7 @@ function EmojiPickerPopover({
|
|
|
4816
4831
|
EmojiPicker,
|
|
4817
4832
|
{
|
|
4818
4833
|
previewPosition: "none",
|
|
4819
|
-
theme:
|
|
4834
|
+
theme: colorScheme,
|
|
4820
4835
|
data,
|
|
4821
4836
|
onEmojiSelect: (emoji) => {
|
|
4822
4837
|
onSelect(emoji.native);
|
|
@@ -4866,11 +4881,36 @@ function CustomRichTextEditor({
|
|
|
4866
4881
|
content = "",
|
|
4867
4882
|
maxLength = 3e3,
|
|
4868
4883
|
onChange,
|
|
4869
|
-
onSubmit
|
|
4884
|
+
onSubmit,
|
|
4885
|
+
colorScheme = "light"
|
|
4870
4886
|
}) {
|
|
4871
4887
|
const [charCount, setCharCount] = useState2(0);
|
|
4888
|
+
const [hasContent, setHasContent] = useState2(false);
|
|
4872
4889
|
const [showWarning, setShowWarning] = useState2(false);
|
|
4873
4890
|
const [showToolbar, setShowToolbar] = useState2(false);
|
|
4891
|
+
const handleSubmitMsg = () => {
|
|
4892
|
+
if (!editor) return;
|
|
4893
|
+
const message = editor.getHTML();
|
|
4894
|
+
if (!editor.getText().trim()) return;
|
|
4895
|
+
onSubmit?.(message);
|
|
4896
|
+
editor.commands.clearContent();
|
|
4897
|
+
editor.commands.focus();
|
|
4898
|
+
setCharCount(0);
|
|
4899
|
+
setHasContent(false);
|
|
4900
|
+
};
|
|
4901
|
+
const handleEditorKeyDown = (_view, event) => {
|
|
4902
|
+
if (event.key === "Enter" && !event.shiftKey) {
|
|
4903
|
+
event.preventDefault();
|
|
4904
|
+
handleSubmitMsg();
|
|
4905
|
+
return true;
|
|
4906
|
+
}
|
|
4907
|
+
if (event.key === "Enter" && event.shiftKey) {
|
|
4908
|
+
event.preventDefault();
|
|
4909
|
+
editor?.commands.setHardBreak();
|
|
4910
|
+
return true;
|
|
4911
|
+
}
|
|
4912
|
+
return false;
|
|
4913
|
+
};
|
|
4874
4914
|
const editor = useEditor({
|
|
4875
4915
|
extensions: [
|
|
4876
4916
|
StarterKit,
|
|
@@ -4883,9 +4923,14 @@ function CustomRichTextEditor({
|
|
|
4883
4923
|
TextAlign.configure({ types: ["heading", "paragraph"] })
|
|
4884
4924
|
],
|
|
4885
4925
|
content,
|
|
4926
|
+
editorProps: {
|
|
4927
|
+
handleKeyDown: handleEditorKeyDown
|
|
4928
|
+
},
|
|
4886
4929
|
onUpdate: ({ editor: editor2 }) => {
|
|
4887
4930
|
const text = editor2.getText();
|
|
4931
|
+
const nextHasContent = text.trim().length > 0;
|
|
4888
4932
|
setCharCount(text.length);
|
|
4933
|
+
setHasContent(nextHasContent);
|
|
4889
4934
|
if (maxLength && text.length >= maxLength) {
|
|
4890
4935
|
setShowWarning(true);
|
|
4891
4936
|
} else {
|
|
@@ -4895,15 +4940,6 @@ function CustomRichTextEditor({
|
|
|
4895
4940
|
},
|
|
4896
4941
|
immediatelyRender: false
|
|
4897
4942
|
});
|
|
4898
|
-
const handleSubmitMsg = () => {
|
|
4899
|
-
if (!editor) return;
|
|
4900
|
-
const message = editor.getHTML();
|
|
4901
|
-
if (!editor.getText().trim()) return;
|
|
4902
|
-
onSubmit?.(message);
|
|
4903
|
-
editor.commands.clearContent();
|
|
4904
|
-
editor.commands.focus();
|
|
4905
|
-
setCharCount(0);
|
|
4906
|
-
};
|
|
4907
4943
|
return /* @__PURE__ */ React4.createElement(React4.Fragment, null, /* @__PURE__ */ React4.createElement(
|
|
4908
4944
|
RichTextEditor,
|
|
4909
4945
|
{
|
|
@@ -4915,6 +4951,7 @@ function CustomRichTextEditor({
|
|
|
4915
4951
|
/* @__PURE__ */ React4.createElement(RichTextEditor.Toolbar, { sticky: true, stickyOffset: "var(--docs-header-height)" }, /* @__PURE__ */ React4.createElement("div", { className: "mrchat-mainActionContainer" }, /* @__PURE__ */ React4.createElement(
|
|
4916
4952
|
EmojiPickerPopover,
|
|
4917
4953
|
{
|
|
4954
|
+
colorScheme,
|
|
4918
4955
|
onSelect: (emoji) => {
|
|
4919
4956
|
editor?.chain().focus().insertContent({
|
|
4920
4957
|
type: "emoji",
|
|
@@ -4951,10 +4988,22 @@ function CustomRichTextEditor({
|
|
|
4951
4988
|
variant: "filled",
|
|
4952
4989
|
"aria-label": "send",
|
|
4953
4990
|
className: "mrchat-mainSendMsgIcon",
|
|
4954
|
-
onClick:
|
|
4991
|
+
onClick: handleSubmitMsg,
|
|
4992
|
+
disabled: !hasContent
|
|
4993
|
+
},
|
|
4994
|
+
/* @__PURE__ */ React4.createElement(IconSend, { size: 18 })
|
|
4995
|
+
)), /* @__PURE__ */ React4.createElement(
|
|
4996
|
+
ActionIcon,
|
|
4997
|
+
{
|
|
4998
|
+
radius: "lg",
|
|
4999
|
+
variant: "filled",
|
|
5000
|
+
"aria-label": "send",
|
|
5001
|
+
className: "mrchat-sm-mainSendMsgIcon",
|
|
5002
|
+
onClick: handleSubmitMsg,
|
|
5003
|
+
disabled: !hasContent
|
|
4955
5004
|
},
|
|
4956
5005
|
/* @__PURE__ */ React4.createElement(IconSend, { size: 18 })
|
|
4957
|
-
)
|
|
5006
|
+
), showToolbar && /* @__PURE__ */ React4.createElement(React4.Fragment, null, /* @__PURE__ */ React4.createElement(RichTextEditor.ControlsGroup, null, /* @__PURE__ */ React4.createElement(RichTextEditor.Bold, null), /* @__PURE__ */ React4.createElement(RichTextEditor.Italic, null), /* @__PURE__ */ React4.createElement(RichTextEditor.Underline, null), /* @__PURE__ */ React4.createElement(RichTextEditor.Strikethrough, null), /* @__PURE__ */ React4.createElement(RichTextEditor.Code, null), /* @__PURE__ */ React4.createElement(RichTextEditor.Highlight, null)), /* @__PURE__ */ React4.createElement(
|
|
4958
5007
|
RichTextEditor.ControlsGroup,
|
|
4959
5008
|
{
|
|
4960
5009
|
className: "mrchat-secondRichTextEditorToolBar"
|
|
@@ -5052,7 +5101,7 @@ function ChatScrollContainer({
|
|
|
5052
5101
|
const handleScroll = () => {
|
|
5053
5102
|
const el = containerRef.current;
|
|
5054
5103
|
if (!el) return;
|
|
5055
|
-
if (el.scrollTop <
|
|
5104
|
+
if (el.scrollTop < 50 && hasMore && !isFetchingRef.current) {
|
|
5056
5105
|
loadOlderMessages();
|
|
5057
5106
|
}
|
|
5058
5107
|
};
|
|
@@ -5068,7 +5117,7 @@ function ChatScrollContainer({
|
|
|
5068
5117
|
const heightDiff = newScrollHeight - prevScrollHeight;
|
|
5069
5118
|
el.scrollTop = prevScrollTop + heightDiff;
|
|
5070
5119
|
isFetchingRef.current = false;
|
|
5071
|
-
},
|
|
5120
|
+
}, 50);
|
|
5072
5121
|
};
|
|
5073
5122
|
return /* @__PURE__ */ React5.createElement(
|
|
5074
5123
|
"div",
|
|
@@ -5144,7 +5193,8 @@ function ChatUserMessage({
|
|
|
5144
5193
|
receiverDetails,
|
|
5145
5194
|
onChatInitialized,
|
|
5146
5195
|
onBack,
|
|
5147
|
-
showBackButton
|
|
5196
|
+
showBackButton,
|
|
5197
|
+
colorScheme
|
|
5148
5198
|
}) {
|
|
5149
5199
|
const dispatch = useDispatch();
|
|
5150
5200
|
const messageList = useSelector(
|
|
@@ -5181,7 +5231,7 @@ function ChatUserMessage({
|
|
|
5181
5231
|
}
|
|
5182
5232
|
}, [chatId]);
|
|
5183
5233
|
useEffect4(() => {
|
|
5184
|
-
if (!senderDetails?.userId) return;
|
|
5234
|
+
if (!senderDetails?.userId || !getEnvironmentAuthorization()) return;
|
|
5185
5235
|
const socket2 = getSocket(senderDetails?.userId || "");
|
|
5186
5236
|
if (!socket2) return;
|
|
5187
5237
|
const handleNewMessage = (data2) => {
|
|
@@ -5363,7 +5413,7 @@ function ChatUserMessage({
|
|
|
5363
5413
|
));
|
|
5364
5414
|
}
|
|
5365
5415
|
}
|
|
5366
|
-
)), (chatId || enableChat) && /* @__PURE__ */ React7.createElement("div", { className: "mrchat-inputBar" }, /* @__PURE__ */ React7.createElement(CustomRichTextEditor, { onSubmit: handleSendMessage })), /* @__PURE__ */ React7.createElement(
|
|
5416
|
+
)), (chatId || enableChat) && /* @__PURE__ */ React7.createElement("div", { className: "mrchat-inputBar" }, /* @__PURE__ */ React7.createElement(CustomRichTextEditor, { onSubmit: handleSendMessage, colorScheme })), /* @__PURE__ */ React7.createElement(
|
|
5367
5417
|
UserProfileDrawer,
|
|
5368
5418
|
{
|
|
5369
5419
|
opened: showUserInfo,
|
|
@@ -5443,7 +5493,8 @@ var getChatDisplayTime = (timestamp) => {
|
|
|
5443
5493
|
// src/components/ChatUserList/ChatUserList.tsx
|
|
5444
5494
|
function ChatUserList({
|
|
5445
5495
|
currentUser,
|
|
5446
|
-
onSearchUsers
|
|
5496
|
+
onSearchUsers,
|
|
5497
|
+
colorScheme
|
|
5447
5498
|
}) {
|
|
5448
5499
|
const [opened, { open, close }] = useDisclosure(false);
|
|
5449
5500
|
const dispatch = useDispatch2();
|
|
@@ -5819,21 +5870,40 @@ function ChatUserList({
|
|
|
5819
5870
|
displayName: receiverDetails?.displayName,
|
|
5820
5871
|
avatar: receiverDetails?.avatar
|
|
5821
5872
|
});
|
|
5822
|
-
}
|
|
5873
|
+
},
|
|
5874
|
+
colorScheme
|
|
5823
5875
|
}
|
|
5824
5876
|
)
|
|
5825
5877
|
)));
|
|
5826
5878
|
}
|
|
5827
5879
|
|
|
5880
|
+
// src/store/reset.tsx
|
|
5881
|
+
import { useEffect as useEffect6 } from "react";
|
|
5882
|
+
import { useDispatch as useDispatch3 } from "react-redux";
|
|
5883
|
+
function ResetHandler() {
|
|
5884
|
+
const dispatch = useDispatch3();
|
|
5885
|
+
useEffect6(() => {
|
|
5886
|
+
return () => {
|
|
5887
|
+
dispatch(resetAllMessages());
|
|
5888
|
+
};
|
|
5889
|
+
}, [dispatch]);
|
|
5890
|
+
return null;
|
|
5891
|
+
}
|
|
5892
|
+
|
|
5828
5893
|
// src/components/MrChat/index.tsx
|
|
5829
5894
|
function MrChat({
|
|
5830
5895
|
colorScheme,
|
|
5831
5896
|
primaryColor = "customBrand",
|
|
5832
5897
|
darkColor,
|
|
5898
|
+
authorization: authorization2,
|
|
5833
5899
|
...props
|
|
5834
5900
|
}) {
|
|
5835
5901
|
const theme = createAppTheme(primaryColor);
|
|
5836
|
-
|
|
5902
|
+
useLayoutEffect(() => {
|
|
5903
|
+
if (typeof window === "undefined") return;
|
|
5904
|
+
setEnvironmentAuthorization(authorization2 || "");
|
|
5905
|
+
}, [authorization2]);
|
|
5906
|
+
useEffect7(() => {
|
|
5837
5907
|
if (typeof document === "undefined" || !darkColor) return;
|
|
5838
5908
|
const previousBodyBackground = document.body.style.backgroundColor;
|
|
5839
5909
|
document.body.style.backgroundColor = colorScheme === "dark" ? darkColor : "";
|
|
@@ -5846,7 +5916,7 @@ function MrChat({
|
|
|
5846
5916
|
document.documentElement.style.removeProperty("--mantine-color-body");
|
|
5847
5917
|
};
|
|
5848
5918
|
}, [colorScheme, darkColor]);
|
|
5849
|
-
return /* @__PURE__ */ React10.createElement(ReduxProvider, null, /* @__PURE__ */ React10.createElement(SocketProvider, null, /* @__PURE__ */ React10.createElement(
|
|
5919
|
+
return /* @__PURE__ */ React10.createElement(ReduxProvider, null, /* @__PURE__ */ React10.createElement(SocketProvider, null, /* @__PURE__ */ React10.createElement(ResetHandler, null), /* @__PURE__ */ React10.createElement(
|
|
5850
5920
|
MantineProvider,
|
|
5851
5921
|
{
|
|
5852
5922
|
defaultColorScheme: colorScheme ?? "light",
|
|
@@ -5854,7 +5924,7 @@ function MrChat({
|
|
|
5854
5924
|
theme
|
|
5855
5925
|
},
|
|
5856
5926
|
/* @__PURE__ */ React10.createElement(Notifications, null),
|
|
5857
|
-
/* @__PURE__ */ React10.createElement(ChatUserList, { ...props })
|
|
5927
|
+
/* @__PURE__ */ React10.createElement(ChatUserList, { colorScheme, ...props })
|
|
5858
5928
|
)));
|
|
5859
5929
|
}
|
|
5860
5930
|
export {
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#000"><path d="M480-480Zm0 400q-83 0-156-31.5T197-197q-54-54-85.5-127T80-480q0-83 31.5-156T197-763q54-54 127-85.5T480-880q33 0 65 5t62 15q23 8 29 23.5t1 30.5q-5 15-18.5 23.5T588-781q-26-9-52.5-14t-55.5-5q-133 0-226.5 93.5T160-480q0 133 93.5 226.5T480-160q133 0 226.5-93.5T800-480q0-18-2-36t-6-35q-5-19 5-31t25-15q15-3 29.5 4.5T871-564q5 20 7 41t2 43q0 83-31.5 156T763-197q-54 54-127 85.5T480-80Zm320-680h-40q-17 0-28.5-11.5T720-800q0-17 11.5-28.5T760-840h40v-40q0-17 11.5-28.5T840-920q17 0 28.5 11.5T880-880v40h40q17 0 28.5 11.5T960-800q0 17-11.5 28.5T920-760h-40v40q0 17-11.5 28.5T840-680q-17 0-28.5-11.5T800-720v-40ZM620-520q25 0 42.5-17.5T680-580q0-25-17.5-42.5T620-640q-25 0-42.5 17.5T560-580q0 25 17.5 42.5T620-520Zm-280 0q25 0 42.5-17.5T400-580q0-25-17.5-42.5T340-640q-25 0-42.5 17.5T280-580q0 25 17.5 42.5T340-520Zm140 260q58 0 107-28t79-76q6-12-1-24t-21-12H316q-14 0-21 12t-1 24q30 48 79.5 76T480-260Z"/></svg>
|