@dialtribe/chat-client 0.2.0 → 0.4.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/dist/index.js CHANGED
@@ -241,6 +241,12 @@ var InboxStore = class extends Store {
241
241
  this.readTimers = /* @__PURE__ */ new Map();
242
242
  /** Rooms currently on screen: activity there is read, not unread. */
243
243
  this.visible = /* @__PURE__ */ new Map();
244
+ /**
245
+ * Rooms the user removed (hide/ignore) and when. Filtered out of every list,
246
+ * so a refresh already in flight can't put them back, until a newer message
247
+ * arrives or the user messages/reopens/accepts them.
248
+ */
249
+ this.removed = /* @__PURE__ */ new Map();
244
250
  }
245
251
  acquire() {
246
252
  this.refs += 1;
@@ -271,11 +277,13 @@ var InboxStore = class extends Store {
271
277
  targetAvatarUrl: hint?.avatarUrl,
272
278
  showRequestId: hint?.showRequestId
273
279
  });
280
+ this.removed.delete(result.roomId);
274
281
  await this.refresh();
275
282
  return { status: result.status, roomId: result.roomId };
276
283
  }
277
284
  async acceptDM(requestId) {
278
285
  const { roomId } = await this.client.dm("chat-dm-accept", { requestId });
286
+ this.removed.delete(roomId);
279
287
  await this.refresh();
280
288
  return roomId;
281
289
  }
@@ -289,6 +297,7 @@ var InboxStore = class extends Store {
289
297
  }
290
298
  async reopenDM(roomId) {
291
299
  await this.client.dm("chat-dm-reopen", { roomId });
300
+ this.removed.delete(roomId);
292
301
  await this.refresh();
293
302
  }
294
303
  /** Add someone. Returns the room to show (a new group when added to a 1:1). */
@@ -302,10 +311,38 @@ var InboxStore = class extends Store {
302
311
  await this.refresh();
303
312
  return result.roomId;
304
313
  }
314
+ /**
315
+ * Remove a conversation from the user's own inbox (optimistic). Not deleted
316
+ * and nobody else is affected: it comes back when a newer message arrives or
317
+ * when the user messages/reopens it.
318
+ */
319
+ async hideDM(roomId) {
320
+ this.removeLocally(roomId);
321
+ try {
322
+ await this.client.dm("chat-dm-hide", { roomId });
323
+ } catch (err) {
324
+ this.removed.delete(roomId);
325
+ await this.refresh();
326
+ throw err;
327
+ }
328
+ }
305
329
  async setMuted(roomId, muted) {
306
330
  this.patchRoom(roomId, (room) => ({ ...room, isMuted: muted }));
307
331
  await this.client.dm("chat-dm-mute", { roomId, muted });
308
332
  }
333
+ /**
334
+ * Archive or unarchive for the signed-in user only (optimistic). The room
335
+ * leaves the rail but stays in the inbox; new messages don't unarchive it.
336
+ */
337
+ async setArchived(roomId, archived) {
338
+ this.patchRoom(roomId, (room) => ({ ...room, isArchived: archived }));
339
+ try {
340
+ await this.client.dm("chat-dm-archive", { roomId, archived });
341
+ } catch (err) {
342
+ this.patchRoom(roomId, (room) => ({ ...room, isArchived: !archived }));
343
+ throw err;
344
+ }
345
+ }
309
346
  /** Mark a room read now (optimistic). */
310
347
  async markRead(roomId) {
311
348
  this.patchRoom(roomId, (room) => room.unreadCount === 0 ? room : { ...room, unreadCount: 0 });
@@ -354,6 +391,7 @@ var InboxStore = class extends Store {
354
391
  }
355
392
  }
