@crvouga/mockingbird-notifications 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/README.md +96 -17
- package/dist/{chunk-QE3TRUI6.js → chunk-3HF2NSFV.js} +280 -10
- package/dist/chunk-3HF2NSFV.js.map +7 -0
- package/dist/chunk-4QVURMVP.js +400 -0
- package/dist/chunk-4QVURMVP.js.map +7 -0
- package/dist/{chunk-LM7R7AR7.js → chunk-FBJ2DRHH.js} +58 -6
- package/dist/chunk-FBJ2DRHH.js.map +7 -0
- package/dist/chunk-GHIEYY5B.js +1177 -0
- package/dist/chunk-GHIEYY5B.js.map +7 -0
- package/dist/cli.js +12 -4
- package/dist/cli.js.map +2 -2
- package/dist/index.d.ts +130 -11
- package/dist/index.js +9 -6
- package/dist/index.js.map +2 -2
- package/dist/server.d.ts +91 -6
- package/dist/server.js +7 -3
- package/dist/ui.d.ts +383 -229
- package/dist/ui.js +808 -133
- package/dist/ui.js.map +4 -4
- package/package.json +14 -10
- package/dist/chunk-GRGR3QZM.js +0 -1066
- package/dist/chunk-GRGR3QZM.js.map +0 -7
- package/dist/chunk-JQ6KPT2C.js +0 -202
- package/dist/chunk-JQ6KPT2C.js.map +0 -7
- package/dist/chunk-LM7R7AR7.js.map +0 -7
- package/dist/chunk-QE3TRUI6.js.map +0 -7
package/dist/ui.js
CHANGED
|
@@ -1,11 +1,196 @@
|
|
|
1
1
|
import {
|
|
2
2
|
TEST_IDS,
|
|
3
3
|
selectors
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-FBJ2DRHH.js";
|
|
5
5
|
import {
|
|
6
|
+
CHANNELS,
|
|
7
|
+
DASHBOARD_ROOT_CLASS,
|
|
8
|
+
DASHBOARD_STYLES,
|
|
6
9
|
ROOT_CLASS,
|
|
7
10
|
STYLES
|
|
8
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-3HF2NSFV.js";
|
|
12
|
+
|
|
13
|
+
// src/ui/chat.ts
|
|
14
|
+
var isRow = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
15
|
+
var row = (value) => isRow(value) ? value : {};
|
|
16
|
+
var rows = (value) => Array.isArray(value) ? value.filter(isRow) : [];
|
|
17
|
+
var str = (value) => typeof value === "string" ? value : "";
|
|
18
|
+
var escapeHtml = (value) => String(value ?? "").replace(/[&<>"']/g, (c) => `&#${c.charCodeAt(0)};`);
|
|
19
|
+
var safeUrl = (value) => /^(https?:\/\/|mailto:)/i.test(value.trim()) ? value.trim() : null;
|
|
20
|
+
var EMOJI = {
|
|
21
|
+
"+1": "\u{1F44D}",
|
|
22
|
+
thumbsup: "\u{1F44D}",
|
|
23
|
+
"-1": "\u{1F44E}",
|
|
24
|
+
thumbsdown: "\u{1F44E}",
|
|
25
|
+
tada: "\u{1F389}",
|
|
26
|
+
rocket: "\u{1F680}",
|
|
27
|
+
white_check_mark: "\u2705",
|
|
28
|
+
heavy_check_mark: "\u2714\uFE0F",
|
|
29
|
+
x: "\u274C",
|
|
30
|
+
warning: "\u26A0\uFE0F",
|
|
31
|
+
rotating_light: "\u{1F6A8}",
|
|
32
|
+
fire: "\u{1F525}",
|
|
33
|
+
eyes: "\u{1F440}",
|
|
34
|
+
heart: "\u2764\uFE0F",
|
|
35
|
+
wave: "\u{1F44B}",
|
|
36
|
+
bell: "\u{1F514}",
|
|
37
|
+
calendar: "\u{1F4C5}",
|
|
38
|
+
package: "\u{1F4E6}",
|
|
39
|
+
bug: "\u{1F41B}",
|
|
40
|
+
hourglass: "\u231B",
|
|
41
|
+
moneybag: "\u{1F4B0}",
|
|
42
|
+
email: "\u2709\uFE0F",
|
|
43
|
+
red_circle: "\u{1F534}",
|
|
44
|
+
large_green_circle: "\u{1F7E2}",
|
|
45
|
+
large_yellow_circle: "\u{1F7E1}",
|
|
46
|
+
sparkles: "\u2728",
|
|
47
|
+
memo: "\u{1F4DD}",
|
|
48
|
+
lock: "\u{1F512}",
|
|
49
|
+
information_source: "\u2139\uFE0F",
|
|
50
|
+
pray: "\u{1F64F}"
|
|
51
|
+
};
|
|
52
|
+
var emoji = (name) => EMOJI[name.toLowerCase()] ?? `:${name}:`;
|
|
53
|
+
var mrkdwn = (text, names = {}) => {
|
|
54
|
+
const parked = [];
|
|
55
|
+
const park = (html) => `\0${parked.push(html) - 1}\0`;
|
|
56
|
+
const entities = (value) => value.replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&amp;/g, "&");
|
|
57
|
+
const raw = (escaped) => escaped.replace(/&#(\d+);/g, (_, code) => String.fromCharCode(Number(code)));
|
|
58
|
+
let out = escapeHtml(text).replace(
|
|
59
|
+
/```\n?([\s\S]*?)```/g,
|
|
60
|
+
(_, code) => park(`<pre class="chat-pre">${entities(code)}</pre>`)
|
|
61
|
+
).replace(
|
|
62
|
+
/`([^`\n]+)`/g,
|
|
63
|
+
(_, code) => park(`<code class="chat-code">${entities(code)}</code>`)
|
|
64
|
+
).replace(/<(.+?)>/g, (whole, inner) => {
|
|
65
|
+
const [target = "", label] = inner.split("|");
|
|
66
|
+
if (target.startsWith("@") || target.startsWith("#")) {
|
|
67
|
+
const id = target.slice(1);
|
|
68
|
+
const shown = label || names.name?.(raw(id)) || id;
|
|
69
|
+
return park(`<span class="chat-mention">${target[0]}${escapeHtml(raw(shown))}</span>`);
|
|
70
|
+
}
|
|
71
|
+
if (target.startsWith("!")) {
|
|
72
|
+
const word = target.slice(1).split("^")[0] ?? "";
|
|
73
|
+
return park(`<span class="chat-mention">${label || `@${word}`}</span>`);
|
|
74
|
+
}
|
|
75
|
+
const href = safeUrl(raw(target));
|
|
76
|
+
if (!href) return whole;
|
|
77
|
+
return park(
|
|
78
|
+
`<a href="${escapeHtml(href)}" target="_blank" rel="noreferrer">${label || target}</a>`
|
|
79
|
+
);
|
|
80
|
+
});
|
|
81
|
+
out = entities(out).replace(/(^|[\s(])\*([^*\n]+)\*(?=$|[\s.,;:!?)])/gm, "$1<b>$2</b>").replace(/(^|[\s(])_([^_\n]+)_(?=$|[\s.,;:!?)])/gm, "$1<i>$2</i>").replace(/(^|[\s(])~([^~\n]+)~(?=$|[\s.,;:!?)])/gm, "$1<s>$2</s>").replace(/:([a-z0-9_+-]+):/gi, (_, name) => emoji(name)).replace(/(?:^> ?.*(?:\n|$))+/gm, (quote) => {
|
|
82
|
+
const body = quote.replace(/\n$/, "").replace(/^> ?/gm, "");
|
|
83
|
+
return `<blockquote class="chat-quote">${body}</blockquote>`;
|
|
84
|
+
});
|
|
85
|
+
const marker = /\u0000(\d+)\u0000/g;
|
|
86
|
+
for (let pass = 0; pass < 3 && out.includes("\0"); pass++)
|
|
87
|
+
out = out.replace(marker, (_, index) => parked[Number(index)] ?? "");
|
|
88
|
+
return out;
|
|
89
|
+
};
|
|
90
|
+
var textObject = (value, names) => {
|
|
91
|
+
if (typeof value === "string") return mrkdwn(value, names);
|
|
92
|
+
const t = row(value);
|
|
93
|
+
const text = str(t.text);
|
|
94
|
+
if (!text) return "";
|
|
95
|
+
return t.type === "plain_text" ? escapeHtml(text).replace(/:([a-z0-9_+-]+):/gi, (_, name) => emoji(name)) : mrkdwn(text, names);
|
|
96
|
+
};
|
|
97
|
+
var image = (src, alt, className) => {
|
|
98
|
+
const url = safeUrl(src);
|
|
99
|
+
return url ? `<img class="${className}" src="${escapeHtml(url)}" alt="${escapeHtml(alt)}" loading="lazy">` : "";
|
|
100
|
+
};
|
|
101
|
+
var button = (element2, names) => {
|
|
102
|
+
const style = element2.style === "primary" || element2.style === "danger" ? element2.style : "";
|
|
103
|
+
return `<span class="chat-btn ${style}" data-block-element="${escapeHtml(str(element2.type))}">${textObject(element2.text ?? element2.placeholder, names) || escapeHtml(str(element2.type))}</span>`;
|
|
104
|
+
};
|
|
105
|
+
var element = (value, names) => {
|
|
106
|
+
if (value.type === "image") return image(str(value.image_url), str(value.alt_text), "chat-thumb");
|
|
107
|
+
if (value.type === "mrkdwn" || value.type === "plain_text")
|
|
108
|
+
return `<span>${textObject(value, names)}</span>`;
|
|
109
|
+
return button(value, names);
|
|
110
|
+
};
|
|
111
|
+
var richRun = (run, names) => {
|
|
112
|
+
const style = row(run.style);
|
|
113
|
+
let html;
|
|
114
|
+
if (run.type === "link") {
|
|
115
|
+
const url = safeUrl(str(run.url));
|
|
116
|
+
const label = escapeHtml(str(run.text) || str(run.url));
|
|
117
|
+
html = url ? `<a href="${escapeHtml(url)}" target="_blank" rel="noreferrer">${label}</a>` : label;
|
|
118
|
+
} else if (run.type === "emoji") html = escapeHtml(emoji(str(run.name)));
|
|
119
|
+
else if (run.type === "user" || run.type === "usergroup")
|
|
120
|
+
html = `<span class="chat-mention">@${escapeHtml(names.name?.(str(run.user_id)) ?? str(run.user_id ?? run.usergroup_id))}</span>`;
|
|
121
|
+
else if (run.type === "channel")
|
|
122
|
+
html = `<span class="chat-mention">#${escapeHtml(names.name?.(str(run.channel_id)) ?? str(run.channel_id))}</span>`;
|
|
123
|
+
else if (run.type === "broadcast")
|
|
124
|
+
html = `<span class="chat-mention">@${escapeHtml(str(run.range))}</span>`;
|
|
125
|
+
else html = escapeHtml(str(run.text));
|
|
126
|
+
if (style.code) html = `<code class="chat-code">${html}</code>`;
|
|
127
|
+
if (style.bold) html = `<b>${html}</b>`;
|
|
128
|
+
if (style.italic) html = `<i>${html}</i>`;
|
|
129
|
+
if (style.strike) html = `<s>${html}</s>`;
|
|
130
|
+
return html;
|
|
131
|
+
};
|
|
132
|
+
var richText = (block2, names) => rows(block2.elements).map((part) => {
|
|
133
|
+
const runs = rows(part.elements);
|
|
134
|
+
if (part.type === "rich_text_list")
|
|
135
|
+
return `<${part.style === "ordered" ? "ol" : "ul"} class="chat-list-block">${runs.map(
|
|
136
|
+
(item) => `<li>${rows(item.elements).map((run) => richRun(run, names)).join("")}</li>`
|
|
137
|
+
).join("")}</${part.style === "ordered" ? "ol" : "ul"}>`;
|
|
138
|
+
const body = runs.map((run) => richRun(run, names)).join("");
|
|
139
|
+
if (part.type === "rich_text_preformatted") return `<pre class="chat-pre">${body}</pre>`;
|
|
140
|
+
if (part.type === "rich_text_quote")
|
|
141
|
+
return `<blockquote class="chat-quote">${body}</blockquote>`;
|
|
142
|
+
return `<div class="chat-text">${body}</div>`;
|
|
143
|
+
}).join("");
|
|
144
|
+
var block = (value, names) => {
|
|
145
|
+
const type = str(value.type);
|
|
146
|
+
const wrap = (body, extra = "") => `<div class="chat-block chat-block-${escapeHtml(type)} ${extra}" data-block="${escapeHtml(type)}">${body}</div>`;
|
|
147
|
+
switch (type) {
|
|
148
|
+
case "section": {
|
|
149
|
+
const fields = rows(value.fields);
|
|
150
|
+
const accessory = isRow(value.accessory) ? element(value.accessory, names) : "";
|
|
151
|
+
return wrap(
|
|
152
|
+
`<div class="chat-section-body">${value.text ? `<div class="chat-text">${textObject(value.text, names)}</div>` : ""}${fields.length ? `<div class="chat-fields">${fields.map((f) => `<div class="chat-text">${textObject(f, names)}</div>`).join("")}</div>` : ""}</div>${accessory ? `<div class="chat-accessory">${accessory}</div>` : ""}`,
|
|
153
|
+
accessory ? "with-accessory" : ""
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
case "header":
|
|
157
|
+
return wrap(textObject(value.text, names));
|
|
158
|
+
case "divider":
|
|
159
|
+
return wrap("<hr>");
|
|
160
|
+
case "context":
|
|
161
|
+
return wrap(
|
|
162
|
+
rows(value.elements).map((e) => element(e, names)).join("")
|
|
163
|
+
);
|
|
164
|
+
case "actions":
|
|
165
|
+
return wrap(
|
|
166
|
+
rows(value.elements).map((e) => button(e, names)).join("")
|
|
167
|
+
);
|
|
168
|
+
case "image":
|
|
169
|
+
return wrap(
|
|
170
|
+
`${value.title ? `<div class="chat-caption">${textObject(value.title, names)}</div>` : ""}${image(str(value.image_url), str(value.alt_text), "chat-image")}`
|
|
171
|
+
);
|
|
172
|
+
case "rich_text":
|
|
173
|
+
return wrap(richText(value, names));
|
|
174
|
+
default:
|
|
175
|
+
return wrap(`<span class="chat-unknown">${escapeHtml(type || "block")}</span>`, "unknown");
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
var renderBlocks = (blocks, names = {}) => rows(blocks).map((b) => block(b, names)).join("");
|
|
179
|
+
var ATTACHMENT_COLORS = {
|
|
180
|
+
good: "#2eb67d",
|
|
181
|
+
warning: "#ecb22e",
|
|
182
|
+
danger: "#e01e5a"
|
|
183
|
+
};
|
|
184
|
+
var renderAttachments = (attachments, names = {}) => rows(attachments).map((a) => {
|
|
185
|
+
const named = str(a.color);
|
|
186
|
+
const color = ATTACHMENT_COLORS[named] ?? (/^#?[0-9a-f]{3,8}$/i.test(named) ? `#${named.replace(/^#/, "")}` : "#dddddd");
|
|
187
|
+
const titleLink = safeUrl(str(a.title_link));
|
|
188
|
+
const title = escapeHtml(str(a.title));
|
|
189
|
+
const fields = rows(a.fields);
|
|
190
|
+
return `<div class="chat-attachment" data-color="${escapeHtml(color)}" style="border-left-color:${escapeHtml(color)}">${a.pretext ? `<div class="chat-text">${mrkdwn(str(a.pretext), names)}</div>` : ""}${a.author_name ? `<div class="chat-att-author">${escapeHtml(str(a.author_name))}</div>` : ""}${title ? `<div class="chat-att-title">${titleLink ? `<a href="${escapeHtml(titleLink)}" target="_blank" rel="noreferrer">${title}</a>` : title}</div>` : ""}${a.text ? `<div class="chat-text">${mrkdwn(str(a.text), names)}</div>` : ""}${fields.length ? `<div class="chat-fields">${fields.map(
|
|
191
|
+
(f) => `<div class="chat-field ${f.short ? "short" : ""}"><b>${escapeHtml(str(f.title))}</b><div class="chat-text">${mrkdwn(str(f.value), names)}</div></div>`
|
|
192
|
+
).join("")}</div>` : ""}${renderBlocks(a.blocks, names)}${image(str(a.image_url), str(a.fallback), "chat-image")}${a.footer ? `<div class="chat-att-footer">${escapeHtml(str(a.footer))}</div>` : ""}</div>`;
|
|
193
|
+
}).join("");
|
|
9
194
|
|
|
10
195
|
// src/ui/icons.ts
|
|
11
196
|
var svg = (w, h, body, extra = "") => `<svg width="${w}" height="${h}" viewBox="0 0 ${w} ${h}" fill="none" aria-hidden="true" ${extra}>${body}</svg>`;
|
|
@@ -261,6 +446,10 @@ var VOICES = {
|
|
|
261
446
|
email: (ctx, out, t) => {
|
|
262
447
|
bell(ctx, out, t, 987.8, 0.45, 0.7);
|
|
263
448
|
bell(ctx, out, t + 0.16, 1318.5, 0.9, 0.7);
|
|
449
|
+
},
|
|
450
|
+
chat: (ctx, out, t) => {
|
|
451
|
+
mallet(ctx, out, t, 587.3, 0.12);
|
|
452
|
+
mallet(ctx, out, t + 0.11, 880, 0.2);
|
|
264
453
|
}
|
|
265
454
|
};
|
|
266
455
|
var VIBRATION = {
|
|
@@ -321,6 +510,33 @@ var createSoundPlayer = (initial = false) => {
|
|
|
321
510
|
return player;
|
|
322
511
|
};
|
|
323
512
|
|
|
513
|
+
// src/ui/tabs.ts
|
|
514
|
+
var TABS_BELOW_WIDTH = 800;
|
|
515
|
+
var TAB_LABELS = {
|
|
516
|
+
all: "All",
|
|
517
|
+
sms: "Text",
|
|
518
|
+
push: "Push",
|
|
519
|
+
email: "Email",
|
|
520
|
+
chat: "Chat"
|
|
521
|
+
};
|
|
522
|
+
var MIN_SCALE = 0.5;
|
|
523
|
+
var deviceScale = (value) => typeof value === "number" && Number.isFinite(value) ? Math.max(MIN_SCALE, Math.min(1, value)) : 1;
|
|
524
|
+
var isCompact = (layout, width, scale = 1) => layout === "tabs" || layout === "auto" && width > 0 && width / scale < TABS_BELOW_WIDTH;
|
|
525
|
+
var phoneFit = (width, scale = 1) => Math.max(0.5, Math.min(1, (width / scale - 16) / 362));
|
|
526
|
+
var tabsFor = (enabled, compact) => enabled.length < 2 ? [] : compact ? [...enabled] : ["all", ...enabled];
|
|
527
|
+
var activeTab = (enabled, compact, only, fallback) => {
|
|
528
|
+
if (only && enabled.includes(only)) return only;
|
|
529
|
+
if (enabled.length === 1 && enabled[0]) return enabled[0];
|
|
530
|
+
if (!compact) return "all";
|
|
531
|
+
return (fallback && enabled.includes(fallback) ? fallback : enabled[0]) ?? "all";
|
|
532
|
+
};
|
|
533
|
+
var moveTab = (tabs, current, key) => {
|
|
534
|
+
if (!tabs.length) return null;
|
|
535
|
+
const index = Math.max(0, tabs.indexOf(current));
|
|
536
|
+
const next = key === "ArrowRight" || key === "ArrowDown" ? (index + 1) % tabs.length : key === "ArrowLeft" || key === "ArrowUp" ? (index - 1 + tabs.length) % tabs.length : key === "Home" ? 0 : key === "End" ? tabs.length - 1 : -1;
|
|
537
|
+
return next < 0 ? null : tabs[next] ?? null;
|
|
538
|
+
};
|
|
539
|
+
|
|
324
540
|
// src/ui/app.ts
|
|
325
541
|
var TAPBACKS = [
|
|
326
542
|
{ id: "heart", glyph: "\u2665", label: "Heart" },
|
|
@@ -330,7 +546,6 @@ var TAPBACKS = [
|
|
|
330
546
|
{ id: "emphasize", glyph: "\u203C", label: "Emphasize" },
|
|
331
547
|
{ id: "question", glyph: "?", label: "Question" }
|
|
332
548
|
];
|
|
333
|
-
var CHANNELS = ["sms", "push", "email"];
|
|
334
549
|
function createApp(root, options = {}) {
|
|
335
550
|
const live = options.live ?? true;
|
|
336
551
|
const syncUrl = options.syncUrl ?? (live && !options.fetch && !options.baseUrl);
|
|
@@ -366,7 +581,7 @@ function createApp(root, options = {}) {
|
|
|
366
581
|
discoveryError: null,
|
|
367
582
|
version: 0,
|
|
368
583
|
view: initialView === "timeline" ? "timeline" : "devices",
|
|
369
|
-
only: initialView
|
|
584
|
+
only: CHANNELS.includes(initialView ?? "") ? initialView : null,
|
|
370
585
|
search: "",
|
|
371
586
|
follow: params.get("follow") !== "0",
|
|
372
587
|
connected: false,
|
|
@@ -385,6 +600,7 @@ function createApp(root, options = {}) {
|
|
|
385
600
|
wake: false
|
|
386
601
|
},
|
|
387
602
|
email: { to: null, open: null, transition: false },
|
|
603
|
+
chat: { to: null },
|
|
388
604
|
inspect: null,
|
|
389
605
|
toast: null,
|
|
390
606
|
arrived: new Set(options.arrived ?? [])
|
|
@@ -394,6 +610,7 @@ function createApp(root, options = {}) {
|
|
|
394
610
|
sms: { ...state.sms, ...init.sms },
|
|
395
611
|
push: { ...state.push, ...init.push },
|
|
396
612
|
email: { ...state.email, ...init.email },
|
|
613
|
+
chat: { ...state.chat, ...init.chat },
|
|
397
614
|
toast: init.toast ? { text: init.toast } : null
|
|
398
615
|
});
|
|
399
616
|
if (initialView === "timeline") state.view = "timeline";
|
|
@@ -415,6 +632,27 @@ function createApp(root, options = {}) {
|
|
|
415
632
|
const pinnedId = params.get("id");
|
|
416
633
|
const pinned = pinnedTo && state.only ? { channel: state.only, to: pinnedTo } : null;
|
|
417
634
|
if (params.get("follow") === null && pinned) state.follow = false;
|
|
635
|
+
const enabled = CHANNELS.filter(
|
|
636
|
+
(channel) => options.channels === void 0 || options.channels.includes(channel)
|
|
637
|
+
);
|
|
638
|
+
const layout = options.layout ?? "auto";
|
|
639
|
+
let scale = deviceScale(options.scale);
|
|
640
|
+
let compact = layout === "tabs";
|
|
641
|
+
let lastTab = state.only;
|
|
642
|
+
const tab = () => activeTab(enabled, compact, state.only, lastTab);
|
|
643
|
+
const fit = () => {
|
|
644
|
+
const width = root.clientWidth;
|
|
645
|
+
root.style.setProperty("--mbn-scale", String(scale));
|
|
646
|
+
if (width > 0) root.style.setProperty("--mbn-fit", String(phoneFit(width, scale)));
|
|
647
|
+
const next = isCompact(
|
|
648
|
+
options.tabs === false && layout === "auto" ? "grid" : layout,
|
|
649
|
+
width,
|
|
650
|
+
scale
|
|
651
|
+
);
|
|
652
|
+
if (next === compact) return false;
|
|
653
|
+
compact = next;
|
|
654
|
+
return true;
|
|
655
|
+
};
|
|
418
656
|
const reducedMotion = () => typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
419
657
|
const motion = () => (options.motion ?? "auto") === "auto" ? reducedMotion() ? "reduce" : "full" : options.motion;
|
|
420
658
|
const animate = () => motion() === "full";
|
|
@@ -463,7 +701,8 @@ function createApp(root, options = {}) {
|
|
|
463
701
|
};
|
|
464
702
|
const esc = (value) => String(value ?? "").replace(/[&<>"']/g, (c) => `&#${c.charCodeAt(0)};`);
|
|
465
703
|
const tid = (id) => `data-testid="${id}"`;
|
|
466
|
-
const nAttrs = (n) => `data-notification-id="${esc(n.id)}" data-channel="${n.channel}" data-service="${esc(n.service)}" data-source="${esc(n.source)}" data-to="${esc(n.to)}" data-from="${esc(n.from.address)}" data-status="${esc(n.status ?? "")}" data-created-at="${esc(n.createdAt)}" data-unread="${!seen.has(n.id)}"`;
|
|
704
|
+
const nAttrs = (n) => `data-notification-id="${esc(n.id)}" data-channel="${n.channel}" data-service="${esc(n.service)}" data-source="${esc(n.source)}" data-to="${esc(n.to)}" data-from="${esc(n.from.address)}" data-status="${esc(n.status ?? "")}" data-created-at="${esc(n.createdAt)}" data-unread="${!seen.has(n.id)}"${isWhatsApp(n) ? ' data-via="whatsapp"' : ""}`;
|
|
705
|
+
const isWhatsApp = (n) => n?.sms?.via === "whatsapp";
|
|
467
706
|
const linkify = (escaped) => escaped.replace(
|
|
468
707
|
/\bhttps?:\/\/[^\s<]+[^\s<.,;:!?)'"]/g,
|
|
469
708
|
(url) => `<a href="${url}" target="_blank" rel="noreferrer">${url}</a>`
|
|
@@ -474,7 +713,11 @@ function createApp(root, options = {}) {
|
|
|
474
713
|
return value;
|
|
475
714
|
};
|
|
476
715
|
const isPhone = (value) => /^\+?\d[\d\s()-]{5,}$/.test(value);
|
|
477
|
-
const
|
|
716
|
+
const bareAddress = (address) => address.replace(/^whatsapp:/i, "");
|
|
717
|
+
const displaySender = (n) => {
|
|
718
|
+
const address = bareAddress(n.from.address);
|
|
719
|
+
return n.from.name ?? (isPhone(address) ? formatPhone(address) : address);
|
|
720
|
+
};
|
|
478
721
|
const initials = (value) => {
|
|
479
722
|
const words = value.replace(/[^\p{L}\p{N}\s]/gu, " ").trim().split(/\s+/).filter(Boolean);
|
|
480
723
|
if (!words.length) return "?";
|
|
@@ -575,7 +818,14 @@ function createApp(root, options = {}) {
|
|
|
575
818
|
ses: "SES",
|
|
576
819
|
sns: "SNS",
|
|
577
820
|
customerio: "Customer.io",
|
|
578
|
-
mailosaur: "Mailosaur"
|
|
821
|
+
mailosaur: "Mailosaur",
|
|
822
|
+
slack: "Slack"
|
|
823
|
+
};
|
|
824
|
+
const CHANNEL_LABEL = {
|
|
825
|
+
sms: "SMS",
|
|
826
|
+
push: "Push",
|
|
827
|
+
email: "Email",
|
|
828
|
+
chat: "Chat"
|
|
579
829
|
};
|
|
580
830
|
const matchesSearch = (n) => {
|
|
581
831
|
const q = state.search.trim().toLowerCase();
|
|
@@ -646,10 +896,12 @@ function createApp(root, options = {}) {
|
|
|
646
896
|
}
|
|
647
897
|
};
|
|
648
898
|
const threadKey = (to, from) => `${to}|${from}`;
|
|
899
|
+
let awaitedSms = null;
|
|
649
900
|
const groupKey = (to, app) => `${to}|${app}`;
|
|
650
901
|
const alertFor = (n) => {
|
|
651
902
|
if (n.channel === "sms") return local.muted.has(threadKey(n.to, n.from.address)) ? null : "sms";
|
|
652
903
|
if (n.channel === "email") return "email";
|
|
904
|
+
if (n.channel === "chat") return "chat";
|
|
653
905
|
const platform = state.push.skin === "auto" ? n.push?.platform === "android" ? "android" : "ios" : state.push.skin;
|
|
654
906
|
if (platform === "android" && local.silent.has(n.push?.app ?? "App")) return null;
|
|
655
907
|
return platform === "android" ? "push-android" : "push-ios";
|
|
@@ -669,6 +921,12 @@ function createApp(root, options = {}) {
|
|
|
669
921
|
}
|
|
670
922
|
if (channel === "push" && state.push.to === latest.to) state.push.wake = true;
|
|
671
923
|
}
|
|
924
|
+
const awaited = awaitedSms && newest.find((n) => n.channel === "sms" && n.to === awaitedSms);
|
|
925
|
+
if (awaited) {
|
|
926
|
+
state.sms.to = awaited.to;
|
|
927
|
+
state.sms.thread = awaited.from.address;
|
|
928
|
+
awaitedSms = null;
|
|
929
|
+
}
|
|
672
930
|
const kinds = new Set(added.map(alertFor).filter((k) => k !== null));
|
|
673
931
|
for (const kind of kinds) sound.play(kind);
|
|
674
932
|
options.onArrive?.(added);
|
|
@@ -735,6 +993,7 @@ function createApp(root, options = {}) {
|
|
|
735
993
|
};
|
|
736
994
|
void run();
|
|
737
995
|
};
|
|
996
|
+
const uid = `mbn-${Math.random().toString(36).slice(2, 8)}`;
|
|
738
997
|
root.classList.add(ROOT_CLASS);
|
|
739
998
|
if (options.embedded) root.classList.add("embedded");
|
|
740
999
|
root.dataset.testid = TEST_IDS.app;
|
|
@@ -742,11 +1001,13 @@ function createApp(root, options = {}) {
|
|
|
742
1001
|
root.innerHTML = `
|
|
743
1002
|
<header class="topbar" data-region="topbar" ${tid(TEST_IDS.topbar)}></header>
|
|
744
1003
|
<div data-region="notice"></div>
|
|
1004
|
+
<div class="channel-tabs" data-region="tabs" role="tablist" aria-label="Notification channels" ${tid(TEST_IDS.channelTabs)} hidden></div>
|
|
745
1005
|
<div class="mbn-scroll" data-region="scroll">
|
|
746
1006
|
<section class="devices" data-region="devices">
|
|
747
|
-
<div class="device-col" data-region="col-sms"></div>
|
|
748
|
-
<div class="device-col" data-region="col-push"></div>
|
|
749
|
-
<div class="device-col wide" data-region="col-email"></div>
|
|
1007
|
+
<div class="device-col" data-region="col-sms" id="${uid}-panel-sms"></div>
|
|
1008
|
+
<div class="device-col" data-region="col-push" id="${uid}-panel-push"></div>
|
|
1009
|
+
<div class="device-col wide" data-region="col-email" id="${uid}-panel-email"></div>
|
|
1010
|
+
<div class="device-col wide chat-col" data-region="col-chat" id="${uid}-panel-chat"></div>
|
|
750
1011
|
</section>
|
|
751
1012
|
<section class="timeline" data-region="timeline" hidden></section>
|
|
752
1013
|
</div>
|
|
@@ -762,7 +1023,9 @@ function createApp(root, options = {}) {
|
|
|
762
1023
|
version: String(state.version),
|
|
763
1024
|
connected: String(state.connected),
|
|
764
1025
|
sound: String(sound.enabled),
|
|
765
|
-
motion: motion()
|
|
1026
|
+
motion: motion(),
|
|
1027
|
+
layout: compact ? "tabs" : "grid",
|
|
1028
|
+
tab: tab()
|
|
766
1029
|
});
|
|
767
1030
|
};
|
|
768
1031
|
const renderTopbar = () => {
|
|
@@ -794,7 +1057,7 @@ function createApp(root, options = {}) {
|
|
|
794
1057
|
input?.setSelectionRange(input.value.length, input.value.length);
|
|
795
1058
|
}
|
|
796
1059
|
const failing = state.sources.filter((s) => s.error);
|
|
797
|
-
$("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 or
|
|
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>` : "";
|
|
798
1061
|
};
|
|
799
1062
|
const recipientSelect = (channel, label, testId, format) => {
|
|
800
1063
|
const list = recipients(channel);
|
|
@@ -804,21 +1067,23 @@ function createApp(root, options = {}) {
|
|
|
804
1067
|
).join("") : "<option>No recipients yet</option>"}</select></label>`;
|
|
805
1068
|
};
|
|
806
1069
|
const countBadge = (n, testId) => n ? `<span class="count" ${tid(testId)} data-count="${n}">${n}</span>` : "";
|
|
1070
|
+
const deviceHead = (heading, badge, select, controls = "") => `<div class="device-head"><div class="head-row"><h2>${heading} ${badge}</h2>${controls}</div>${select}</div>`;
|
|
807
1071
|
const statusBar = (light = false) => `
|
|
808
1072
|
<div class="statusbar ${light ? "light" : ""}"><span>${clock(new Date(nowMs())).replace(/\s?[AP]M$/i, "")}</span>
|
|
809
1073
|
<span class="icons">${icons.signal()}${icons.wifi()}${icons.battery()}</span></div>`;
|
|
1074
|
+
const zoomOf = (el2) => el2.currentCSSZoom || 1;
|
|
810
1075
|
const flip = (container, mutate) => {
|
|
811
1076
|
if (!animate() || typeof container.animate !== "function") return mutate();
|
|
812
1077
|
const before = /* @__PURE__ */ new Map();
|
|
813
|
-
for (const
|
|
814
|
-
before.set(
|
|
1078
|
+
for (const el2 of container.querySelectorAll("[data-flip]"))
|
|
1079
|
+
before.set(el2.dataset.flip ?? "", el2.getBoundingClientRect().top);
|
|
815
1080
|
mutate();
|
|
816
|
-
for (const
|
|
817
|
-
const top = before.get(
|
|
1081
|
+
for (const el2 of container.querySelectorAll("[data-flip]")) {
|
|
1082
|
+
const top = before.get(el2.dataset.flip ?? "");
|
|
818
1083
|
if (top === void 0) continue;
|
|
819
|
-
const dy = top -
|
|
1084
|
+
const dy = (top - el2.getBoundingClientRect().top) / zoomOf(el2);
|
|
820
1085
|
if (Math.abs(dy) < 1) continue;
|
|
821
|
-
|
|
1086
|
+
el2.animate([{ transform: `translateY(${dy}px)` }, { transform: "none" }], {
|
|
822
1087
|
duration: 380,
|
|
823
1088
|
easing: "cubic-bezier(.2,.9,.25,1)"
|
|
824
1089
|
});
|
|
@@ -840,7 +1105,7 @@ function createApp(root, options = {}) {
|
|
|
840
1105
|
};
|
|
841
1106
|
const avatarFor = (n) => {
|
|
842
1107
|
const name = n ? displaySender(n) : "";
|
|
843
|
-
return isPhone(n?.from.address ?? "") && !n?.from.name ? icons.person() : esc(initials(name));
|
|
1108
|
+
return isPhone(bareAddress(n?.from.address ?? "")) && !n?.from.name ? icons.person() : esc(initials(name));
|
|
844
1109
|
};
|
|
845
1110
|
const otpOf = (n) => n.sms?.code ?? (/\b(code|otp|passcode|pin|verif)/i.test(n.sms?.body ?? "") ? /\b(\d{4,8})\b/.exec(n.sms?.body ?? "")?.[1] ?? null : null);
|
|
846
1111
|
const highlightCode = (escaped, code) => code ? escaped.replace(new RegExp(`\\b${code}\\b`), `<span class="code">${code}</span>`) : escaped;
|
|
@@ -865,33 +1130,34 @@ function createApp(root, options = {}) {
|
|
|
865
1130
|
if (thread && to) {
|
|
866
1131
|
markSeen(thread.items.map((n) => n.id));
|
|
867
1132
|
const first = thread.items[0];
|
|
1133
|
+
const whatsapp = isWhatsApp(first);
|
|
868
1134
|
const otherUnread = threads.filter((t) => t !== thread).reduce((s, t) => s + t.items.filter((n) => !seen.has(n.id)).length, 0);
|
|
869
1135
|
let last = 0;
|
|
870
1136
|
let prevTail = true;
|
|
871
|
-
const
|
|
1137
|
+
const rows2 = thread.items.map((n, i) => {
|
|
872
1138
|
const at = Date.parse(n.createdAt);
|
|
873
|
-
const stamp = i === 0 || at - last > 15 * 6e4 ? `<div class="stamp" ${tid(TEST_IDS.smsTimestamp)}>${i === 0 ? "Text Message<br>" : ""}${iosStamp(n.createdAt)}</div>` : "";
|
|
1139
|
+
const stamp = i === 0 || at - last > 15 * 6e4 ? `<div class="stamp" ${tid(TEST_IDS.smsTimestamp)}>${i === 0 ? whatsapp ? "WhatsApp<br>" : "Text Message<br>" : ""}${iosStamp(n.createdAt)}</div>` : "";
|
|
874
1140
|
const next = thread.items[i + 1];
|
|
875
1141
|
const tail = !next || Date.parse(next.createdAt) - at > 6e4;
|
|
876
1142
|
const gap = !stamp && prevTail && i > 0;
|
|
877
1143
|
last = at;
|
|
878
1144
|
prevTail = tail;
|
|
879
1145
|
const code2 = otpOf(n);
|
|
880
|
-
return `${stamp}<div class="bubble-row ${gap ? "gap" : ""}"><div class="bubble ${tail ? "tail" : ""} ${state.arrived.has(n.id) ? "arrive" : ""}" ${nAttrs(n)} ${tid(TEST_IDS.smsBubble)} ${code2 ? `data-code="${esc(code2)}"` : ""} data-longpress="sms-bubble" tabindex="0" aria-haspopup="menu">${bubbleBody(n)}${tapbackBadge(n.id)}</div><span class="bubble-time" ${tid(TEST_IDS.smsBubbleTime)} aria-hidden="true">${esc(clock(new Date(at)))}</span></div>`;
|
|
1146
|
+
return `${stamp}<div class="bubble-row ${gap ? "gap" : ""}"><div class="bubble ${tail ? "tail" : ""} ${state.arrived.has(n.id) ? "arrive" : ""}" ${nAttrs(n)} ${tid(TEST_IDS.smsBubble)} ${code2 ? `data-code="${esc(code2)}"` : ""} data-longpress="sms-bubble" tabindex="0" aria-haspopup="menu">${bubbleBody(n)}${whatsapp ? `<span class="wa-time">${esc(clock(new Date(at)))}</span>` : ""}${tapbackBadge(n.id)}</div><span class="bubble-time" ${tid(TEST_IDS.smsBubbleTime)} aria-hidden="true">${esc(clock(new Date(at)))}</span></div>`;
|
|
881
1147
|
}).join("");
|
|
882
1148
|
const latest = thread.items.at(-1);
|
|
883
1149
|
const code = latest ? otpOf(latest) : null;
|
|
884
1150
|
const menuFor = state.sms.menu ? thread.items.find((n) => n.id === state.sms.menu) : null;
|
|
885
1151
|
const muted = local.muted.has(threadKey(to, thread.from));
|
|
886
|
-
screen = `<div class="convo ${transition === "push" && animate() ? "enter" : ""}" ${tid(TEST_IDS.smsConversation)} data-from="${esc(thread.from)}">
|
|
1152
|
+
screen = `<div class="convo ${whatsapp ? "wa" : ""} ${transition === "push" && animate() ? "enter" : ""}" ${tid(TEST_IDS.smsConversation)} data-from="${esc(thread.from)}" data-via="${whatsapp ? "whatsapp" : "sms"}">
|
|
887
1153
|
<div class="convo-nav"><div class="bar">
|
|
888
1154
|
<button class="back" data-action="sms-back" ${tid(TEST_IDS.smsBack)} aria-label="Back to Messages">${icons.chevronBack()}${otherUnread ? `<span class="badge">${otherUnread}</span>` : ""}</button>
|
|
889
1155
|
<div class="avatar">${avatarFor(first)}</div>
|
|
890
|
-
<div class="who" ${tid(TEST_IDS.smsConversationTitle)}>${esc(first ? displaySender(first) : thread.from)}
|
|
1156
|
+
<div class="who"><span ${tid(TEST_IDS.smsConversationTitle)}>${esc(first ? displaySender(first) : thread.from)}</span>${muted ? ` <span class="flag">${icons.bellSlash(12)}</span>` : ""} ${whatsapp ? '<small class="wa-sub">WhatsApp</small>' : icons.chevronRight("#8e8e93")}</div>
|
|
891
1157
|
</div></div>
|
|
892
|
-
<div class="convo-body" data-swipe="sms-convo">${
|
|
893
|
-
${code && latest && nowMs() - Date.parse(latest.createdAt) < 10 * 6e4 ? `<button class="qt" data-action="sms-copy-code" data-code="${esc(code)}" ${tid(TEST_IDS.smsCode)}><small>From Messages</small>${esc(code)}</button>` : ""}
|
|
894
|
-
<div class="convo-input"><span class="plus">${icons.plus()}</span><span class="field-ios"
|
|
1158
|
+
<div class="convo-body" data-swipe="sms-convo">${rows2}</div>
|
|
1159
|
+
${code && latest && nowMs() - Date.parse(latest.createdAt) < 10 * 6e4 ? `<button class="qt" data-action="sms-copy-code" data-code="${esc(code)}" ${tid(TEST_IDS.smsCode)}><small>From ${whatsapp ? "WhatsApp" : "Messages"}</small>${esc(code)}</button>` : ""}
|
|
1160
|
+
<div class="convo-input"><span class="plus">${icons.plus()}</span><span class="field-ios">${whatsapp ? "Message" : "Text Message"}<span>${icons.mic()}</span></span></div>
|
|
895
1161
|
${menuFor ? smsMenu(menuFor) : ""}
|
|
896
1162
|
</div>`;
|
|
897
1163
|
} else {
|
|
@@ -906,23 +1172,24 @@ function createApp(root, options = {}) {
|
|
|
906
1172
|
const key = threadKey(to, t.from);
|
|
907
1173
|
const muted = local.muted.has(key);
|
|
908
1174
|
const name = latest ? displaySender(latest) : t.from;
|
|
1175
|
+
const whatsapp = isWhatsApp(latest);
|
|
909
1176
|
return `<div class="swipe thread-swipe" data-swipe="sms-thread" data-from="${esc(t.from)}" data-flip="thread:${esc(t.from)}" role="listitem">
|
|
910
1177
|
<div class="swipe-actions">
|
|
911
1178
|
<div class="side"><button class="act-unread" data-action="thread-unread" data-from="${esc(t.from)}" ${tid(TEST_IDS.smsThreadToggleUnread)}>${unread ? icons.markRead(22) : icons.markUnread(22)}${unread ? "Read" : "Unread"}</button><button class="act-pin" data-action="thread-pin" data-from="${esc(t.from)}" ${tid(TEST_IDS.smsThreadPin)}>${icons.pin(22)}${t.pinned ? "Unpin" : "Pin"}</button></div>
|
|
912
1179
|
<div class="side"><button class="act-mute" data-action="thread-mute" data-from="${esc(t.from)}" ${tid(TEST_IDS.smsThreadMute)}>${icons.bellSlash(22)}${muted ? "Show Alerts" : "Hide Alerts"}</button><button class="act-delete" data-action="thread-delete" data-from="${esc(t.from)}" ${tid(TEST_IDS.smsThreadDelete)}>${icons.trash()}Delete</button></div>
|
|
913
1180
|
</div>
|
|
914
|
-
<div class="thread swipe-card" data-action="sms-open" data-from="${esc(t.from)}" ${tid(TEST_IDS.smsThread)} ${latest ? nAttrs(latest) : ""} data-unread="${unread}" data-pinned="${t.pinned}" data-muted="${muted}" role="button" tabindex="0" aria-label="${esc(name)}${unread ? ", unread" : ""}">
|
|
915
|
-
${unread ? `<span class="unread" ${tid(TEST_IDS.smsThreadUnread)}></span>` : ""}<div class="avatar">${avatarFor(latest)}</div>
|
|
916
|
-
<div class="text"><div class="top"><span class="name-line"><span class="name" ${tid(TEST_IDS.smsThreadName)}>${esc(name)}</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>
|
|
1181
|
+
<div class="thread swipe-card" data-action="sms-open" data-from="${esc(t.from)}" ${tid(TEST_IDS.smsThread)} ${latest ? nAttrs(latest) : ""} data-unread="${unread}" data-pinned="${t.pinned}" data-muted="${muted}" role="button" tabindex="0" aria-label="${esc(name)}${whatsapp ? ", WhatsApp" : ""}${unread ? ", unread" : ""}">
|
|
1182
|
+
${unread ? `<span class="unread" ${tid(TEST_IDS.smsThreadUnread)}></span>` : ""}<div class="avatar ${whatsapp ? "wa" : ""}">${avatarFor(latest)}</div>
|
|
1183
|
+
<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>
|
|
917
1184
|
<div class="preview" ${tid(TEST_IDS.smsThreadPreview)}>${esc(latest?.sms?.body ?? "")}</div></div></div></div>`;
|
|
918
|
-
}).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
|
|
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>`}
|
|
919
1186
|
</div>`;
|
|
920
1187
|
}
|
|
921
1188
|
const col = $("col-sms");
|
|
922
1189
|
flip(col, () => {
|
|
923
1190
|
col.innerHTML = `
|
|
924
|
-
|
|
925
|
-
<div class="iphone" ${tid(TEST_IDS.smsDevice)} data-screen="${thread ? "conversation" : "threads"}" data-recipient="${esc(to ?? "")}" data-thread="${esc(thread?.from ?? "")}"><div class="screen"><div class="island"></div>${statusBar()}${screen}<div class="home-indicator"></div></div></div>`;
|
|
1191
|
+
${deviceHead("Text messages", countBadge(unreadTotal, TEST_IDS.smsUnreadCount), recipientSelect("sms", "Phone", TEST_IDS.smsRecipient, formatPhone))}
|
|
1192
|
+
<div class="iphone" ${tid(TEST_IDS.smsDevice)} data-screen="${thread ? "conversation" : "threads"}" data-recipient="${esc(to ?? "")}" data-thread="${esc(thread?.from ?? "")}"${thread && isWhatsApp(thread.items[0]) ? ' data-via="whatsapp"' : ""}><div class="screen"><div class="island"></div>${statusBar()}${screen}<div class="home-indicator"></div></div></div>`;
|
|
926
1193
|
});
|
|
927
1194
|
const body = col.querySelector(".convo-body");
|
|
928
1195
|
const toBottom = () => {
|
|
@@ -930,6 +1197,7 @@ function createApp(root, options = {}) {
|
|
|
930
1197
|
};
|
|
931
1198
|
toBottom();
|
|
932
1199
|
requestAnimationFrame(toBottom);
|
|
1200
|
+
renderTabs();
|
|
933
1201
|
};
|
|
934
1202
|
const smsMenu = (n) => {
|
|
935
1203
|
const current = local.tapbacks.get(n.id);
|
|
@@ -1063,12 +1331,16 @@ function createApp(root, options = {}) {
|
|
|
1063
1331
|
const col = $("col-push");
|
|
1064
1332
|
flip(col, () => {
|
|
1065
1333
|
col.innerHTML = `
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
(
|
|
1070
|
-
|
|
1334
|
+
${deviceHead(
|
|
1335
|
+
"Push",
|
|
1336
|
+
countBadge(unread, TEST_IDS.pushUnreadCount),
|
|
1337
|
+
recipientSelect("push", "Device", TEST_IDS.pushRecipient, tokenLabel),
|
|
1338
|
+
`<div class="seg" role="group" aria-label="Phone">${["auto", "ios", "android"].map(
|
|
1339
|
+
(s) => `<button data-action="skin" data-value="${s}" ${tid(TEST_IDS.pushSkin)} aria-pressed="${state.push.skin === s}">${s === "auto" ? "Auto" : s === "ios" ? "iOS" : "Android"}</button>`
|
|
1340
|
+
).join("")}</div>`
|
|
1341
|
+
)}${device}`;
|
|
1071
1342
|
});
|
|
1343
|
+
renderTabs();
|
|
1072
1344
|
};
|
|
1073
1345
|
const mailHtml = (n) => {
|
|
1074
1346
|
const html = n.email?.html ?? "";
|
|
@@ -1166,7 +1438,11 @@ function createApp(root, options = {}) {
|
|
|
1166
1438
|
const col = $("col-email");
|
|
1167
1439
|
flip(col, () => {
|
|
1168
1440
|
col.innerHTML = `
|
|
1169
|
-
|
|
1441
|
+
${deviceHead(
|
|
1442
|
+
"Email",
|
|
1443
|
+
countBadge(unreadAll, TEST_IDS.emailUnreadCount),
|
|
1444
|
+
recipientSelect("email", "Mailbox", TEST_IDS.emailRecipient, (t) => t)
|
|
1445
|
+
)}
|
|
1170
1446
|
<div class="window" ${tid(TEST_IDS.emailDevice)} data-screen="${open ? "message" : "inbox"}" data-recipient="${esc(to ?? "")}">
|
|
1171
1447
|
<div class="chrome"><span class="lights"><i></i><i></i><i></i></span><span class="omnibox">${icons.lock()} mail.example.test/#inbox${open ? `/${esc(open.providerId)}` : ""}</span></div>
|
|
1172
1448
|
<div class="mail-top"><span class="icon-btn">${icons.menu()}</span><span class="mail-logo">${icons.envelope()}<span class="lbl">Mail</span></span>
|
|
@@ -1194,39 +1470,110 @@ function createApp(root, options = {}) {
|
|
|
1194
1470
|
});
|
|
1195
1471
|
frame.srcdoc = mailHtml(open);
|
|
1196
1472
|
}
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1473
|
+
updateTitle();
|
|
1474
|
+
renderTabs();
|
|
1475
|
+
};
|
|
1476
|
+
const unreadIn = (channel) => byChannel(channel).filter((n) => !seen.has(n.id)).length;
|
|
1477
|
+
const updateTitle = () => {
|
|
1478
|
+
if (!syncUrl || !live) return;
|
|
1479
|
+
const total = CHANNELS.reduce((sum, c) => sum + unreadIn(c), 0);
|
|
1480
|
+
document.title = `${total ? `(${total}) ` : ""}${title()} \xB7 Mockingbird`;
|
|
1481
|
+
};
|
|
1482
|
+
const chatLabel = (to) => to.startsWith("/services/") ? `Webhook \u2026${to.slice(-6)}` : to;
|
|
1483
|
+
const chatDay = (iso) => {
|
|
1484
|
+
const d = new Date(iso);
|
|
1485
|
+
const now = new Date(nowMs());
|
|
1486
|
+
if (sameDay(d, now)) return "Today";
|
|
1487
|
+
const y = new Date(now);
|
|
1488
|
+
y.setDate(now.getDate() - 1);
|
|
1489
|
+
if (sameDay(d, y)) return "Yesterday";
|
|
1490
|
+
return d.toLocaleDateString([], { weekday: "long", month: "long", day: "numeric" });
|
|
1491
|
+
};
|
|
1492
|
+
const chatMessage = (n) => {
|
|
1493
|
+
const c = n.chat;
|
|
1494
|
+
const author = n.from.name ?? n.from.address;
|
|
1495
|
+
const names = { name: (id) => c?.names?.[id] };
|
|
1496
|
+
const text = c?.text && !c.blocks.length ? `<div class="chat-text" ${tid(TEST_IDS.chatMessageText)}>${mrkdwn(c.text, names)}</div>` : "";
|
|
1497
|
+
const blocks = c?.blocks.length ? `<div class="chat-blocks" ${tid(TEST_IDS.chatMessageBlocks)}>${renderBlocks(c.blocks, names)}</div>` : "";
|
|
1498
|
+
const attachments = c?.attachments.length ? `<div class="chat-attachments" ${tid(TEST_IDS.chatMessageAttachments)}>${renderAttachments(c.attachments, names)}</div>` : "";
|
|
1499
|
+
const reactions = c?.reactions.length ? `<div class="chat-reactions">${c.reactions.map(
|
|
1500
|
+
(r) => `<span class="chat-reaction" ${tid(TEST_IDS.chatMessageReaction)} data-name="${esc(r.name)}" data-count="${r.count}">${esc(emoji(r.name))} ${r.count}</span>`
|
|
1501
|
+
).join("")}</div>` : "";
|
|
1502
|
+
return `<div class="chat-msg ${state.arrived.has(n.id) ? "arrive" : ""}" ${nAttrs(n)} ${tid(TEST_IDS.chatMessage)} data-method="${esc(c?.method ?? "")}" data-ephemeral="${c?.ephemeral ?? false}" data-thread="${esc(c?.threadTs ?? "")}" role="listitem" tabindex="0">
|
|
1503
|
+
<span class="chat-avatar" style="background:${colorFor(n.from.address, APP)}" aria-hidden="true">${esc(initials(author))}</span>
|
|
1504
|
+
<div class="chat-msg-main">
|
|
1505
|
+
<div class="chat-meta"><b ${tid(TEST_IDS.chatMessageAuthor)}>${esc(author)}</b><span class="chat-app">APP</span><span class="chat-time" ${tid(TEST_IDS.chatMessageTime)}>${esc(clock(new Date(n.createdAt)))}</span>${c?.edited ? '<span class="chat-edited">(edited)</span>' : ""}</div>
|
|
1506
|
+
${c?.ephemeral ? '<div class="chat-note">Only visible to you</div>' : ""}${c?.threadTs ? '<div class="chat-note">replied to a thread</div>' : ""}
|
|
1507
|
+
${text}${blocks}${attachments}${reactions}
|
|
1508
|
+
</div></div>`;
|
|
1509
|
+
};
|
|
1510
|
+
const renderChat = () => {
|
|
1511
|
+
const to = state.chat.to;
|
|
1512
|
+
const all = byChannel("chat");
|
|
1513
|
+
const items = to ? all.filter((n) => n.to === to).sort((a, b) => a.createdAt < b.createdAt ? -1 : 1) : [];
|
|
1514
|
+
markSeen(items.map((n) => n.id));
|
|
1515
|
+
const channels = recipients("chat");
|
|
1516
|
+
const workspace = all[0]?.chat?.workspace ?? "Workspace";
|
|
1517
|
+
let day = "";
|
|
1518
|
+
const list = items.map((n) => {
|
|
1519
|
+
const label = chatDay(n.createdAt);
|
|
1520
|
+
const divider = label === day ? "" : `<div class="chat-day"><span>${esc(label)}</span></div>`;
|
|
1521
|
+
day = label;
|
|
1522
|
+
return divider + chatMessage(n);
|
|
1523
|
+
}).join("");
|
|
1524
|
+
const col = $("col-chat");
|
|
1525
|
+
col.innerHTML = `
|
|
1526
|
+
${deviceHead("Chat", countBadge(unreadIn("chat"), TEST_IDS.chatUnreadCount), recipientSelect("chat", "Channel", TEST_IDS.chatRecipient, chatLabel))}
|
|
1527
|
+
<div class="window chat" ${tid(TEST_IDS.chatDevice)} data-recipient="${esc(to ?? "")}" data-workspace="${esc(workspace)}">
|
|
1528
|
+
<div class="chrome"><span class="lights"><i></i><i></i><i></i></span><span class="omnibox">${icons.lock()} chat.example.test/${esc(to ? chatLabel(to).replace(/^#/, "") : "")}</span></div>
|
|
1529
|
+
<div class="chat-body">
|
|
1530
|
+
<nav class="chat-side" aria-label="Channels">
|
|
1531
|
+
<div class="chat-team" ${tid(TEST_IDS.chatWorkspace)}>${esc(workspace)} ${icons.dropdown()}</div>
|
|
1532
|
+
<div class="chat-side-label">Channels</div>
|
|
1533
|
+
${channels.map(
|
|
1534
|
+
(r) => `<button class="chat-chan ${r.to === to ? "on" : ""} ${r.unread ? "unread" : ""}" data-action="chat-channel" data-value="${esc(r.to)}" ${tid(TEST_IDS.chatChannel)} data-to="${esc(r.to)}" data-unread="${r.unread}" aria-current="${r.to === to}"><span class="hash">${r.to.startsWith("#") ? "#" : "~"}</span><span class="lbl">${esc(chatLabel(r.to).replace(/^#/, ""))}</span>${r.unread ? `<span class="n">${r.unread}</span>` : ""}</button>`
|
|
1535
|
+
).join("")}
|
|
1536
|
+
</nav>
|
|
1537
|
+
<main class="chat-main">
|
|
1538
|
+
<header class="chat-head"><b ${tid(TEST_IDS.chatTitle)}>${esc(to ? chatLabel(to) : "Chat")}</b><span>${items.length ? `${items.length} message${items.length === 1 ? "" : "s"}` : ""}</span></header>
|
|
1539
|
+
<div class="chat-list" role="list">${list || `<div class="chat-empty" ${tid(TEST_IDS.chatEmpty)}><b>${to ? "No messages in this channel" : "No chat messages yet"}</b>${to ? "" : "Messages posted to the Slack emulator, with chat.postMessage or an incoming webhook, land here."}</div>`}</div>
|
|
1540
|
+
<div class="chat-compose"><span>Message ${esc(to ? chatLabel(to) : "channel")}</span><span class="send">${icons.send()}</span></div>
|
|
1541
|
+
</main>
|
|
1542
|
+
</div>
|
|
1543
|
+
</div>`;
|
|
1544
|
+
const log = col.querySelector(".chat-list");
|
|
1545
|
+
const toBottom = () => {
|
|
1546
|
+
if (log) log.scrollTop = log.scrollHeight;
|
|
1547
|
+
};
|
|
1548
|
+
toBottom();
|
|
1549
|
+
requestAnimationFrame(toBottom);
|
|
1550
|
+
renderTabs();
|
|
1204
1551
|
};
|
|
1205
1552
|
const renderTimeline = () => {
|
|
1206
1553
|
const items = visible();
|
|
1207
1554
|
$("timeline").innerHTML = items.length ? `<table class="tl" ${tid(TEST_IDS.timeline)}><thead><tr><th>Time</th><th>Channel</th><th>Source</th><th>To</th><th>From</th><th>Content</th><th>Status</th></tr></thead><tbody>${items.map(
|
|
1208
1555
|
(n) => `<tr data-action="inspect" data-id="${esc(n.id)}" ${nAttrs(n)} ${tid(TEST_IDS.timelineRow)} tabindex="0">
|
|
1209
1556
|
<td class="mono" data-col="time">${esc(timelineTime(n.createdAt))}</td>
|
|
1210
|
-
<td data-col="channel"><span class="chan ${n.channel}
|
|
1557
|
+
<td data-col="channel"><span class="chan ${n.channel} ${isWhatsApp(n) ? "wa" : ""}">${isWhatsApp(n) ? "WhatsApp" : CHANNEL_LABEL[n.channel]}</span></td>
|
|
1211
1558
|
<td data-col="source"><span class="svc-tag">${esc(SERVICE_LABEL[n.service] ?? n.service)}${n.source !== n.service ? ` \xB7 ${esc(n.source)}` : ""}</span></td>
|
|
1212
|
-
<td class="mono" data-col="to">${esc(n.channel === "sms" ? formatPhone(n.to) : n.to.length > 28 ? `${n.to.slice(0, 26)}\u2026` : n.to)}</td>
|
|
1559
|
+
<td class="mono" data-col="to">${esc(n.channel === "sms" ? formatPhone(n.to) : n.channel === "chat" ? chatLabel(n.to) : n.to.length > 28 ? `${n.to.slice(0, 26)}\u2026` : n.to)}</td>
|
|
1213
1560
|
<td data-col="from">${esc(displaySender(n))}</td>
|
|
1214
|
-
<td class="content" data-col="content">${n.email ? `<b>${esc(n.email.subject)}</b> \u2014 ` : n.push?.title ? `<b>${esc(n.push.title)}</b> \u2014 ` : ""}${esc(n.channel === "email" ? n.preview.slice(0, 120) : n.sms?.body ?? n.push?.body ?? n.preview)}</td>
|
|
1561
|
+
<td class="content" data-col="content">${n.email ? `<b>${esc(n.email.subject)}</b> \u2014 ` : n.push?.title ? `<b>${esc(n.push.title)}</b> \u2014 ` : ""}${esc(n.channel === "email" || n.channel === "chat" ? n.preview.slice(0, 120) : n.sms?.body ?? n.push?.body ?? n.preview)}</td>
|
|
1215
1562
|
<td class="svc-tag" data-col="status">${esc(n.status ?? "")}</td></tr>`
|
|
1216
1563
|
).join("")}</tbody></table>` : `<div class="empty-tl" ${tid(TEST_IDS.timelineEmpty)}>Nothing sent in namespace <b>${esc(state.namespace)}</b> yet.</div>`;
|
|
1217
1564
|
};
|
|
1218
1565
|
const renderInspector = () => {
|
|
1219
1566
|
const n = state.items.find((x) => x.id === state.inspect);
|
|
1220
|
-
const
|
|
1567
|
+
const el2 = $("inspector");
|
|
1221
1568
|
if (!n) {
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
for (const k of Object.keys(
|
|
1225
|
-
if (k !== "region" && k !== "testid") delete
|
|
1569
|
+
el2.hidden = true;
|
|
1570
|
+
el2.innerHTML = "";
|
|
1571
|
+
for (const k of Object.keys(el2.dataset))
|
|
1572
|
+
if (k !== "region" && k !== "testid") delete el2.dataset[k];
|
|
1226
1573
|
return;
|
|
1227
1574
|
}
|
|
1228
|
-
|
|
1229
|
-
Object.assign(
|
|
1575
|
+
el2.hidden = false;
|
|
1576
|
+
Object.assign(el2.dataset, {
|
|
1230
1577
|
notificationId: n.id,
|
|
1231
1578
|
channel: n.channel,
|
|
1232
1579
|
service: n.service,
|
|
@@ -1238,14 +1585,60 @@ function createApp(root, options = {}) {
|
|
|
1238
1585
|
});
|
|
1239
1586
|
const { raw, ...normalized } = n;
|
|
1240
1587
|
const field = (key, label, value) => `<span>${label}</span><span ${tid(TEST_IDS.inspectorField)} data-field="${key}">${esc(value)}</span>`;
|
|
1241
|
-
|
|
1588
|
+
el2.innerHTML = `<header><h3 ${tid(TEST_IDS.inspectorTitle)}>${esc(isWhatsApp(n) ? "WHATSAPP" : n.channel.toUpperCase())} \xB7 ${esc(n.email?.subject ?? n.push?.title ?? n.preview.slice(0, 60))}</h3>
|
|
1242
1589
|
<button class="btn" data-action="show-on-device" data-id="${esc(n.id)}" ${tid(TEST_IDS.inspectorShowOnDevice)}>Show on device</button><button class="btn" data-action="close-inspector" ${tid(TEST_IDS.inspectorClose)}>Close</button></header>
|
|
1243
1590
|
<div class="kv">${field("id", "Id", n.id)}${field("providerId", "Provider id", n.providerId)}${field("service", "Service", `${n.service} (${n.source})`)}
|
|
1244
1591
|
${field("namespace", "Namespace", n.namespace)}${field("to", "To", n.to)}${field("from", "From", n.from.name ? `${n.from.name} <${n.from.address}>` : n.from.address)}
|
|
1245
1592
|
${field("createdAt", "Created", n.createdAt)}${field("status", "Status", n.status ?? "\u2014")}</div>
|
|
1246
1593
|
<pre ${tid(TEST_IDS.inspectorJson)}>${esc(JSON.stringify({ ...normalized, raw }, null, 2))}</pre>`;
|
|
1247
1594
|
};
|
|
1248
|
-
const shown = (channel) =>
|
|
1595
|
+
const shown = (channel) => {
|
|
1596
|
+
const current = tab();
|
|
1597
|
+
return enabled.includes(channel) && (current === "all" || current === channel);
|
|
1598
|
+
};
|
|
1599
|
+
const selectTab = (value) => {
|
|
1600
|
+
state.only = value === "all" ? null : value;
|
|
1601
|
+
if (value !== "all") lastTab = value;
|
|
1602
|
+
if (syncUrl) {
|
|
1603
|
+
const url = new URL(location.href);
|
|
1604
|
+
if (value === "all") url.searchParams.delete("view");
|
|
1605
|
+
else url.searchParams.set("view", value);
|
|
1606
|
+
for (const key of ["to", "from", "id"]) url.searchParams.delete(key);
|
|
1607
|
+
if (pinned?.channel === value) url.searchParams.set("to", pinned.to);
|
|
1608
|
+
history.replaceState(null, "", url);
|
|
1609
|
+
}
|
|
1610
|
+
render();
|
|
1611
|
+
};
|
|
1612
|
+
const tabButton = (value) => root.querySelector(`[data-action="tab"][data-value="${value}"]`);
|
|
1613
|
+
const renderTabs = () => {
|
|
1614
|
+
const el2 = $("tabs");
|
|
1615
|
+
const tabs = options.tabs === false ? [] : tabsFor(enabled, compact);
|
|
1616
|
+
el2.hidden = !tabs.length || state.view !== "devices";
|
|
1617
|
+
for (const channel of CHANNELS) {
|
|
1618
|
+
const col = $(`col-${channel}`);
|
|
1619
|
+
if (tabs.length) {
|
|
1620
|
+
col.setAttribute("role", "tabpanel");
|
|
1621
|
+
col.setAttribute("aria-labelledby", `${uid}-tab-${channel}`);
|
|
1622
|
+
} else {
|
|
1623
|
+
col.removeAttribute("role");
|
|
1624
|
+
col.removeAttribute("aria-labelledby");
|
|
1625
|
+
}
|
|
1626
|
+
}
|
|
1627
|
+
if (el2.hidden) {
|
|
1628
|
+
el2.innerHTML = "";
|
|
1629
|
+
return;
|
|
1630
|
+
}
|
|
1631
|
+
const current = tab();
|
|
1632
|
+
const focused = el2.contains(document.activeElement) ? document.activeElement.dataset.value : void 0;
|
|
1633
|
+
el2.dataset.layout = compact ? "tabs" : "grid";
|
|
1634
|
+
el2.innerHTML = tabs.map((value) => {
|
|
1635
|
+
const selected = value === current;
|
|
1636
|
+
const unread = value === "all" ? 0 : unreadIn(value);
|
|
1637
|
+
const controls = value === "all" ? enabled.map((c) => `${uid}-panel-${c}`).join(" ") : `${uid}-panel-${value}`;
|
|
1638
|
+
return `<button role="tab" id="${uid}-tab-${value}" aria-selected="${selected}" aria-controls="${controls}" tabindex="${selected ? 0 : -1}" data-action="tab" data-value="${value}" ${tid(TEST_IDS.channelTab)} data-unread="${unread}">${TAB_LABELS[value]}${unread && !selected ? `<span class="tab-unread" ${tid(TEST_IDS.channelTabUnread)} aria-label="${unread} unread">${unread}</span>` : ""}</button>`;
|
|
1639
|
+
}).join("");
|
|
1640
|
+
if (focused) tabButton(focused)?.focus();
|
|
1641
|
+
};
|
|
1249
1642
|
const render = () => {
|
|
1250
1643
|
if (destroyed) return;
|
|
1251
1644
|
renderTopbar();
|
|
@@ -1257,11 +1650,21 @@ function createApp(root, options = {}) {
|
|
|
1257
1650
|
if (shown("sms")) renderSms();
|
|
1258
1651
|
if (shown("push")) renderPush();
|
|
1259
1652
|
if (shown("email")) renderEmail();
|
|
1653
|
+
if (shown("chat")) renderChat();
|
|
1260
1654
|
} else renderTimeline();
|
|
1655
|
+
renderTabs();
|
|
1261
1656
|
renderInspector();
|
|
1657
|
+
updateTitle();
|
|
1658
|
+
};
|
|
1659
|
+
const reveal = (channel) => {
|
|
1660
|
+
if (!enabled.includes(channel)) return;
|
|
1661
|
+
lastTab = channel;
|
|
1662
|
+
if (shown(channel)) return;
|
|
1663
|
+
state.only = channel;
|
|
1262
1664
|
};
|
|
1263
1665
|
const showOnDevice = (n) => {
|
|
1264
1666
|
state.view = "devices";
|
|
1667
|
+
reveal(n.channel);
|
|
1265
1668
|
state[n.channel].to = n.to;
|
|
1266
1669
|
if (n.channel === "sms") state.sms.thread = n.from.address;
|
|
1267
1670
|
if (n.channel === "email") state.email.open = n.id;
|
|
@@ -1274,12 +1677,12 @@ function createApp(root, options = {}) {
|
|
|
1274
1677
|
render();
|
|
1275
1678
|
root.querySelector(`.devices [data-notification-id="${CSS.escape(n.id)}"]`)?.scrollIntoView({ block: "nearest" });
|
|
1276
1679
|
};
|
|
1277
|
-
const collapse = (
|
|
1680
|
+
const collapse = (el2, then) => {
|
|
1278
1681
|
if (!animate()) return then();
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
void
|
|
1282
|
-
Object.assign(
|
|
1682
|
+
el2.style.height = `${el2.offsetHeight}px`;
|
|
1683
|
+
el2.classList.add("collapsing");
|
|
1684
|
+
void el2.offsetHeight;
|
|
1685
|
+
Object.assign(el2.style, {
|
|
1283
1686
|
height: "0px",
|
|
1284
1687
|
marginTop: "0px",
|
|
1285
1688
|
marginBottom: "0px",
|
|
@@ -1289,66 +1692,66 @@ function createApp(root, options = {}) {
|
|
|
1289
1692
|
});
|
|
1290
1693
|
later(270, then);
|
|
1291
1694
|
};
|
|
1292
|
-
const flyOut = (
|
|
1695
|
+
const flyOut = (row2, card, direction, then) => {
|
|
1293
1696
|
if (!animate()) return then();
|
|
1294
|
-
|
|
1697
|
+
row2.classList.add("settling");
|
|
1295
1698
|
card.classList.add("settling");
|
|
1296
|
-
card.style.transform = `translateX(${direction * (
|
|
1699
|
+
card.style.transform = `translateX(${direction * (row2.offsetWidth + 40)}px)`;
|
|
1297
1700
|
card.style.opacity = "0";
|
|
1298
|
-
later(230, () => collapse(
|
|
1701
|
+
later(230, () => collapse(row2, then));
|
|
1299
1702
|
};
|
|
1300
1703
|
const rowFor = (selector) => root.querySelector(selector);
|
|
1301
|
-
const cardIn = (
|
|
1704
|
+
const cardIn = (row2) => row2.querySelector(".swipe-card") ?? row2;
|
|
1302
1705
|
const dismissPush = (id, direction = -1) => {
|
|
1303
|
-
const
|
|
1706
|
+
const row2 = rowFor(`.ios-swipe[data-id="${CSS.escape(id)}"]`) ?? rowFor(`.a-note[data-id="${CSS.escape(id)}"]`);
|
|
1304
1707
|
const done = () => {
|
|
1305
1708
|
local.dismissed.add(id);
|
|
1306
1709
|
if (state.push.preview === id) state.push.preview = null;
|
|
1307
1710
|
renderPush();
|
|
1308
1711
|
};
|
|
1309
|
-
if (!
|
|
1310
|
-
flyOut(
|
|
1712
|
+
if (!row2) return done();
|
|
1713
|
+
flyOut(row2, cardIn(row2), direction, done);
|
|
1311
1714
|
};
|
|
1312
1715
|
const deleteThread = (from) => {
|
|
1313
1716
|
const to = state.sms.to;
|
|
1314
1717
|
if (!to) return;
|
|
1315
1718
|
const ids = byChannel("sms").filter((n) => n.to === to && n.from.address === from).map((n) => n.id);
|
|
1316
|
-
const
|
|
1719
|
+
const row2 = rowFor(`.thread-swipe[data-from="${CSS.escape(from)}"]`);
|
|
1317
1720
|
const done = () => {
|
|
1318
1721
|
for (const id of ids) local.dismissed.add(id);
|
|
1319
1722
|
renderSms();
|
|
1320
1723
|
};
|
|
1321
|
-
if (!
|
|
1322
|
-
flyOut(
|
|
1724
|
+
if (!row2) return done();
|
|
1725
|
+
flyOut(row2, cardIn(row2), -1, done);
|
|
1323
1726
|
};
|
|
1324
1727
|
const removeEmail = (id, verb, direction = -1) => {
|
|
1325
|
-
const
|
|
1326
|
-
if (!
|
|
1327
|
-
flyOut(
|
|
1728
|
+
const row2 = rowFor(`.mrow-swipe[data-id="${CSS.escape(id)}"]`);
|
|
1729
|
+
if (!row2) return archiveEmail(id, verb);
|
|
1730
|
+
flyOut(row2, cardIn(row2), direction, () => archiveEmail(id, verb));
|
|
1328
1731
|
};
|
|
1329
1732
|
let drag = null;
|
|
1330
1733
|
let suppressClick = false;
|
|
1331
1734
|
const IOS_OPEN = 160;
|
|
1332
1735
|
const THREAD_OPEN = 148;
|
|
1333
|
-
const setOffset = (
|
|
1334
|
-
const card = cardIn(
|
|
1736
|
+
const setOffset = (row2, x) => {
|
|
1737
|
+
const card = cardIn(row2);
|
|
1335
1738
|
card.style.transform = x ? `translateX(${x}px)` : "";
|
|
1336
|
-
if (
|
|
1337
|
-
card.style.opacity = String(1 - Math.min(0.9, Math.abs(x) /
|
|
1338
|
-
};
|
|
1339
|
-
const settle = (
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
if (
|
|
1343
|
-
setOffset(
|
|
1739
|
+
if (row2.dataset.swipe === "a-note")
|
|
1740
|
+
card.style.opacity = String(1 - Math.min(0.9, Math.abs(x) / row2.offsetWidth));
|
|
1741
|
+
};
|
|
1742
|
+
const settle = (row2, x, open) => {
|
|
1743
|
+
row2.classList.add("settling");
|
|
1744
|
+
row2.classList.toggle("open", open);
|
|
1745
|
+
if (row2.dataset.swipe === "a-note") row2.classList.add("settling");
|
|
1746
|
+
setOffset(row2, x);
|
|
1344
1747
|
later(340, () => {
|
|
1345
|
-
|
|
1346
|
-
|
|
1748
|
+
row2.classList.remove("settling", "swiping");
|
|
1749
|
+
row2.dataset.offset = String(x);
|
|
1347
1750
|
});
|
|
1348
1751
|
};
|
|
1349
|
-
const longPress = (
|
|
1350
|
-
const kind =
|
|
1351
|
-
const id =
|
|
1752
|
+
const longPress = (el2) => {
|
|
1753
|
+
const kind = el2.dataset.longpress;
|
|
1754
|
+
const id = el2.dataset.notificationId ?? el2.dataset.id ?? "";
|
|
1352
1755
|
if (kind === "sms-bubble") {
|
|
1353
1756
|
state.sms.menu = id;
|
|
1354
1757
|
renderSms();
|
|
@@ -1397,8 +1800,9 @@ function createApp(root, options = {}) {
|
|
|
1397
1800
|
});
|
|
1398
1801
|
on("pointermove", (event) => {
|
|
1399
1802
|
if (!drag || event.pointerId !== drag.pointerId) return;
|
|
1400
|
-
const
|
|
1401
|
-
const
|
|
1803
|
+
const zoom = zoomOf(drag.swipe ?? root);
|
|
1804
|
+
const dx = (event.clientX - drag.x0) / zoom;
|
|
1805
|
+
const dy = (event.clientY - drag.y0) / zoom;
|
|
1402
1806
|
if (!drag.axis) {
|
|
1403
1807
|
if (Math.hypot(dx, dy) < 8) return;
|
|
1404
1808
|
drag.axis = Math.abs(dx) > Math.abs(dy) ? "x" : "y";
|
|
@@ -1419,8 +1823,8 @@ function createApp(root, options = {}) {
|
|
|
1419
1823
|
const kind = drag.swipe.dataset.swipe;
|
|
1420
1824
|
let x = drag.base + dx;
|
|
1421
1825
|
if (kind === "sms-convo") {
|
|
1422
|
-
const
|
|
1423
|
-
drag.swipe.style.setProperty("--reveal", `${
|
|
1826
|
+
const reveal2 = Math.max(0, Math.min(72, -dx));
|
|
1827
|
+
drag.swipe.style.setProperty("--reveal", `${reveal2}px`);
|
|
1424
1828
|
return;
|
|
1425
1829
|
}
|
|
1426
1830
|
if (kind === "ios-note" && x > 0) x = x * 0.35;
|
|
@@ -1434,38 +1838,38 @@ function createApp(root, options = {}) {
|
|
|
1434
1838
|
if (d.timer) clearTimeout(d.timer);
|
|
1435
1839
|
if (d.axis !== "x" || !d.swipe) return;
|
|
1436
1840
|
suppressClick = true;
|
|
1437
|
-
const
|
|
1438
|
-
const kind =
|
|
1439
|
-
const width =
|
|
1841
|
+
const row2 = d.swipe;
|
|
1842
|
+
const kind = row2.dataset.swipe;
|
|
1843
|
+
const width = row2.offsetWidth || 1;
|
|
1440
1844
|
const velocity = d.dx / Math.max(1, performance.now() - d.t0);
|
|
1441
1845
|
const x = d.base + d.dx;
|
|
1442
1846
|
if (kind === "sms-convo") {
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
later(320, () =>
|
|
1847
|
+
row2.classList.add("settling");
|
|
1848
|
+
row2.style.setProperty("--reveal", "0px");
|
|
1849
|
+
later(320, () => row2.classList.remove("settling"));
|
|
1446
1850
|
} else if (kind === "ios-note") {
|
|
1447
|
-
const id =
|
|
1851
|
+
const id = row2.dataset.id ?? "";
|
|
1448
1852
|
if (x < -width * 0.7 || velocity < -1.1 && x < -60) dismissPush(id);
|
|
1449
|
-
else if (x < -60) settle(
|
|
1853
|
+
else if (x < -60) settle(row2, -IOS_OPEN, true);
|
|
1450
1854
|
else if (x > 70) {
|
|
1451
|
-
settle(
|
|
1855
|
+
settle(row2, 0, false);
|
|
1452
1856
|
state.push.expanded = id;
|
|
1453
1857
|
renderPush();
|
|
1454
|
-
} else settle(
|
|
1858
|
+
} else settle(row2, 0, false);
|
|
1455
1859
|
} else if (kind === "a-note") {
|
|
1456
1860
|
if (Math.abs(x) > width * 0.4 || Math.abs(velocity) > 0.7)
|
|
1457
|
-
dismissPush(
|
|
1458
|
-
else settle(
|
|
1861
|
+
dismissPush(row2.dataset.id ?? "", Math.sign(x) || 1);
|
|
1862
|
+
else settle(row2, 0, false);
|
|
1459
1863
|
} else if (kind === "sms-thread") {
|
|
1460
|
-
const from =
|
|
1864
|
+
const from = row2.dataset.from ?? "";
|
|
1461
1865
|
if (x < -width * 0.6) deleteThread(from);
|
|
1462
|
-
else if (x < -50) settle(
|
|
1463
|
-
else if (x > 50) settle(
|
|
1464
|
-
else settle(
|
|
1866
|
+
else if (x < -50) settle(row2, -THREAD_OPEN, true);
|
|
1867
|
+
else if (x > 50) settle(row2, THREAD_OPEN, true);
|
|
1868
|
+
else settle(row2, 0, false);
|
|
1465
1869
|
} else if (kind === "mrow") {
|
|
1466
1870
|
if (Math.abs(x) > width * 0.35 || Math.abs(velocity) > 0.8)
|
|
1467
|
-
removeEmail(
|
|
1468
|
-
else settle(
|
|
1871
|
+
removeEmail(row2.dataset.id ?? "", "archived", Math.sign(x) || 1);
|
|
1872
|
+
else settle(row2, 0, false);
|
|
1469
1873
|
}
|
|
1470
1874
|
};
|
|
1471
1875
|
on("pointerup", endDrag);
|
|
@@ -1521,6 +1925,13 @@ function createApp(root, options = {}) {
|
|
|
1521
1925
|
state.view = target.dataset.value === "timeline" ? "timeline" : "devices";
|
|
1522
1926
|
render();
|
|
1523
1927
|
break;
|
|
1928
|
+
case "tab":
|
|
1929
|
+
selectTab(target.dataset.value ?? "all");
|
|
1930
|
+
break;
|
|
1931
|
+
case "chat-channel":
|
|
1932
|
+
state.chat.to = target.dataset.value ?? null;
|
|
1933
|
+
renderChat();
|
|
1934
|
+
break;
|
|
1524
1935
|
case "sound":
|
|
1525
1936
|
handle.setSound(!sound.enabled);
|
|
1526
1937
|
break;
|
|
@@ -1609,21 +2020,21 @@ function createApp(root, options = {}) {
|
|
|
1609
2020
|
break;
|
|
1610
2021
|
}
|
|
1611
2022
|
case "push-clear-all": {
|
|
1612
|
-
const
|
|
1613
|
-
const ids =
|
|
2023
|
+
const rows2 = [...root.querySelectorAll(".shade-list .a-note")];
|
|
2024
|
+
const ids = rows2.map((r) => r.dataset.id ?? "");
|
|
1614
2025
|
const done = () => {
|
|
1615
2026
|
for (const x of ids) local.dismissed.add(x);
|
|
1616
2027
|
renderPush();
|
|
1617
2028
|
};
|
|
1618
2029
|
if (!animate()) return done();
|
|
1619
|
-
|
|
2030
|
+
rows2.forEach((row2, i) => {
|
|
1620
2031
|
later(i * 60, () => {
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
2032
|
+
row2.classList.add("settling");
|
|
2033
|
+
row2.style.transform = `translateX(${row2.offsetWidth + 40}px)`;
|
|
2034
|
+
row2.style.opacity = "0";
|
|
1624
2035
|
});
|
|
1625
2036
|
});
|
|
1626
|
-
later(
|
|
2037
|
+
later(rows2.length * 60 + 300, done);
|
|
1627
2038
|
break;
|
|
1628
2039
|
}
|
|
1629
2040
|
case "group-open":
|
|
@@ -1750,6 +2161,15 @@ function createApp(root, options = {}) {
|
|
|
1750
2161
|
return;
|
|
1751
2162
|
}
|
|
1752
2163
|
if (target.matches("input, select, textarea")) return;
|
|
2164
|
+
if (target.matches('[role="tab"]')) {
|
|
2165
|
+
const next = moveTab(tabsFor(enabled, compact), tab(), event.key);
|
|
2166
|
+
if (next) {
|
|
2167
|
+
event.preventDefault();
|
|
2168
|
+
selectTab(next);
|
|
2169
|
+
tabButton(next)?.focus();
|
|
2170
|
+
}
|
|
2171
|
+
return;
|
|
2172
|
+
}
|
|
1753
2173
|
if (event.key === "ContextMenu" || event.shiftKey && event.key === "F10") {
|
|
1754
2174
|
const press = target.closest("[data-longpress]");
|
|
1755
2175
|
if (press) {
|
|
@@ -1806,9 +2226,13 @@ function createApp(root, options = {}) {
|
|
|
1806
2226
|
if (n) return showOnDevice(n);
|
|
1807
2227
|
if (target.channel) {
|
|
1808
2228
|
state.view = "devices";
|
|
2229
|
+
reveal(target.channel);
|
|
1809
2230
|
if (target.to) state[target.channel].to = target.to;
|
|
1810
|
-
if (target.channel === "sms" && target.to)
|
|
2231
|
+
if (target.channel === "sms" && target.to) {
|
|
1811
2232
|
state.sms.thread = smsThreads(target.to)[0]?.from ?? null;
|
|
2233
|
+
awaitedSms = state.sms.thread === null ? target.to : null;
|
|
2234
|
+
}
|
|
2235
|
+
if (target.channel === "email") state.email.open = null;
|
|
1812
2236
|
render();
|
|
1813
2237
|
}
|
|
1814
2238
|
},
|
|
@@ -1819,6 +2243,7 @@ function createApp(root, options = {}) {
|
|
|
1819
2243
|
state.sms = { ...state.sms, to: null, thread: null, menu: null };
|
|
1820
2244
|
state.email = { ...state.email, to: null, open: null };
|
|
1821
2245
|
state.push.to = null;
|
|
2246
|
+
state.chat.to = null;
|
|
1822
2247
|
loadSeen();
|
|
1823
2248
|
if (syncUrl) {
|
|
1824
2249
|
const url = new URL(location.href);
|
|
@@ -1831,16 +2256,22 @@ function createApp(root, options = {}) {
|
|
|
1831
2256
|
});
|
|
1832
2257
|
} else render();
|
|
1833
2258
|
},
|
|
1834
|
-
setSound(
|
|
1835
|
-
sound.enabled =
|
|
1836
|
-
if (
|
|
2259
|
+
setSound(enabled2) {
|
|
2260
|
+
sound.enabled = enabled2;
|
|
2261
|
+
if (enabled2) sound.unlock();
|
|
1837
2262
|
if (storage)
|
|
1838
2263
|
try {
|
|
1839
|
-
localStorage.setItem(soundKey,
|
|
2264
|
+
localStorage.setItem(soundKey, enabled2 ? "1" : "0");
|
|
1840
2265
|
} catch {
|
|
1841
2266
|
}
|
|
1842
2267
|
renderTopbar();
|
|
1843
2268
|
},
|
|
2269
|
+
setScale(next) {
|
|
2270
|
+
if (deviceScale(next) === scale) return;
|
|
2271
|
+
scale = deviceScale(next);
|
|
2272
|
+
fit();
|
|
2273
|
+
render();
|
|
2274
|
+
},
|
|
1844
2275
|
destroy() {
|
|
1845
2276
|
destroyed = true;
|
|
1846
2277
|
listeners.abort();
|
|
@@ -1848,12 +2279,23 @@ function createApp(root, options = {}) {
|
|
|
1848
2279
|
for (const t of timers) clearTimeout(t);
|
|
1849
2280
|
timers.clear();
|
|
1850
2281
|
for (const t of intervals) clearInterval(t);
|
|
2282
|
+
resizes?.disconnect();
|
|
1851
2283
|
sound.close();
|
|
1852
2284
|
root.innerHTML = "";
|
|
1853
2285
|
root.classList.remove(ROOT_CLASS, "embedded");
|
|
2286
|
+
root.style.removeProperty("--mbn-fit");
|
|
2287
|
+
root.style.removeProperty("--mbn-scale");
|
|
1854
2288
|
}
|
|
1855
2289
|
};
|
|
1856
2290
|
const intervals = [];
|
|
2291
|
+
fit();
|
|
2292
|
+
const refit = () => {
|
|
2293
|
+
if (fit()) render();
|
|
2294
|
+
};
|
|
2295
|
+
const resizes = typeof ResizeObserver === "function" ? new ResizeObserver(refit) : null;
|
|
2296
|
+
if (resizes) resizes.observe(root);
|
|
2297
|
+
else if (typeof window !== "undefined")
|
|
2298
|
+
window.addEventListener("resize", refit, { signal: listeners.signal });
|
|
1857
2299
|
if (!live) {
|
|
1858
2300
|
state.items = [...options.items ?? []].sort((a, b) => a.createdAt < b.createdAt ? 1 : -1);
|
|
1859
2301
|
state.sources = options.sources ?? [];
|
|
@@ -1895,28 +2337,261 @@ function createApp(root, options = {}) {
|
|
|
1895
2337
|
return handle;
|
|
1896
2338
|
}
|
|
1897
2339
|
|
|
1898
|
-
// src/ui.ts
|
|
1899
|
-
var
|
|
1900
|
-
var installStyles = (host) => {
|
|
2340
|
+
// src/ui/mount.ts
|
|
2341
|
+
var installStyles = (host, id, css) => {
|
|
1901
2342
|
const rootNode = host.getRootNode();
|
|
1902
2343
|
const target = rootNode instanceof ShadowRoot ? rootNode : document.head;
|
|
1903
|
-
if (target.querySelector(`#${
|
|
2344
|
+
if (target.querySelector(`#${id}`)) return;
|
|
1904
2345
|
const style = document.createElement("style");
|
|
1905
|
-
style.id =
|
|
1906
|
-
style.textContent =
|
|
2346
|
+
style.id = id;
|
|
2347
|
+
style.textContent = css;
|
|
1907
2348
|
target.append(style);
|
|
1908
2349
|
};
|
|
1909
2350
|
var mountNotifications = (host, options = {}) => {
|
|
1910
2351
|
const { harness, injectStyles = true, ...rest } = options;
|
|
1911
|
-
if (injectStyles) installStyles(host);
|
|
2352
|
+
if (injectStyles) installStyles(host, "mockingbird-notifications-styles", STYLES);
|
|
1912
2353
|
if (harness) rest.fetch = (request) => harness.fetch(request);
|
|
1913
2354
|
return createApp(host, { embedded: true, syncUrl: false, ...rest });
|
|
1914
2355
|
};
|
|
2356
|
+
|
|
2357
|
+
// src/ui/dashboard.ts
|
|
2358
|
+
var EMULATORS_TAB = "emulators";
|
|
2359
|
+
var NOTIFICATIONS_TAB = "notifications";
|
|
2360
|
+
var el = (tag, className, attrs = {}) => {
|
|
2361
|
+
const node = document.createElement(tag);
|
|
2362
|
+
node.className = className;
|
|
2363
|
+
for (const [name, value] of Object.entries(attrs)) node.setAttribute(name, value);
|
|
2364
|
+
return node;
|
|
2365
|
+
};
|
|
2366
|
+
var instances = 0;
|
|
2367
|
+
var createDashboard = (host, options, mountUi) => {
|
|
2368
|
+
const uid = `mbd-${++instances}`;
|
|
2369
|
+
const specs = [
|
|
2370
|
+
...options.tabs ?? [],
|
|
2371
|
+
...options.emulators ? [
|
|
2372
|
+
{
|
|
2373
|
+
id: EMULATORS_TAB,
|
|
2374
|
+
label: options.emulators.label ?? "Emulators",
|
|
2375
|
+
mount: options.emulators.mount
|
|
2376
|
+
}
|
|
2377
|
+
] : [],
|
|
2378
|
+
...options.notifications ? [
|
|
2379
|
+
{
|
|
2380
|
+
id: NOTIFICATIONS_TAB,
|
|
2381
|
+
label: options.notifications.label ?? "Notifications",
|
|
2382
|
+
mount: null
|
|
2383
|
+
}
|
|
2384
|
+
] : []
|
|
2385
|
+
];
|
|
2386
|
+
if (specs.length === 0) throw new Error("mountDashboard: pass tabs, emulators or notifications");
|
|
2387
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2388
|
+
for (const spec of specs) {
|
|
2389
|
+
if (seen.has(spec.id)) throw new Error(`mountDashboard: duplicate tab id ${spec.id}`);
|
|
2390
|
+
seen.add(spec.id);
|
|
2391
|
+
}
|
|
2392
|
+
if (options.injectStyles ?? true)
|
|
2393
|
+
installStyles(host, "mockingbird-dashboard-styles", DASHBOARD_STYLES);
|
|
2394
|
+
host.classList.add(DASHBOARD_ROOT_CLASS);
|
|
2395
|
+
host.setAttribute("data-testid", TEST_IDS.dashboard);
|
|
2396
|
+
host.setAttribute("data-theme", options.theme ?? "dark");
|
|
2397
|
+
host.replaceChildren();
|
|
2398
|
+
const bar = el("header", "mbd-bar");
|
|
2399
|
+
if (options.title) {
|
|
2400
|
+
const brand = el("div", "mbd-brand");
|
|
2401
|
+
const mark = el("i", "mbd-mark", { "aria-hidden": "true" });
|
|
2402
|
+
mark.textContent = "\u25C6";
|
|
2403
|
+
const name = el("span", "");
|
|
2404
|
+
name.textContent = options.title;
|
|
2405
|
+
brand.append(mark, name);
|
|
2406
|
+
bar.append(brand);
|
|
2407
|
+
}
|
|
2408
|
+
const tablist = el("div", "mbd-tabs", {
|
|
2409
|
+
role: "tablist",
|
|
2410
|
+
"aria-label": options.title ?? "Dashboard"
|
|
2411
|
+
});
|
|
2412
|
+
const aside = el("div", "mbd-aside");
|
|
2413
|
+
const panels = el("div", "mbd-panels");
|
|
2414
|
+
bar.append(tablist, aside);
|
|
2415
|
+
host.append(bar, panels);
|
|
2416
|
+
const badge = el("span", "mbd-badge", { "data-testid": TEST_IDS.dashboardBadge });
|
|
2417
|
+
badge.hidden = true;
|
|
2418
|
+
let unread = 0;
|
|
2419
|
+
const drawBadge = () => {
|
|
2420
|
+
badge.hidden = unread === 0;
|
|
2421
|
+
badge.textContent = unread > 99 ? "99+" : String(unread);
|
|
2422
|
+
badge.setAttribute("data-count", String(unread));
|
|
2423
|
+
badge.setAttribute("aria-label", `${unread} new`);
|
|
2424
|
+
};
|
|
2425
|
+
drawBadge();
|
|
2426
|
+
const entries = specs.map((spec) => {
|
|
2427
|
+
const button2 = el("button", "mbd-tab", {
|
|
2428
|
+
type: "button",
|
|
2429
|
+
role: "tab",
|
|
2430
|
+
id: `${uid}-tab-${spec.id}`,
|
|
2431
|
+
"aria-controls": `${uid}-panel-${spec.id}`,
|
|
2432
|
+
"aria-selected": "false",
|
|
2433
|
+
tabindex: "-1",
|
|
2434
|
+
"data-testid": TEST_IDS.dashboardTab,
|
|
2435
|
+
"data-tab": spec.id
|
|
2436
|
+
});
|
|
2437
|
+
const label = el("span", "");
|
|
2438
|
+
label.textContent = spec.label;
|
|
2439
|
+
button2.append(label);
|
|
2440
|
+
if (spec.id === NOTIFICATIONS_TAB) button2.append(badge);
|
|
2441
|
+
const panel = el("section", "mbd-panel", {
|
|
2442
|
+
role: "tabpanel",
|
|
2443
|
+
id: `${uid}-panel-${spec.id}`,
|
|
2444
|
+
"aria-labelledby": `${uid}-tab-${spec.id}`,
|
|
2445
|
+
"data-testid": TEST_IDS.dashboardPanel,
|
|
2446
|
+
"data-tab": spec.id
|
|
2447
|
+
});
|
|
2448
|
+
panel.hidden = true;
|
|
2449
|
+
tablist.append(button2);
|
|
2450
|
+
panels.append(panel);
|
|
2451
|
+
return { id: spec.id, button: button2, panel, mount: spec.mount, mounted: false, dispose: null };
|
|
2452
|
+
});
|
|
2453
|
+
let destroyed = false;
|
|
2454
|
+
let current = "";
|
|
2455
|
+
const status = (entry, kind, text) => {
|
|
2456
|
+
const note = el("div", "mbd-status", { "data-kind": kind });
|
|
2457
|
+
note.textContent = text;
|
|
2458
|
+
entry.panel.append(note);
|
|
2459
|
+
return note;
|
|
2460
|
+
};
|
|
2461
|
+
const mountEntry = (entry) => {
|
|
2462
|
+
if (entry.mounted || !entry.mount) return;
|
|
2463
|
+
entry.mounted = true;
|
|
2464
|
+
const settle = (result) => {
|
|
2465
|
+
if (typeof result !== "function") return;
|
|
2466
|
+
const dispose = result;
|
|
2467
|
+
if (destroyed) dispose();
|
|
2468
|
+
else entry.dispose = dispose;
|
|
2469
|
+
};
|
|
2470
|
+
try {
|
|
2471
|
+
const result = entry.mount(entry.panel);
|
|
2472
|
+
if (!(result instanceof Promise)) return settle(result);
|
|
2473
|
+
entry.panel.setAttribute("aria-busy", "true");
|
|
2474
|
+
const loading = status(entry, "loading", "Loading\u2026");
|
|
2475
|
+
result.then(
|
|
2476
|
+
(dispose) => {
|
|
2477
|
+
loading.remove();
|
|
2478
|
+
entry.panel.removeAttribute("aria-busy");
|
|
2479
|
+
settle(dispose);
|
|
2480
|
+
},
|
|
2481
|
+
(error) => {
|
|
2482
|
+
loading.remove();
|
|
2483
|
+
entry.panel.removeAttribute("aria-busy");
|
|
2484
|
+
if (!destroyed)
|
|
2485
|
+
status(entry, "error", error instanceof Error ? error.message : String(error));
|
|
2486
|
+
}
|
|
2487
|
+
);
|
|
2488
|
+
} catch (error) {
|
|
2489
|
+
status(entry, "error", error instanceof Error ? error.message : String(error));
|
|
2490
|
+
}
|
|
2491
|
+
};
|
|
2492
|
+
const show = (id) => {
|
|
2493
|
+
const next = entries.find((entry) => entry.id === id);
|
|
2494
|
+
if (!next || destroyed || id === current) return;
|
|
2495
|
+
const first = current === "";
|
|
2496
|
+
current = id;
|
|
2497
|
+
host.setAttribute("data-tab", id);
|
|
2498
|
+
for (const entry of entries) {
|
|
2499
|
+
const on = entry === next;
|
|
2500
|
+
entry.button.setAttribute("aria-selected", String(on));
|
|
2501
|
+
entry.button.setAttribute("tabindex", on ? "0" : "-1");
|
|
2502
|
+
entry.panel.hidden = !on;
|
|
2503
|
+
}
|
|
2504
|
+
if (id === NOTIFICATIONS_TAB) {
|
|
2505
|
+
unread = 0;
|
|
2506
|
+
drawBadge();
|
|
2507
|
+
}
|
|
2508
|
+
mountEntry(next);
|
|
2509
|
+
if (options.syncUrl && typeof location !== "undefined" && typeof history !== "undefined") {
|
|
2510
|
+
const url = new URL(location.href);
|
|
2511
|
+
if (url.searchParams.get("tab") !== id && !(first && !url.searchParams.has("tab"))) {
|
|
2512
|
+
url.searchParams.set("tab", id);
|
|
2513
|
+
history.replaceState(history.state, "", url);
|
|
2514
|
+
}
|
|
2515
|
+
}
|
|
2516
|
+
if (!first) options.onTabChange?.(id);
|
|
2517
|
+
};
|
|
2518
|
+
const onClick = (entry) => () => show(entry.id);
|
|
2519
|
+
const onKey = (entry) => (event) => {
|
|
2520
|
+
const key = event.key;
|
|
2521
|
+
const at = entries.indexOf(entry);
|
|
2522
|
+
const to = key === "ArrowRight" ? (at + 1) % entries.length : key === "ArrowLeft" ? (at - 1 + entries.length) % entries.length : key === "Home" ? 0 : key === "End" ? entries.length - 1 : -1;
|
|
2523
|
+
const target = entries[to];
|
|
2524
|
+
if (!target) return;
|
|
2525
|
+
event.preventDefault();
|
|
2526
|
+
show(target.id);
|
|
2527
|
+
target.button.focus();
|
|
2528
|
+
};
|
|
2529
|
+
const unlisten = entries.map((entry) => {
|
|
2530
|
+
const click = onClick(entry);
|
|
2531
|
+
const key = onKey(entry);
|
|
2532
|
+
entry.button.addEventListener("click", click);
|
|
2533
|
+
entry.button.addEventListener("keydown", key);
|
|
2534
|
+
return () => {
|
|
2535
|
+
entry.button.removeEventListener("click", click);
|
|
2536
|
+
entry.button.removeEventListener("keydown", key);
|
|
2537
|
+
};
|
|
2538
|
+
});
|
|
2539
|
+
let notifications;
|
|
2540
|
+
const notificationsEntry = entries.find((entry) => entry.id === NOTIFICATIONS_TAB);
|
|
2541
|
+
if (options.notifications && notificationsEntry) {
|
|
2542
|
+
const { label: _label, onArrive, ...rest } = options.notifications;
|
|
2543
|
+
notificationsEntry.mounted = true;
|
|
2544
|
+
const frame = el("div", "mbd-fill");
|
|
2545
|
+
notificationsEntry.panel.append(frame);
|
|
2546
|
+
notifications = mountUi(frame, {
|
|
2547
|
+
...rest,
|
|
2548
|
+
onArrive(added) {
|
|
2549
|
+
if (current !== NOTIFICATIONS_TAB) {
|
|
2550
|
+
unread += added.length;
|
|
2551
|
+
drawBadge();
|
|
2552
|
+
}
|
|
2553
|
+
onArrive?.(added);
|
|
2554
|
+
}
|
|
2555
|
+
});
|
|
2556
|
+
}
|
|
2557
|
+
const fromUrl = options.syncUrl && typeof location !== "undefined" ? new URL(location.href).searchParams.get("tab") : null;
|
|
2558
|
+
const wanted = [fromUrl, options.initialTab].find(
|
|
2559
|
+
(id) => id != null && entries.some((entry) => entry.id === id)
|
|
2560
|
+
);
|
|
2561
|
+
show(wanted ?? entries[0].id);
|
|
2562
|
+
return {
|
|
2563
|
+
show,
|
|
2564
|
+
active: () => current,
|
|
2565
|
+
tabs: () => entries.map((entry) => entry.id),
|
|
2566
|
+
aside,
|
|
2567
|
+
...notifications ? { notifications } : {},
|
|
2568
|
+
destroy() {
|
|
2569
|
+
if (destroyed) return;
|
|
2570
|
+
destroyed = true;
|
|
2571
|
+
for (const off of unlisten) off();
|
|
2572
|
+
notifications?.destroy();
|
|
2573
|
+
for (const entry of entries) {
|
|
2574
|
+
try {
|
|
2575
|
+
entry.dispose?.();
|
|
2576
|
+
} catch {
|
|
2577
|
+
}
|
|
2578
|
+
entry.dispose = null;
|
|
2579
|
+
}
|
|
2580
|
+
host.replaceChildren();
|
|
2581
|
+
host.classList.remove(DASHBOARD_ROOT_CLASS);
|
|
2582
|
+
for (const name of ["data-testid", "data-theme", "data-tab"]) host.removeAttribute(name);
|
|
2583
|
+
}
|
|
2584
|
+
};
|
|
2585
|
+
};
|
|
2586
|
+
var mountDashboard = (host, options) => createDashboard(host, options, mountNotifications);
|
|
1915
2587
|
export {
|
|
2588
|
+
DASHBOARD_ROOT_CLASS,
|
|
2589
|
+
DASHBOARD_STYLES,
|
|
1916
2590
|
ROOT_CLASS,
|
|
1917
2591
|
STYLES,
|
|
1918
2592
|
TEST_IDS,
|
|
1919
2593
|
createApp,
|
|
2594
|
+
mountDashboard,
|
|
1920
2595
|
mountNotifications,
|
|
1921
2596
|
selectors
|
|
1922
2597
|
};
|