@crvouga/mockingbird-notifications 0.2.1 → 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/ui.js CHANGED
@@ -1,14 +1,14 @@
1
1
  import {
2
2
  TEST_IDS,
3
3
  selectors
4
- } from "./chunk-FBJ2DRHH.js";
4
+ } from "./chunk-OR6VYHWA.js";
5
5
  import {
6
6
  CHANNELS,
7
7
  DASHBOARD_ROOT_CLASS,
8
8
  DASHBOARD_STYLES,
9
9
  ROOT_CLASS,
10
10
  STYLES
11
- } from "./chunk-3HF2NSFV.js";
11
+ } from "./chunk-QQK27AFM.js";
12
12
 
13
13
  // src/ui/chat.ts
14
14
  var isRow = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
@@ -274,9 +274,9 @@ var icons = {
274
274
  15
275
275
  ),
276
276
  menu: () => material("M3 18h18v-2H3v2zm0-5h18v-2H3v2zm0-7v2h18V6H3z", 24),
277
- tune: () => material(
277
+ tune: (size = 24) => material(
278
278
  "M3 17v2h6v-2H3zM3 5v2h10V5H3zm10 16v-2h8v-2h-8v-2h-2v6h2zM7 9v2H3v2h4v2h2V9H7zm14 4v-2H11v2h10zm-6-4h2V7h4V5h-4V3h-2v6z",
279
- 24
279
+ size
280
280
  ),
281
281
  help: () => material(
282
282
  "M11 18h2v-2h-2v2zm1-16a10 10 0 1 0 0 20 10 10 0 0 0 0-20zm0 18a8 8 0 1 1 0-16 8 8 0 0 1 0 16zm0-14a4 4 0 0 0-4 4h2a2 2 0 1 1 4 0c0 2-3 1.75-3 5h2c0-2.25 3-2.5 3-5a4 4 0 0 0-4-4z",
@@ -522,6 +522,8 @@ var TAB_LABELS = {
522
522
  var MIN_SCALE = 0.5;
523
523
  var deviceScale = (value) => typeof value === "number" && Number.isFinite(value) ? Math.max(MIN_SCALE, Math.min(1, value)) : 1;
524
524
  var isCompact = (layout, width, scale = 1) => layout === "tabs" || layout === "auto" && width > 0 && width / scale < TABS_BELOW_WIDTH;
525
+ var PHONE_BELOW_WIDTH = 640;
526
+ var isPhoneWidth = (width) => width > 0 && width < PHONE_BELOW_WIDTH;
525
527
  var phoneFit = (width, scale = 1) => Math.max(0.5, Math.min(1, (width / scale - 16) / 362));
526
528
  var tabsFor = (enabled, compact) => enabled.length < 2 ? [] : compact ? [...enabled] : ["all", ...enabled];
527
529
  var activeTab = (enabled, compact, only, fallback) => {
@@ -583,6 +585,8 @@ function createApp(root, options = {}) {
583
585
  view: initialView === "timeline" ? "timeline" : "devices",
584
586
  only: CHANNELS.includes(initialView ?? "") ? initialView : null,
585
587
  search: "",
588
+ /** Narrow screens: whether the rest of the top bar is open. */
589
+ menu: false,
586
590
  follow: params.get("follow") !== "0",
587
591
  connected: false,
588
592
  sms: {
@@ -644,12 +648,15 @@ function createApp(root, options = {}) {
644
648
  const width = root.clientWidth;
645
649
  root.style.setProperty("--mbn-scale", String(scale));
646
650
  if (width > 0) root.style.setProperty("--mbn-fit", String(phoneFit(width, scale)));
651
+ const size = width > 0 ? isPhoneWidth(width) ? "phone" : "wide" : root.dataset.size;
652
+ const resized = size !== root.dataset.size;
653
+ if (size) root.dataset.size = size;
647
654
  const next = isCompact(
648
655
  options.tabs === false && layout === "auto" ? "grid" : layout,
649
656
  width,
650
657
  scale
651
658
  );
652
- if (next === compact) return false;
659
+ if (next === compact) return resized;
653
660
  compact = next;
654
661
  return true;
655
662
  };
@@ -819,7 +826,8 @@ function createApp(root, options = {}) {
819
826
  sns: "SNS",
820
827
  customerio: "Customer.io",
821
828
  mailosaur: "Mailosaur",
822
- slack: "Slack"
829
+ slack: "Slack",
830
+ cognito: "Cognito"
823
831
  };
824
832
  const CHANNEL_LABEL = {
825
833
  sms: "SMS",
@@ -1036,28 +1044,31 @@ function createApp(root, options = {}) {
1036
1044
  const namespaces = [.../* @__PURE__ */ new Set([...state.namespaces, state.namespace])].sort();
1037
1045
  const searchFocused = document.activeElement === byTestId(TEST_IDS.search);
1038
1046
  bar.innerHTML = `
1039
- <div class="brand"><span class="brand-mark">${icons.bell()}</span><span>${esc(title())} <small>Mockingbird</small></span></div>
1040
- <label class="field">Namespace <select data-action="namespace" ${tid(TEST_IDS.namespace)} aria-label="Namespace">${namespaces.map((ns) => `<option ${ns === state.namespace ? "selected" : ""}>${esc(ns)}</option>`).join("")}</select></label>
1041
- <div class="field search">${icons.search("#9aa1b1", 14)}<input type="search" data-action="search" ${tid(TEST_IDS.search)} aria-label="Filter notifications" placeholder="Filter by recipient, sender, text\u2026" value="${esc(state.search)}"></div>
1047
+ <div class="brand"><span class="brand-mark">${icons.bell()}</span><span class="brand-name">${esc(title())} <small>Mockingbird</small></span></div>
1048
+ <div class="field search">${icons.search("#9aa1b1", 14)}<input type="search" data-action="search" ${tid(TEST_IDS.search)} aria-label="Filter notifications" placeholder="${root.dataset.size === "phone" ? "Filter notifications\u2026" : "Filter by recipient, sender, text\u2026"}" value="${esc(state.search)}"></div>
1049
+ <span class="live" ${tid(TEST_IDS.connection)} data-state="${state.connected ? "live" : "reconnecting"}" role="status"><span class="dot ${state.connected ? "ok" : "bad"}"></span><span class="live-label">${state.connected ? "Live" : "Reconnecting"}</span></span>
1050
+ <button class="menu-btn" data-action="menu" ${tid(TEST_IDS.menu)} aria-expanded="${state.menu}" aria-controls="${uid}-more" aria-label="More options">${state.menu ? icons.close(18) : icons.tune(20)}</button>
1051
+ <div class="topbar-more" id="${uid}-more">
1052
+ <label class="field namespace">Namespace <select data-action="namespace" ${tid(TEST_IDS.namespace)} aria-label="Namespace">${namespaces.map((ns) => `<option ${ns === state.namespace ? "selected" : ""}>${esc(ns)}</option>`).join("")}</select></label>
1042
1053
  <div class="tabs" role="group" aria-label="View">
1043
1054
  <button data-action="view" data-value="devices" ${tid(TEST_IDS.viewDevices)} aria-pressed="${state.view === "devices"}">Devices</button>
1044
1055
  <button data-action="view" data-value="timeline" ${tid(TEST_IDS.viewTimeline)} aria-pressed="${state.view === "timeline"}">Timeline <span style="opacity:.6">${state.items.length}</span></button>
1045
1056
  </div>
1046
1057
  <label class="toggle" title="Jump each device to the newest arrival"><input type="checkbox" data-action="follow" ${tid(TEST_IDS.follow)} ${state.follow ? "checked" : ""}> Follow new</label>
1047
1058
  <button class="icon-toggle" data-action="sound" ${tid(TEST_IDS.sound)} aria-pressed="${sound.enabled}" title="Play alert sounds on arrivals">${sound.enabled ? icons.volumeOn() : icons.volumeOff()}<span>Sound</span></button>
1048
- <span class="live" ${tid(TEST_IDS.connection)} data-state="${state.connected ? "live" : "reconnecting"}" role="status"><span class="dot ${state.connected ? "ok" : "bad"}"></span>${state.connected ? "Live" : "Reconnecting"}</span>
1049
1059
  <div class="sources">${state.sources.map(
1050
1060
  (s) => `<span class="pill" title="${esc(s.error ?? s.url)}" ${tid(TEST_IDS.source)} data-name="${esc(s.name)}" data-service="${esc(s.service ?? "")}" data-ok="${s.ok}" data-count="${s.count}"><span class="dot ${s.ok ? "ok" : s.error ? "bad" : ""}"></span>${esc(
1051
1061
  s.service && s.name !== s.service ? `${s.name} \xB7 ${SERVICE_LABEL[s.service] ?? s.service}` : SERVICE_LABEL[s.name] ?? s.name
1052
1062
  )} <b>${s.count}</b></span>`
1053
- ).join("")}</div>`;
1063
+ ).join("")}</div>
1064
+ </div>`;
1054
1065
  if (searchFocused) {
1055
1066
  const input = byTestId(TEST_IDS.search);
1056
1067
  input?.focus();
1057
1068
  input?.setSelectionRange(input.value.length, input.value.length);
1058
1069
  }
1059
1070
  const failing = state.sources.filter((s) => s.error);
1060
- $("notice").innerHTML = state.discoveryError || failing.length ? `<div class="notice" ${tid(TEST_IDS.notice)} data-kind="error" role="alert">${state.discoveryError ? `Fleet discovery failed: ${esc(state.discoveryError)}. ` : ""}${failing.map((s) => `<b>${esc(s.name)}</b>: ${esc(s.error)}`).join(" \xB7 ")}</div>` : !state.sources.length ? `<div class="notice" ${tid(TEST_IDS.notice)} data-kind="empty" style="border-color:#3a3f4b;background:#171a21;color:#9aa1b1">No messaging emulators found yet. Start the fleet with twilio, resend, fcm, ses, sns, customerio, mailosaur or slack.</div>` : "";
1071
+ $("notice").innerHTML = state.discoveryError || failing.length ? `<div class="notice" ${tid(TEST_IDS.notice)} data-kind="error" role="alert">${state.discoveryError ? `Fleet discovery failed: ${esc(state.discoveryError)}. ` : ""}${failing.map((s) => `<b>${esc(s.name)}</b>: ${esc(s.error)}`).join(" \xB7 ")}</div>` : !state.sources.length ? `<div class="notice" ${tid(TEST_IDS.notice)} data-kind="empty" style="border-color:#3a3f4b;background:#171a21;color:#9aa1b1">No messaging emulators found yet. Start the fleet with twilio, resend, fcm, ses, sns, customerio, mailosaur, slack or cognito.</div>` : "";
1061
1072
  };
1062
1073
  const recipientSelect = (channel, label, testId, format) => {
1063
1074
  const list = recipients(channel);
@@ -1182,7 +1193,7 @@ function createApp(root, options = {}) {
1182
1193
  ${unread ? `<span class="unread" ${tid(TEST_IDS.smsThreadUnread)}></span>` : ""}<div class="avatar ${whatsapp ? "wa" : ""}">${avatarFor(latest)}</div>
1183
1194
  <div class="text"><div class="top"><span class="name-line"><span class="name" ${tid(TEST_IDS.smsThreadName)}>${esc(name)}</span>${whatsapp ? `<span class="via-wa" ${tid(TEST_IDS.smsThreadVia)}>WhatsApp</span>` : ""}${t.pinned ? `<span class="flag">${icons.pin(13)}</span>` : ""}${muted ? `<span class="flag">${icons.bellSlash(13)}</span>` : ""}</span><span class="when" ${tid(TEST_IDS.smsThreadTime)}>${esc(iosListTime(latest?.createdAt ?? ""))} ${icons.chevronRight()}</span></div>
1184
1195
  <div class="preview" ${tid(TEST_IDS.smsThreadPreview)}>${esc(latest?.sms?.body ?? "")}</div></div></div></div>`;
1185
- }).join("")}</div>` : `<div class="empty-ios" ${tid(TEST_IDS.smsEmpty)}>${to ? "No Messages" : "No text messages yet.<br><br>SMS sent through Twilio, SNS, Customer.io or Mailosaur, and WhatsApp sent through Twilio, show up here."}</div>`}
1196
+ }).join("")}</div>` : `<div class="empty-ios" ${tid(TEST_IDS.smsEmpty)}>${to ? "No Messages" : "No text messages yet.<br><br>SMS sent through Twilio, SNS, Customer.io, Mailosaur or Cognito, and WhatsApp sent through Twilio, show up here."}</div>`}
1186
1197
  </div>`;
1187
1198
  }
1188
1199
  const col = $("col-sms");
@@ -1923,6 +1934,7 @@ function createApp(root, options = {}) {
1923
1934
  switch (action) {
1924
1935
  case "view":
1925
1936
  state.view = target.dataset.value === "timeline" ? "timeline" : "devices";
1937
+ state.menu = false;
1926
1938
  render();
1927
1939
  break;
1928
1940
  case "tab":
@@ -1935,6 +1947,10 @@ function createApp(root, options = {}) {
1935
1947
  case "sound":
1936
1948
  handle.setSound(!sound.enabled);
1937
1949
  break;
1950
+ case "menu":
1951
+ state.menu = !state.menu;
1952
+ renderTopbar();
1953
+ break;
1938
1954
  case "sms-open":
1939
1955
  state.sms.thread = from || null;
1940
1956
  state.sms.transition = "push";