356
393
  onActivity(roomId, message) {
394
+ this.removed.delete(roomId);
357
395
  const known = this.getSnapshot().rooms.some((r) => r.roomId === roomId);
358
396
  if (!known) {
359
397
  this.scheduleRefresh(REFRESH_DEBOUNCE_MS);
@@ -411,9 +449,14 @@ var InboxStore = class extends Store {
411
449
  this.setRooms(moveToTop ? [next, ...rest] : rooms.map((r, i) => i === index ? next : r));
412
450
  }
413
451
  removeLocally(roomId) {
414
- this.setRooms(this.getSnapshot().rooms.filter((r) => r.roomId !== roomId));
452
+ this.removed.set(roomId, Date.now());
453
+ this.setRooms(this.getSnapshot().rooms);
415
454
  }
416
- setRooms(rooms) {
455
+ setRooms(all) {
456
+ const rooms = all.filter((r) => {
457
+ const removedAt = this.removed.get(r.roomId);
458
+ return removedAt === void 0 || r.lastMessageAt !== null && Date.parse(r.lastMessageAt) > removedAt;
459
+ });
417
460
  this.update({
418
461
  rooms,
419
462
  requests: rooms.filter((r) => r.myStatus === "pending"),
@@ -764,8 +807,10 @@ function useChatRooms() {
764
807
  ignoreDM: inbox.ignoreDM.bind(inbox),
765
808
  closeDM: inbox.closeDM.bind(inbox),
766
809
  reopenDM: inbox.reopenDM.bind(inbox),
810
+ hideDM: inbox.hideDM.bind(inbox),
767
811
  addParticipant: inbox.addParticipant.bind(inbox),
768
812
  setMuted: inbox.setMuted.bind(inbox),
813
+ setArchived: inbox.setArchived.bind(inbox),
769
814
  markRead: inbox.markRead.bind(inbox),
770
815
  setVisible: inbox.setVisible.bind(inbox),
771
816
  refresh: inbox.refresh.bind(inbox)
@@ -1100,38 +1145,174 @@ var DEFAULT_LABELS = {
1100
1145
  conversationClosed: "This conversation is closed",
1101
1146
  reopen: "Reopen",
1102
1147
  closeConversation: "Close conversation",
1103
- mute: "Mute",
1104
- unmute: "Unmute",
1148
+ removeConversation: "Remove from inbox",
1149
+ mute: "Mute notifications",
1150
+ unmute: "Unmute notifications",
1151
+ archive: "Archive conversation",
1152
+ unarchive: "Unarchive conversation",
1153
+ archived: "Archived",
1154
+ moreOptions: "More options",
1155
+ muteConfirmTitle: (name) => `Mute notifications from ${name}?`,
1156
+ muteConfirmBody: "You won't get alerts or unread badges for this conversation. Messages still arrive.",
1157
+ muteConfirm: "Mute",
1158
+ archiveConfirmTitle: (name) => `Archive your conversation with ${name}?`,
1159
+ archiveConfirmBody: "It moves off your rail and into Archived in Messages. New messages still count toward your unread. Only you will see that it's archived.",
1160
+ archiveConfirm: "Archive",
1161
+ cancel: "Cancel",
1105
1162
  messagePlaceholder: "Message...",
1106
1163
  openMessages: "Open messages"
1107
1164
  };
1108
1165
  function badgeText(count) {
1109
1166
  return count > 99 ? "99+" : String(count);
1110
1167
  }
1111
- function MessagesInbox({ rooms, requests, labels, onOpenRoom }) {
1112
- const conversations = rooms.filter((r) => r.myStatus === "accepted");
1168
+ function MessagesInbox({ rooms, requests, labels, onOpenRoom, onRemoveRoom }) {
1169
+ const [showArchived, setShowArchived] = react.useState(false);
1170
+ const accepted = rooms.filter((r) => r.myStatus === "accepted");
1171
+ const conversations = accepted.filter((r) => !r.isArchived);
1172
+ const archived = accepted.filter((r) => r.isArchived);
1173
+ const archivedUnread = archived.reduce((sum, r) => sum + (r.isMuted ? 0 : r.unreadCount), 0);
1113
1174
  if (rooms.length === 0) return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "dtc-empty", children: labels.noMessages });
1114
1175
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "dtc-inbox", children: [
1115
1176
  requests.length > 0 && /* @__PURE__ */ jsxRuntime.jsxs("section", { className: "dtc-inbox-section", children: [
1116
1177
  /* @__PURE__ */ jsxRuntime.jsx("h3", { className: "dtc-inbox-heading", children: labels.requests }),
1117
1178
  requests.map((room) => /* @__PURE__ */ jsxRuntime.jsx(InboxRow, { room, onOpen: onOpenRoom }, room.roomId))
1118
1179
  ] }),
1119
- conversations.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("section", { className: "dtc-inbox-section", children: conversations.map((room) => /* @__PURE__ */ jsxRuntime.jsx(InboxRow, { room, onOpen: onOpenRoom }, room.roomId)) })
1180
+ conversations.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("section", { className: "dtc-inbox-section", children: conversations.map((room) => /* @__PURE__ */ jsxRuntime.jsx(
1181
+ InboxRow,
1182
+ {
1183
+ room,
1184
+ onOpen: onOpenRoom,
1185
+ onRemove: onRemoveRoom,
1186
+ removeLabel: labels.removeConversation
1187
+ },
1188
+ room.roomId
1189
+ )) }),
1190
+ archived.length > 0 && /* @__PURE__ */ jsxRuntime.jsxs("section", { className: "dtc-inbox-section", children: [
1191
+ /* @__PURE__ */ jsxRuntime.jsxs(
1192
+ "button",
1193
+ {
1194
+ type: "button",
1195
+ className: "dtc-inbox-heading dtc-inbox-toggle",
1196
+ "aria-expanded": showArchived,
1197
+ onClick: () => setShowArchived((v) => !v),
1198
+ children: [
1199
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { children: [
1200
+ labels.archived,
1201
+ " (",
1202
+ archived.length,
1203
+ ")"
1204
+ ] }),
1205
+ !showArchived && archivedUnread > 0 && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "dtc-badge-count", children: badgeText(archivedUnread) }),
1206
+ /* @__PURE__ */ jsxRuntime.jsx("svg", { className: "dtc-inbox-toggle-icon", viewBox: "0 0 24 24", width: "14", height: "14", fill: "none", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M6 9l6 6 6-6" }) })
1207
+ ]
1208
+ }
1209
+ ),
1210
+ showArchived && archived.map((room) => /* @__PURE__ */ jsxRuntime.jsx(InboxRow, { room, onOpen: onOpenRoom }, room.roomId))
1211
+ ] })
1120
1212
  ] });
1121
1213
  }
1122
- function InboxRow({ room, onOpen }) {
1214
+ function InboxRow({
1215
+ room,
1216
+ onOpen,
1217
+ onRemove,
1218
+ removeLabel
1219
+ }) {
1123
1220
  const unread = room.unreadCount > 0 && !room.isMuted;
1124
1221
  const lead = room.participants[0];
1125
- return /* @__PURE__ */ jsxRuntime.jsxs("button", { type: "button", className: `dtc-inbox-row ${unread ? "dtc-inbox-row-unread" : ""}`, onClick: () => onOpen(room.roomId), children: [
1126
- /* @__PURE__ */ jsxRuntime.jsx(Avatar, { name: room.name, url: room.kind === "dm" ? lead?.avatarUrl : null, size: 40 }),
1127
- /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "dtc-inbox-text", children: [
1128
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "dtc-inbox-name", children: room.name }),
1129
- room.lastMessage && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "dtc-inbox-preview", children: room.lastMessage.text })
1222
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: `dtc-inbox-item ${unread ? "dtc-inbox-row-unread" : ""}`, children: [
1223
+ /* @__PURE__ */ jsxRuntime.jsxs("button", { type: "button", className: "dtc-inbox-row", onClick: () => onOpen(room.roomId), children: [
1224
+ /* @__PURE__ */ jsxRuntime.jsx(Avatar, { name: room.name, url: room.kind === "dm" ? lead?.avatarUrl : null, size: 40 }),
1225
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "dtc-inbox-text", children: [
1226
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "dtc-inbox-name", children: room.name }),
1227
+ room.lastMessage && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "dtc-inbox-preview", children: room.lastMessage.text })
1228
+ ] }),
1229
+ unread && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "dtc-badge-count", children: badgeText(room.unreadCount) })
1130
1230
  ] }),
