@poolse/react-ui 0.1.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/CHANGELOG.md +24 -0
- package/LICENSE +21 -0
- package/README.md +91 -0
- package/dist/index.cjs +1024 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +424 -0
- package/dist/index.d.ts +424 -0
- package/dist/index.js +1008 -0
- package/dist/index.js.map +1 -0
- package/dist/styles.css +841 -0
- package/package.json +69 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,1008 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useMe, useMessages, useTyping, useRealtimeStatus, useConversations, useMembers, useAttachmentUrl, useReactions } from '@poolse/react';
|
|
3
|
+
import { useEffect, useState, useRef } from 'react';
|
|
4
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
5
|
+
|
|
6
|
+
// src/ConversationView.tsx
|
|
7
|
+
var FONT_HREF = "https://fonts.googleapis.com/css2?family=Bricolage+Grotesque:opsz,wght@12..96,400;12..96,600;12..96,800&family=Hanken+Grotesk:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap";
|
|
8
|
+
var FONT_HREF_PRECONNECT_GOOGLE = "https://fonts.googleapis.com";
|
|
9
|
+
var FONT_HREF_PRECONNECT_STATIC = "https://fonts.gstatic.com";
|
|
10
|
+
var MARKER_ATTR = "data-poolse-fonts";
|
|
11
|
+
function injectFontLinks() {
|
|
12
|
+
if (typeof document === "undefined") return;
|
|
13
|
+
if (document.querySelector(`link[${MARKER_ATTR}]`)) return;
|
|
14
|
+
const head = document.head;
|
|
15
|
+
const pre1 = document.createElement("link");
|
|
16
|
+
pre1.rel = "preconnect";
|
|
17
|
+
pre1.href = FONT_HREF_PRECONNECT_GOOGLE;
|
|
18
|
+
pre1.setAttribute(MARKER_ATTR, "preconnect");
|
|
19
|
+
head.appendChild(pre1);
|
|
20
|
+
const pre2 = document.createElement("link");
|
|
21
|
+
pre2.rel = "preconnect";
|
|
22
|
+
pre2.href = FONT_HREF_PRECONNECT_STATIC;
|
|
23
|
+
pre2.crossOrigin = "anonymous";
|
|
24
|
+
pre2.setAttribute(MARKER_ATTR, "preconnect");
|
|
25
|
+
head.appendChild(pre2);
|
|
26
|
+
const font = document.createElement("link");
|
|
27
|
+
font.rel = "stylesheet";
|
|
28
|
+
font.href = FONT_HREF;
|
|
29
|
+
font.setAttribute(MARKER_ATTR, "stylesheet");
|
|
30
|
+
head.appendChild(font);
|
|
31
|
+
}
|
|
32
|
+
function usePoolseFonts(enabled = true) {
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
if (!enabled) return;
|
|
35
|
+
injectFontLinks();
|
|
36
|
+
}, [enabled]);
|
|
37
|
+
}
|
|
38
|
+
function PoolseFonts() {
|
|
39
|
+
usePoolseFonts(true);
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// src/icons-data.ts
|
|
44
|
+
var ICONS = {
|
|
45
|
+
attachment: {
|
|
46
|
+
vb: "0 0 24 24",
|
|
47
|
+
d: '<path d="M20 11.6 11.4 20.2a5 5 0 0 1-7.1-7.1l8.7-8.7a3.3 3.3 0 0 1 4.7 4.7l-8.6 8.6a1.65 1.65 0 0 1-2.36-2.32l7.86-7.86"/>'
|
|
48
|
+
},
|
|
49
|
+
bell: {
|
|
50
|
+
vb: "0 0 24 24",
|
|
51
|
+
d: '<path d="M6 9.2a6 6 0 0 1 12 0c0 4.8 1.4 6.3 1.9 6.8H4.1C4.6 15.5 6 14 6 9.2Z"/><path d="M9.6 19.8a2.5 2.5 0 0 0 4.8 0"/>'
|
|
52
|
+
},
|
|
53
|
+
"check-double": {
|
|
54
|
+
vb: "0 0 24 24",
|
|
55
|
+
d: '<path d="M2.5 12.8 6.9 17 15.4 7.6"/><path d="M11.4 16.4 12.3 17.2 21 7.6"/>'
|
|
56
|
+
},
|
|
57
|
+
check: {
|
|
58
|
+
vb: "0 0 24 24",
|
|
59
|
+
d: '<path d="M4.5 12.6 9.4 17.4 19.5 6.6"/>'
|
|
60
|
+
},
|
|
61
|
+
"chevron-down": {
|
|
62
|
+
vb: "0 0 24 24",
|
|
63
|
+
d: '<path d="M5 9 12 16 19 9"/>'
|
|
64
|
+
},
|
|
65
|
+
"chevron-right": {
|
|
66
|
+
vb: "0 0 24 24",
|
|
67
|
+
d: '<path d="M9 5 16 12 9 19"/>'
|
|
68
|
+
},
|
|
69
|
+
close: {
|
|
70
|
+
vb: "0 0 24 24",
|
|
71
|
+
d: '<path d="M6 6 18 18M18 6 6 18"/>'
|
|
72
|
+
},
|
|
73
|
+
code: {
|
|
74
|
+
vb: "0 0 24 24",
|
|
75
|
+
d: '<path d="M9 7.5 4.5 12 9 16.5"/><path d="M15 7.5 19.5 12 15 16.5"/><path d="M13.2 5 10.8 19"/>'
|
|
76
|
+
},
|
|
77
|
+
compose: {
|
|
78
|
+
vb: "0 0 24 24",
|
|
79
|
+
d: '<path d="M11.5 4H6a2.5 2.5 0 0 0-2.5 2.5V18A2.5 2.5 0 0 0 6 20.5h11.5A2.5 2.5 0 0 0 20 18v-5.5"/><path d="M18.4 2.7a2.05 2.05 0 0 1 2.9 2.9L12 15l-4 1 1-4 9.4-9.3Z"/>'
|
|
80
|
+
},
|
|
81
|
+
copy: {
|
|
82
|
+
vb: "0 0 24 24",
|
|
83
|
+
d: '<rect x="8.4" y="8.4" width="11.2" height="11.2" rx="2.3"/><path d="M5.6 15.6H5A1.6 1.6 0 0 1 3.4 14V5A1.6 1.6 0 0 1 5 3.4h9A1.6 1.6 0 0 1 15.6 5v.6"/>'
|
|
84
|
+
},
|
|
85
|
+
download: {
|
|
86
|
+
vb: "0 0 24 24",
|
|
87
|
+
d: '<path d="M12 3.2v11.6"/><path d="M7.4 10.2 12 14.8 16.6 10.2"/><path d="M4 19.6h16"/>'
|
|
88
|
+
},
|
|
89
|
+
edit: {
|
|
90
|
+
vb: "0 0 24 24",
|
|
91
|
+
d: '<path d="M16.7 3.3a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4 12.7-12.7Z"/>'
|
|
92
|
+
},
|
|
93
|
+
emoji: {
|
|
94
|
+
vb: "0 0 24 24",
|
|
95
|
+
d: '<circle cx="12" cy="12" r="8.6"/><circle cx="9" cy="10" r="1" fill="currentColor" stroke="none"/><circle cx="15" cy="10" r="1" fill="currentColor" stroke="none"/><path d="M8.4 14.2a4.6 4.6 0 0 0 7.2 0"/>'
|
|
96
|
+
},
|
|
97
|
+
heart: {
|
|
98
|
+
vb: "0 0 24 24",
|
|
99
|
+
d: '<path d="M12 20.3 4.4 12.9a4.6 4.6 0 1 1 6.5-6.5l1.1 1.1 1.1-1.1a4.6 4.6 0 1 1 6.5 6.5L12 20.3Z"/>'
|
|
100
|
+
},
|
|
101
|
+
image: {
|
|
102
|
+
vb: "0 0 24 24",
|
|
103
|
+
d: '<rect x="3.2" y="4.2" width="17.6" height="15.6" rx="2.6"/><circle cx="8.6" cy="9.4" r="1.7" fill="currentColor" stroke="none"/><path d="M20.8 15.8 16 11 6 19.8"/>'
|
|
104
|
+
},
|
|
105
|
+
info: {
|
|
106
|
+
vb: "0 0 24 24",
|
|
107
|
+
d: '<circle cx="12" cy="12" r="8.6"/><path d="M12 11v5.2"/><circle cx="12" cy="7.7" r="1" fill="currentColor" stroke="none"/>'
|
|
108
|
+
},
|
|
109
|
+
key: {
|
|
110
|
+
vb: "0 0 24 24",
|
|
111
|
+
d: '<circle cx="8" cy="8" r="4.4"/><path d="M11.1 11.1 20 20"/><path d="M16.6 16.6 18.6 14.6M14 14l2-2"/>'
|
|
112
|
+
},
|
|
113
|
+
link: {
|
|
114
|
+
vb: "0 0 24 24",
|
|
115
|
+
d: '<path d="M10.2 13.8a3.5 3.5 0 0 0 5 0l3-3a3.5 3.5 0 0 0-5-5l-1.2 1.2"/><path d="M13.8 10.2a3.5 3.5 0 0 0-5 0l-3 3a3.5 3.5 0 0 0 5 5l1.2-1.2"/>'
|
|
116
|
+
},
|
|
117
|
+
lock: {
|
|
118
|
+
vb: "0 0 24 24",
|
|
119
|
+
d: '<rect x="4.6" y="10.4" width="14.8" height="9.8" rx="2.2"/><path d="M8 10.4V7a4 4 0 0 1 8 0v3.4"/>'
|
|
120
|
+
},
|
|
121
|
+
message: {
|
|
122
|
+
vb: "0 0 24 24",
|
|
123
|
+
d: '<path d="M20.5 11.4c0 4.5-3.9 8.1-8.5 8.1a9 9 0 0 1-3.7-.78L3.5 20.5l1.8-4.6A7.9 7.9 0 0 1 3.5 11.4C3.5 6.9 7.4 3.3 12 3.3s8.5 3.6 8.5 8.1Z"/>'
|
|
124
|
+
},
|
|
125
|
+
messages: {
|
|
126
|
+
vb: "0 0 24 24",
|
|
127
|
+
d: '<path d="M14 9.2a4.7 4.7 0 0 1-4.7 4.7H6.8L3.5 16.4v-2.9A4.7 4.7 0 0 1 6.8 4.5h2.5A4.7 4.7 0 0 1 14 9.2Z"/><path d="M9.4 13.6A4.7 4.7 0 0 0 13.6 16h3.6l3.3 2.5v-2.9a4.7 4.7 0 0 0-2.4-4.1"/>'
|
|
128
|
+
},
|
|
129
|
+
mic: {
|
|
130
|
+
vb: "0 0 24 24",
|
|
131
|
+
d: '<rect x="9" y="2.6" width="6" height="11.2" rx="3"/><path d="M5.6 11.2a6.4 6.4 0 0 0 12.8 0"/><path d="M12 17.6v3.4"/><path d="M8.6 21h6.8"/>'
|
|
132
|
+
},
|
|
133
|
+
"more-h": {
|
|
134
|
+
vb: "0 0 24 24",
|
|
135
|
+
d: '<circle cx="5.4" cy="12" r="1.6" fill="currentColor" stroke="none"/><circle cx="12" cy="12" r="1.6" fill="currentColor" stroke="none"/><circle cx="18.6" cy="12" r="1.6" fill="currentColor" stroke="none"/>'
|
|
136
|
+
},
|
|
137
|
+
"more-v": {
|
|
138
|
+
vb: "0 0 24 24",
|
|
139
|
+
d: '<circle cx="12" cy="5.4" r="1.6" fill="currentColor" stroke="none"/><circle cx="12" cy="12" r="1.6" fill="currentColor" stroke="none"/><circle cx="12" cy="18.6" r="1.6" fill="currentColor" stroke="none"/>'
|
|
140
|
+
},
|
|
141
|
+
pin: {
|
|
142
|
+
vb: "0 0 24 24",
|
|
143
|
+
d: '<path d="M9 3.4h6v1.8l-1 5.6 3 3.2H7l3-3.2-1-5.6V3.4Z"/><path d="M12 17v3.6"/>'
|
|
144
|
+
},
|
|
145
|
+
plus: {
|
|
146
|
+
vb: "0 0 24 24",
|
|
147
|
+
d: '<path d="M12 5v14M5 12h14"/>'
|
|
148
|
+
},
|
|
149
|
+
presence: {
|
|
150
|
+
vb: "0 0 24 24",
|
|
151
|
+
d: '<circle cx="12" cy="12" r="9" fill="currentColor" opacity="0.18" stroke="none"/><circle cx="12" cy="12" r="5" fill="currentColor" stroke="none"/>'
|
|
152
|
+
},
|
|
153
|
+
pulse: {
|
|
154
|
+
vb: "0 0 24 24",
|
|
155
|
+
d: '<path d="M3 13h4.6l2.2-4.6 3.4 9 2.2-4.4H21"/>'
|
|
156
|
+
},
|
|
157
|
+
reply: {
|
|
158
|
+
vb: "0 0 24 24",
|
|
159
|
+
d: '<path d="M9 7 4 12l5 5"/><path d="M4 12h9.5a6.5 6.5 0 0 1 6.5 6.5V20"/>'
|
|
160
|
+
},
|
|
161
|
+
search: {
|
|
162
|
+
vb: "0 0 24 24",
|
|
163
|
+
d: '<circle cx="11" cy="11" r="6.8"/><path d="M20.8 20.8 16 16"/>'
|
|
164
|
+
},
|
|
165
|
+
"send-fill": {
|
|
166
|
+
vb: "0 0 24 24",
|
|
167
|
+
d: '<path fill="currentColor" stroke="none" d="M21.7 2.3a1 1 0 0 1 .25 1L15.3 21.8a1 1 0 0 1-1.86.06L10.6 14.2 3 11.4a1 1 0 0 1 .06-1.9L20.7 2.05a1 1 0 0 1 1 .25Z"/>'
|
|
168
|
+
},
|
|
169
|
+
send: {
|
|
170
|
+
vb: "0 0 24 24",
|
|
171
|
+
d: '<path d="M21.4 2.6 11 13"/><path d="M21.4 2.6 14.8 21.5a.6.6 0 0 1-1.1.05L11 14l-7.5-2.7a.6.6 0 0 1 .05-1.1L21.4 2.6Z"/>'
|
|
172
|
+
},
|
|
173
|
+
settings: {
|
|
174
|
+
vb: "0 0 24 24",
|
|
175
|
+
d: '<circle cx="12" cy="12" r="3.1"/><path d="M12 2.6V5M12 19v2.4M4.2 4.2 5.9 5.9M18.1 18.1l1.7 1.7M2.6 12H5M19 12h2.4M4.2 19.8 5.9 18.1M18.1 5.9l1.7-1.7"/>'
|
|
176
|
+
},
|
|
177
|
+
sliders: {
|
|
178
|
+
vb: "0 0 24 24",
|
|
179
|
+
d: '<path d="M4 7h9M17 7h3"/><circle cx="15" cy="7" r="2.1"/><path d="M4 17h3M11 17h9"/><circle cx="9" cy="17" r="2.1"/>'
|
|
180
|
+
},
|
|
181
|
+
"thumbs-up": {
|
|
182
|
+
vb: "0 0 24 24",
|
|
183
|
+
d: '<path d="M7 10.4V20H4.2V10.4Z"/><path d="M7 10.4 11 3.2a2 2 0 0 1 1.9 2.2L12.4 9H18a2 2 0 0 1 2 2.4l-1.1 6A2 2 0 0 1 16.9 20H7"/>'
|
|
184
|
+
},
|
|
185
|
+
trash: {
|
|
186
|
+
vb: "0 0 24 24",
|
|
187
|
+
d: '<path d="M4 7h16"/><path d="M9.2 7V5.2A1.8 1.8 0 0 1 11 3.4h2a1.8 1.8 0 0 1 1.8 1.8V7"/><path d="M6.2 7 7.2 19A1.9 1.9 0 0 0 9.1 20.7h5.8A1.9 1.9 0 0 0 16.8 19L17.8 7"/><path d="M10.3 11v5M13.7 11v5"/>'
|
|
188
|
+
},
|
|
189
|
+
typing: {
|
|
190
|
+
vb: "0 0 24 24",
|
|
191
|
+
d: '<circle cx="6" cy="12" r="1.7" fill="currentColor" stroke="none"/><circle cx="12" cy="12" r="1.7" fill="currentColor" stroke="none"/><circle cx="18" cy="12" r="1.7" fill="currentColor" stroke="none"/>'
|
|
192
|
+
},
|
|
193
|
+
"user-plus": {
|
|
194
|
+
vb: "0 0 24 24",
|
|
195
|
+
d: '<circle cx="9" cy="8" r="3.8"/><path d="M3 20a6 6 0 0 1 12 0"/><path d="M18 8v6M15 11h6"/>'
|
|
196
|
+
},
|
|
197
|
+
user: {
|
|
198
|
+
vb: "0 0 24 24",
|
|
199
|
+
d: '<circle cx="12" cy="8" r="4"/><path d="M4.6 20a7.4 7.4 0 0 1 14.8 0"/>'
|
|
200
|
+
},
|
|
201
|
+
users: {
|
|
202
|
+
vb: "0 0 24 24",
|
|
203
|
+
d: '<circle cx="9" cy="8" r="3.6"/><path d="M2.6 20a6.4 6.4 0 0 1 12.8 0"/><path d="M15.8 4.7a3.6 3.6 0 0 1 0 6.6"/><path d="M17.6 20a6.4 6.4 0 0 0-3.1-5.5"/>'
|
|
204
|
+
},
|
|
205
|
+
webhook: {
|
|
206
|
+
vb: "0 0 24 24",
|
|
207
|
+
d: '<circle cx="6" cy="6" r="2.6"/><circle cx="18" cy="9" r="2.6"/><circle cx="9.5" cy="18" r="2.6"/><path d="M7.9 7.9 12 12l3.7-1.5"/><path d="M11.6 12.7 9.8 16"/>'
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
function PoolseIcon({
|
|
211
|
+
name,
|
|
212
|
+
size,
|
|
213
|
+
label,
|
|
214
|
+
className,
|
|
215
|
+
style,
|
|
216
|
+
...rest
|
|
217
|
+
}) {
|
|
218
|
+
const def = ICONS[name];
|
|
219
|
+
if (!def) {
|
|
220
|
+
if (process.env.NODE_ENV !== "production") {
|
|
221
|
+
console.warn(`PoolseIcon: unknown icon "${String(name)}"`);
|
|
222
|
+
}
|
|
223
|
+
return /* @__PURE__ */ jsx("svg", { "aria-hidden": "true", className, style });
|
|
224
|
+
}
|
|
225
|
+
const aria = label === null ? { "aria-hidden": true, focusable: false } : { role: "img", "aria-label": label ?? name };
|
|
226
|
+
const dimension = size ?? "1.2em";
|
|
227
|
+
return /* @__PURE__ */ jsx(
|
|
228
|
+
"svg",
|
|
229
|
+
{
|
|
230
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
231
|
+
viewBox: def.vb,
|
|
232
|
+
width: dimension,
|
|
233
|
+
height: dimension,
|
|
234
|
+
fill: "none",
|
|
235
|
+
stroke: "currentColor",
|
|
236
|
+
strokeWidth: 1.8,
|
|
237
|
+
strokeLinecap: "round",
|
|
238
|
+
strokeLinejoin: "round",
|
|
239
|
+
className: ["poolse-icon", className].filter(Boolean).join(" "),
|
|
240
|
+
style,
|
|
241
|
+
...aria,
|
|
242
|
+
...rest,
|
|
243
|
+
dangerouslySetInnerHTML: { __html: def.d }
|
|
244
|
+
}
|
|
245
|
+
);
|
|
246
|
+
}
|
|
247
|
+
function MessageBubble({ message, currentUserId, readState }) {
|
|
248
|
+
const isSelf = currentUserId !== null && message.sender_id === currentUserId;
|
|
249
|
+
const className = [
|
|
250
|
+
"poolse-message",
|
|
251
|
+
isSelf ? "poolse-message--self" : "poolse-message--other"
|
|
252
|
+
].join(" ");
|
|
253
|
+
const time = message.inserted_at ? new Date(message.inserted_at).toLocaleTimeString(void 0, {
|
|
254
|
+
hour: "2-digit",
|
|
255
|
+
minute: "2-digit"
|
|
256
|
+
}) : "";
|
|
257
|
+
return /* @__PURE__ */ jsxs("div", { className, children: [
|
|
258
|
+
message.deleted_at ? /* @__PURE__ */ jsx("span", { className: "poolse-message__body--deleted", children: "[deleted]" }) : /* @__PURE__ */ jsx("span", { children: message.body ?? "" }),
|
|
259
|
+
/* @__PURE__ */ jsxs("span", { className: "poolse-message__meta", children: [
|
|
260
|
+
/* @__PURE__ */ jsx("span", { children: time }),
|
|
261
|
+
message.edited_at ? /* @__PURE__ */ jsx("span", { children: " \xB7 edited" }) : null,
|
|
262
|
+
isSelf && readState ? /* @__PURE__ */ jsx(
|
|
263
|
+
PoolseIcon,
|
|
264
|
+
{
|
|
265
|
+
name: readState === "read" ? "check-double" : "check",
|
|
266
|
+
size: 14,
|
|
267
|
+
label: readState === "read" ? "Read" : "Sent"
|
|
268
|
+
}
|
|
269
|
+
) : null
|
|
270
|
+
] })
|
|
271
|
+
] });
|
|
272
|
+
}
|
|
273
|
+
function MessageComposer({
|
|
274
|
+
onSend,
|
|
275
|
+
onTyping,
|
|
276
|
+
placeholder = "Type a message\u2026",
|
|
277
|
+
disabled = false
|
|
278
|
+
}) {
|
|
279
|
+
const [value, setValue] = useState("");
|
|
280
|
+
const [sending, setSending] = useState(false);
|
|
281
|
+
const submit = async () => {
|
|
282
|
+
const trimmed = value.trim();
|
|
283
|
+
if (!trimmed || sending) return;
|
|
284
|
+
setSending(true);
|
|
285
|
+
try {
|
|
286
|
+
await onSend(trimmed);
|
|
287
|
+
setValue("");
|
|
288
|
+
} finally {
|
|
289
|
+
setSending(false);
|
|
290
|
+
}
|
|
291
|
+
};
|
|
292
|
+
const onKeyDown = (e) => {
|
|
293
|
+
if (e.key === "Enter" && !e.shiftKey) {
|
|
294
|
+
e.preventDefault();
|
|
295
|
+
void submit();
|
|
296
|
+
}
|
|
297
|
+
};
|
|
298
|
+
const onChange = (e) => {
|
|
299
|
+
setValue(e.target.value);
|
|
300
|
+
onTyping?.();
|
|
301
|
+
};
|
|
302
|
+
return /* @__PURE__ */ jsxs(
|
|
303
|
+
"form",
|
|
304
|
+
{
|
|
305
|
+
className: "poolse-composer",
|
|
306
|
+
onSubmit: (e) => {
|
|
307
|
+
e.preventDefault();
|
|
308
|
+
void submit();
|
|
309
|
+
},
|
|
310
|
+
children: [
|
|
311
|
+
/* @__PURE__ */ jsx(
|
|
312
|
+
"textarea",
|
|
313
|
+
{
|
|
314
|
+
className: "poolse-composer__input",
|
|
315
|
+
rows: 1,
|
|
316
|
+
value,
|
|
317
|
+
onChange,
|
|
318
|
+
onKeyDown,
|
|
319
|
+
placeholder,
|
|
320
|
+
disabled: disabled || sending
|
|
321
|
+
}
|
|
322
|
+
),
|
|
323
|
+
/* @__PURE__ */ jsx(
|
|
324
|
+
"button",
|
|
325
|
+
{
|
|
326
|
+
type: "submit",
|
|
327
|
+
className: "poolse-composer__send",
|
|
328
|
+
disabled: disabled || sending || value.trim() === "",
|
|
329
|
+
"aria-label": "Send message",
|
|
330
|
+
children: /* @__PURE__ */ jsx(PoolseIcon, { name: "send-fill", label: null })
|
|
331
|
+
}
|
|
332
|
+
)
|
|
333
|
+
]
|
|
334
|
+
}
|
|
335
|
+
);
|
|
336
|
+
}
|
|
337
|
+
function TypingIndicator({ typing, labelFor }) {
|
|
338
|
+
const ids = Array.from(typing);
|
|
339
|
+
if (ids.length === 0) {
|
|
340
|
+
return /* @__PURE__ */ jsx("div", { className: "poolse-typing", "aria-hidden": "true" });
|
|
341
|
+
}
|
|
342
|
+
const label = labelFor ?? ((id) => id.slice(0, 6));
|
|
343
|
+
const names = ids.slice(0, 2).map(label);
|
|
344
|
+
let text;
|
|
345
|
+
if (ids.length === 1) text = `${names[0]} is typing`;
|
|
346
|
+
else if (ids.length === 2) text = `${names[0]} and ${names[1]} are typing`;
|
|
347
|
+
else text = `${ids.length} people are typing`;
|
|
348
|
+
return /* @__PURE__ */ jsxs("div", { className: "poolse-typing", children: [
|
|
349
|
+
/* @__PURE__ */ jsxs("span", { className: "poolse-typing__dots", role: "status", "aria-live": "polite", children: [
|
|
350
|
+
/* @__PURE__ */ jsx("span", { className: "poolse-typing__dot" }),
|
|
351
|
+
/* @__PURE__ */ jsx("span", { className: "poolse-typing__dot" }),
|
|
352
|
+
/* @__PURE__ */ jsx("span", { className: "poolse-typing__dot" })
|
|
353
|
+
] }),
|
|
354
|
+
/* @__PURE__ */ jsx("span", { className: "poolse-typing__label", children: text })
|
|
355
|
+
] });
|
|
356
|
+
}
|
|
357
|
+
function ConversationView({
|
|
358
|
+
conversationId,
|
|
359
|
+
emptyState,
|
|
360
|
+
renderMessage,
|
|
361
|
+
labelFor,
|
|
362
|
+
loadFonts = true
|
|
363
|
+
}) {
|
|
364
|
+
usePoolseFonts(loadFonts);
|
|
365
|
+
const { me } = useMe();
|
|
366
|
+
const { messages, loading, error, hasMore, loadMore, send } = useMessages(conversationId);
|
|
367
|
+
const { typing, signalTyping } = useTyping(conversationId);
|
|
368
|
+
const status = useRealtimeStatus();
|
|
369
|
+
const listRef = useRef(null);
|
|
370
|
+
const lastMessageIdRef = useRef(null);
|
|
371
|
+
useEffect(() => {
|
|
372
|
+
const tail = messages[messages.length - 1];
|
|
373
|
+
if (!tail) return;
|
|
374
|
+
if (tail.id === lastMessageIdRef.current) return;
|
|
375
|
+
lastMessageIdRef.current = tail.id;
|
|
376
|
+
const el = listRef.current;
|
|
377
|
+
if (el) el.scrollTop = el.scrollHeight;
|
|
378
|
+
}, [messages]);
|
|
379
|
+
const renderOne = renderMessage ?? defaultRenderMessage;
|
|
380
|
+
return /* @__PURE__ */ jsxs("div", { className: "poolse-conversation", children: [
|
|
381
|
+
status !== "connected" && status !== "idle" && /* @__PURE__ */ jsxs("div", { className: "poolse-conversation__status", children: [
|
|
382
|
+
status === "connecting" && "Connecting\u2026",
|
|
383
|
+
status === "reconnecting" && "Reconnecting\u2026",
|
|
384
|
+
status === "closed" && "Disconnected"
|
|
385
|
+
] }),
|
|
386
|
+
/* @__PURE__ */ jsxs("div", { className: "poolse-conversation__messages", ref: listRef, children: [
|
|
387
|
+
hasMore && !loading && /* @__PURE__ */ jsx("button", { type: "button", className: "poolse-conversation__load-more", onClick: loadMore, children: "Load older messages" }),
|
|
388
|
+
loading && messages.length === 0 ? /* @__PURE__ */ jsx("div", { className: "poolse-conversation__empty", children: "Loading\u2026" }) : messages.length === 0 ? /* @__PURE__ */ jsx("div", { className: "poolse-conversation__empty", children: emptyState ?? "No messages yet." }) : messages.map((msg) => /* @__PURE__ */ jsx("div", { children: renderOne(msg, me?.id ?? null) }, msg.id)),
|
|
389
|
+
error && /* @__PURE__ */ jsxs("div", { className: "poolse-conversation__empty", children: [
|
|
390
|
+
"Failed to load: ",
|
|
391
|
+
error.message
|
|
392
|
+
] })
|
|
393
|
+
] }),
|
|
394
|
+
/* @__PURE__ */ jsx(TypingIndicator, { typing, ...labelFor ? { labelFor } : {} }),
|
|
395
|
+
/* @__PURE__ */ jsx(MessageComposer, { onSend: (body) => send({ body }), onTyping: signalTyping })
|
|
396
|
+
] });
|
|
397
|
+
}
|
|
398
|
+
function defaultRenderMessage(msg, currentUserId) {
|
|
399
|
+
return /* @__PURE__ */ jsx(MessageBubble, { message: msg, currentUserId });
|
|
400
|
+
}
|
|
401
|
+
function Avatar({ src, name, online, size = "md", className }) {
|
|
402
|
+
const initials = computeInitials(name);
|
|
403
|
+
const classes = [
|
|
404
|
+
"poolse-avatar",
|
|
405
|
+
size === "sm" ? "poolse-avatar--sm" : null,
|
|
406
|
+
size === "lg" ? "poolse-avatar--lg" : null,
|
|
407
|
+
className
|
|
408
|
+
].filter(Boolean).join(" ");
|
|
409
|
+
return /* @__PURE__ */ jsxs("span", { className: classes, "aria-label": name ?? "avatar", role: "img", children: [
|
|
410
|
+
src ? /* @__PURE__ */ jsx("img", { src, alt: name ?? "" }) : /* @__PURE__ */ jsx("span", { "aria-hidden": "true", children: initials }),
|
|
411
|
+
online ? /* @__PURE__ */ jsx("span", { className: "poolse-avatar__presence", "aria-hidden": "true" }) : null
|
|
412
|
+
] });
|
|
413
|
+
}
|
|
414
|
+
function computeInitials(name) {
|
|
415
|
+
if (!name) return "?";
|
|
416
|
+
const parts = name.trim().split(/\s+/).slice(0, 2);
|
|
417
|
+
return parts.map((p) => p.charAt(0).toUpperCase()).join("").slice(0, 2) || "?";
|
|
418
|
+
}
|
|
419
|
+
function ConversationList({
|
|
420
|
+
selectedId,
|
|
421
|
+
onSelect,
|
|
422
|
+
renderItem,
|
|
423
|
+
emptyState
|
|
424
|
+
}) {
|
|
425
|
+
const { conversations, loading, error } = useConversations();
|
|
426
|
+
if (loading && conversations.length === 0) {
|
|
427
|
+
return /* @__PURE__ */ jsx("div", { className: "poolse-list poolse-list--placeholder", children: "Loading conversations\u2026" });
|
|
428
|
+
}
|
|
429
|
+
if (error) {
|
|
430
|
+
return /* @__PURE__ */ jsx("div", { className: "poolse-list poolse-list--placeholder poolse-list--error", children: "Failed to load conversations." });
|
|
431
|
+
}
|
|
432
|
+
if (conversations.length === 0) {
|
|
433
|
+
return /* @__PURE__ */ jsx("div", { className: "poolse-list poolse-list--placeholder", children: emptyState ?? "No conversations yet." });
|
|
434
|
+
}
|
|
435
|
+
return /* @__PURE__ */ jsx("ul", { className: "poolse-list", role: "listbox", "aria-label": "Conversations", children: conversations.map((conv) => {
|
|
436
|
+
const selected = selectedId === conv.id;
|
|
437
|
+
const content = renderItem ? renderItem(conv, selected) : /* @__PURE__ */ jsx(DefaultRow, { conv, selected });
|
|
438
|
+
return /* @__PURE__ */ jsx(
|
|
439
|
+
"li",
|
|
440
|
+
{
|
|
441
|
+
role: "option",
|
|
442
|
+
"aria-selected": selected,
|
|
443
|
+
className: `poolse-list__item${selected ? " poolse-list__item--selected" : ""}`,
|
|
444
|
+
onClick: () => onSelect?.(conv),
|
|
445
|
+
onKeyDown: (e) => {
|
|
446
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
447
|
+
e.preventDefault();
|
|
448
|
+
onSelect?.(conv);
|
|
449
|
+
}
|
|
450
|
+
},
|
|
451
|
+
tabIndex: 0,
|
|
452
|
+
children: content
|
|
453
|
+
},
|
|
454
|
+
conv.id
|
|
455
|
+
);
|
|
456
|
+
}) });
|
|
457
|
+
}
|
|
458
|
+
function DefaultRow({ conv, selected: _selected }) {
|
|
459
|
+
const title = conv.name ?? "Untitled conversation";
|
|
460
|
+
const time = conv.last_message_at ? formatRelative(conv.last_message_at) : "";
|
|
461
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
462
|
+
/* @__PURE__ */ jsx(Avatar, { src: conv.avatar_url ?? null, name: conv.name, size: "md" }),
|
|
463
|
+
/* @__PURE__ */ jsxs("div", { className: "poolse-list__body", children: [
|
|
464
|
+
/* @__PURE__ */ jsxs("div", { className: "poolse-list__head", children: [
|
|
465
|
+
/* @__PURE__ */ jsx("span", { className: "poolse-list__title", children: title }),
|
|
466
|
+
time && /* @__PURE__ */ jsx("span", { className: "poolse-list__time", children: time })
|
|
467
|
+
] }),
|
|
468
|
+
/* @__PURE__ */ jsx("div", { className: "poolse-list__preview", children: conv.last_sequence > 0 ? `${conv.last_sequence} message${conv.last_sequence === 1 ? "" : "s"}` : "No messages yet" })
|
|
469
|
+
] })
|
|
470
|
+
] });
|
|
471
|
+
}
|
|
472
|
+
function formatRelative(iso) {
|
|
473
|
+
const then = new Date(iso).getTime();
|
|
474
|
+
const now = Date.now();
|
|
475
|
+
const diffSec = Math.max(0, Math.floor((now - then) / 1e3));
|
|
476
|
+
if (diffSec < 60) return "now";
|
|
477
|
+
if (diffSec < 3600) return `${Math.floor(diffSec / 60)}m`;
|
|
478
|
+
if (diffSec < 86400) return `${Math.floor(diffSec / 3600)}h`;
|
|
479
|
+
return `${Math.floor(diffSec / 86400)}d`;
|
|
480
|
+
}
|
|
481
|
+
function MemberList({
|
|
482
|
+
conversationId,
|
|
483
|
+
labelFor,
|
|
484
|
+
avatarFor,
|
|
485
|
+
onlineUserIds,
|
|
486
|
+
canRemove,
|
|
487
|
+
renderItem,
|
|
488
|
+
emptyState
|
|
489
|
+
}) {
|
|
490
|
+
const { members, loading, error, removeMember } = useMembers(conversationId);
|
|
491
|
+
if (loading && members.length === 0) {
|
|
492
|
+
return /* @__PURE__ */ jsx("div", { className: "poolse-list poolse-list--placeholder", children: "Loading members\u2026" });
|
|
493
|
+
}
|
|
494
|
+
if (error) {
|
|
495
|
+
return /* @__PURE__ */ jsx("div", { className: "poolse-list poolse-list--placeholder poolse-list--error", children: "Failed to load members." });
|
|
496
|
+
}
|
|
497
|
+
if (members.length === 0) {
|
|
498
|
+
return /* @__PURE__ */ jsx("div", { className: "poolse-list poolse-list--placeholder", children: emptyState ?? "No members yet." });
|
|
499
|
+
}
|
|
500
|
+
const label = labelFor ?? ((id) => id.slice(0, 8));
|
|
501
|
+
return /* @__PURE__ */ jsx("ul", { className: "poolse-list", role: "list", "aria-label": "Members", children: members.map((m) => {
|
|
502
|
+
const content = renderItem ? renderItem(m) : /* @__PURE__ */ jsx(
|
|
503
|
+
DefaultMemberRow,
|
|
504
|
+
{
|
|
505
|
+
membership: m,
|
|
506
|
+
name: label(m.user_id),
|
|
507
|
+
avatarUrl: avatarFor?.(m.user_id) ?? null,
|
|
508
|
+
online: onlineUserIds?.has(m.user_id) ?? false,
|
|
509
|
+
removable: canRemove?.(m) ?? false,
|
|
510
|
+
onRemove: () => {
|
|
511
|
+
void removeMember(m.user_id);
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
);
|
|
515
|
+
return /* @__PURE__ */ jsx("li", { className: "poolse-list__item", children: content }, m.id);
|
|
516
|
+
}) });
|
|
517
|
+
}
|
|
518
|
+
function DefaultMemberRow({
|
|
519
|
+
membership,
|
|
520
|
+
name,
|
|
521
|
+
avatarUrl,
|
|
522
|
+
online,
|
|
523
|
+
removable,
|
|
524
|
+
onRemove
|
|
525
|
+
}) {
|
|
526
|
+
return /* @__PURE__ */ jsxs("div", { className: "poolse-member-row", children: [
|
|
527
|
+
/* @__PURE__ */ jsx(Avatar, { src: avatarUrl, name, online, size: "md" }),
|
|
528
|
+
/* @__PURE__ */ jsxs("div", { className: "poolse-member-row__body", children: [
|
|
529
|
+
/* @__PURE__ */ jsx("div", { className: "poolse-member-row__name", children: name }),
|
|
530
|
+
/* @__PURE__ */ jsx("div", { className: "poolse-member-row__sub", children: online ? "online" : "offline" })
|
|
531
|
+
] }),
|
|
532
|
+
/* @__PURE__ */ jsx(RoleBadge, { role: membership.role }),
|
|
533
|
+
removable && /* @__PURE__ */ jsx(
|
|
534
|
+
"button",
|
|
535
|
+
{
|
|
536
|
+
type: "button",
|
|
537
|
+
className: "poolse-icon-btn poolse-icon-btn--danger",
|
|
538
|
+
"aria-label": `Remove ${name}`,
|
|
539
|
+
onClick: (e) => {
|
|
540
|
+
e.stopPropagation();
|
|
541
|
+
onRemove();
|
|
542
|
+
},
|
|
543
|
+
children: /* @__PURE__ */ jsx(PoolseIcon, { name: "trash", size: 16, label: null })
|
|
544
|
+
}
|
|
545
|
+
)
|
|
546
|
+
] });
|
|
547
|
+
}
|
|
548
|
+
function RoleBadge({ role }) {
|
|
549
|
+
const mod = role === "owner" ? "owner" : role === "admin" ? "admin" : null;
|
|
550
|
+
return /* @__PURE__ */ jsx("span", { className: `poolse-badge${mod ? ` poolse-badge--${mod}` : ""}`, children: role });
|
|
551
|
+
}
|
|
552
|
+
function AttachmentPreview({ attachment, onClick }) {
|
|
553
|
+
const isFullRow = "content_type" in attachment;
|
|
554
|
+
const { url, loading, error } = useAttachmentUrl(attachment.id);
|
|
555
|
+
if (loading) {
|
|
556
|
+
return /* @__PURE__ */ jsx("div", { className: "poolse-attachment poolse-list--placeholder", "aria-busy": "true", children: "Loading attachment\u2026" });
|
|
557
|
+
}
|
|
558
|
+
if (error || !url) {
|
|
559
|
+
return /* @__PURE__ */ jsx("div", { className: "poolse-attachment poolse-list--placeholder poolse-list--error", children: "Failed to load attachment." });
|
|
560
|
+
}
|
|
561
|
+
const ct = isFullRow ? attachment.content_type : guessContentType(url);
|
|
562
|
+
const isImage = ct.startsWith("image/");
|
|
563
|
+
if (isImage) {
|
|
564
|
+
const filename2 = isFullRow ? attachment.original_filename : null;
|
|
565
|
+
return /* @__PURE__ */ jsx("div", { className: "poolse-attachment", children: /* @__PURE__ */ jsx(
|
|
566
|
+
"a",
|
|
567
|
+
{
|
|
568
|
+
href: url,
|
|
569
|
+
target: "_blank",
|
|
570
|
+
rel: "noopener noreferrer",
|
|
571
|
+
onClick: (e) => {
|
|
572
|
+
if (onClick) {
|
|
573
|
+
e.preventDefault();
|
|
574
|
+
onClick({ id: attachment.id });
|
|
575
|
+
}
|
|
576
|
+
},
|
|
577
|
+
children: /* @__PURE__ */ jsx(
|
|
578
|
+
"img",
|
|
579
|
+
{
|
|
580
|
+
className: "poolse-attachment__image",
|
|
581
|
+
src: url,
|
|
582
|
+
alt: filename2 ?? "attachment",
|
|
583
|
+
loading: "lazy"
|
|
584
|
+
}
|
|
585
|
+
)
|
|
586
|
+
}
|
|
587
|
+
) });
|
|
588
|
+
}
|
|
589
|
+
const filename = isFullRow ? attachment.original_filename ?? "file" : "file";
|
|
590
|
+
const byteSize = isFullRow ? attachment.byte_size : null;
|
|
591
|
+
return /* @__PURE__ */ jsx("div", { className: "poolse-attachment", children: /* @__PURE__ */ jsxs(
|
|
592
|
+
"a",
|
|
593
|
+
{
|
|
594
|
+
className: "poolse-attachment__file",
|
|
595
|
+
href: url,
|
|
596
|
+
download: filename,
|
|
597
|
+
target: "_blank",
|
|
598
|
+
rel: "noopener noreferrer",
|
|
599
|
+
onClick: (e) => {
|
|
600
|
+
if (onClick) {
|
|
601
|
+
e.preventDefault();
|
|
602
|
+
onClick({ id: attachment.id });
|
|
603
|
+
}
|
|
604
|
+
},
|
|
605
|
+
children: [
|
|
606
|
+
/* @__PURE__ */ jsx(
|
|
607
|
+
PoolseIcon,
|
|
608
|
+
{
|
|
609
|
+
name: "attachment",
|
|
610
|
+
size: 20,
|
|
611
|
+
className: "poolse-attachment__file-icon",
|
|
612
|
+
label: null
|
|
613
|
+
}
|
|
614
|
+
),
|
|
615
|
+
/* @__PURE__ */ jsxs("div", { className: "poolse-attachment__file-body", children: [
|
|
616
|
+
/* @__PURE__ */ jsx("div", { className: "poolse-attachment__file-name", children: filename }),
|
|
617
|
+
byteSize !== null && /* @__PURE__ */ jsx("div", { className: "poolse-attachment__file-meta", children: formatBytes(byteSize) })
|
|
618
|
+
] }),
|
|
619
|
+
/* @__PURE__ */ jsx(
|
|
620
|
+
PoolseIcon,
|
|
621
|
+
{
|
|
622
|
+
name: "download",
|
|
623
|
+
size: 16,
|
|
624
|
+
className: "poolse-attachment__file-icon",
|
|
625
|
+
label: "Download"
|
|
626
|
+
}
|
|
627
|
+
)
|
|
628
|
+
]
|
|
629
|
+
}
|
|
630
|
+
) });
|
|
631
|
+
}
|
|
632
|
+
function guessContentType(url) {
|
|
633
|
+
const m = url.match(/\.([a-z0-9]+)(?:\?|#|$)/i);
|
|
634
|
+
if (!m) return "application/octet-stream";
|
|
635
|
+
const ext = m[1].toLowerCase();
|
|
636
|
+
const imageExts = /* @__PURE__ */ new Set(["png", "jpg", "jpeg", "gif", "webp", "avif", "svg"]);
|
|
637
|
+
if (imageExts.has(ext)) return `image/${ext === "jpg" ? "jpeg" : ext}`;
|
|
638
|
+
return "application/octet-stream";
|
|
639
|
+
}
|
|
640
|
+
function formatBytes(n) {
|
|
641
|
+
if (n < 1024) return `${n} B`;
|
|
642
|
+
if (n < 1024 * 1024) return `${(n / 1024).toFixed(1)} KB`;
|
|
643
|
+
if (n < 1024 * 1024 * 1024) return `${(n / (1024 * 1024)).toFixed(1)} MB`;
|
|
644
|
+
return `${(n / (1024 * 1024 * 1024)).toFixed(2)} GB`;
|
|
645
|
+
}
|
|
646
|
+
var COMMON_EMOJIS = ["\u{1F44D}", "\u2764\uFE0F", "\u{1F602}", "\u{1F389}", "\u{1F622}", "\u{1F64F}"];
|
|
647
|
+
function ReactionStrip({
|
|
648
|
+
messageId,
|
|
649
|
+
conversationId,
|
|
650
|
+
initialReactions,
|
|
651
|
+
currentUserId,
|
|
652
|
+
picker = true
|
|
653
|
+
}) {
|
|
654
|
+
const { reactions, addReaction, removeReaction } = useReactions(messageId, {
|
|
655
|
+
conversationId,
|
|
656
|
+
...initialReactions !== void 0 ? { initialReactions } : {},
|
|
657
|
+
...currentUserId !== void 0 ? { currentUserId } : {}
|
|
658
|
+
});
|
|
659
|
+
const [pickerOpen, setPickerOpen] = useState(false);
|
|
660
|
+
const entries = Object.entries(reactions);
|
|
661
|
+
if (entries.length === 0 && !picker) return null;
|
|
662
|
+
return /* @__PURE__ */ jsxs("div", { className: "poolse-reactions", style: { position: "relative" }, children: [
|
|
663
|
+
entries.map(([emoji, users]) => {
|
|
664
|
+
const mine = currentUserId !== void 0 && currentUserId !== null && users.includes(currentUserId);
|
|
665
|
+
return /* @__PURE__ */ jsxs(
|
|
666
|
+
"button",
|
|
667
|
+
{
|
|
668
|
+
type: "button",
|
|
669
|
+
className: `poolse-reaction-pill${mine ? " poolse-reaction-pill--mine" : ""}`,
|
|
670
|
+
onClick: () => {
|
|
671
|
+
if (mine) void removeReaction(emoji);
|
|
672
|
+
else void addReaction(emoji);
|
|
673
|
+
},
|
|
674
|
+
"aria-pressed": mine,
|
|
675
|
+
"aria-label": `${emoji} reacted by ${users.length} ${users.length === 1 ? "user" : "users"}`,
|
|
676
|
+
children: [
|
|
677
|
+
/* @__PURE__ */ jsx("span", { children: emoji }),
|
|
678
|
+
/* @__PURE__ */ jsx("span", { className: "poolse-reaction-pill__count", children: users.length })
|
|
679
|
+
]
|
|
680
|
+
},
|
|
681
|
+
emoji
|
|
682
|
+
);
|
|
683
|
+
}),
|
|
684
|
+
picker && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
685
|
+
/* @__PURE__ */ jsxs(
|
|
686
|
+
"button",
|
|
687
|
+
{
|
|
688
|
+
type: "button",
|
|
689
|
+
className: "poolse-reaction-pill",
|
|
690
|
+
onClick: () => setPickerOpen((o) => !o),
|
|
691
|
+
"aria-label": "Add reaction",
|
|
692
|
+
"aria-expanded": pickerOpen,
|
|
693
|
+
children: [
|
|
694
|
+
/* @__PURE__ */ jsx(PoolseIcon, { name: "emoji", size: 14, label: null }),
|
|
695
|
+
/* @__PURE__ */ jsx("span", { className: "poolse-reaction-pill__count", "aria-hidden": "true", children: "+" })
|
|
696
|
+
]
|
|
697
|
+
}
|
|
698
|
+
),
|
|
699
|
+
pickerOpen && /* @__PURE__ */ jsx(
|
|
700
|
+
ReactionPicker,
|
|
701
|
+
{
|
|
702
|
+
onPick: (emoji) => {
|
|
703
|
+
setPickerOpen(false);
|
|
704
|
+
void addReaction(emoji);
|
|
705
|
+
},
|
|
706
|
+
onClose: () => setPickerOpen(false)
|
|
707
|
+
}
|
|
708
|
+
)
|
|
709
|
+
] })
|
|
710
|
+
] });
|
|
711
|
+
}
|
|
712
|
+
function ReactionPicker({
|
|
713
|
+
onPick,
|
|
714
|
+
onClose
|
|
715
|
+
}) {
|
|
716
|
+
return /* @__PURE__ */ jsx(
|
|
717
|
+
"div",
|
|
718
|
+
{
|
|
719
|
+
className: "poolse-reaction-picker",
|
|
720
|
+
role: "menu",
|
|
721
|
+
style: { position: "absolute", bottom: "100%", left: 0, marginBottom: 6 },
|
|
722
|
+
onKeyDown: (e) => {
|
|
723
|
+
if (e.key === "Escape") onClose?.();
|
|
724
|
+
},
|
|
725
|
+
children: COMMON_EMOJIS.map((e) => /* @__PURE__ */ jsx(
|
|
726
|
+
"button",
|
|
727
|
+
{
|
|
728
|
+
type: "button",
|
|
729
|
+
className: "poolse-reaction-picker__btn",
|
|
730
|
+
onClick: () => onPick(e),
|
|
731
|
+
"aria-label": `React with ${e}`,
|
|
732
|
+
children: e
|
|
733
|
+
},
|
|
734
|
+
e
|
|
735
|
+
))
|
|
736
|
+
}
|
|
737
|
+
);
|
|
738
|
+
}
|
|
739
|
+
function MentionInput({
|
|
740
|
+
conversationId,
|
|
741
|
+
onSend,
|
|
742
|
+
onTyping,
|
|
743
|
+
placeholder = "Type a message\u2026",
|
|
744
|
+
disabled = false,
|
|
745
|
+
labelFor
|
|
746
|
+
}) {
|
|
747
|
+
const { members } = useMembers(conversationId);
|
|
748
|
+
const [value, setValue] = useState("");
|
|
749
|
+
const [sending, setSending] = useState(false);
|
|
750
|
+
const [mention, setMention] = useState(null);
|
|
751
|
+
const [activeIdx, setActiveIdx] = useState(0);
|
|
752
|
+
const selectedMentions = useRef(/* @__PURE__ */ new Set());
|
|
753
|
+
const taRef = useRef(null);
|
|
754
|
+
const label = labelFor ?? ((id) => id.slice(0, 8));
|
|
755
|
+
const filtered = mention ? members.filter((m) => label(m.user_id).toLowerCase().includes(mention.query.toLowerCase())) : [];
|
|
756
|
+
useEffect(() => {
|
|
757
|
+
setActiveIdx(0);
|
|
758
|
+
}, [filtered.length, mention?.query]);
|
|
759
|
+
const submit = async () => {
|
|
760
|
+
const trimmed = value.trim();
|
|
761
|
+
if (!trimmed || sending) return;
|
|
762
|
+
setSending(true);
|
|
763
|
+
try {
|
|
764
|
+
const mentions = Array.from(selectedMentions.current);
|
|
765
|
+
await onSend({
|
|
766
|
+
body: trimmed,
|
|
767
|
+
...mentions.length > 0 ? { mentions } : {}
|
|
768
|
+
});
|
|
769
|
+
setValue("");
|
|
770
|
+
selectedMentions.current = /* @__PURE__ */ new Set();
|
|
771
|
+
} finally {
|
|
772
|
+
setSending(false);
|
|
773
|
+
}
|
|
774
|
+
};
|
|
775
|
+
const insertMention = (m) => {
|
|
776
|
+
if (!mention) return;
|
|
777
|
+
const name = label(m.user_id);
|
|
778
|
+
const before = value.slice(0, mention.start);
|
|
779
|
+
const after = value.slice(mention.start + 1 + mention.query.length);
|
|
780
|
+
const inserted = `@${name} `;
|
|
781
|
+
const next = `${before}${inserted}${after}`;
|
|
782
|
+
selectedMentions.current.add(m.user_id);
|
|
783
|
+
setValue(next);
|
|
784
|
+
setMention(null);
|
|
785
|
+
requestAnimationFrame(() => {
|
|
786
|
+
const ta = taRef.current;
|
|
787
|
+
if (!ta) return;
|
|
788
|
+
const pos = before.length + inserted.length;
|
|
789
|
+
ta.focus();
|
|
790
|
+
ta.setSelectionRange(pos, pos);
|
|
791
|
+
});
|
|
792
|
+
};
|
|
793
|
+
const onChange = (e) => {
|
|
794
|
+
const next = e.target.value;
|
|
795
|
+
setValue(next);
|
|
796
|
+
onTyping?.();
|
|
797
|
+
const caret = e.target.selectionStart ?? next.length;
|
|
798
|
+
const head = next.slice(0, caret);
|
|
799
|
+
const at = head.lastIndexOf("@");
|
|
800
|
+
if (at === -1) {
|
|
801
|
+
setMention(null);
|
|
802
|
+
return;
|
|
803
|
+
}
|
|
804
|
+
const charBefore = at === 0 ? " " : head.charAt(at - 1);
|
|
805
|
+
const isAtBoundary = /\s/.test(charBefore);
|
|
806
|
+
const query = head.slice(at + 1);
|
|
807
|
+
if (isAtBoundary && !/\s/.test(query)) {
|
|
808
|
+
setMention({ start: at, query });
|
|
809
|
+
} else {
|
|
810
|
+
setMention(null);
|
|
811
|
+
}
|
|
812
|
+
};
|
|
813
|
+
const onKeyDown = (e) => {
|
|
814
|
+
if (mention && filtered.length > 0) {
|
|
815
|
+
if (e.key === "ArrowDown") {
|
|
816
|
+
e.preventDefault();
|
|
817
|
+
setActiveIdx((i) => (i + 1) % filtered.length);
|
|
818
|
+
return;
|
|
819
|
+
}
|
|
820
|
+
if (e.key === "ArrowUp") {
|
|
821
|
+
e.preventDefault();
|
|
822
|
+
setActiveIdx((i) => (i - 1 + filtered.length) % filtered.length);
|
|
823
|
+
return;
|
|
824
|
+
}
|
|
825
|
+
if (e.key === "Enter" || e.key === "Tab") {
|
|
826
|
+
const pick = filtered[activeIdx];
|
|
827
|
+
if (pick) {
|
|
828
|
+
e.preventDefault();
|
|
829
|
+
insertMention(pick);
|
|
830
|
+
return;
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
if (e.key === "Escape") {
|
|
834
|
+
e.preventDefault();
|
|
835
|
+
setMention(null);
|
|
836
|
+
return;
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
if (e.key === "Enter" && !e.shiftKey) {
|
|
840
|
+
e.preventDefault();
|
|
841
|
+
void submit();
|
|
842
|
+
}
|
|
843
|
+
};
|
|
844
|
+
return /* @__PURE__ */ jsxs(
|
|
845
|
+
"form",
|
|
846
|
+
{
|
|
847
|
+
className: "poolse-composer",
|
|
848
|
+
onSubmit: (e) => {
|
|
849
|
+
e.preventDefault();
|
|
850
|
+
void submit();
|
|
851
|
+
},
|
|
852
|
+
style: { position: "relative" },
|
|
853
|
+
children: [
|
|
854
|
+
/* @__PURE__ */ jsx(
|
|
855
|
+
"textarea",
|
|
856
|
+
{
|
|
857
|
+
ref: taRef,
|
|
858
|
+
className: "poolse-composer__input",
|
|
859
|
+
rows: 1,
|
|
860
|
+
value,
|
|
861
|
+
onChange,
|
|
862
|
+
onKeyDown,
|
|
863
|
+
placeholder,
|
|
864
|
+
disabled: disabled || sending
|
|
865
|
+
}
|
|
866
|
+
),
|
|
867
|
+
/* @__PURE__ */ jsx(
|
|
868
|
+
"button",
|
|
869
|
+
{
|
|
870
|
+
type: "submit",
|
|
871
|
+
className: "poolse-composer__send",
|
|
872
|
+
disabled: disabled || sending || value.trim() === "",
|
|
873
|
+
"aria-label": "Send message",
|
|
874
|
+
children: /* @__PURE__ */ jsx(PoolseIcon, { name: "send-fill", label: null })
|
|
875
|
+
}
|
|
876
|
+
),
|
|
877
|
+
mention && filtered.length > 0 && /* @__PURE__ */ jsx("div", { className: "poolse-mention-menu", role: "listbox", "aria-label": "Members", children: filtered.map((m, i) => /* @__PURE__ */ jsx(
|
|
878
|
+
"div",
|
|
879
|
+
{
|
|
880
|
+
role: "option",
|
|
881
|
+
"aria-selected": i === activeIdx,
|
|
882
|
+
className: `poolse-mention-menu__item${i === activeIdx ? " poolse-mention-menu__item--active" : ""}`,
|
|
883
|
+
onMouseDown: (e) => {
|
|
884
|
+
e.preventDefault();
|
|
885
|
+
insertMention(m);
|
|
886
|
+
},
|
|
887
|
+
children: /* @__PURE__ */ jsxs("span", { children: [
|
|
888
|
+
"@",
|
|
889
|
+
label(m.user_id)
|
|
890
|
+
] })
|
|
891
|
+
},
|
|
892
|
+
m.id
|
|
893
|
+
)) })
|
|
894
|
+
]
|
|
895
|
+
}
|
|
896
|
+
);
|
|
897
|
+
}
|
|
898
|
+
var MARK_PATHS = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
899
|
+
/* @__PURE__ */ jsx(
|
|
900
|
+
"path",
|
|
901
|
+
{
|
|
902
|
+
className: "mk-tile",
|
|
903
|
+
d: "M50 4 C20 4 4 20 4 50 C4 80 20 96 50 96 C80 96 96 80 96 50 C96 20 80 4 50 4 Z"
|
|
904
|
+
}
|
|
905
|
+
),
|
|
906
|
+
/* @__PURE__ */ jsx(
|
|
907
|
+
"path",
|
|
908
|
+
{
|
|
909
|
+
className: "mk-pulse",
|
|
910
|
+
d: "M16 55 H34 L40 55 L47 30 L54 73 L60 55 H72",
|
|
911
|
+
fill: "none",
|
|
912
|
+
strokeWidth: 9,
|
|
913
|
+
strokeLinecap: "round",
|
|
914
|
+
strokeLinejoin: "round"
|
|
915
|
+
}
|
|
916
|
+
),
|
|
917
|
+
/* @__PURE__ */ jsx("circle", { className: "mk-pulse-dot", cx: 72, cy: 55, r: 6.2 })
|
|
918
|
+
] });
|
|
919
|
+
var WORDMARK_PATHS = (offsetX) => /* @__PURE__ */ jsxs("g", { transform: `translate(${offsetX},85.0) scale(0.09722222222222222,-0.09722222222222222)`, children: [
|
|
920
|
+
/* @__PURE__ */ jsx(
|
|
921
|
+
"path",
|
|
922
|
+
{
|
|
923
|
+
className: "wm-ink",
|
|
924
|
+
transform: "translate(0,0)",
|
|
925
|
+
d: "M62 -169V258V528H194L196 378L214 376Q223 432 246.0 469.0Q269 506 305.5 524.0Q342 542 389 542Q459 542 509.5 508.0Q560 474 587.0 411.0Q614 348 614 260Q614 182 590.5 120.0Q567 58 519.5 22.0Q472 -14 399 -14Q350 -14 316.0 3.5Q282 21 258.5 55.0Q235 89 219 140H200Q206 113 211.0 85.0Q216 57 219.5 31.0Q223 5 223 -19V-169ZM340 113Q373 113 396.5 131.0Q420 149 433.0 182.0Q446 215 446 259Q446 306 432.5 339.5Q419 373 394.0 391.5Q369 410 336 410Q305 410 283.5 396.5Q262 383 248.5 361.5Q235 340 229.0 316.0Q223 292 223 271V249Q223 230 228.0 211.0Q233 192 243.0 174.5Q253 157 267.0 143.0Q281 129 299.5 121.0Q318 113 340 113Z"
|
|
926
|
+
}
|
|
927
|
+
),
|
|
928
|
+
/* @__PURE__ */ jsx(
|
|
929
|
+
"path",
|
|
930
|
+
{
|
|
931
|
+
className: "wm-o",
|
|
932
|
+
transform: "translate(658,0)",
|
|
933
|
+
d: "M305 -14Q225 -14 163.5 17.0Q102 48 67.0 110.0Q32 172 32 265Q32 358 67.0 419.5Q102 481 164.0 511.5Q226 542 306 542Q386 542 448.0 511.0Q510 480 545.0 418.5Q580 357 580 264Q580 169 544.0 107.0Q508 45 445.5 15.5Q383 -14 305 -14ZM310 103Q346 103 370.0 119.5Q394 136 406.0 170.0Q418 204 418 254Q418 307 405.0 343.5Q392 380 366.5 399.5Q341 419 301 419Q267 419 242.5 402.5Q218 386 206.0 352.0Q194 318 194 267Q194 185 224.5 144.0Q255 103 310 103Z"
|
|
934
|
+
}
|
|
935
|
+
),
|
|
936
|
+
/* @__PURE__ */ jsx(
|
|
937
|
+
"path",
|
|
938
|
+
{
|
|
939
|
+
className: "wm-o",
|
|
940
|
+
transform: "translate(1280,0)",
|
|
941
|
+
d: "M305 -14Q225 -14 163.5 17.0Q102 48 67.0 110.0Q32 172 32 265Q32 358 67.0 419.5Q102 481 164.0 511.5Q226 542 306 542Q386 542 448.0 511.0Q510 480 545.0 418.5Q580 357 580 264Q580 169 544.0 107.0Q508 45 445.5 15.5Q383 -14 305 -14ZM310 103Q346 103 370.0 119.5Q394 136 406.0 170.0Q418 204 418 254Q418 307 405.0 343.5Q392 380 366.5 399.5Q341 419 301 419Q267 419 242.5 402.5Q218 386 206.0 352.0Q194 318 194 267Q194 185 224.5 144.0Q255 103 310 103Z"
|
|
942
|
+
}
|
|
943
|
+
),
|
|
944
|
+
/* @__PURE__ */ jsx("path", { className: "wm-ink", transform: "translate(1902,0)", d: "M62 0V720H220V0Z" }),
|
|
945
|
+
/* @__PURE__ */ jsx(
|
|
946
|
+
"path",
|
|
947
|
+
{
|
|
948
|
+
className: "wm-ink",
|
|
949
|
+
transform: "translate(2195,0)",
|
|
950
|
+
d: "M278 -14Q225 -14 182.0 -4.5Q139 5 107.0 23.0Q75 41 54.5 66.5Q34 92 26 123L146 176Q153 159 170.5 141.5Q188 124 217.5 113.0Q247 102 289 102Q329 102 351.5 113.5Q374 125 374 147Q374 163 361.5 172.5Q349 182 324.0 189.5Q299 197 262 204Q224 212 185.0 222.5Q146 233 112.0 251.5Q78 270 57.5 300.5Q37 331 37 378Q37 427 63.0 463.5Q89 500 140.5 521.0Q192 542 266 542Q332 542 382.0 525.0Q432 508 465.5 476.5Q499 445 512 401L383 355Q378 377 362.5 393.0Q347 409 323.5 417.5Q300 426 268 426Q229 426 207.5 414.0Q186 402 186 382Q186 366 200.5 355.5Q215 345 242.0 338.0Q269 331 306 323Q345 315 383.5 304.5Q422 294 453.5 276.5Q485 259 503.5 230.5Q522 202 522 157Q522 104 494.0 65.5Q466 27 411.5 6.5Q357 -14 278 -14Z"
|
|
951
|
+
}
|
|
952
|
+
),
|
|
953
|
+
/* @__PURE__ */ jsx(
|
|
954
|
+
"path",
|
|
955
|
+
{
|
|
956
|
+
className: "wm-ink",
|
|
957
|
+
transform: "translate(2754,0)",
|
|
958
|
+
d: "M313 -14Q247 -14 195.0 3.5Q143 21 106.5 55.0Q70 89 51.0 139.0Q32 189 32 254Q32 317 50.5 370.0Q69 423 103.5 461.5Q138 500 188.5 521.0Q239 542 302 542Q366 542 414.5 521.5Q463 501 494.5 461.0Q526 421 541.0 363.5Q556 306 551 232L138 229V313L459 316L402 277Q409 327 396.0 358.5Q383 390 358.0 404.5Q333 419 304 419Q269 419 242.5 400.0Q216 381 201.0 345.0Q186 309 186 257Q186 175 221.5 138.0Q257 101 312 101Q339 101 357.0 108.5Q375 116 386.5 127.5Q398 139 404.5 153.0Q411 167 415 180L555 150Q547 113 529.5 83.0Q512 53 482.5 31.0Q453 9 411.5 -2.5Q370 -14 313 -14Z"
|
|
959
|
+
}
|
|
960
|
+
)
|
|
961
|
+
] });
|
|
962
|
+
var VARIANTS = {
|
|
963
|
+
lockup: {
|
|
964
|
+
vb: "0 0 454 100",
|
|
965
|
+
aspect: 4.54,
|
|
966
|
+
render: () => /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
967
|
+
MARK_PATHS,
|
|
968
|
+
WORDMARK_PATHS(126)
|
|
969
|
+
] })
|
|
970
|
+
},
|
|
971
|
+
mark: { vb: "0 0 100 100", aspect: 1, render: () => MARK_PATHS },
|
|
972
|
+
wordmark: { vb: "0 0 350 100", aspect: 3.5, render: () => WORDMARK_PATHS(0) },
|
|
973
|
+
mono: {
|
|
974
|
+
vb: "0 0 454 100",
|
|
975
|
+
aspect: 4.54,
|
|
976
|
+
render: () => /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
977
|
+
MARK_PATHS,
|
|
978
|
+
WORDMARK_PATHS(126)
|
|
979
|
+
] })
|
|
980
|
+
}
|
|
981
|
+
};
|
|
982
|
+
function PoolseLogo({
|
|
983
|
+
variant = "lockup",
|
|
984
|
+
size = 28,
|
|
985
|
+
label,
|
|
986
|
+
className,
|
|
987
|
+
...rest
|
|
988
|
+
}) {
|
|
989
|
+
const v = VARIANTS[variant];
|
|
990
|
+
const aria = label === null ? { "aria-hidden": true, focusable: false } : { role: "img", "aria-label": label ?? "poolse" };
|
|
991
|
+
return /* @__PURE__ */ jsx(
|
|
992
|
+
"svg",
|
|
993
|
+
{
|
|
994
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
995
|
+
viewBox: v.vb,
|
|
996
|
+
width: size * v.aspect,
|
|
997
|
+
height: size,
|
|
998
|
+
className: ["poolse-logo", variant === "mono" ? "poolse-logo--mono" : null, className].filter(Boolean).join(" ") || void 0,
|
|
999
|
+
...aria,
|
|
1000
|
+
...rest,
|
|
1001
|
+
children: v.render()
|
|
1002
|
+
}
|
|
1003
|
+
);
|
|
1004
|
+
}
|
|
1005
|
+
|
|
1006
|
+
export { AttachmentPreview, Avatar, ConversationList, ConversationView, MemberList, MentionInput, MessageBubble, MessageComposer, PoolseFonts, PoolseIcon, PoolseLogo, ReactionPicker, ReactionStrip, TypingIndicator, usePoolseFonts };
|
|
1007
|
+
//# sourceMappingURL=index.js.map
|
|
1008
|
+
//# sourceMappingURL=index.js.map
|