inboxer 0.4.8 → 0.4.10
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/core/mail.d.ts +16 -0
- package/dist/core/mail.js +67 -23
- package/dist/core/threads.d.ts +1 -1
- package/dist/core/threads.js +2 -2
- package/dist/ui/routes.js +28 -17
- package/dist/ui/static/app.js +64 -3
- package/dist/ui/static/style.css +14 -10
- package/dist/ui/views.d.ts +19 -8
- package/dist/ui/views.js +51 -26
- package/package.json +1 -1
- package/src/core/mail.ts +30 -15
- package/src/ui/routes.ts +15 -5
- package/src/ui/static/app.js +64 -3
- package/src/ui/static/style.css +6 -5
- package/src/ui/views.ts +38 -20
package/src/ui/views.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { crc32 } from "node:zlib";
|
|
1
2
|
import { html, raw } from "hono/html";
|
|
2
3
|
import type { HtmlEscapedString } from "hono/utils/html";
|
|
3
4
|
import { bareAddress } from "../core/address.ts";
|
|
4
5
|
import type { MessageView } from "../core/mail.ts";
|
|
5
|
-
import {
|
|
6
|
+
import { type Contact, type Context, type Message, type Session, type Thread } from "../types.ts";
|
|
6
7
|
import { ASSETS } from "./assets.ts";
|
|
7
8
|
import { S } from "./strings.ts";
|
|
8
9
|
|
|
@@ -85,8 +86,18 @@ export interface Mailbox {
|
|
|
85
86
|
address: string;
|
|
86
87
|
}
|
|
87
88
|
|
|
89
|
+
/** Pastel hues (OKLCH degrees) for the accent, so several Inboxers tell apart at a glance. */
|
|
90
|
+
const ACCENT_HUES = [45, 75, 105, 145, 175, 205, 235, 265, 295, 325, 355];
|
|
91
|
+
|
|
92
|
+
/** The accent hue of an instance, picked by a hash of its mail domains. */
|
|
93
|
+
export function accentHue(domains: string[]): number {
|
|
94
|
+
return ACCENT_HUES[crc32([...domains].sort().join(",")) % ACCENT_HUES.length]!;
|
|
95
|
+
}
|
|
96
|
+
|
|
88
97
|
export interface LayoutOptions {
|
|
89
98
|
theme: Theme;
|
|
99
|
+
/** The accent's hue, from `accentHue`. */
|
|
100
|
+
hue: number;
|
|
90
101
|
page: Page;
|
|
91
102
|
signedIn: boolean;
|
|
92
103
|
draftCount?: number;
|
|
@@ -102,20 +113,21 @@ export function layout(title: string, body: View, opts: LayoutOptions): View {
|
|
|
102
113
|
const count = opts.draftCount ? h`<span class="count">${opts.draftCount}</span>` : "";
|
|
103
114
|
const canSend = !!opts.senders?.length;
|
|
104
115
|
return h`<!doctype html>
|
|
105
|
-
<html lang="en" ${raw(opts.theme === "system" ? "" : `data-theme="${opts.theme}"`)}>
|
|
116
|
+
<html lang="en" style="--hue: ${opts.hue}" ${raw(opts.theme === "system" ? "" : `data-theme="${opts.theme}"`)}>
|
|
106
117
|
<head>
|
|
107
118
|
<meta charset="utf-8">
|
|
108
119
|
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
|
|
109
120
|
<title>${title} · ${S.appName}</title>
|
|
121
|
+
<meta name="htmx-config" content='{"historyCacheSize":0,"refreshOnHistoryMiss":true}'>
|
|
110
122
|
<link rel="stylesheet" href="${ASSETS["style.css"]!.url}">
|
|
111
123
|
<script src="${ASSETS["htmx.min.js"]!.url}" defer></script>
|
|
112
124
|
<script src="${ASSETS["app.js"]!.url}" defer></script>
|
|
113
125
|
</head>
|
|
114
|
-
<body class="${opts.signedIn ? "app" : ""} ${opts.fullScreen ? "full" : ""}">
|
|
126
|
+
<body class="${opts.signedIn ? "app" : ""} ${opts.fullScreen ? "full" : ""}" hx-boost="true">
|
|
115
127
|
${when(opts.signedIn, () => h`<aside class="sidebar">
|
|
116
128
|
<div class="brand">${S.appName}<span>.</span></div>
|
|
117
129
|
${when(canSend, () => h`<button type="button" class="primary new-mail" data-compose>${icon("plus")}${S.newMail}</button>`)}
|
|
118
|
-
<nav class="side-nav" aria-label="${S.mainNav}">
|
|
130
|
+
<nav class="side-nav" id="side-nav" data-live aria-label="${S.mainNav}">
|
|
119
131
|
${link("drafts", "/", S.navDrafts, "drafts", count)}
|
|
120
132
|
${link("inbox", "/inbox", S.navInbox, "inbox")}
|
|
121
133
|
${link("devices", "/devices", S.navDevices, "devices")}
|
|
@@ -123,7 +135,7 @@ ${when(opts.signedIn, () => h`<aside class="sidebar">
|
|
|
123
135
|
<nav class="side-nav side-end" aria-label="${S.navSettings}">${link("settings", "/settings", S.navSettings, "settings")}</nav>
|
|
124
136
|
</aside>`)}
|
|
125
137
|
<main>${body}</main>
|
|
126
|
-
${when(opts.signedIn, () => h`<nav class="tabbar" aria-label="${S.mainNav}">
|
|
138
|
+
${when(opts.signedIn, () => h`<nav class="tabbar" id="tabbar" data-live aria-label="${S.mainNav}">
|
|
127
139
|
${link("drafts", "/", S.navDrafts, "drafts", count)}
|
|
128
140
|
${link("inbox", "/inbox", S.navInbox, "inbox")}
|
|
129
141
|
${when(canSend, () => h`<button type="button" class="tab-compose" data-compose aria-label="${S.newMail}"><span>${icon("plus")}</span></button>`)}
|
|
@@ -195,13 +207,17 @@ export function signIn(token: string, valid: boolean): View {
|
|
|
195
207
|
</div>`;
|
|
196
208
|
}
|
|
197
209
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
210
|
+
function localPart(address: string): string {
|
|
211
|
+
return address.includes("@") ? address.slice(0, address.lastIndexOf("@")) : address;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/** An account by the local part of the address it receives mail at. */
|
|
215
|
+
function mailboxBadge(address: string): View {
|
|
216
|
+
return h`<span class="badge mailbox">${localPart(address)}</span>`;
|
|
201
217
|
}
|
|
202
218
|
|
|
203
219
|
function draftAccount(d: Message): string {
|
|
204
|
-
return
|
|
220
|
+
return bareAddress(d.from);
|
|
205
221
|
}
|
|
206
222
|
|
|
207
223
|
const PREVIEWABLE = new Set(["image/png", "image/jpeg", "image/gif", "image/webp", "image/avif"]);
|
|
@@ -383,7 +399,7 @@ function listTitle(domains: string[], label: string): View {
|
|
|
383
399
|
|
|
384
400
|
/** Drafts waiting for review, listed like the inbox; each opens its thread. */
|
|
385
401
|
export function draftList(drafts: Message[], domains: string[], current: string | null): View {
|
|
386
|
-
return h`<section class="list">
|
|
402
|
+
return h`<section class="list" id="list" data-live>
|
|
387
403
|
<header class="list-head">${listTitle(domains, S.navDrafts)}</header>
|
|
388
404
|
${drafts.length ? join(drafts.map(d => h`<a class="row" href="/drafts/${d.id}" ${raw(d.id === current ? 'aria-current="page"' : "")}>
|
|
389
405
|
<span class="avatar" aria-hidden="true">${initials(d.to[0] ?? d.mailbox)}</span>
|
|
@@ -392,7 +408,7 @@ export function draftList(drafts: Message[], domains: string[], current: string
|
|
|
392
408
|
<span class="row-subject">${d.subject || "—"}</span>
|
|
393
409
|
<span class="row-snippet">${d.text}</span>
|
|
394
410
|
<span class="row-tags">
|
|
395
|
-
${mailboxBadge(d
|
|
411
|
+
${mailboxBadge(draftAccount(d))}
|
|
396
412
|
<span class="row-by">${d.edited_by_human ? S.editedByHuman : S.byAgent}</span>
|
|
397
413
|
</span>
|
|
398
414
|
</span>
|
|
@@ -412,17 +428,18 @@ export function inboxQuery(filter: InboxFilter): string {
|
|
|
412
428
|
/** The thread list; on a wide screen it stays beside the open thread. */
|
|
413
429
|
export function threadList(threads: Thread[], opts: ThreadListOptions & { domains: string[] }): View {
|
|
414
430
|
const { filter } = opts;
|
|
415
|
-
const
|
|
431
|
+
const mailboxLabel = (m: string) => opts.domains.length === 1 ? localPart(opts.addressOf(m)) : opts.addressOf(m);
|
|
432
|
+
const tab =(status: string, label: string) =>
|
|
416
433
|
h`<a class="chip" href="/inbox?${inboxQuery({ ...filter, status })}" ${raw(filter.status === status ? 'aria-current="page"' : "")}>${label}</a>`;
|
|
417
|
-
return h`<section class="list">
|
|
434
|
+
return h`<section class="list" id="list" data-live>
|
|
418
435
|
<header class="list-head">
|
|
419
436
|
${listTitle(opts.domains, S.navInbox)}
|
|
420
437
|
<form class="filters" method="get" action="/inbox">
|
|
421
438
|
<input type="hidden" name="status" value="${filter.status}">
|
|
422
439
|
<nav class="chips" aria-label="${S.filter}">${tab("unanswered", S.filterPending)}${tab("all", S.filterAll)}${tab("archived", S.filterArchived)}</nav>
|
|
423
|
-
${when(opts.accounts.length > 1, () => h`<span class="select"><select name="mailbox" aria-label="${S.allMailboxes}" onchange="this.form.
|
|
440
|
+
${when(opts.accounts.length > 1, () => h`<span class="select"><select name="mailbox" aria-label="${S.allMailboxes}" onchange="this.form.requestSubmit()">
|
|
424
441
|
<option value="">${S.allMailboxes}</option>
|
|
425
|
-
${join(opts.accounts.map(m => h`<option value="${m}" ${raw(m === filter.mailbox ? "selected" : "")}>${m}</option>`))}
|
|
442
|
+
${join(opts.accounts.map(m => h`<option value="${m}" ${raw(m === filter.mailbox ? "selected" : "")}>${mailboxLabel(m)}</option>`))}
|
|
426
443
|
</select></span>`)}
|
|
427
444
|
</form>
|
|
428
445
|
</header>
|
|
@@ -434,6 +451,7 @@ interface ThreadListOptions {
|
|
|
434
451
|
/** Mailbox ids and catch-all addresses, as filter values. */
|
|
435
452
|
accounts: string[];
|
|
436
453
|
accountOf: (t: Thread) => string;
|
|
454
|
+
addressOf: (account: string) => string;
|
|
437
455
|
filter: InboxFilter;
|
|
438
456
|
own: (address: string) => boolean;
|
|
439
457
|
current: string | null;
|
|
@@ -448,7 +466,7 @@ function threadRow(t: Thread, opts: ThreadListOptions): View {
|
|
|
448
466
|
<span class="row-subject">${t.subject || "—"}</span>
|
|
449
467
|
${when(t.has_draft || opts.accounts.length > 1 || t.unread, () => h`<span class="row-tags">
|
|
450
468
|
${when(t.has_draft, () => h`<span class="badge draft">${S.hasDraft}</span>`)}
|
|
451
|
-
${when(opts.accounts.length > 1, () => mailboxBadge(opts.accountOf(t)))}
|
|
469
|
+
${when(opts.accounts.length > 1, () => mailboxBadge(opts.addressOf(opts.accountOf(t))))}
|
|
452
470
|
${when(t.unread, () => h`<span class="dot" title="${S.unread}"></span>`)}
|
|
453
471
|
</span>`)}
|
|
454
472
|
</span>
|
|
@@ -488,7 +506,7 @@ export function threadView(thread: Thread, entries: ThreadEntry[], ctx: ContextV
|
|
|
488
506
|
${when(rows.length, () => h`<button type="button" class="context-btn" data-context-toggle aria-controls="context">${S.context}</button>`)}
|
|
489
507
|
${archiveButton(thread)}
|
|
490
508
|
</header>
|
|
491
|
-
<div class="messages" data-scroll-end>${join(items)}</div>
|
|
509
|
+
<div class="messages" id="messages" data-live data-scroll-end>${join(items)}</div>
|
|
492
510
|
${when(opts.reply.allowed, () => h`<form class="composer" method="post" action="/threads/${thread.id}/reply?${query}">
|
|
493
511
|
${when(opts.reply.replyAll, () => h`<label class="reply-all"><input type="checkbox" name="reply_all" value="1">${S.replyAll}</label>`)}
|
|
494
512
|
<button type="button" class="icon-btn" aria-label="${S.fullReply}" title="${S.fullReply}" hx-get="/threads/${thread.id}/reply/full?${query}" hx-include="closest form" hx-target="#edit-sheet" hx-swap="innerHTML">${icon("plus")}</button>
|
|
@@ -512,7 +530,7 @@ export function archiveButton(thread: Thread): View {
|
|
|
512
530
|
</form>`;
|
|
513
531
|
}
|
|
514
532
|
|
|
515
|
-
export function devicesPage(sessions: Session[], currentId: string): View {
|
|
533
|
+
export function devicesPage(sessions: Session[], currentId: string, addressOf: (account: string) => string): View {
|
|
516
534
|
return h`<section class="list">
|
|
517
535
|
<header class="list-head"><h1>${S.navDevices}</h1></header>
|
|
518
536
|
${sessions.length ? join(sessions.map(s => h`<div class="row device" id="session-${s.id}">
|
|
@@ -522,7 +540,7 @@ export function devicesPage(sessions: Session[], currentId: string): View {
|
|
|
522
540
|
${when(s.label && s.user_agent, () => h`<span class="row-subject">${s.user_agent}</span>`)}
|
|
523
541
|
<span class="row-tags">
|
|
524
542
|
${when(s.id === currentId, () => h`<span class="badge">${S.thisDevice}</span>`)}
|
|
525
|
-
${when(s.scope, () => join(s.scope!.map(mailboxBadge)))}
|
|
543
|
+
${when(s.scope, () => join(s.scope!.map(m => mailboxBadge(addressOf(m)))))}
|
|
526
544
|
<span class="row-by">${S.signedIn} ${formatDate(s.created_at)} · ${S.createdBy} ${s.created_by}</span>
|
|
527
545
|
</span>
|
|
528
546
|
</span>
|
|
@@ -536,7 +554,7 @@ export function devicesPage(sessions: Session[], currentId: string): View {
|
|
|
536
554
|
export function settingsPage(theme: Theme): View {
|
|
537
555
|
return h`<div class="page">
|
|
538
556
|
<h1>${S.navSettings}</h1>
|
|
539
|
-
<form class="setting" method="post" action="/theme">
|
|
557
|
+
<form class="setting" method="post" action="/theme" hx-boost="false">
|
|
540
558
|
<label for="theme">${S.theme}</label>
|
|
541
559
|
<span class="select"><select id="theme" name="theme" onchange="this.form.submit()">
|
|
542
560
|
${join((["system", "light", "dark"] as const).map(t =>
|