1131
- unread && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "dtc-badge-count", children: badgeText(room.unreadCount) })
1231
+ onRemove && /* @__PURE__ */ jsxRuntime.jsx(
1232
+ "button",
1233
+ {
1234
+ type: "button",
1235
+ className: "dtc-inbox-remove",
1236
+ onClick: () => onRemove(room.roomId),
1237
+ "aria-label": `${removeLabel ?? "Remove"}: ${room.name}`,
1238
+ title: removeLabel,
1239
+ children: /* @__PURE__ */ jsxRuntime.jsx("svg", { viewBox: "0 0 24 24", width: "14", height: "14", fill: "none", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round", "aria-hidden": "true", children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M18 6L6 18M6 6l12 12" }) })
1240
+ }
1241
+ )
1242
+ ] });
1243
+ }
1244
+ function ConversationMenu({ label, items }) {
1245
+ const [open, setOpen] = react.useState(false);
1246
+ const rootRef = react.useRef(null);
1247
+ const buttonRef = react.useRef(null);
1248
+ const menuRef = react.useRef(null);
1249
+ react.useEffect(() => {
1250
+ if (!open) return;
1251
+ menuRef.current?.querySelector("[role=menuitem]")?.focus();
1252
+ const onPointer = (e) => {
1253
+ if (rootRef.current && !rootRef.current.contains(e.target)) setOpen(false);
1254
+ };
1255
+ const onKey = (e) => {
1256
+ if (e.key !== "Escape") return;
1257
+ e.preventDefault();
1258
+ setOpen(false);
1259
+ buttonRef.current?.focus();
1260
+ };
1261
+ document.addEventListener("pointerdown", onPointer);
1262
+ window.addEventListener("keydown", onKey, true);
1263
+ return () => {
1264
+ document.removeEventListener("pointerdown", onPointer);
1265
+ window.removeEventListener("keydown", onKey, true);
1266
+ };
1267
+ }, [open]);
1268
+ const onMenuKey = (e) => {
1269
+ if (e.key !== "ArrowDown" && e.key !== "ArrowUp") return;
1270
+ e.preventDefault();
1271
+ const buttons = Array.from(menuRef.current?.querySelectorAll("[role=menuitem]") ?? []);
1272
+ const i = buttons.indexOf(document.activeElement);
1273
+ const next = e.key === "ArrowDown" ? (i + 1) % buttons.length : (i - 1 + buttons.length) % buttons.length;
1274
+ buttons[next]?.focus();
1275
+ };
1276
+ if (items.length === 0) return null;
1277
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "dtc-menu-root", ref: rootRef, children: [
1278
+ /* @__PURE__ */ jsxRuntime.jsx(
1279
+ "button",
1280
+ {
1281
+ ref: buttonRef,
1282
+ type: "button",
1283
+ className: "dtc-icon-btn",
1284
+ "aria-label": label,
1285
+ title: label,
1286
+ "aria-haspopup": "menu",
1287
+ "aria-expanded": open,
1288
+ onClick: () => setOpen((v) => !v),
1289
+ children: /* @__PURE__ */ jsxRuntime.jsx(KebabIcon, {})
1290
+ }
1291
+ ),
1292
+ open && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "dtc-menu", role: "menu", ref: menuRef, onKeyDown: onMenuKey, children: items.map((item) => /* @__PURE__ */ jsxRuntime.jsx(
1293
+ "button",
1294
+ {
1295
+ type: "button",
1296
+ role: "menuitem",
1297
+ className: "dtc-menu-item",
1298
+ onClick: () => {
1299
+ setOpen(false);
1300
+ item.onSelect();
1301
+ },
1302
+ children: item.label
1303
+ },
1304
+ item.id
1305
+ )) })
1306
+ ] });
1307
+ }
1308
+ function KebabIcon() {
1309
+ return /* @__PURE__ */ jsxRuntime.jsxs("svg", { viewBox: "0 0 24 24", width: "18", height: "18", fill: "currentColor", "aria-hidden": "true", children: [
1310
+ /* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "12", cy: "5", r: "1.8" }),
1311
+ /* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "12", cy: "12", r: "1.8" }),
1312
+ /* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "12", cy: "19", r: "1.8" })
1132
1313
  ] });
1133
1314
  }
1134
- function ConversationView({ roomId, labels, onBack }) {
1315
+ function ConversationView({ roomId, labels, onBack, onClose, confirm }) {
1135
1316
  const inbox = useChatRooms();
1136
1317
  const room = inbox.rooms.find((r) => r.roomId === roomId);
1137
1318
  const { setVisible } = inbox;
@@ -1139,16 +1320,49 @@ function ConversationView({ roomId, labels, onBack }) {
1139
1320
  const isRequest = room?.myStatus === "pending";
1140
1321
  const isClosed = room?.state === "closed";
1141
1322
  const waitingOnThem = !isRequest && !!room && room.participants.length > 0 && room.participants.every((p) => p.status === "pending");
1323
+ const menuItems = [];
1324
+ if (room && !isRequest) {
1325
+ menuItems.push({
1326
+ id: "mute",
1327
+ label: room.isMuted ? labels.unmute : labels.mute,
1328
+ onSelect: async () => {
1329
+ if (room.isMuted) return void inbox.setMuted(roomId, false).catch(() => {
1330
+ });
1331
+ const ok = await confirm({
1332
+ title: labels.muteConfirmTitle(room.name),
1333
+ body: labels.muteConfirmBody,
1334
+ confirmLabel: labels.muteConfirm,
1335
+ cancelLabel: labels.cancel
1336
+ });
1337
+ if (ok) void inbox.setMuted(roomId, true).catch(() => {
1338
+ });
1339
+ }
1340
+ });
1341
+ menuItems.push({
1342
+ id: "archive",
1343
+ label: room.isArchived ? labels.unarchive : labels.archive,
1344
+ onSelect: async () => {
1345
+ if (room.isArchived) return void inbox.setArchived(roomId, false).catch(() => {
1346
+ });
1347
+ const ok = await confirm({
1348
+ title: labels.archiveConfirmTitle(room.name),
1349
+ body: labels.archiveConfirmBody,
1350
+ confirmLabel: labels.archiveConfirm,
1351
+ cancelLabel: labels.cancel
1352
+ });
1353
+ if (ok) void inbox.setArchived(roomId, true).catch(() => {
1354
+ });
1355
+ }
1356
+ });
1357
+ }
1142
1358
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "dtc-conversation", children: [
1143
1359
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "dtc-conversation-header", children: [
1144
1360
  /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "dtc-icon-btn", onClick: onBack, "aria-label": labels.back, title: labels.back, children: /* @__PURE__ */ jsxRuntime.jsx(ChevronLeft, {}) }),
1145
1361
  room && /* @__PURE__ */ jsxRuntime.jsx(Avatar, { name: room.name, url: room.kind === "dm" ? room.participants[0]?.avatarUrl : null, size: 28 }),
1146
1362
  /* @__PURE__ */ jsxRuntime.jsx("span", { className: "dtc-conversation-title", children: room?.name ?? "" }),
1147
- room && !isRequest && /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "dtc-conversation-actions", children: [
1148
- /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "dtc-text-btn", onClick: () => void inbox.setMuted(roomId, !room.isMuted).catch(() => {
1149
- }), children: room.isMuted ? labels.unmute : labels.mute }),
1150
- !isClosed && /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "dtc-text-btn", onClick: () => void inbox.closeDM(roomId).catch(() => {
1151
- }), children: labels.closeConversation })
1363
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "dtc-conversation-actions", children: [
1364
+ /* @__PURE__ */ jsxRuntime.jsx(ConversationMenu, { label: labels.moreOptions, items: menuItems }),
1365
+ /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "dtc-icon-btn", onClick: onClose, "aria-label": labels.close, title: labels.close, children: /* @__PURE__ */ jsxRuntime.jsx(CloseIcon, {}) })
1152
1366
  ] })
