@terrafirmagreg-team/chat 0.1.0 → 1.2.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/package.json +18 -13
- package/src/{ui → components}/box.tsx +23 -14
- package/src/{ui → components}/index.ts +1 -0
- package/src/{ui → components}/message.tsx +5 -4
- package/src/lib/identity.ts +1 -1
- package/src/lib/index.ts +1 -0
- package/src/locales/en_us.json +14 -14
- package/src/locales/pl_pl.json +14 -16
- package/src/locales/ru_ru.json +14 -14
- package/src/locales/uk_ua.json +14 -16
- package/src/locales/zh_cn.json +14 -16
- package/src/locales/zh_tw.json +14 -16
- package/src/locales.ts +1 -0
- package/src/styles.css +1 -0
- package/src/types.ts +5 -1
package/package.json
CHANGED
|
@@ -1,27 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@terrafirmagreg-team/chat",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"type": "module",
|
|
5
|
+
"description": "Chat",
|
|
6
|
+
"license": "LGPL-3.0-only",
|
|
5
7
|
"exports": {
|
|
6
|
-
".": "./src/
|
|
8
|
+
".": "./src/components/index.ts",
|
|
7
9
|
"./lib": "./src/lib/index.ts",
|
|
10
|
+
"./lib/*": [
|
|
11
|
+
"./src/lib/*.ts",
|
|
12
|
+
"./src/lib/*/index.ts"
|
|
13
|
+
],
|
|
14
|
+
"./types": "./src/types.ts",
|
|
8
15
|
"./styles.css": "./src/styles.css",
|
|
9
|
-
"
|
|
10
|
-
|
|
11
|
-
"./src/*.tsx",
|
|
12
|
-
"./src/*/index.
|
|
13
|
-
"./src/*/index.
|
|
16
|
+
"./locales": "./src/locales.ts",
|
|
17
|
+
"./components/*": [
|
|
18
|
+
"./src/components/*.tsx",
|
|
19
|
+
"./src/components/*/index.tsx",
|
|
20
|
+
"./src/components/*/index.ts"
|
|
14
21
|
]
|
|
15
22
|
},
|
|
16
23
|
"files": [
|
|
17
|
-
"src"
|
|
18
|
-
"styles",
|
|
19
|
-
"styles.css"
|
|
24
|
+
"src"
|
|
20
25
|
],
|
|
21
26
|
"dependencies": {
|
|
22
|
-
"@terrafirmagreg-team/ui": "
|
|
23
|
-
"lucide-react": "^
|
|
24
|
-
"@terrafirmagreg-team/translate": "
|
|
27
|
+
"@terrafirmagreg-team/ui": "1.2.1",
|
|
28
|
+
"lucide-react": "^0.577.0",
|
|
29
|
+
"@terrafirmagreg-team/translate": "1.2.1"
|
|
25
30
|
},
|
|
26
31
|
"peerDependencies": {
|
|
27
32
|
"react": ">=19"
|
|
@@ -45,7 +45,7 @@ export function ChatBox({
|
|
|
45
45
|
onClose,
|
|
46
46
|
onLogin,
|
|
47
47
|
renderAvatar,
|
|
48
|
-
unknownError = '
|
|
48
|
+
unknownError = 'Unknown error',
|
|
49
49
|
}: {
|
|
50
50
|
messages: readonly ChatMessage[];
|
|
51
51
|
t: ChatTranslate;
|
|
@@ -101,7 +101,11 @@ export function ChatBox({
|
|
|
101
101
|
await send(message, loggedIn ? undefined : chatName.trim() || undefined);
|
|
102
102
|
setEnteredMessage('');
|
|
103
103
|
} catch (err) {
|
|
104
|
-
setSendingError(
|
|
104
|
+
setSendingError(
|
|
105
|
+
err instanceof Error
|
|
106
|
+
? err.message
|
|
107
|
+
: t(unknownError, { note: 'chat.errorUnknown' }),
|
|
108
|
+
);
|
|
105
109
|
} finally {
|
|
106
110
|
setSendingMessage(false);
|
|
107
111
|
requestAnimationFrame(() => inputRef.current?.focus());
|
|
@@ -111,13 +115,13 @@ export function ChatBox({
|
|
|
111
115
|
return (
|
|
112
116
|
<section className="chat">
|
|
113
117
|
<header className="chat__header">
|
|
114
|
-
<p className="chat__title">{t('chat.title')}</p>
|
|
118
|
+
<p className="chat__title">{t('Chat', { note: 'chat.title' })}</p>
|
|
115
119
|
{onClose && (
|
|
116
|
-
<Hint label={t('common.close')}>
|
|
120
|
+
<Hint label={t('Close', { note: 'common.close' })}>
|
|
117
121
|
<button
|
|
118
122
|
type="button"
|
|
119
123
|
className="chat__close"
|
|
120
|
-
aria-label={t('common.close')}
|
|
124
|
+
aria-label={t('Close', { note: 'common.close' })}
|
|
121
125
|
onClick={onClose}>
|
|
122
126
|
<X className="size-4" aria-hidden="true" />
|
|
123
127
|
</button>
|
|
@@ -128,7 +132,7 @@ export function ChatBox({
|
|
|
128
132
|
<div className="chat__offline" role="status">
|
|
129
133
|
<span className="chat__offline-chip">
|
|
130
134
|
<WifiOff className="size-3.5" aria-hidden="true" />
|
|
131
|
-
{t('servers.offline')}
|
|
135
|
+
{t('Servers offline', { note: 'servers.offline' })}
|
|
132
136
|
</span>
|
|
133
137
|
</div>
|
|
134
138
|
) : (
|
|
@@ -153,8 +157,12 @@ export function ChatBox({
|
|
|
153
157
|
{!shown.length && (
|
|
154
158
|
<Empty>
|
|
155
159
|
<EmptyHeader>
|
|
156
|
-
<EmptyTitle>
|
|
157
|
-
|
|
160
|
+
<EmptyTitle>
|
|
161
|
+
{t('Chat', { note: 'chat.title' })}
|
|
162
|
+
</EmptyTitle>
|
|
163
|
+
<EmptyDescription>
|
|
164
|
+
{t('No messages yet', { note: 'chat.noMessages' })}
|
|
165
|
+
</EmptyDescription>
|
|
158
166
|
</EmptyHeader>
|
|
159
167
|
</Empty>
|
|
160
168
|
)}
|
|
@@ -181,8 +189,8 @@ export function ChatBox({
|
|
|
181
189
|
type="text"
|
|
182
190
|
value={chatName}
|
|
183
191
|
maxLength={24}
|
|
184
|
-
placeholder={t('chat.namePlaceholder')}
|
|
185
|
-
aria-label={t('chat.nameLabel')}
|
|
192
|
+
placeholder={t('Name', { note: 'chat.namePlaceholder' })}
|
|
193
|
+
aria-label={t('Name', { note: 'chat.nameLabel' })}
|
|
186
194
|
onChange={e => rememberChatName(e.target.value)}
|
|
187
195
|
/>
|
|
188
196
|
</InputGroupAddon>
|
|
@@ -192,9 +200,9 @@ export function ChatBox({
|
|
|
192
200
|
rows={2}
|
|
193
201
|
value={enteredMessage}
|
|
194
202
|
maxLength={maxLength}
|
|
195
|
-
placeholder={nameMissing ? t('chat.namePlaceholder') : t('chat.placeholder')}
|
|
203
|
+
placeholder={nameMissing ? t('Name', { note: 'chat.namePlaceholder' }) : t('Message', { note: 'chat.placeholder' })}
|
|
196
204
|
disabled={sendingMessage || nameMissing}
|
|
197
|
-
aria-label={t('chat.placeholder')}
|
|
205
|
+
aria-label={t('Message', { note: 'chat.placeholder' })}
|
|
198
206
|
onChange={e => setEnteredMessage(e.target.value)}
|
|
199
207
|
onKeyDown={e => {
|
|
200
208
|
if (e.nativeEvent.isComposing || e.keyCode === 229) return;
|
|
@@ -210,7 +218,7 @@ export function ChatBox({
|
|
|
210
218
|
variant="default"
|
|
211
219
|
size="icon-sm"
|
|
212
220
|
disabled={!enteredMessage.trim() || sendingMessage || nameMissing}
|
|
213
|
-
aria-label={t('chat.send')}>
|
|
221
|
+
aria-label={t('Send', { note: 'chat.send' })}>
|
|
214
222
|
<ArrowUp strokeWidth={2.25} aria-hidden="true" />
|
|
215
223
|
</InputGroupButton>
|
|
216
224
|
</InputGroupAddon>
|
|
@@ -220,9 +228,10 @@ export function ChatBox({
|
|
|
220
228
|
{send && loginRequired && !loggedIn && onLogin && (
|
|
221
229
|
<button type="button" className="chat__login" onClick={onLogin}>
|
|
222
230
|
<LogIn className="size-4" aria-hidden="true" />
|
|
223
|
-
{t('chat.login')}
|
|
231
|
+
{t('Log in', { note: 'chat.login' })}
|
|
224
232
|
</button>
|
|
225
233
|
)}
|
|
226
234
|
</section>
|
|
227
235
|
);
|
|
228
236
|
}
|
|
237
|
+
|
|
@@ -23,12 +23,12 @@ export function ChatMessageRow({
|
|
|
23
23
|
return message.message;
|
|
24
24
|
case 'playerjoin':
|
|
25
25
|
return message.playerName
|
|
26
|
-
? t('chat.playerJoin', {playername: message.playerName})
|
|
27
|
-
: t('chat.anonymousJoin');
|
|
26
|
+
? t('{playername} joined the game', {note: 'chat.playerJoin', variables: {playername: message.playerName}})
|
|
27
|
+
: t('A player joined the game', {note: 'chat.anonymousJoin'});
|
|
28
28
|
case 'playerleave':
|
|
29
29
|
return message.playerName
|
|
30
|
-
? t('chat.playerQuit', {playername: message.playerName})
|
|
31
|
-
: t('chat.anonymousQuit');
|
|
30
|
+
? t('{playername} left the game', {note: 'chat.playerQuit', variables: {playername: message.playerName}})
|
|
31
|
+
: t('A player left the game', {note: 'chat.anonymousQuit'});
|
|
32
32
|
}
|
|
33
33
|
})();
|
|
34
34
|
|
|
@@ -56,3 +56,4 @@ export function ChatMessageRow({
|
|
|
56
56
|
</Message>
|
|
57
57
|
);
|
|
58
58
|
}
|
|
59
|
+
|
package/src/lib/identity.ts
CHANGED
|
@@ -16,7 +16,6 @@ export function setStoredName(key: string, name: string): void {
|
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
|
|
20
19
|
export function isOwnChatMessage(
|
|
21
20
|
message: ChatMessage,
|
|
22
21
|
names: {chatName?: string; loginName?: string},
|
|
@@ -26,3 +25,4 @@ export function isOwnChatMessage(
|
|
|
26
25
|
const login = names.loginName?.trim();
|
|
27
26
|
return (!!chat && message.playerName === chat) || (!!login && message.playerName === login);
|
|
28
27
|
}
|
|
28
|
+
|
package/src/lib/index.ts
CHANGED
package/src/locales/en_us.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
|
-
"chat":
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
2
|
+
"A player joined the game(chat.anonymousJoin)": "A player joined the game",
|
|
3
|
+
"A player left the game(chat.anonymousQuit)": "A player left the game",
|
|
4
|
+
"Chat(chat.title)": "Chat",
|
|
5
|
+
"Close(common.close)": "Close",
|
|
6
|
+
"Log in(chat.login)": "Log in",
|
|
7
|
+
"Message(chat.placeholder)": "Message",
|
|
8
|
+
"Name(chat.nameLabel)": "Name",
|
|
9
|
+
"Name(chat.namePlaceholder)": "Name",
|
|
10
|
+
"No messages yet(chat.noMessages)": "No messages yet",
|
|
11
|
+
"Send(chat.send)": "Send",
|
|
12
|
+
"Servers offline(servers.offline)": "Servers offline",
|
|
13
|
+
"Unknown error(chat.errorUnknown)": "Unknown error",
|
|
14
|
+
"{playername} joined the game(chat.playerJoin)": "{playername} joined the game",
|
|
15
|
+
"{playername} left the game(chat.playerQuit)": "{playername} left the game"
|
|
16
16
|
}
|
package/src/locales/pl_pl.json
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
{
|
|
2
|
-
"chat":
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"A player joined the game(chat.anonymousJoin)": "Gracz dołączył do gry",
|
|
3
|
+
"A player left the game(chat.anonymousQuit)": "Gracz opuścił grę",
|
|
4
|
+
"Chat(chat.title)": "Czat",
|
|
5
|
+
"Log in(chat.login)": "Zaloguj się",
|
|
6
|
+
"Message(chat.placeholder)": "Wiadomość",
|
|
7
|
+
"Name(chat.nameLabel)": "Nazwa",
|
|
8
|
+
"Name(chat.namePlaceholder)": "Nazwa",
|
|
9
|
+
"No messages yet(chat.noMessages)": "Brak wiadomości",
|
|
10
|
+
"Send(chat.send)": "Wyślij",
|
|
11
|
+
"Unknown error(chat.errorUnknown)": "Nieznany błąd",
|
|
12
|
+
"{playername} joined the game(chat.playerJoin)": "{playername} dołączył do gry",
|
|
13
|
+
"{playername} left the game(chat.playerQuit)": "{playername} opuścił grę"
|
|
14
|
+
}
|
package/src/locales/ru_ru.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
|
-
"chat":
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
2
|
+
"A player joined the game(chat.anonymousJoin)": "Игрок зашёл в игру",
|
|
3
|
+
"A player left the game(chat.anonymousQuit)": "Игрок вышел из игры",
|
|
4
|
+
"Chat(chat.title)": "Чат",
|
|
5
|
+
"Close(common.close)": "Закрыть",
|
|
6
|
+
"Log in(chat.login)": "Войти",
|
|
7
|
+
"Message(chat.placeholder)": "Сообщение",
|
|
8
|
+
"Name(chat.nameLabel)": "Имя",
|
|
9
|
+
"Name(chat.namePlaceholder)": "Имя",
|
|
10
|
+
"No messages yet(chat.noMessages)": "Пока нет сообщений",
|
|
11
|
+
"Send(chat.send)": "Отправить",
|
|
12
|
+
"Servers offline(servers.offline)": "Серверы недоступны",
|
|
13
|
+
"Unknown error(chat.errorUnknown)": "Неизвестная ошибка",
|
|
14
|
+
"{playername} joined the game(chat.playerJoin)": "{playername} зашёл в игру",
|
|
15
|
+
"{playername} left the game(chat.playerQuit)": "{playername} вышел из игры"
|
|
16
16
|
}
|
package/src/locales/uk_ua.json
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
{
|
|
2
|
-
"chat":
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"A player joined the game(chat.anonymousJoin)": "Гравець зайшов у гру",
|
|
3
|
+
"A player left the game(chat.anonymousQuit)": "Гравець вийшов з гри",
|
|
4
|
+
"Chat(chat.title)": "Чат",
|
|
5
|
+
"Log in(chat.login)": "Увійти",
|
|
6
|
+
"Message(chat.placeholder)": "Повідомлення",
|
|
7
|
+
"Name(chat.nameLabel)": "Ім'я",
|
|
8
|
+
"Name(chat.namePlaceholder)": "Ім'я",
|
|
9
|
+
"No messages yet(chat.noMessages)": "Поки немає повідомлень",
|
|
10
|
+
"Send(chat.send)": "Надіслати",
|
|
11
|
+
"Unknown error(chat.errorUnknown)": "Невідома помилка",
|
|
12
|
+
"{playername} joined the game(chat.playerJoin)": "{playername} зайшов у гру",
|
|
13
|
+
"{playername} left the game(chat.playerQuit)": "{playername} вийшов з гри"
|
|
14
|
+
}
|
package/src/locales/zh_cn.json
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
{
|
|
2
|
-
"chat":
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"A player joined the game(chat.anonymousJoin)": "",
|
|
3
|
+
"A player left the game(chat.anonymousQuit)": "",
|
|
4
|
+
"Chat(chat.title)": "",
|
|
5
|
+
"Log in(chat.login)": "",
|
|
6
|
+
"Message(chat.placeholder)": "",
|
|
7
|
+
"Name(chat.nameLabel)": "",
|
|
8
|
+
"Name(chat.namePlaceholder)": "",
|
|
9
|
+
"No messages yet(chat.noMessages)": "",
|
|
10
|
+
"Send(chat.send)": "",
|
|
11
|
+
"Unknown error(chat.errorUnknown)": "",
|
|
12
|
+
"{playername} joined the game(chat.playerJoin)": "{playername} ",
|
|
13
|
+
"{playername} left the game(chat.playerQuit)": "{playername} "
|
|
14
|
+
}
|
package/src/locales/zh_tw.json
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
{
|
|
2
|
-
"chat":
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"A player joined the game(chat.anonymousJoin)": "",
|
|
3
|
+
"A player left the game(chat.anonymousQuit)": "",
|
|
4
|
+
"Chat(chat.title)": "",
|
|
5
|
+
"Log in(chat.login)": "",
|
|
6
|
+
"Message(chat.placeholder)": "",
|
|
7
|
+
"Name(chat.nameLabel)": "",
|
|
8
|
+
"Name(chat.namePlaceholder)": "",
|
|
9
|
+
"No messages yet(chat.noMessages)": "",
|
|
10
|
+
"Send(chat.send)": "",
|
|
11
|
+
"Unknown error(chat.errorUnknown)": "",
|
|
12
|
+
"{playername} joined the game(chat.playerJoin)": "{playername} ",
|
|
13
|
+
"{playername} left the game(chat.playerQuit)": "{playername} "
|
|
14
|
+
}
|
package/src/locales.ts
CHANGED
package/src/styles.css
CHANGED
package/src/types.ts
CHANGED
|
@@ -28,4 +28,8 @@ export interface ChatSendingSettings {
|
|
|
28
28
|
loginRequired?: boolean;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
export type ChatTranslate = (
|
|
31
|
+
export type ChatTranslate = (
|
|
32
|
+
text: string,
|
|
33
|
+
opts?: { note?: string; variables?: Record<string, string> },
|
|
34
|
+
) => string;
|
|
35
|
+
|