@terrafirmagreg-team/chat 0.1.0 → 1.2.0

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 CHANGED
@@ -1,27 +1,32 @@
1
1
  {
2
2
  "name": "@terrafirmagreg-team/chat",
3
- "version": "0.1.0",
3
+ "version": "1.2.0",
4
4
  "type": "module",
5
+ "description": "Chat",
6
+ "license": "LGPL-3.0-only",
5
7
  "exports": {
6
- ".": "./src/ui/index.ts",
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
- "./src/*.ts",
11
- "./src/*.tsx",
12
- "./src/*/index.ts",
13
- "./src/*/index.tsx"
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": "0.1.0",
23
- "lucide-react": "^1.63.0",
24
- "@terrafirmagreg-team/translate": "0.1.0"
27
+ "@terrafirmagreg-team/ui": "1.2.0",
28
+ "lucide-react": "^0.577.0",
29
+ "@terrafirmagreg-team/translate": "1.2.0"
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 = 'chat.errorUnknown',
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(err instanceof Error ? err.message : t(unknownError));
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>{t('chat.title')}</EmptyTitle>
157
- <EmptyDescription>{t('chat.noMessages')}</EmptyDescription>
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
+
@@ -8,3 +8,4 @@ export type {
8
8
  ChatTranslate,
9
9
  } from '@terrafirmagreg-team/chat/types';
10
10
  export {getStoredName, isOwnChatMessage, setStoredName} from '@terrafirmagreg-team/chat/lib';
11
+
@@ -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
+
@@ -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
@@ -10,3 +10,4 @@ export {
10
10
  setStoredName,
11
11
  } from './identity';
12
12
  export { type ChatTranslate } from '@terrafirmagreg-team/chat/types';
13
+
@@ -1,16 +1,16 @@
1
1
  {
2
- "chat": {
3
- "title": "Chat",
4
- "noMessages": "No messages yet",
5
- "placeholder": "Message",
6
- "namePlaceholder": "Name",
7
- "nameLabel": "Name",
8
- "send": "Send",
9
- "login": "Log in",
10
- "playerJoin": "{playername} joined the game",
11
- "playerQuit": "{playername} left the game",
12
- "anonymousJoin": "A player joined the game",
13
- "anonymousQuit": "A player left the game",
14
- "errorUnknown": "Unknown error"
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
  }
@@ -1,16 +1,14 @@
1
- {
2
- "chat": {
3
- "title": "Czat",
4
- "noMessages": "Brak wiadomości",
5
- "placeholder": "Wiadomość",
6
- "namePlaceholder": "Nazwa",
7
- "nameLabel": "Nazwa",
8
- "send": "Wyślij",
9
- "login": "Zaloguj się",
10
- "playerJoin": "{playername} dołączył do gry",
11
- "playerQuit": "{playername} opuścił grę",
12
- "anonymousJoin": "Gracz dołączył do gry",
13
- "anonymousQuit": "Gracz opuścił grę",
14
- "errorUnknown": "Nieznany błąd"
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
+ }
@@ -1,16 +1,16 @@
1
1
  {
2
- "chat": {
3
- "title": "Чат",
4
- "noMessages": "Пока нет сообщений",
5
- "placeholder": "Сообщение",
6
- "namePlaceholder": "Имя",
7
- "nameLabel": "Имя",
8
- "send": "Отправить",
9
- "login": "Войти",
10
- "playerJoin": "{playername} зашёл в игру",
11
- "playerQuit": "{playername} вышел из игры",
12
- "anonymousJoin": "Игрок зашёл в игру",
13
- "anonymousQuit": "Игрок вышел из игры",
14
- "errorUnknown": "Неизвестная ошибка"
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
  }
@@ -1,16 +1,14 @@
1
- {
2
- "chat": {
3
- "title": "Чат",
4
- "noMessages": "Поки немає повідомлень",
5
- "placeholder": "Повідомлення",
6
- "namePlaceholder": "Ім'я",
7
- "nameLabel": "Ім'я",
8
- "send": "Надіслати",
9
- "login": "Увійти",
10
- "playerJoin": "{playername} зайшов у гру",
11
- "playerQuit": "{playername} вийшов з гри",
12
- "anonymousJoin": "Гравець зайшов у гру",
13
- "anonymousQuit": "Гравець вийшов з гри",
14
- "errorUnknown": "Невідома помилка"
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
+ }
@@ -1,16 +1,14 @@
1
- {
2
- "chat": {
3
- "title": "",
4
- "noMessages": "",
5
- "placeholder": "",
6
- "namePlaceholder": "",
7
- "nameLabel": "",
8
- "send": "",
9
- "login": "",
10
- "playerJoin": "{playername} ",
11
- "playerQuit": "{playername} ",
12
- "anonymousJoin": "",
13
- "anonymousQuit": "",
14
- "errorUnknown": ""
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
+ }
@@ -1,16 +1,14 @@
1
- {
2
- "chat": {
3
- "title": "",
4
- "noMessages": "",
5
- "placeholder": "",
6
- "namePlaceholder": "",
7
- "nameLabel": "",
8
- "send": "",
9
- "login": "",
10
- "playerJoin": "{playername} ",
11
- "playerQuit": "{playername} ",
12
- "anonymousJoin": "",
13
- "anonymousQuit": "",
14
- "errorUnknown": ""
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
@@ -3,3 +3,4 @@ import { createLocaleCatalog } from '@terrafirmagreg-team/translate/lib/locales'
3
3
  export const locales = createLocaleCatalog(
4
4
  import.meta.glob('./locales/*.json', { eager: true, import: 'default' }),
5
5
  );
6
+
package/src/styles.css CHANGED
@@ -177,3 +177,4 @@
177
177
  max-width: calc(100% - 7rem);
178
178
  }
179
179
  }
180
+
package/src/types.ts CHANGED
@@ -28,4 +28,8 @@ export interface ChatSendingSettings {
28
28
  loginRequired?: boolean;
29
29
  }
30
30
 
31
- export type ChatTranslate = (key: string, params?: Record<string, unknown>) => string;
31
+ export type ChatTranslate = (
32
+ text: string,
33
+ opts?: { note?: string; variables?: Record<string, string> },
34
+ ) => string;
35
+