1153
1367
  ] }),
1154
1368
  isRequest && room && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "dtc-request-banner", role: "region", "aria-label": labels.requests, children: [
@@ -1187,6 +1401,9 @@ function ConversationView({ roomId, labels, onBack }) {
1187
1401
  ) })
1188
1402
  ] });
1189
1403
  }
1404
+ function CloseIcon() {
1405
+ return /* @__PURE__ */ jsxRuntime.jsx("svg", { viewBox: "0 0 24 24", width: "18", height: "18", fill: "none", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round", "aria-hidden": "true", children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M18 6L6 18M6 6l12 12" }) });
1406
+ }
1190
1407
  function ChevronLeft() {
1191
1408
  return /* @__PURE__ */ jsxRuntime.jsx("svg", { viewBox: "0 0 24 24", width: "18", height: "18", fill: "none", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M15 18l-6-6 6-6" }) });
1192
1409
  }
@@ -1194,15 +1411,18 @@ var RAIL_WIDTH = 64;
1194
1411
  var EDGE_SWIPE_ZONE = 24;
1195
1412
  var SWIPE_DISTANCE = 60;
1196
1413
  function DialtribeMessages({
1414
+ side = "right",
1197
1415
  placement = "push",
1198
1416
  openPlacement = "push",
1199
1417
  items = [],
1418
+ inboxRowClose = true,
1200
1419
  contexts = [],
1201
1420
  theme,
1202
1421
  labels: labelOverrides,
1203
1422
  panelWidth = 380,
1204
1423
  railDmLimit = 5,
1205
- mobileBreakpoint = 768
1424
+ mobileBreakpoint = 768,
1425
+ confirm: hostConfirm
1206
1426
  }) {
1207
1427
  const labels = react.useMemo(() => ({ ...DEFAULT_LABELS, ...labelOverrides }), [labelOverrides]);
1208
1428
  const inbox = useChatRooms();
@@ -1211,20 +1431,37 @@ function DialtribeMessages({
1211
1431
  const { isOpen, view } = ui;
1212
1432
  const pendingCount = inbox.requests.length;
1213
1433
  const rollup = inbox.totalUnread + pendingCount;
1214
- const recentDms = inbox.rooms.filter((r) => r.myStatus === "accepted").slice(0, railDmLimit);
1434
+ const recentDms = inbox.rooms.filter((r) => r.myStatus === "accepted" && !r.isArchived).slice(0, railDmLimit);
1435
+ const [builtInConfirm, setBuiltInConfirm] = react.useState(null);
1436
+ const confirmOpen = react.useRef(false);
1437
+ const confirm = react.useMemo(
1438
+ () => async (options) => {
1439
+ confirmOpen.current = true;
1440
+ try {
1441
+ return hostConfirm ? await hostConfirm(options) : await new Promise((resolve) => setBuiltInConfirm({ options, resolve }));
1442
+ } finally {
1443
+ confirmOpen.current = false;
1444
+ setBuiltInConfirm(null);
1445
+ }
1446
+ },
1447
+ [hostConfirm]
1448
+ );
1215
1449
  const activeRoomId = isOpen && view.kind === "room" ? view.roomId : null;
1216
1450
  const activeContext = contexts.find((c) => c.roomId === activeRoomId);
1217
1451
  const activeItemId = isOpen && view.kind === "item" ? view.itemId : null;
1218
1452
  const activeItem = items.find((i) => i.id === activeItemId);
1219
1453
  const topItems = items.filter((i) => (i.placement ?? "top") === "top");
1220
1454
  const bottomItems = items.filter((i) => i.placement === "bottom");
1455
+ const footerItems = items.filter((i) => i.placement === "footer");
1221
1456
  const panelInset = isOpen && openPlacement === "push" ? panelWidth : 0;
1222
- usePushLayout(placement === "push" && !isMobile, RAIL_WIDTH + panelInset);
1457
+ usePushLayout(placement === "push" && !isMobile, RAIL_WIDTH + panelInset, side);
1223
1458
  useScrollLock(isMobile && isOpen);
1224
- useEdgeSwipe(isMobile, isOpen, ui.open, ui.close);
1459
+ useEdgeSwipe(isMobile, isOpen, ui.open, ui.close, side);
1225
1460
  react.useEffect(() => {
1226
1461
  if (!isOpen) return;
1227
- const onKey = (e) => e.key === "Escape" && ui.close();
1462
+ const onKey = (e) => {
1463
+ if (e.key === "Escape" && !e.defaultPrevented && !confirmOpen.current) ui.close();
1464
+ };
1228
1465
  window.addEventListener("keydown", onKey);
1229
1466
  return () => window.removeEventListener("keydown", onKey);
1230
1467
  }, [isOpen, ui]);
@@ -1255,70 +1492,134 @@ function DialtribeMessages({
1255
1492
  "div",
1256
1493
  {
1257
1494
  className: `dtc-rail-root ${isMobile ? "dtc-rail-root-mobile" : ""} ${isOpen ? "dtc-rail-root-open" : ""}`,
1495
+ "data-side": side,
1258
1496
  style,
1259
1497
  children: [
1260
1498
  isMobile && !isOpen && /* @__PURE__ */ jsxRuntime.jsxs("button", { type: "button", className: "dtc-messages-fab", onClick: ui.openInbox, "aria-label": labels.openMessages, children: [
1261
1499
  /* @__PURE__ */ jsxRuntime.jsx(ChatIcon, {}),
1262
1500
  rollup > 0 && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "dtc-badge-count dtc-badge-float", children: badgeText(rollup) })
1263
1501
  ] }),
1264
- isOpen && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "dtc-messages-panel", role: "dialog", "aria-label": activeItem?.label ?? labels.messages, children: activeItem ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "dtc-item-panel", children: typeof activeItem.panel === "function" ? activeItem.panel({ close: ui.close }) : activeItem.panel }) : view.kind !== "room" ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1265
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "dtc-panel-header", children: [
1266
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "dtc-panel-title", children: labels.messages }),
1267
- /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "dtc-icon-btn", onClick: ui.close, "aria-label": labels.close, title: labels.close, children: /* @__PURE__ */ jsxRuntime.jsx(CloseIcon, {}) })
1268
- ] }),
1269
- /* @__PURE__ */ jsxRuntime.jsx(MessagesInbox, { rooms: inbox.rooms, requests: inbox.requests, labels, onOpenRoom: ui.openRoom })
1270
- ] }) : activeContext ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "dtc-conversation", children: [
1271
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "dtc-conversation-header", children: [
1272
- /* @__PURE__ */ jsxRuntime.jsx(Avatar, { name: activeContext.label, url: activeContext.avatarUrl, size: 28 }),
1273
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "dtc-conversation-title", children: activeContext.label }),
1274
- /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "dtc-icon-btn", onClick: ui.close, "aria-label": labels.close, title: labels.close, children: /* @__PURE__ */ jsxRuntime.jsx(CloseIcon, {}) })
1275
- ] }),
1276
- /* @__PURE__ */ jsxRuntime.jsx(ChatRoomProvider, { roomId: activeContext.roomId, children: /* @__PURE__ */ jsxRuntime.jsx(ChatPanel, { showHeader: false, emptyLabel: labels.noMessages, placeholder: labels.messagePlaceholder }) })
1277
- ] }) : /* @__PURE__ */ jsxRuntime.jsx(ConversationView, { roomId: view.roomId, labels, onBack: ui.openInbox }, view.roomId) }),
1278
- showRail && /* @__PURE__ */ jsxRuntime.jsxs("nav", { className: "dtc-rail", "aria-label": labels.messages, children: [
1279
- topItems.map(renderItemButton),
1280
- topItems.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "dtc-rail-divider" }),
1281
- /* @__PURE__ */ jsxRuntime.jsx(
1282
- RailButton,
1283
- {
1284
- label: labels.messages,
1285
- active: isOpen && view.kind === "inbox",
1286
- badge: rollup,
1287
- onClick: () => select({ kind: "inbox" }),
1288
- children: /* @__PURE__ */ jsxRuntime.jsx(ChatIcon, {})
1289
- }
1290
- ),
1291
- contexts.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "dtc-rail-divider" }),
1292
- contexts.map((c) => /* @__PURE__ */ jsxRuntime.jsx(
1293
- RailButton,
1502
+ isOpen && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "dtc-messages-panel", role: "dialog", "aria-label": activeItem?.label ?? labels.messages, children: [
1503
+ activeItem ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "dtc-item-panel", children: typeof activeItem.panel === "function" ? activeItem.panel({ close: ui.close }) : activeItem.panel }) : view.kind !== "room" ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1504
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "dtc-panel-header", children: [
1505
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "dtc-panel-title", children: labels.messages }),
1506
+ /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "dtc-icon-btn", onClick: ui.close, "aria-label": labels.close, title: labels.close, children: /* @__PURE__ */ jsxRuntime.jsx(CloseIcon2, {}) })
1507
+ ] }),
1508
+ /* @__PURE__ */ jsxRuntime.jsx(
1509
+ MessagesInbox,
1510
+ {
1511
+ rooms: inbox.rooms,
1512
+ requests: inbox.requests,
1513
+ labels,
1514
+ onOpenRoom: ui.openRoom,
1515
+ onRemoveRoom: inboxRowClose ? (roomId) => void inbox.hideDM(roomId).catch(() => {
1516
+ }) : void 0
1517
+ }
1518
+ )
1519
+ ] }) : activeContext ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "dtc-conversation", children: [
1520
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "dtc-conversation-header", children: [
1521
+ /* @__PURE__ */ jsxRuntime.jsx(Avatar, { name: activeContext.label, url: activeContext.avatarUrl, size: 28 }),
1522
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "dtc-conversation-title", children: activeContext.label }),
1523
+ /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "dtc-icon-btn", onClick: ui.close, "aria-label": labels.close, title: labels.close, children: /* @__PURE__ */ jsxRuntime.jsx(CloseIcon2, {}) })
1524
+ ] }),
1525
+ /* @__PURE__ */ jsxRuntime.jsx(ChatRoomProvider, { roomId: activeContext.roomId, children: /* @__PURE__ */ jsxRuntime.jsx(ChatPanel, { showHeader: false, emptyLabel: labels.noMessages, placeholder: labels.messagePlaceholder }) })
1526
+ ] }) : /* @__PURE__ */ jsxRuntime.jsx(
1527
+ ConversationView,
1294
1528
  {
1295
- label: c.label,
1296
- active: activeRoomId === c.roomId,
1297
- badge: c.badge ?? 0,
1298
- onClick: () => select({ kind: "room", roomId: c.roomId }),
1299
- children: /* @__PURE__ */ jsxRuntime.jsx(Avatar, { name: c.label, url: c.avatarUrl, size: 36 })
1529
+ roomId: view.roomId,
1530
+ labels,
1531
+ onBack: ui.openInbox,
1532
+ onClose: ui.close,
1533
+ confirm
1300
1534
  },
1301
- c.roomId
1302
- )),
1303
- recentDms.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "dtc-rail-divider" }),
1304
- recentDms.map((room) => /* @__PURE__ */ jsxRuntime.jsx(
1305
- RailButton,
1535
+ view.roomId
1536
+ ),
1537
+ builtInConfirm && /* @__PURE__ */ jsxRuntime.jsx(
1538
+ ConfirmDialog,
1306
1539
  {
1307
- label: room.name,
1308
- active: activeRoomId === room.roomId,
1309
- badge: room.isMuted ? 0 : room.unreadCount,
1310
- onClick: () => select({ kind: "room", roomId: room.roomId }),
1311
- children: /* @__PURE__ */ jsxRuntime.jsx(Avatar, { name: room.name, url: room.kind === "dm" ? room.participants[0]?.avatarUrl : null, size: 36 })
1312
- },
1313
- room.roomId
1314
- )),
1315
- bottomItems.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "dtc-rail-divider" }),
1316
- bottomItems.map(renderItemButton)
1540
+ options: builtInConfirm.options,
1541
+ onAnswer: builtInConfirm.resolve
1542
+ }
1543
+ )
1544
+ ] }),
1545
+ showRail && /* @__PURE__ */ jsxRuntime.jsxs("nav", { className: "dtc-rail", "aria-label": labels.messages, children: [
1546
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "dtc-rail-scroll", children: [
1547
+ topItems.map(renderItemButton),
1548
+ topItems.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "dtc-rail-divider" }),
1549
+ /* @__PURE__ */ jsxRuntime.jsx(
1550
+ RailButton,
1551
+ {
1552
+ label: labels.messages,
1553
+ active: isOpen && view.kind === "inbox",
1554
+ badge: rollup,
1555
+ onClick: () => select({ kind: "inbox" }),
1556
+ children: /* @__PURE__ */ jsxRuntime.jsx(ChatIcon, {})
1557
+ }
1558
+ ),
1559
+ contexts.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "dtc-rail-divider" }),
1560
+ contexts.map((c) => /* @__PURE__ */ jsxRuntime.jsx(
1561
+ RailButton,
1562
+ {
1563
+ label: c.label,
1564
+ active: activeRoomId === c.roomId,
1565
+ badge: c.badge ?? 0,
1566
+ onClick: () => select({ kind: "room", roomId: c.roomId }),
1567
+ children: /* @__PURE__ */ jsxRuntime.jsx(Avatar, { name: c.label, url: c.avatarUrl, size: 36 })
1568
+ },
1569
+ c.roomId
1570
+ )),
1571
+ recentDms.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "dtc-rail-divider" }),
1572
+ recentDms.map((room) => /* @__PURE__ */ jsxRuntime.jsx(
1573
+ RailButton,
1574
+ {
1575
+ label: room.name,
1576
+ active: activeRoomId === room.roomId,
1577
+ badge: room.isMuted ? 0 : room.unreadCount,
1578
+ onClick: () => select({ kind: "room", roomId: room.roomId }),
1579
+ children: /* @__PURE__ */ jsxRuntime.jsx(Avatar, { name: room.name, url: room.kind === "dm" ? room.participants[0]?.avatarUrl : null, size: 36 })
1580
+ },
1581
+ room.roomId
1582
+ )),
1583
+ bottomItems.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "dtc-rail-divider" }),
1584
+ bottomItems.map(renderItemButton)
1585
+ ] }),
1586
+ footerItems.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "dtc-rail-footer", children: footerItems.map(renderItemButton) })
1317
1587
  ] })
