@rpg-engine/long-bow 0.7.0 → 0.7.2
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/long-bow.cjs.development.js +160 -166
- package/dist/long-bow.cjs.development.js.map +1 -1
- package/dist/long-bow.cjs.production.min.js +1 -1
- package/dist/long-bow.cjs.production.min.js.map +1 -1
- package/dist/long-bow.esm.js +161 -167
- package/dist/long-bow.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/Chat/Chat.tsx +145 -100
- package/src/components/ChatRevamp/ChatRevamp.tsx +6 -3
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import dayjs from 'dayjs';
|
|
1
|
+
import dayjs from 'dayjs'; // Import dayjs for timestamp formatting
|
|
2
2
|
import React, { useEffect, useState } from 'react';
|
|
3
3
|
import { ErrorBoundary } from 'react-error-boundary';
|
|
4
|
-
import {
|
|
4
|
+
import { FaTimes } from 'react-icons/fa'; // Import the close icon
|
|
5
5
|
import styled from 'styled-components';
|
|
6
|
+
import { uiColors } from '../../constants/uiColors';
|
|
6
7
|
import { ChatMessage } from '../ChatRevamp/ChatRevamp';
|
|
7
|
-
import { Column } from '../shared/Column';
|
|
8
8
|
|
|
9
9
|
export interface IStyles {
|
|
10
10
|
textColor?: string;
|
|
@@ -33,22 +33,19 @@ export interface IChatProps {
|
|
|
33
33
|
export const Chat: React.FC<IChatProps> = ({
|
|
34
34
|
chatMessages,
|
|
35
35
|
onSendChatMessage,
|
|
36
|
+
onCloseButton, // Make sure this prop is being passed
|
|
36
37
|
onFocus,
|
|
37
38
|
onBlur,
|
|
38
39
|
styles = {
|
|
39
|
-
textColor: '#
|
|
40
|
-
buttonColor: '#
|
|
41
|
-
buttonBackgroundColor: '
|
|
42
|
-
width: '
|
|
43
|
-
height: '
|
|
40
|
+
textColor: '#ff6600', // Keeping the original color
|
|
41
|
+
buttonColor: '#ff6600',
|
|
42
|
+
buttonBackgroundColor: '#333',
|
|
43
|
+
width: '100%',
|
|
44
|
+
height: '100%',
|
|
44
45
|
},
|
|
45
46
|
}) => {
|
|
46
47
|
const [message, setMessage] = useState('');
|
|
47
48
|
|
|
48
|
-
useEffect(() => {
|
|
49
|
-
scrollChatToBottom();
|
|
50
|
-
}, []);
|
|
51
|
-
|
|
52
49
|
useEffect(() => {
|
|
53
50
|
scrollChatToBottom();
|
|
54
51
|
}, [chatMessages]);
|
|
@@ -60,84 +57,58 @@ export const Chat: React.FC<IChatProps> = ({
|
|
|
60
57
|
}
|
|
61
58
|
};
|
|
62
59
|
|
|
63
|
-
const handleSubmit = (event: React.
|
|
60
|
+
const handleSubmit = (event: React.FormEvent<HTMLFormElement>) => {
|
|
64
61
|
event.preventDefault();
|
|
65
|
-
if (!message
|
|
62
|
+
if (!message.trim()) return;
|
|
66
63
|
onSendChatMessage(message);
|
|
67
64
|
setMessage('');
|
|
68
65
|
};
|
|
69
|
-
const getInputValue = (value: string) => {
|
|
70
|
-
setMessage(value);
|
|
71
|
-
};
|
|
72
66
|
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
createdAt: string | undefined,
|
|
76
|
-
message: string
|
|
77
|
-
) => {
|
|
78
|
-
return `${dayjs(createdAt || new Date()).format('HH:mm')} ${
|
|
79
|
-
emitter?.name ? `${emitter.name}: ` : 'Unknown: '
|
|
80
|
-
} ${message}`;
|
|
67
|
+
const truncateName = (name: string, maxLength: number = 10) => {
|
|
68
|
+
return name.length > maxLength ? name.slice(0, maxLength) + '...' : name;
|
|
81
69
|
};
|
|
82
70
|
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
color={styles?.textColor || '#c65102'}
|
|
88
|
-
key={`${chatMessage._id}_${index}`}
|
|
89
|
-
>
|
|
90
|
-
{onRenderMessageLines(
|
|
91
|
-
chatMessage.emitter,
|
|
92
|
-
chatMessage.createdAt as string,
|
|
93
|
-
chatMessage.message
|
|
94
|
-
)}
|
|
95
|
-
</Message>
|
|
96
|
-
))
|
|
97
|
-
) : (
|
|
98
|
-
<Message color={styles?.textColor || '#c65102'}>
|
|
99
|
-
No messages available.
|
|
100
|
-
</Message>
|
|
101
|
-
);
|
|
71
|
+
const formatMessage = (chatMessage: ChatMessage) => {
|
|
72
|
+
const timestamp = dayjs(chatMessage.createdAt).format('HH:mm');
|
|
73
|
+
const truncatedName = truncateName(chatMessage.emitter.name);
|
|
74
|
+
return `${timestamp} ${truncatedName}: ${chatMessage.message}`;
|
|
102
75
|
};
|
|
103
76
|
|
|
104
77
|
return (
|
|
105
78
|
<ChatContainer
|
|
106
|
-
width={styles
|
|
107
|
-
height={styles
|
|
79
|
+
width={styles.width || 'auto'}
|
|
80
|
+
height={styles.height || 'auto'}
|
|
108
81
|
>
|
|
82
|
+
<CloseButton onClick={onCloseButton}>
|
|
83
|
+
<FaTimes />
|
|
84
|
+
</CloseButton>
|
|
109
85
|
<ErrorBoundary fallback={<p>Oops! Your chat has crashed.</p>}>
|
|
110
86
|
<MessagesContainer className="chat-body">
|
|
111
|
-
{
|
|
87
|
+
{chatMessages.map((chatMessage, index) => (
|
|
88
|
+
<Message
|
|
89
|
+
color={styles.textColor || uiColors.yellow}
|
|
90
|
+
key={`${chatMessage._id}_${index}`}
|
|
91
|
+
>
|
|
92
|
+
{formatMessage(chatMessage)}
|
|
93
|
+
</Message>
|
|
94
|
+
))}
|
|
112
95
|
</MessagesContainer>
|
|
113
96
|
|
|
114
97
|
<Form onSubmit={handleSubmit}>
|
|
115
|
-
<
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
</
|
|
129
|
-
<Column justifyContent="flex-end">
|
|
130
|
-
<Button
|
|
131
|
-
buttonColor={styles?.buttonColor || '#005b96'}
|
|
132
|
-
buttonBackgroundColor={
|
|
133
|
-
styles?.buttonBackgroundColor || 'rgba(0,0,0,.5)'
|
|
134
|
-
}
|
|
135
|
-
id="chat-send-button"
|
|
136
|
-
style={{ borderRadius: '20%' }}
|
|
137
|
-
>
|
|
138
|
-
<RxPaperPlane size={15} />
|
|
139
|
-
</Button>
|
|
140
|
-
</Column>
|
|
98
|
+
<TextField
|
|
99
|
+
value={message}
|
|
100
|
+
onChange={e => setMessage(e.target.value)}
|
|
101
|
+
type="text"
|
|
102
|
+
autoComplete="off"
|
|
103
|
+
onFocus={onFocus}
|
|
104
|
+
onBlur={onBlur}
|
|
105
|
+
onPointerDown={onFocus}
|
|
106
|
+
autoFocus
|
|
107
|
+
placeholder="Type your message..."
|
|
108
|
+
/>
|
|
109
|
+
<SendButton type="submit" disabled={!message.trim()}>
|
|
110
|
+
▶
|
|
111
|
+
</SendButton>
|
|
141
112
|
</Form>
|
|
142
113
|
</ErrorBoundary>
|
|
143
114
|
</ChatContainer>
|
|
@@ -153,48 +124,122 @@ interface IMessageProps {
|
|
|
153
124
|
color: string;
|
|
154
125
|
}
|
|
155
126
|
|
|
156
|
-
interface IButtonProps {
|
|
157
|
-
buttonColor: string;
|
|
158
|
-
buttonBackgroundColor: string;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
127
|
const ChatContainer = styled.div<IContainerProps>`
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
background-color: rgba(0, 0, 0, 0.2);
|
|
166
|
-
height: auto;
|
|
167
|
-
`;
|
|
128
|
+
width: ${props => props.width};
|
|
129
|
+
height: ${props => props.height};
|
|
130
|
+
background-color: #1e1e1e81;
|
|
168
131
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
border: none !important;
|
|
173
|
-
max-height: 28px !important;
|
|
132
|
+
display: flex;
|
|
133
|
+
flex-direction: column;
|
|
134
|
+
position: relative; // Added for absolute positioning of close button
|
|
174
135
|
`;
|
|
175
136
|
|
|
176
137
|
const MessagesContainer = styled.div`
|
|
177
|
-
|
|
178
|
-
margin-bottom: 10px;
|
|
138
|
+
flex-grow: 1;
|
|
179
139
|
overflow-y: auto;
|
|
140
|
+
padding: 10px;
|
|
141
|
+
margin-left: 0.9rem;
|
|
142
|
+
|
|
143
|
+
&::-webkit-scrollbar {
|
|
144
|
+
width: 6px;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
&::-webkit-scrollbar-track {
|
|
148
|
+
background: #333;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
&::-webkit-scrollbar-thumb {
|
|
152
|
+
background: transparent;
|
|
153
|
+
border-radius: 3px;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
&::-webkit-scrollbar-thumb:hover {
|
|
157
|
+
background: #222;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
&::-webkit-scrollbar-corner {
|
|
161
|
+
background: #333;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
&::-webkit-scrollbar-button {
|
|
165
|
+
background: #333;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
&::-webkit-scrollbar-button:hover {
|
|
169
|
+
background: #222;
|
|
170
|
+
}
|
|
180
171
|
`;
|
|
181
172
|
|
|
182
173
|
const Message = styled.div<IMessageProps>`
|
|
183
|
-
margin-bottom:
|
|
174
|
+
margin-bottom: 4px;
|
|
184
175
|
color: ${({ color }) => color};
|
|
176
|
+
font-family: 'Press Start 2P', cursive;
|
|
177
|
+
font-size: 0.7rem; // Adjusted font size for pixel font
|
|
178
|
+
white-space: pre-wrap; // Preserve line breaks and spaces
|
|
179
|
+
word-break: break-word; // Break long words if necessary
|
|
185
180
|
`;
|
|
186
181
|
|
|
187
182
|
const Form = styled.form`
|
|
188
183
|
display: flex;
|
|
189
184
|
width: 100%;
|
|
190
|
-
|
|
191
|
-
|
|
185
|
+
padding: 5px;
|
|
186
|
+
`;
|
|
187
|
+
|
|
188
|
+
const TextField = styled.input`
|
|
189
|
+
flex-grow: 1;
|
|
190
|
+
background-color: transparent;
|
|
191
|
+
color: #ff6600;
|
|
192
|
+
border: none;
|
|
193
|
+
font-family: 'Press Start 2P', cursive;
|
|
194
|
+
font-size: 0.7rem; // Matching the font size of messages
|
|
195
|
+
border-radius: 5px;
|
|
196
|
+
margin-left: 0.9rem;
|
|
197
|
+
|
|
198
|
+
&::placeholder {
|
|
199
|
+
color: ${uiColors.lightGray};
|
|
200
|
+
font-size: 0.7rem;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
&:focus {
|
|
204
|
+
outline: none;
|
|
205
|
+
}
|
|
206
|
+
`;
|
|
207
|
+
|
|
208
|
+
const SendButton = styled.button`
|
|
209
|
+
background-color: transparent;
|
|
210
|
+
color: #ff6600;
|
|
211
|
+
border: none;
|
|
212
|
+
padding: 0 10px;
|
|
213
|
+
font-size: 18px;
|
|
214
|
+
cursor: pointer;
|
|
215
|
+
transition: color 0.3s ease;
|
|
216
|
+
|
|
217
|
+
&:hover {
|
|
218
|
+
color: #ff8533;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
&:disabled {
|
|
222
|
+
color: #666;
|
|
223
|
+
cursor: not-allowed;
|
|
224
|
+
}
|
|
192
225
|
`;
|
|
193
226
|
|
|
194
|
-
const
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
border: none
|
|
227
|
+
const CloseButton = styled.button`
|
|
228
|
+
position: absolute;
|
|
229
|
+
top: 0;
|
|
230
|
+
right: 0;
|
|
231
|
+
background-color: transparent;
|
|
232
|
+
border: none;
|
|
233
|
+
color: white;
|
|
234
|
+
font-size: 16px;
|
|
235
|
+
cursor: pointer;
|
|
236
|
+
padding: 5px;
|
|
237
|
+
display: flex;
|
|
238
|
+
align-items: center;
|
|
239
|
+
justify-content: center;
|
|
240
|
+
transition: color 0.3s ease;
|
|
241
|
+
|
|
242
|
+
&:hover {
|
|
243
|
+
color: ${uiColors.darkYellow};
|
|
244
|
+
}
|
|
200
245
|
`;
|
|
@@ -174,7 +174,7 @@ export const ChatRevamp: React.FC<IChatRevampProps> = ({
|
|
|
174
174
|
};
|
|
175
175
|
|
|
176
176
|
return (
|
|
177
|
-
|
|
177
|
+
<Container>
|
|
178
178
|
{renderTabs()}
|
|
179
179
|
<PrivateChatContainer
|
|
180
180
|
width={styles?.width || '80%'}
|
|
@@ -186,10 +186,14 @@ export const ChatRevamp: React.FC<IChatRevampProps> = ({
|
|
|
186
186
|
</RecentChatTabContainer>
|
|
187
187
|
{renderChatContent()}
|
|
188
188
|
</PrivateChatContainer>
|
|
189
|
-
|
|
189
|
+
</Container>
|
|
190
190
|
);
|
|
191
191
|
};
|
|
192
192
|
|
|
193
|
+
const Container = styled.div`
|
|
194
|
+
max-width: 800px;
|
|
195
|
+
`;
|
|
196
|
+
|
|
193
197
|
const TabContainer = styled.div`
|
|
194
198
|
width: 100%;
|
|
195
199
|
display: flex;
|
|
@@ -237,7 +241,6 @@ const RecentChatTabContainer = styled.div<{
|
|
|
237
241
|
min-width: ${props => (props.isOpen ? '180px' : '30px')};
|
|
238
242
|
transition: all 0.3s ease-in-out;
|
|
239
243
|
overflow: hidden;
|
|
240
|
-
|
|
241
244
|
@media (max-width: 768px) {
|
|
242
245
|
width: ${props => (props.isOpen ? '50%' : '30px')};
|
|
243
246
|
min-width: ${props => (props.isOpen ? '150px' : '30px')};
|