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