1318
1588
  ]
1319
1589
  }
1320
1590
  );
1321
1591
  }
1592
+ function ConfirmDialog({ options, onAnswer }) {
1593
+ const confirmRef = react.useRef(null);
1594
+ react.useEffect(() => {
1595
+ confirmRef.current?.focus();
1596
+ const onKey = (e) => {
1597
+ if (e.key !== "Escape") return;
1598
+ e.preventDefault();
1599
+ onAnswer(false);
1600
+ };
1601
+ window.addEventListener("keydown", onKey, true);
1602
+ return () => window.removeEventListener("keydown", onKey, true);
1603
+ }, [onAnswer]);
1604
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "dtc-confirm-backdrop", onClick: () => onAnswer(false), children: /* @__PURE__ */ jsxRuntime.jsxs(
1605
+ "div",
1606
+ {
1607
+ className: "dtc-confirm",
1608
+ role: "alertdialog",
1609
+ "aria-modal": "true",
1610
+ "aria-labelledby": "dtc-confirm-title",
1611
+ onClick: (e) => e.stopPropagation(),
1612
+ children: [
1613
+ /* @__PURE__ */ jsxRuntime.jsx("h3", { id: "dtc-confirm-title", className: "dtc-confirm-title", children: options.title }),
1614
+ options.body && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "dtc-confirm-body", children: options.body }),
1615
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "dtc-confirm-actions", children: [
1616
+ /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "dtc-btn", onClick: () => onAnswer(false), children: options.cancelLabel }),
1617
+ /* @__PURE__ */ jsxRuntime.jsx("button", { ref: confirmRef, type: "button", className: "dtc-btn dtc-btn-primary", onClick: () => onAnswer(true), children: options.confirmLabel })
1618
+ ] })
1619
+ ]
1620
+ }
1621
+ ) });
1622
+ }
1322
1623
  function RailButton({
1323
1624
  label,
1324
1625
  active,
@@ -1353,37 +1654,25 @@ function useMediaQuery(query) {
1353
1654
  }, [query]);
1354
1655
  return matches;
1355
1656
  }
