@dialtribe/chat-client 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -674,6 +674,9 @@ var MessagesUiStore = class extends Store {
674
674
  openRoom(roomId) {
675
675
  this.update({ open: true, view: { kind: "room", roomId } });
676
676
  }
677
+ openItem(itemId) {
678
+ this.update({ open: true, view: { kind: "item", itemId } });
679
+ }
677
680
  };
678
681
  var ClientContext = createContext(null);
679
682
  var MessagesUiContext = createContext(null);
@@ -784,6 +787,7 @@ function useDialtribeMessages() {
784
787
  toggle: () => ui.toggle(),
785
788
  openInbox: () => ui.openInbox(),
786
789
  openRoom: (roomId) => ui.openRoom(roomId),
790
+ openItem: (itemId) => ui.openItem(itemId),
787
791
  messageUser: async (userId, hint) => {
788
792
  const result = await client.inbox.requestDM(userId, hint);
789
793
  ui.openRoom(result.roomId);
@@ -1189,6 +1193,8 @@ var EDGE_SWIPE_ZONE = 24;
1189
1193
  var SWIPE_DISTANCE = 60;
1190
1194
  function DialtribeMessages({
1191
1195
  placement = "push",
1196
+ openPlacement = "push",
1197
+ items = [],
1192
1198
  contexts = [],
1193
1199
  theme,
1194
1200
  labels: labelOverrides,
@@ -1206,7 +1212,12 @@ function DialtribeMessages({
1206
1212
  const recentDms = inbox.rooms.filter((r) => r.myStatus === "accepted").slice(0, railDmLimit);
1207
1213
  const activeRoomId = isOpen && view.kind === "room" ? view.roomId : null;
1208
1214
  const activeContext = contexts.find((c) => c.roomId === activeRoomId);
1209
- usePushLayout(placement === "push" && !isMobile, RAIL_WIDTH + (isOpen ? panelWidth : 0));
1215
+ const activeItemId = isOpen && view.kind === "item" ? view.itemId : null;
1216
+ const activeItem = items.find((i) => i.id === activeItemId);
1217
+ const topItems = items.filter((i) => (i.placement ?? "top") === "top");
1218
+ const bottomItems = items.filter((i) => i.placement === "bottom");
1219
+ const panelInset = isOpen && openPlacement === "push" ? panelWidth : 0;
1220
+ usePushLayout(placement === "push" && !isMobile, RAIL_WIDTH + panelInset);
1210
1221
  useScrollLock(isMobile && isOpen);
1211
1222
  useEdgeSwipe(isMobile, isOpen, ui.open, ui.close);
1212
1223
  useEffect(() => {
@@ -1216,10 +1227,25 @@ function DialtribeMessages({
1216
1227
  return () => window.removeEventListener("keydown", onKey);
1217
1228
  }, [isOpen, ui]);
1218
1229
  const select = (target) => {
1219
- const showing = isOpen && (target.kind === "inbox" ? view.kind === "inbox" : activeRoomId === target.roomId);
1230
+ const showing = isOpen && (target.kind === "inbox" ? view.kind === "inbox" : target.kind === "room" ? activeRoomId === target.roomId : activeItemId === target.itemId);
1220
1231
  if (showing) ui.close();
1221
1232
  else if (target.kind === "inbox") ui.openInbox();
1222
- else ui.openRoom(target.roomId);
1233
+ else if (target.kind === "room") ui.openRoom(target.roomId);
1234
+ else ui.openItem(target.itemId);
1235
+ };
1236
+ const renderItemButton = (item) => {
1237
+ const active = activeItemId === item.id;
1238
+ return /* @__PURE__ */ jsx(
1239
+ RailButton,
1240
+ {
1241
+ label: item.label ?? item.id,
1242
+ active,
1243
+ badge: item.badge ?? 0,
1244
+ onClick: () => select({ kind: "item", itemId: item.id }),
1245
+ children: typeof item.trigger === "function" ? item.trigger({ active }) : item.trigger
1246
+ },
1247
+ item.id
1248
+ );
1223
1249
  };
1224
1250
  const style = { ...themeVars(theme), "--dtc-panel-width": `${panelWidth}px`, "--dtc-rail-width": `${RAIL_WIDTH}px` };
1225
1251
  const showRail = !isMobile || isOpen;
@@ -1233,7 +1259,7 @@ function DialtribeMessages({
1233
1259
  /* @__PURE__ */ jsx(ChatIcon, {}),
1234
1260
  rollup > 0 && /* @__PURE__ */ jsx("span", { className: "dtc-badge-count dtc-badge-float", children: badgeText(rollup) })
1235
1261
  ] }),
1236
- isOpen && /* @__PURE__ */ jsx("div", { className: "dtc-messages-panel", role: "dialog", "aria-label": labels.messages, children: view.kind === "inbox" ? /* @__PURE__ */ jsxs(Fragment, { children: [
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: [
1237
1263
  /* @__PURE__ */ jsxs("div", { className: "dtc-panel-header", children: [
1238
1264
  /* @__PURE__ */ jsx("span", { className: "dtc-panel-title", children: labels.messages }),
1239
1265
  /* @__PURE__ */ jsx("button", { type: "button", className: "dtc-icon-btn", onClick: ui.close, "aria-label": labels.close, title: labels.close, children: /* @__PURE__ */ jsx(CloseIcon, {}) })
@@ -1248,6 +1274,8 @@ function DialtribeMessages({
1248
1274
  /* @__PURE__ */ jsx(ChatRoomProvider, { roomId: activeContext.roomId, children: /* @__PURE__ */ jsx(ChatPanel, { showHeader: false, emptyLabel: labels.noMessages, placeholder: labels.messagePlaceholder }) })
1249
1275
  ] }) : /* @__PURE__ */ jsx(ConversationView, { roomId: view.roomId, labels, onBack: ui.openInbox }, view.roomId) }),
1250
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" }),
1251
1279
  /* @__PURE__ */ jsx(
1252
1280
  RailButton,
1253
1281
  {
@@ -1281,7 +1309,9 @@ function DialtribeMessages({
1281
1309
  children: /* @__PURE__ */ jsx(Avatar, { name: room.name, url: room.kind === "dm" ? room.participants[0]?.avatarUrl : null, size: 36 })
1282
1310
  },
1283
1311
  room.roomId
1284
- ))
1312
+ )),
1313
+ bottomItems.length > 0 && /* @__PURE__ */ jsx("span", { className: "dtc-rail-divider" }),
1314
+ bottomItems.map(renderItemButton)
1285
1315
  ] })
1286
1316
  ]
1287
1317
  }