inboxer 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ui/routes.js +141 -58
- package/dist/ui/static/app.js +46 -0
- package/dist/ui/static/style.css +295 -70
- package/dist/ui/strings.d.ts +12 -6
- package/dist/ui/strings.js +12 -6
- package/dist/ui/views.d.ts +50 -15
- package/dist/ui/views.js +300 -136
- package/package.json +3 -2
- package/src/ui/routes.ts +59 -41
- package/src/ui/static/app.js +19 -0
- package/src/ui/static/style.css +31 -19
- package/src/ui/strings.ts +0 -4
- package/src/ui/views.ts +82 -90
package/dist/ui/views.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { html, raw } from "hono/html";
|
|
2
|
+
import { bareAddress } from "../core/address.js";
|
|
2
3
|
import { ASSETS } from "./assets.js";
|
|
3
4
|
import { S } from "./strings.js";
|
|
4
5
|
/** Views never await, so `html` returns a plain escaped string. */
|
|
@@ -11,43 +12,129 @@ function join(items) {
|
|
|
11
12
|
function when(condition, view) {
|
|
12
13
|
return condition ? view() : "";
|
|
13
14
|
}
|
|
14
|
-
|
|
15
|
+
const ICONS = {
|
|
16
|
+
back: '<path d="M15 18l-6-6 6-6"/>',
|
|
17
|
+
archive: '<rect x="3" y="4" width="18" height="5" rx="1"/><path d="M5 9v10a1 1 0 001 1h12a1 1 0 001-1V9"/><path d="M10 13h4"/>',
|
|
18
|
+
unarchive: '<rect x="3" y="4" width="18" height="5" rx="1"/><path d="M5 9v10a1 1 0 001 1h12a1 1 0 001-1V9"/><path d="M12 17v-5M9.5 14.5L12 12l2.5 2.5"/>',
|
|
19
|
+
drafts: '<path d="M4 20h4L19 9l-4-4L4 16z"/><path d="M13 7l4 4"/>',
|
|
20
|
+
inbox: '<path d="M3 13l3-8h12l3 8v6a1 1 0 01-1 1H4a1 1 0 01-1-1z"/><path d="M3 13h5l1 3h6l1-3h5"/>',
|
|
21
|
+
plus: '<path d="M12 5v14M5 12h14"/>',
|
|
22
|
+
devices: '<rect x="6" y="2" width="12" height="20" rx="2"/><path d="M11 18h2"/>',
|
|
23
|
+
settings: '<circle cx="12" cy="12" r="3"/><path d="M12 2v3M12 19v3M4.2 4.2l2.1 2.1M17.7 17.7l2.1 2.1M2 12h3M19 12h3M4.2 19.8l2.1-2.1M17.7 6.3l2.1-2.1"/>',
|
|
24
|
+
send: '<path d="M5 12h14"/><path d="M13 6l6 6-6 6"/>',
|
|
25
|
+
close: '<path d="M6 6l12 12M18 6L6 18"/>',
|
|
26
|
+
attach: '<path d="M20.5 11.5l-8.2 8.2a5 5 0 01-7-7l8.2-8.2a3.3 3.3 0 014.7 4.7l-8.2 8.2a1.7 1.7 0 01-2.4-2.4l7.6-7.6"/>',
|
|
27
|
+
};
|
|
28
|
+
function icon(name) {
|
|
29
|
+
return raw(`<svg class="icon" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">${ICONS[name]}</svg>`);
|
|
30
|
+
}
|
|
31
|
+
const sameDay = (a, b) => a.toDateString() === b.toDateString();
|
|
32
|
+
function formatTime(iso) {
|
|
33
|
+
return new Date(iso).toLocaleTimeString("en", { hour: "2-digit", minute: "2-digit", hourCycle: "h23" });
|
|
34
|
+
}
|
|
35
|
+
function formatDay(iso) {
|
|
15
36
|
const date = new Date(iso);
|
|
16
|
-
const
|
|
17
|
-
return
|
|
18
|
-
? date.
|
|
37
|
+
const now = new Date();
|
|
38
|
+
return date.getFullYear() === now.getFullYear()
|
|
39
|
+
? date.toLocaleDateString("en", { month: "short", day: "numeric" })
|
|
19
40
|
: date.toLocaleDateString("en", { month: "short", day: "numeric", year: "numeric" });
|
|
20
41
|
}
|
|
42
|
+
/** A time today, a day otherwise. */
|
|
43
|
+
function formatDate(iso) {
|
|
44
|
+
return sameDay(new Date(iso), new Date()) ? formatTime(iso) : formatDay(iso);
|
|
45
|
+
}
|
|
46
|
+
function dayLabel(iso) {
|
|
47
|
+
const date = new Date(iso);
|
|
48
|
+
const yesterday = new Date(Date.now() - 86_400_000);
|
|
49
|
+
if (sameDay(date, new Date()))
|
|
50
|
+
return S.today;
|
|
51
|
+
if (sameDay(date, yesterday))
|
|
52
|
+
return S.yesterday;
|
|
53
|
+
return formatDay(iso);
|
|
54
|
+
}
|
|
55
|
+
/** Display name from `Name <a@b.com>`, else the bare address. */
|
|
56
|
+
function displayName(address) {
|
|
57
|
+
const match = /^\s*"?([^"<]+?)"?\s*</.exec(address);
|
|
58
|
+
return match ? match[1] : bareAddress(address);
|
|
59
|
+
}
|
|
60
|
+
function initials(address) {
|
|
61
|
+
const name = displayName(address);
|
|
62
|
+
const words = (name.includes("@") ? name.split("@")[0] : name).split(/[\s._-]+/).filter(Boolean);
|
|
63
|
+
return (words.length > 1 ? words[0][0] + words[1][0] : (words[0] ?? "?").slice(0, 2)).toUpperCase();
|
|
64
|
+
}
|
|
21
65
|
export function layout(title, body, opts) {
|
|
22
|
-
const
|
|
66
|
+
const link = (page, href, label, name, extra = "") => h `<a href="${href}" ${raw(opts.page === page ? 'aria-current="page"' : "")}>${icon(name)}<span>${label}</span>${extra}</a>`;
|
|
67
|
+
const count = opts.draftCount ? h `<span class="count">${opts.draftCount}</span>` : "";
|
|
68
|
+
const canSend = !!opts.senders?.length;
|
|
23
69
|
return h `<!doctype html>
|
|
24
70
|
<html lang="en" ${raw(opts.theme === "system" ? "" : `data-theme="${opts.theme}"`)}>
|
|
25
71
|
<head>
|
|
26
72
|
<meta charset="utf-8">
|
|
27
|
-
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
73
|
+
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
|
|
28
74
|
<title>${title} · ${S.appName}</title>
|
|
29
75
|
<link rel="stylesheet" href="${ASSETS["style.css"].url}">
|
|
30
76
|
<script src="${ASSETS["htmx.min.js"].url}" defer></script>
|
|
31
77
|
<script src="${ASSETS["app.js"].url}" defer></script>
|
|
32
78
|
</head>
|
|
33
|
-
<body>
|
|
34
|
-
${when(opts.signedIn, () => h `<
|
|
35
|
-
<
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
${
|
|
79
|
+
<body class="${opts.signedIn ? "app" : ""} ${opts.fullScreen ? "full" : ""}">
|
|
80
|
+
${when(opts.signedIn, () => h `<aside class="sidebar">
|
|
81
|
+
<div class="brand">${S.appName}<span>.</span></div>
|
|
82
|
+
${when(canSend, () => h `<button type="button" class="primary new-mail" data-compose>${icon("plus")}${S.newMail}</button>`)}
|
|
83
|
+
<nav class="side-nav" aria-label="${S.mainNav}">
|
|
84
|
+
${link("drafts", "/", S.navDrafts, "drafts", count)}
|
|
85
|
+
${link("inbox", "/inbox", S.navInbox, "inbox")}
|
|
86
|
+
${link("devices", "/devices", S.navDevices, "devices")}
|
|
39
87
|
</nav>
|
|
40
|
-
<
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
</
|
|
47
|
-
|
|
88
|
+
<nav class="side-nav side-end" aria-label="${S.navSettings}">${link("settings", "/settings", S.navSettings, "settings")}</nav>
|
|
89
|
+
</aside>`)}
|
|
90
|
+
<main>${body}</main>
|
|
91
|
+
${when(opts.signedIn, () => h `<nav class="tabbar" aria-label="${S.mainNav}">
|
|
92
|
+
${link("drafts", "/", S.navDrafts, "drafts", count)}
|
|
93
|
+
${link("inbox", "/inbox", S.navInbox, "inbox")}
|
|
94
|
+
${when(canSend, () => h `<button type="button" class="tab-compose" data-compose aria-label="${S.newMail}"><span>${icon("plus")}</span></button>`)}
|
|
95
|
+
${link("devices", "/devices", S.navDevices, "devices")}
|
|
96
|
+
${link("settings", "/settings", S.navSettings, "settings")}
|
|
97
|
+
</nav>`)}
|
|
98
|
+
${when(opts.signedIn && canSend, () => composeDialog(opts.senders))}
|
|
99
|
+
${when(opts.signedIn, () => h `<dialog class="sheet" id="edit-sheet" aria-label="${S.edit}"></dialog>`)}
|
|
48
100
|
</body>
|
|
49
101
|
</html>`;
|
|
50
102
|
}
|
|
103
|
+
/** New mail, opened from the sidebar or the tab bar; a bottom sheet on a phone. */
|
|
104
|
+
function composeDialog(senders) {
|
|
105
|
+
return h `<dialog class="sheet" id="compose" aria-label="${S.newMail}">
|
|
106
|
+
<form method="post" action="/compose" enctype="multipart/form-data" data-drop>
|
|
107
|
+
<div class="grabber" aria-hidden="true"></div>
|
|
108
|
+
<button type="button" class="icon-btn sheet-close" data-close aria-label="${S.close}">${icon("close")}</button>
|
|
109
|
+
<div class="field compact">
|
|
110
|
+
<label for="compose-from">${S.from}</label>
|
|
111
|
+
${senders.length > 1
|
|
112
|
+
? h `<span class="select"><select id="compose-from" name="mailbox">${join(senders.map(m => h `<option value="${m.id}">${m.address}</option>`))}</select></span>`
|
|
113
|
+
: h `<input type="hidden" name="mailbox" value="${senders[0].id}"><output id="compose-from">${senders[0].address}</output>`}
|
|
114
|
+
</div>
|
|
115
|
+
<div class="field">
|
|
116
|
+
<label for="compose-to">${S.to}</label>
|
|
117
|
+
<input id="compose-to" name="to" autocomplete="off" required>
|
|
118
|
+
<button type="button" class="link" onclick="this.remove();var r=document.getElementById('compose-cc-row');r.hidden=false;r.querySelector('input').focus()">${S.cc}</button>
|
|
119
|
+
</div>
|
|
120
|
+
<div class="field" id="compose-cc-row" hidden>
|
|
121
|
+
<label for="compose-cc">${S.cc}</label>
|
|
122
|
+
<input id="compose-cc" name="cc" autocomplete="off">
|
|
123
|
+
</div>
|
|
124
|
+
<div class="field">
|
|
125
|
+
<label for="compose-subject">${S.subject}</label>
|
|
126
|
+
<input id="compose-subject" name="subject" required>
|
|
127
|
+
</div>
|
|
128
|
+
<textarea name="text" aria-label="${S.body}" required></textarea>
|
|
129
|
+
<div class="sheet-actions">
|
|
130
|
+
<label class="icon-btn" aria-label="${S.attach}">${icon("attach")}<input type="file" name="files" id="compose-files" multiple hidden></label>
|
|
131
|
+
<output class="sheet-files" id="compose-file-names"></output>
|
|
132
|
+
<button type="submit" name="action" value="save">${S.saveDraft}</button>
|
|
133
|
+
<button type="submit" name="action" value="send" class="primary">${S.send}${icon("send")}</button>
|
|
134
|
+
</div>
|
|
135
|
+
</form>
|
|
136
|
+
</dialog>`;
|
|
137
|
+
}
|
|
51
138
|
export function message(lines) {
|
|
52
139
|
return h `<div class="centered">${join(lines.map(l => h `<p>${l}</p>`))}</div>`;
|
|
53
140
|
}
|
|
@@ -60,7 +147,7 @@ export function signIn(token, valid) {
|
|
|
60
147
|
</div>`;
|
|
61
148
|
}
|
|
62
149
|
function mailboxBadge(mailbox) {
|
|
63
|
-
return h `<span class="badge">${mailbox}</span>`;
|
|
150
|
+
return h `<span class="badge mailbox">${mailbox}</span>`;
|
|
64
151
|
}
|
|
65
152
|
const PREVIEWABLE = new Set(["image/png", "image/jpeg", "image/gif", "image/webp", "image/avif"]);
|
|
66
153
|
/** Image types a browser renders without running code; SVG is left out on purpose. */
|
|
@@ -95,33 +182,35 @@ function withoutImagePlaceholders(m) {
|
|
|
95
182
|
}
|
|
96
183
|
return text.replace(/\n{3,}/g, "\n\n").trim();
|
|
97
184
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
185
|
+
function recipients(m) {
|
|
186
|
+
if (!m.to.length && !m.cc.length)
|
|
187
|
+
return "";
|
|
188
|
+
return h `<div class="meta">${when(m.to.length, () => h `<span>${S.to}: ${m.to.join(", ")}</span>`)}${when(m.cc.length, () => h `<span>${S.cc}: ${m.cc.join(", ")}</span>`)}</div>`;
|
|
189
|
+
}
|
|
190
|
+
/** A message in a thread: received ones on the left, ours on the right. */
|
|
191
|
+
export function messageBubble(m, showSender) {
|
|
192
|
+
const mine = m.direction === "out";
|
|
193
|
+
const extra = m.cc.length || m.to.length > (mine ? 1 : 0);
|
|
194
|
+
return h `<article class="msg ${mine ? "mine" : "theirs"}" id="m-${m.id}">
|
|
195
|
+
${when(showSender && !mine, () => h `<div class="msg-from">${displayName(m.from)}</div>`)}
|
|
196
|
+
${extra ? recipients(m) : ""}
|
|
106
197
|
<pre class="body">${withoutImagePlaceholders(m)}</pre>
|
|
107
198
|
${attachments(m)}
|
|
199
|
+
<span class="msg-time">${formatTime(m.date)}${mine ? ` · ${m.status}` : ""}</span>
|
|
108
200
|
</article>`;
|
|
109
201
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
if (!ctx)
|
|
113
|
-
return "";
|
|
114
|
-
const rows = [
|
|
115
|
-
...ctx.contacts.map(c => ({ who: c.address, meta: c.meta, note: c.note })),
|
|
202
|
+
function contextRows(ctx) {
|
|
203
|
+
return [
|
|
116
204
|
...(ctx.context ? [{ who: S.thisThread, meta: ctx.context.meta, note: ctx.context.note }] : []),
|
|
205
|
+
...ctx.contacts.map(c => ({ who: c.address, meta: c.meta, note: c.note })),
|
|
117
206
|
].filter(r => r.note || Object.keys(r.meta).length);
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
return
|
|
207
|
+
}
|
|
208
|
+
function contextSections(rows) {
|
|
209
|
+
return join(rows.map(r => h `<section>
|
|
121
210
|
<div class="who">${r.who}</div>
|
|
122
211
|
${when(Object.keys(r.meta).length, () => h `<dl>${join(Object.entries(r.meta).map(([k, v]) => h `<dt>${k}</dt><dd>${String(v)}</dd>`))}</dl>`)}
|
|
123
212
|
${when(r.note, () => h `<p>${r.note}</p>`)}
|
|
124
|
-
</section>`))
|
|
213
|
+
</section>`));
|
|
125
214
|
}
|
|
126
215
|
/** A send or discard in its undo window; reloads itself when the window closes. */
|
|
127
216
|
function pendingCard(d) {
|
|
@@ -134,142 +223,217 @@ function pendingCard(d) {
|
|
|
134
223
|
<i class="countdown" style="animation-duration: ${left}ms"></i>
|
|
135
224
|
</article>`;
|
|
136
225
|
}
|
|
137
|
-
|
|
226
|
+
/** A draft for review, on our side of its thread. */
|
|
227
|
+
export function draftCard(d) {
|
|
138
228
|
if (d.pending)
|
|
139
229
|
return pendingCard(d);
|
|
140
|
-
return h `<article class="card" id="draft-${d.id}">
|
|
230
|
+
return h `<article class="card draft" id="draft-${d.id}">
|
|
141
231
|
<div class="meta">
|
|
142
|
-
${mailboxBadge(d.mailbox)}
|
|
143
232
|
<span class="badge draft">${S.draft}</span>
|
|
144
|
-
${
|
|
145
|
-
<span>${formatDate(d.created_at)}</span>
|
|
233
|
+
${mailboxBadge(d.mailbox)}
|
|
234
|
+
<span>${d.edited_by_human ? S.editedByHuman : S.byAgent} · ${formatDate(d.created_at)}</span>
|
|
235
|
+
</div>
|
|
236
|
+
<div class="draft-head">
|
|
237
|
+
<div class="meta"><span>${S.to}: <strong>${d.to.join(", ")}</strong></span>${when(d.cc.length, () => h `<span>${S.cc}: ${d.cc.join(", ")}</span>`)}</div>
|
|
238
|
+
<div class="subject">${d.subject}</div>
|
|
146
239
|
</div>
|
|
147
|
-
<div class="meta"><span>${S.to}: <strong>${d.to.join(", ")}</strong></span>${when(d.cc.length, () => h `<span>${S.cc}: ${d.cc.join(", ")}</span>`)}</div>
|
|
148
|
-
<div class="subject">${d.subject}</div>
|
|
149
|
-
${contextBlock(ctx)}
|
|
150
240
|
${when(d.note, () => h `<div class="note">${d.note}</div>`)}
|
|
151
241
|
<pre class="body">${d.text}</pre>
|
|
152
242
|
${attachments(d)}
|
|
153
243
|
<div class="actions">
|
|
154
|
-
<button hx-get="/drafts/${d.id}/edit" hx-target="#draft-${d.id}" hx-swap="outerHTML">${S.edit}</button>
|
|
155
|
-
<button class="primary" hx-post="/drafts/${d.id}/send" hx-target="#draft-${d.id}" hx-swap="outerHTML">${S.send}</button>
|
|
156
244
|
<button class="danger" hx-post="/drafts/${d.id}/discard" hx-target="#draft-${d.id}" hx-swap="outerHTML">${S.discard}</button>
|
|
245
|
+
<button hx-get="/drafts/${d.id}/edit" hx-target="#edit-sheet" hx-swap="innerHTML">${S.edit}</button>
|
|
246
|
+
<button class="primary" hx-post="/drafts/${d.id}/send" hx-target="#draft-${d.id}" hx-swap="outerHTML">${S.send}</button>
|
|
157
247
|
</div>
|
|
158
|
-
${when(history.length, () => h `<details>
|
|
159
|
-
<summary>${S.thread} (${history.length})</summary>
|
|
160
|
-
${join(history.map(messageCard))}
|
|
161
|
-
</details>`)}
|
|
162
248
|
</article>`;
|
|
163
249
|
}
|
|
250
|
+
/** The edit sheet's content; one draft is edited at a time. */
|
|
164
251
|
export function draftEditor(d, form, conflict) {
|
|
165
252
|
const version = conflict ? conflict.version : d.version;
|
|
166
|
-
return h `<
|
|
253
|
+
return h `<form class="${conflict ? "conflict" : ""}" hx-post="/drafts/${d.id}/save" hx-target="#edit-sheet" hx-swap="innerHTML" data-drop>
|
|
254
|
+
<div class="grabber" aria-hidden="true"></div>
|
|
167
255
|
<div class="drop-hint">${S.dropFiles}</div>
|
|
168
|
-
<
|
|
256
|
+
<button type="button" class="icon-btn sheet-close" data-close aria-label="${S.close}">${icon("close")}</button>
|
|
257
|
+
<div class="sheet-head"><span class="badge draft">${S.draft}</span>${mailboxBadge(d.mailbox)}</div>
|
|
169
258
|
${when(d.note, () => h `<div class="note">${d.note}</div>`)}
|
|
170
|
-
${when(conflict, () => h `<
|
|
171
|
-
|
|
172
|
-
<
|
|
173
|
-
|
|
174
|
-
<label for="to-${d.id}">${S.to}</label>
|
|
175
|
-
<input id="to-${d.id}" name="to" value="${form.to}" autocomplete="off" required>
|
|
176
|
-
${when(!form.cc, () => h `<button type="button" class="link" onclick="this.remove();var r=document.getElementById('cc-row-${d.id}');r.hidden=false;r.querySelector('input').focus()">${S.cc}</button>`)}
|
|
177
|
-
</div>
|
|
178
|
-
<div class="field" id="cc-row-${d.id}" ${raw(form.cc ? "" : "hidden")}>
|
|
179
|
-
<label for="cc-${d.id}">${S.cc}</label>
|
|
180
|
-
<input id="cc-${d.id}" name="cc" value="${form.cc}" autocomplete="off">
|
|
181
|
-
</div>
|
|
182
|
-
<div class="field">
|
|
183
|
-
<label for="subject-${d.id}">${S.subject}</label>
|
|
184
|
-
<input id="subject-${d.id}" name="subject" value="${form.subject}" required>
|
|
185
|
-
</div>
|
|
186
|
-
<textarea id="text-${d.id}" name="text" aria-label="${S.body}" required>${form.text}</textarea>
|
|
187
|
-
${draftFiles(d, null)}
|
|
188
|
-
<div class="actions">
|
|
189
|
-
<button type="submit">${S.save}</button>
|
|
190
|
-
<button type="submit" name="send" value="1" class="primary">${S.saveAndSend}</button>
|
|
191
|
-
<button type="button" class="link" hx-get="/drafts/${d.id}/card" hx-target="#draft-${d.id}" hx-swap="outerHTML">${S.cancel}</button>
|
|
192
|
-
</div>
|
|
193
|
-
</form>
|
|
194
|
-
${when(conflict, () => h `<details open>
|
|
195
|
-
<summary>${S.currentVersion}</summary>
|
|
196
|
-
<div class="card">
|
|
259
|
+
${when(conflict, () => h `<div class="sheet-conflict">
|
|
260
|
+
<p class="warn">${S.conflictTitle}</p>
|
|
261
|
+
<details>
|
|
262
|
+
<summary>${S.currentVersion}</summary>
|
|
197
263
|
<div class="meta"><span>${S.to}: ${conflict.to.join(", ")}</span>${when(conflict.cc.length, () => h `<span>${S.cc}: ${conflict.cc.join(", ")}</span>`)}</div>
|
|
198
264
|
<div class="subject">${conflict.subject}</div>
|
|
199
265
|
<pre class="body">${conflict.text}</pre>
|
|
200
|
-
</
|
|
201
|
-
</
|
|
202
|
-
|
|
266
|
+
</details>
|
|
267
|
+
</div>`)}
|
|
268
|
+
<input type="hidden" name="version" value="${version}">
|
|
269
|
+
<div class="field">
|
|
270
|
+
<label for="to-${d.id}">${S.to}</label>
|
|
271
|
+
<input id="to-${d.id}" name="to" value="${form.to}" autocomplete="off" required>
|
|
272
|
+
${when(!form.cc, () => h `<button type="button" class="link" onclick="this.remove();var r=document.getElementById('cc-row-${d.id}');r.hidden=false;r.querySelector('input').focus()">${S.cc}</button>`)}
|
|
273
|
+
</div>
|
|
274
|
+
<div class="field" id="cc-row-${d.id}" ${raw(form.cc ? "" : "hidden")}>
|
|
275
|
+
<label for="cc-${d.id}">${S.cc}</label>
|
|
276
|
+
<input id="cc-${d.id}" name="cc" value="${form.cc}" autocomplete="off">
|
|
277
|
+
</div>
|
|
278
|
+
<div class="field">
|
|
279
|
+
<label for="subject-${d.id}">${S.subject}</label>
|
|
280
|
+
<input id="subject-${d.id}" name="subject" value="${form.subject}" required>
|
|
281
|
+
</div>
|
|
282
|
+
<textarea id="text-${d.id}" name="text" aria-label="${S.body}" required>${form.text}</textarea>
|
|
283
|
+
<div class="sheet-actions">
|
|
284
|
+
${draftFiles(d, null)}
|
|
285
|
+
<button type="submit">${S.save}</button>
|
|
286
|
+
<button type="submit" name="send" value="1" class="primary">${S.saveAndSend}</button>
|
|
287
|
+
</div>
|
|
288
|
+
</form>`;
|
|
289
|
+
}
|
|
290
|
+
/** A reply opened in the edit sheet from the reply box; the thread reloads when the sheet closes, to show the new draft. */
|
|
291
|
+
export function newReplyEditor(d) {
|
|
292
|
+
return h `<div data-reload-on-close hidden></div>${draftEditor(d, { to: d.to.join(", "), cc: d.cc.join(", "), subject: d.subject, text: d.text }, null)}`;
|
|
203
293
|
}
|
|
204
294
|
/** The editor's attachment list with remove buttons, and the picker that drag and drop also feeds. */
|
|
205
295
|
export function draftFiles(d, error) {
|
|
206
296
|
return h `<div class="draft-files" id="files-${d.id}">
|
|
297
|
+
<label class="icon-btn" aria-label="${S.attach}">${icon("attach")}<input type="file" name="files" multiple hidden hx-post="/drafts/${d.id}/attachments" hx-encoding="multipart/form-data" hx-trigger="change" hx-target="#files-${d.id}" hx-swap="outerHTML" hx-include="this"></label>
|
|
207
298
|
${join(d.attachments.map(a => h `<span class="file"><span>${a.filename}</span><span class="size">${formatSize(a.size)}</span><button type="button" class="link" aria-label="${S.remove} ${a.filename}" hx-post="/drafts/${d.id}/attachments/${a.id}/remove" hx-target="#files-${d.id}" hx-swap="outerHTML">×</button></span>`))}
|
|
208
|
-
<label class="file attach">${S.attach}<input type="file" name="files" multiple hidden hx-post="/drafts/${d.id}/attachments" hx-encoding="multipart/form-data" hx-trigger="change" hx-target="#files-${d.id}" hx-swap="outerHTML" hx-include="this"></label>
|
|
209
299
|
${when(error, () => h `<p class="warn">${error}</p>`)}
|
|
210
300
|
</div>`;
|
|
211
301
|
}
|
|
212
302
|
export function draftDone(id, text) {
|
|
213
303
|
return h `<article class="card notice" id="draft-${id}">${text}</article>`;
|
|
214
304
|
}
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
<
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
</
|
|
231
|
-
|
|
232
|
-
</form>
|
|
233
|
-
${threads.length ? join(threads.map(t => threadRow(t, own))) : h `<p class="empty">${S.inboxEmpty}</p>`}`;
|
|
305
|
+
/** Drafts waiting for review, listed like the inbox; each opens its thread. */
|
|
306
|
+
export function draftList(drafts, current) {
|
|
307
|
+
return h `<section class="list">
|
|
308
|
+
<header class="list-head"><h1>${S.navDrafts}</h1></header>
|
|
309
|
+
${drafts.length ? join(drafts.map(d => h `<a class="row" href="/drafts/${d.id}" ${raw(d.id === current ? 'aria-current="page"' : "")}>
|
|
310
|
+
<span class="avatar" aria-hidden="true">${initials(d.to[0] ?? d.mailbox)}</span>
|
|
311
|
+
<span class="row-main">
|
|
312
|
+
<span class="row-top"><span class="who">${d.to.map(displayName).join(", ") || "—"}</span><time datetime="${d.created_at}">${formatDate(d.created_at)}</time></span>
|
|
313
|
+
<span class="row-subject">${d.subject || "—"}</span>
|
|
314
|
+
<span class="row-snippet">${d.text}</span>
|
|
315
|
+
<span class="row-tags">
|
|
316
|
+
${mailboxBadge(d.mailbox)}
|
|
317
|
+
<span class="row-by">${d.edited_by_human ? S.editedByHuman : S.byAgent}</span>
|
|
318
|
+
</span>
|
|
319
|
+
</span>
|
|
320
|
+
</a>`)) : h `<p class="empty">${S.draftsEmpty}</p>`}
|
|
321
|
+
</section>`;
|
|
234
322
|
}
|
|
235
|
-
function
|
|
236
|
-
return
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
<
|
|
244
|
-
|
|
323
|
+
export function inboxQuery(filter) {
|
|
324
|
+
return new URLSearchParams({ status: filter.status, ...(filter.mailbox ? { mailbox: filter.mailbox } : {}) }).toString();
|
|
325
|
+
}
|
|
326
|
+
/** The thread list; on a wide screen it stays beside the open thread. */
|
|
327
|
+
export function threadList(threads, opts) {
|
|
328
|
+
const { filter } = opts;
|
|
329
|
+
const tab = (status, label) => h `<a class="chip" href="/inbox?${inboxQuery({ ...filter, status })}" ${raw(filter.status === status ? 'aria-current="page"' : "")}>${label}</a>`;
|
|
330
|
+
return h `<section class="list">
|
|
331
|
+
<header class="list-head">
|
|
332
|
+
<h1>${opts.domains.length ? opts.domains.join(" · ") : S.navInbox}</h1>
|
|
333
|
+
<form class="filters" method="get" action="/inbox">
|
|
334
|
+
<input type="hidden" name="status" value="${filter.status}">
|
|
335
|
+
<nav class="chips" aria-label="${S.filter}">${tab("unanswered", S.filterPending)}${tab("all", S.filterAll)}${tab("archived", S.filterArchived)}</nav>
|
|
336
|
+
${when(opts.mailboxes.length > 1, () => h `<span class="select"><select name="mailbox" aria-label="${S.allMailboxes}" onchange="this.form.submit()">
|
|
337
|
+
<option value="">${S.allMailboxes}</option>
|
|
338
|
+
${join(opts.mailboxes.map(m => h `<option value="${m}" ${raw(m === filter.mailbox ? "selected" : "")}>${m}</option>`))}
|
|
339
|
+
</select></span>`)}
|
|
340
|
+
</form>
|
|
341
|
+
</header>
|
|
342
|
+
${threads.length ? join(threads.map(t => threadRow(t, opts))) : h `<p class="empty">${S.inboxEmpty}</p>`}
|
|
343
|
+
</section>`;
|
|
344
|
+
}
|
|
345
|
+
function threadRow(t, opts) {
|
|
346
|
+
const people = t.participants.filter(p => !opts.own.has(p));
|
|
347
|
+
return h `<a class="row ${t.unread ? "unread" : ""}" href="/threads/${t.id}?${inboxQuery(opts.filter)}" ${raw(t.id === opts.current ? 'aria-current="page"' : "")}>
|
|
348
|
+
<span class="avatar" aria-hidden="true">${initials(people[0] ?? t.mailbox)}</span>
|
|
349
|
+
<span class="row-main">
|
|
350
|
+
<span class="row-top"><span class="who">${people.join(", ") || t.mailbox}</span><time datetime="${t.last_at}">${formatDate(t.last_at)}</time></span>
|
|
351
|
+
<span class="row-subject">${t.subject || "—"}</span>
|
|
352
|
+
${when(t.has_draft || opts.mailboxes.length > 1 || t.unread, () => h `<span class="row-tags">
|
|
353
|
+
${when(t.has_draft, () => h `<span class="badge draft">${S.hasDraft}</span>`)}
|
|
354
|
+
${when(opts.mailboxes.length > 1, () => mailboxBadge(t.mailbox))}
|
|
355
|
+
${when(t.unread, () => h `<span class="dot" title="${S.unread}"></span>`)}
|
|
356
|
+
</span>`)}
|
|
357
|
+
</span>
|
|
245
358
|
</a>`;
|
|
246
359
|
}
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
360
|
+
/** The thread list and the open thread side by side; a phone shows one of the two. */
|
|
361
|
+
export function inboxPage(list, thread) {
|
|
362
|
+
return h `<div class="split ${thread ? "has-thread" : ""}">${list}<section class="pane">${thread ?? ""}</section></div>`;
|
|
363
|
+
}
|
|
364
|
+
/** The conversation, oldest first, with day separators, a reply box and the context panel. */
|
|
365
|
+
export function threadView(thread, entries, ctx, opts) {
|
|
366
|
+
const query = inboxQuery(opts.filter);
|
|
367
|
+
const rows = contextRows(ctx);
|
|
368
|
+
const people = thread.participants.filter(p => !opts.own.has(p));
|
|
369
|
+
const title = h `<span class="thread-subject">${thread.subject || "—"}</span><span class="thread-meta">${[...people, thread.mailbox].join(" · ")}</span>`;
|
|
370
|
+
const items = [];
|
|
371
|
+
let day = "";
|
|
372
|
+
for (const entry of entries) {
|
|
373
|
+
const label = dayLabel(entry.at);
|
|
374
|
+
if (label !== day)
|
|
375
|
+
items.push(h `<div class="day">${label}</div>`);
|
|
376
|
+
day = label;
|
|
377
|
+
items.push(entry.view);
|
|
378
|
+
}
|
|
379
|
+
return h `<div class="thread">
|
|
380
|
+
<header class="thread-head">
|
|
381
|
+
<a class="icon-btn back" href="${opts.back}" aria-label="${S.back}">${icon("back")}</a>
|
|
382
|
+
${rows.length
|
|
383
|
+
? h `<button type="button" class="thread-title" data-context-toggle aria-controls="context">${title}</button>`
|
|
384
|
+
: h `<div class="thread-title">${title}</div>`}
|
|
385
|
+
${when(rows.length, () => h `<button type="button" class="context-btn" data-context-toggle aria-controls="context">${S.context}</button>`)}
|
|
386
|
+
${archiveButton(thread)}
|
|
387
|
+
</header>
|
|
388
|
+
<div class="messages" data-scroll-end>${join(items)}</div>
|
|
389
|
+
${when(opts.reply.allowed, () => h `<form class="composer" method="post" action="/threads/${thread.id}/reply?${query}">
|
|
390
|
+
${when(opts.reply.replyAll, () => h `<label class="reply-all"><input type="checkbox" name="reply_all" value="1">${S.replyAll}</label>`)}
|
|
391
|
+
<button type="button" class="icon-btn" aria-label="${S.attach}" title="${S.attach}" hx-post="/threads/${thread.id}/reply/full" hx-target="#edit-sheet" hx-swap="innerHTML">${icon("attach")}</button>
|
|
392
|
+
<textarea name="text" rows="1" aria-label="${S.reply}" placeholder="${S.reply}…" required></textarea>
|
|
393
|
+
<button type="submit" name="action" value="save" class="icon-btn" aria-label="${S.saveDraft}" title="${S.saveDraft}">${icon("drafts")}</button>
|
|
394
|
+
<button type="submit" name="action" value="send" class="primary send" aria-label="${S.send}" title="${S.send}">${icon("send")}</button>
|
|
395
|
+
</form>`)}
|
|
396
|
+
${when(rows.length, () => h `<aside class="context-panel" id="context" aria-label="${S.context}">
|
|
397
|
+
<div class="context-head"><h2>${S.context}</h2><button type="button" class="icon-btn" data-context-toggle aria-label="${S.close}">${icon("close")}</button></div>
|
|
398
|
+
<div class="context-body">${contextSections(rows)}</div>
|
|
399
|
+
</aside>
|
|
400
|
+
<div class="context-backdrop" data-context-toggle></div>`)}
|
|
401
|
+
</div>`;
|
|
252
402
|
}
|
|
253
403
|
export function archiveButton(thread) {
|
|
404
|
+
const label = thread.archived ? S.unarchive : S.archive;
|
|
254
405
|
return h `<form id="archive" hx-post="/threads/${thread.id}/archive" hx-swap="outerHTML">
|
|
255
406
|
<input type="hidden" name="archived" value="${thread.archived ? "0" : "1"}">
|
|
256
|
-
<button class="
|
|
407
|
+
<button class="icon-btn" aria-label="${label}" title="${label}">${icon(thread.archived ? "unarchive" : "archive")}</button>
|
|
257
408
|
</form>`;
|
|
258
409
|
}
|
|
259
410
|
export function devicesPage(sessions, currentId) {
|
|
260
|
-
return h `<
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
<
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
</
|
|
411
|
+
return h `<section class="list">
|
|
412
|
+
<header class="list-head"><h1>${S.navDevices}</h1></header>
|
|
413
|
+
${sessions.length ? join(sessions.map(s => h `<div class="row device" id="session-${s.id}">
|
|
414
|
+
<span class="avatar" aria-hidden="true">${icon("devices")}</span>
|
|
415
|
+
<span class="row-main">
|
|
416
|
+
<span class="row-top"><span class="who">${s.label ?? s.user_agent ?? S.unknownDevice}</span><time datetime="${s.last_seen}">${formatDate(s.last_seen)}</time></span>
|
|
417
|
+
${when(s.label && s.user_agent, () => h `<span class="row-subject">${s.user_agent}</span>`)}
|
|
418
|
+
<span class="row-tags">
|
|
419
|
+
${when(s.id === currentId, () => h `<span class="badge">${S.thisDevice}</span>`)}
|
|
420
|
+
${when(s.scope, () => join(s.scope.map(mailboxBadge)))}
|
|
421
|
+
<span class="row-by">${S.signedIn} ${formatDate(s.created_at)} · ${S.createdBy} ${s.created_by}</span>
|
|
422
|
+
</span>
|
|
423
|
+
</span>
|
|
424
|
+
${when(s.id !== currentId, () => h `<button class="danger" hx-post="/devices/${s.id}/revoke" hx-target="#session-${s.id}" hx-swap="delete">${S.revoke}</button>`)}
|
|
425
|
+
</div>`)) : h `<p class="empty">${S.devicesEmpty}</p>`}
|
|
426
|
+
</section>`;
|
|
427
|
+
}
|
|
428
|
+
export function settingsPage(theme) {
|
|
429
|
+
return h `<div class="page">
|
|
430
|
+
<h1>${S.navSettings}</h1>
|
|
431
|
+
<form class="setting" method="post" action="/theme">
|
|
432
|
+
<label for="theme">${S.theme}</label>
|
|
433
|
+
<span class="select"><select id="theme" name="theme" onchange="this.form.submit()">
|
|
434
|
+
${join(["system", "light", "dark"].map(t => h `<option value="${t}" ${raw(t === theme ? "selected" : "")}>${{ system: S.themeSystem, light: S.themeLight, dark: S.themeDark }[t]}</option>`))}
|
|
435
|
+
</select></span>
|
|
436
|
+
</form>
|
|
437
|
+
<form class="setting" method="post" action="/logout"><button class="danger">${S.logout}</button></form>
|
|
438
|
+
</div>`;
|
|
275
439
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "inboxer",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "A self-hosted mail layer for agents: persists every inbound and outbound email, exposes an MCP server, and ships a minimal UI to review drafts.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -24,7 +24,8 @@
|
|
|
24
24
|
"typecheck": "tsc --noEmit -p tsconfig.json",
|
|
25
25
|
"test": "node --test 'test/**/*.test.ts'",
|
|
26
26
|
"test:bun": "bun test test",
|
|
27
|
-
"prepack": "npm run build"
|
|
27
|
+
"prepack": "npm run build",
|
|
28
|
+
"preview": "node scripts/preview.ts"
|
|
28
29
|
},
|
|
29
30
|
"keywords": [
|
|
30
31
|
"email",
|