1356
- function usePushLayout(enabled, inset) {
1357
- const original = react.useRef(null);
1657
+ function usePushLayout(enabled, inset, side) {
1358
1658
  react.useEffect(() => {
1359
- const root = document.documentElement;
1360
1659
  if (!enabled) return;
1361
- original.current ?? (original.current = { padding: root.style.paddingRight, transition: root.style.transition });
1362
- root.style.transition = "padding-right 250ms ease-out";
1363
- root.style.paddingRight = `${inset}px`;
1364
- root.style.setProperty("--dtc-messages-inset", `${inset}px`);
1365
- }, [enabled, inset]);
1366
- react.useEffect(() => {
1367
- if (enabled) return;
1368
1660
  const root = document.documentElement;
1369
- if (original.current) {
1370
- root.style.paddingRight = original.current.padding;
1371
- root.style.transition = original.current.transition;
1372
- original.current = null;
1373
- }
1374
- root.style.removeProperty("--dtc-messages-inset");
1375
- }, [enabled]);
1376
- react.useEffect(
1377
- () => () => {
1378
- const root = document.documentElement;
1379
- if (original.current) {
1380
- root.style.paddingRight = original.current.padding;
1381
- root.style.transition = original.current.transition;
1382
- }
1661
+ const prop = side === "left" ? "paddingLeft" : "paddingRight";
1662
+ const original = { padding: root.style[prop], transition: root.style.transition };
1663
+ root.style.transition = `${side === "left" ? "padding-left" : "padding-right"} 250ms ease-out`;
1664
+ root.style[prop] = `${inset}px`;
1665
+ root.style.setProperty("--dtc-messages-inset", `${inset}px`);
1666
+ root.style.setProperty("--dtc-messages-side", side);
1667
+ root.dataset.dtcMessagesSide = side;
1668
+ return () => {
1669
+ root.style[prop] = original.padding;
1670
+ root.style.transition = original.transition;
1383
1671
  root.style.removeProperty("--dtc-messages-inset");
1384
- },
1385
- []
1386
- );
1672
+ root.style.removeProperty("--dtc-messages-side");
1673
+ delete root.dataset.dtcMessagesSide;
1674
+ };
1675
+ }, [enabled, inset, side]);
1387
1676
  }
1388
1677
  function useScrollLock(locked) {
1389
1678
  react.useEffect(() => {
@@ -1395,14 +1684,15 @@ function useScrollLock(locked) {
1395
1684
  };
1396
1685
  }, [locked]);
1397
1686
  }
1398
- function useEdgeSwipe(enabled, isOpen, open, close) {
1687
+ function useEdgeSwipe(enabled, isOpen, open, close, side) {
1399
1688
  react.useEffect(() => {
1400
1689
  if (!enabled) return;
1401
1690
  let start = null;
1402
1691
  const onStart = (e) => {
1403
1692
  const t = e.touches[0];
1404
1693
  if (!t) return;
1405
- if (isOpen || t.clientX >= window.innerWidth - EDGE_SWIPE_ZONE) start = { x: t.clientX, y: t.clientY };
1694
+ const atEdge = side === "left" ? t.clientX <= EDGE_SWIPE_ZONE : t.clientX >= window.innerWidth - EDGE_SWIPE_ZONE;
1695
+ if (isOpen || atEdge) start = { x: t.clientX, y: t.clientY };
1406
1696
  };
1407
1697
  const onEnd = (e) => {
1408
1698
  const t = e.changedTouches[0];
@@ -1411,8 +1701,9 @@ function useEdgeSwipe(enabled, isOpen, open, close) {
1411
1701
  const dy = Math.abs(t.clientY - start.y);
1412
1702
  start = null;
1413
1703
  if (Math.abs(dx) < SWIPE_DISTANCE || dy > Math.abs(dx)) return;
1414
- if (!isOpen && dx < 0) open();
1415
- else if (isOpen && dx > 0) close();
1704
+ const inward = side === "left" ? dx > 0 : dx < 0;
1705
+ if (!isOpen && inward) open();
1706
+ else if (isOpen && !inward) close();
1416
1707
  };
1417
1708
  window.addEventListener("touchstart", onStart, { passive: true });
1418
1709
  window.addEventListener("touchend", onEnd, { passive: true });
@@ -1420,7 +1711,7 @@ function useEdgeSwipe(enabled, isOpen, open, close) {
1420
1711
  window.removeEventListener("touchstart", onStart);
1421
1712
  window.removeEventListener("touchend", onEnd);
1422
1713
  };
1423
- }, [enabled, isOpen, open, close]);
1714
+ }, [enabled, isOpen, open, close, side]);
1424
1715
  }
1425
1716
  function themeVars(theme) {
1426
1717
  if (!theme) return {};
@@ -1436,7 +1727,7 @@ function themeVars(theme) {
1436
1727
  function ChatIcon() {
1437
1728
  return /* @__PURE__ */ jsxRuntime.jsx("svg", { viewBox: "0 0 24 24", width: "20", height: "20", fill: "none", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z" }) });
1438
1729
  }
1439
- function CloseIcon() {
1730
+ function CloseIcon2() {
1440
1731
  return /* @__PURE__ */ jsxRuntime.jsx("svg", { viewBox: "0 0 24 24", width: "18", height: "18", fill: "none", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round", "aria-hidden": "true", children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M18 6L6 18M6 6l12 12" }) });
1441
1732
  }
1442
1733