@open-workspace/email 0.5.2 → 0.6.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 +1 -2
- package/alchemy/index.ts +0 -16
- package/migrations/0003_after_0_5_2.sql +1 -0
- package/migrations/meta/0003_snapshot.json +703 -0
- package/migrations/meta/_journal.json +7 -0
- package/package.json +6 -5
- package/shared/mail.ts +3 -2
- package/shared/module.ts +1 -1
- package/src/client.tsx +20 -30
- package/src/extensions.ts +176 -0
- package/src/mail/compose-window-chrome.tsx +5 -10
- package/src/mail/compose-window.tsx +13 -2
- package/src/mail/composer-attach-button.tsx +106 -0
- package/src/mail/composer-editor.tsx +17 -0
- package/src/mail/composer-inserts.tsx +186 -0
- package/src/mail/composer-toolbar.tsx +3 -0
- package/src/mail/conversation-message.tsx +37 -1
- package/src/mail/conversation-reply.tsx +5 -10
- package/src/mail/message-actions.tsx +30 -0
- package/src/mail/message-attachments.tsx +62 -0
- package/src/mail/message-panels.tsx +206 -0
- package/src/mail/module-extensions.ts +87 -0
- package/src/mail/reader-pane.tsx +75 -47
- package/src/mail/recipient-combobox.tsx +32 -12
- package/src/mail/shared-compose.ts +45 -0
- package/src/settings/mail-notifications.tsx +119 -0
- package/src/settings/settings-queries.ts +0 -7
- package/worker/backups/file-parts.ts +9 -6
- package/worker/backups/mail-backup.ts +21 -4
- package/worker/backups/settings-backup.ts +56 -24
- package/worker/db/schema.ts +0 -36
- package/worker/jmap/method-core.ts +2 -3
- package/worker/jmap/push-subscription-methods.ts +5 -2
- package/worker/jmap/push.ts +10 -11
- package/worker/jmap/routes.ts +10 -49
- package/worker/mail/bimi.ts +2 -3
- package/worker/mail/person-erasure.ts +58 -0
- package/worker/mail/push-notifications.ts +59 -419
- package/worker/mail/remote-proxy.ts +3 -206
- package/worker/mail/remote-routes.ts +2 -2
- package/worker/mail/uploads.ts +14 -6
- package/worker/mail/webhook-source.ts +13 -1
- package/worker/mailbox/index.ts +27 -0
- package/worker/mailbox/mailbox-drafts.ts +5 -0
- package/worker/module-api.ts +239 -0
- package/worker/module.ts +11 -7
- package/src/pwa/push-key.ts +0 -18
- package/src/pwa/push-subscription.ts +0 -213
- package/src/settings/notifications-page.tsx +0 -306
- package/worker/mail/push-endpoint.ts +0 -17
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Dialog,
|
|
3
|
+
DialogContent,
|
|
4
|
+
DialogHeader,
|
|
5
|
+
DialogTitle,
|
|
6
|
+
DropdownMenu,
|
|
7
|
+
DropdownMenuContent,
|
|
8
|
+
DropdownMenuItem,
|
|
9
|
+
DropdownMenuTrigger,
|
|
10
|
+
Tooltip,
|
|
11
|
+
TooltipContent,
|
|
12
|
+
TooltipTrigger,
|
|
13
|
+
moduleExtensions,
|
|
14
|
+
toggleVariants,
|
|
15
|
+
} from "@open-workspace/core/ui";
|
|
16
|
+
import type { Editor, JSONContent } from "@tiptap/react";
|
|
17
|
+
import { Plus } from "lucide-react";
|
|
18
|
+
import { Suspense, useEffect, useRef, useState } from "react";
|
|
19
|
+
import { toast } from "sonner";
|
|
20
|
+
|
|
21
|
+
import type { ComposerInsert, ComposerInsertContent } from "../extensions";
|
|
22
|
+
|
|
23
|
+
const LINK_PROTOCOLS = new Set(["http:", "https:", "mailto:"]);
|
|
24
|
+
|
|
25
|
+
/** Text as the editor's nodes: its line breaks kept. */
|
|
26
|
+
export function textNodes(text: string) {
|
|
27
|
+
const nodes: JSONContent[] = text
|
|
28
|
+
.split(/\r?\n/u)
|
|
29
|
+
.flatMap((line, index) => [
|
|
30
|
+
...(index ? [{ type: "hardBreak" }] : []),
|
|
31
|
+
...(line ? [{ type: "text", text: line }] : []),
|
|
32
|
+
]);
|
|
33
|
+
|
|
34
|
+
return nodes;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* A module's text or link as the editor's nodes. A link goes only to a web
|
|
39
|
+
* or mail address.
|
|
40
|
+
*/
|
|
41
|
+
function insertedNodes(content: ComposerInsertContent) {
|
|
42
|
+
if ("text" in content) return textNodes(content.text);
|
|
43
|
+
|
|
44
|
+
const { url, text } = content.link;
|
|
45
|
+
let href: URL;
|
|
46
|
+
|
|
47
|
+
try {
|
|
48
|
+
href = new URL(url);
|
|
49
|
+
} catch {
|
|
50
|
+
throw new Error("The link's address isn't valid");
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (!LINK_PROTOCOLS.has(href.protocol)) {
|
|
54
|
+
throw new Error("Only web and mail addresses can be linked");
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const nodes: JSONContent[] = [
|
|
58
|
+
{
|
|
59
|
+
type: "text",
|
|
60
|
+
text: text.trim() || href.href,
|
|
61
|
+
marks: [{ type: "link", attrs: { href: href.href } }],
|
|
62
|
+
},
|
|
63
|
+
];
|
|
64
|
+
|
|
65
|
+
return nodes;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* The composer toolbar's entries from other modules (`email.composerInserts`):
|
|
70
|
+
* a button for one, a menu for more. Each opens in a dialog, and what it
|
|
71
|
+
* inserts goes where the cursor was.
|
|
72
|
+
*/
|
|
73
|
+
export function ComposerInserts({
|
|
74
|
+
editor,
|
|
75
|
+
disabled,
|
|
76
|
+
}: {
|
|
77
|
+
editor: Editor;
|
|
78
|
+
disabled: boolean;
|
|
79
|
+
}) {
|
|
80
|
+
const inserts = moduleExtensions("email.composerInserts");
|
|
81
|
+
const [open, setOpen] = useState<ComposerInsert | null>(null);
|
|
82
|
+
// What to insert once the dialog has closed, with the focus back in the
|
|
83
|
+
// text and the cursor after what was inserted.
|
|
84
|
+
const pending = useRef<JSONContent[] | null>(null);
|
|
85
|
+
|
|
86
|
+
useEffect(() => {
|
|
87
|
+
if (open || !pending.current) return;
|
|
88
|
+
const nodes = pending.current;
|
|
89
|
+
pending.current = null;
|
|
90
|
+
// Typing after a link is plain text.
|
|
91
|
+
editor.chain().focus().insertContent(nodes).unsetMark("link").run();
|
|
92
|
+
}, [open, editor]);
|
|
93
|
+
|
|
94
|
+
if (!inserts.length) return null;
|
|
95
|
+
|
|
96
|
+
function show(entry: ComposerInsert) {
|
|
97
|
+
pending.current = null;
|
|
98
|
+
setOpen(entry);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const [single] = inserts;
|
|
102
|
+
|
|
103
|
+
return (
|
|
104
|
+
<>
|
|
105
|
+
<span className="bg-border mx-1 h-4 w-px" />
|
|
106
|
+
{inserts.length === 1 && single ? (
|
|
107
|
+
<Tooltip>
|
|
108
|
+
<TooltipTrigger
|
|
109
|
+
render={
|
|
110
|
+
<button
|
|
111
|
+
type="button"
|
|
112
|
+
className={toggleVariants({ size: "xs" })}
|
|
113
|
+
aria-label={single.label}
|
|
114
|
+
disabled={disabled}
|
|
115
|
+
onClick={() => show(single)}
|
|
116
|
+
/>
|
|
117
|
+
}
|
|
118
|
+
>
|
|
119
|
+
<single.Icon />
|
|
120
|
+
</TooltipTrigger>
|
|
121
|
+
<TooltipContent>{single.label}</TooltipContent>
|
|
122
|
+
</Tooltip>
|
|
123
|
+
) : (
|
|
124
|
+
<DropdownMenu>
|
|
125
|
+
<DropdownMenuTrigger
|
|
126
|
+
className={toggleVariants({ size: "xs" })}
|
|
127
|
+
aria-label="Insert"
|
|
128
|
+
disabled={disabled}
|
|
129
|
+
>
|
|
130
|
+
<Plus />
|
|
131
|
+
</DropdownMenuTrigger>
|
|
132
|
+
<DropdownMenuContent align="start" side="top" className="w-56">
|
|
133
|
+
{inserts.map((entry) => (
|
|
134
|
+
<DropdownMenuItem key={entry.id} onClick={() => show(entry)}>
|
|
135
|
+
<entry.Icon /> {entry.label}
|
|
136
|
+
</DropdownMenuItem>
|
|
137
|
+
))}
|
|
138
|
+
</DropdownMenuContent>
|
|
139
|
+
</DropdownMenu>
|
|
140
|
+
)}
|
|
141
|
+
<Dialog
|
|
142
|
+
open={open !== null}
|
|
143
|
+
onOpenChange={(next) => {
|
|
144
|
+
if (!next) setOpen(null);
|
|
145
|
+
}}
|
|
146
|
+
>
|
|
147
|
+
{open ? (
|
|
148
|
+
<DialogContent
|
|
149
|
+
anchor="top"
|
|
150
|
+
className="sm:max-w-md"
|
|
151
|
+
// Inserting returns to the text; any other close, to the trigger.
|
|
152
|
+
finalFocus={() => pending.current === null}
|
|
153
|
+
>
|
|
154
|
+
<DialogHeader>
|
|
155
|
+
<DialogTitle>{open.label}</DialogTitle>
|
|
156
|
+
</DialogHeader>
|
|
157
|
+
{/* The dialog is a portal, but React still bubbles its events
|
|
158
|
+
to the composer's form: an insert's own form mustn't send. */}
|
|
159
|
+
<div onSubmit={(event) => event.stopPropagation()}>
|
|
160
|
+
<Suspense fallback={null}>
|
|
161
|
+
<open.Component
|
|
162
|
+
insert={(content) => {
|
|
163
|
+
try {
|
|
164
|
+
pending.current = insertedNodes(content);
|
|
165
|
+
} catch (error) {
|
|
166
|
+
toast.error(
|
|
167
|
+
error instanceof Error
|
|
168
|
+
? error.message
|
|
169
|
+
: "Could not insert it"
|
|
170
|
+
);
|
|
171
|
+
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
setOpen(null);
|
|
176
|
+
}}
|
|
177
|
+
onClose={() => setOpen(null)}
|
|
178
|
+
/>
|
|
179
|
+
</Suspense>
|
|
180
|
+
</div>
|
|
181
|
+
</DialogContent>
|
|
182
|
+
) : null}
|
|
183
|
+
</Dialog>
|
|
184
|
+
</>
|
|
185
|
+
);
|
|
186
|
+
}
|
|
@@ -29,6 +29,8 @@ import {
|
|
|
29
29
|
import { useRef, useState } from "react";
|
|
30
30
|
import type { ReactNode } from "react";
|
|
31
31
|
|
|
32
|
+
import { ComposerInserts } from "./composer-inserts";
|
|
33
|
+
|
|
32
34
|
/** A formatting toggle: pressed while the selection has the format. */
|
|
33
35
|
function FormatToggle({
|
|
34
36
|
label,
|
|
@@ -312,6 +314,7 @@ export function ComposerToolbar({
|
|
|
312
314
|
>
|
|
313
315
|
<RemoveFormatting />
|
|
314
316
|
</EditorButton>
|
|
317
|
+
<ComposerInserts editor={editor} disabled={disabled} />
|
|
315
318
|
</div>
|
|
316
319
|
);
|
|
317
320
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Button, cn } from "@open-workspace/core/ui";
|
|
2
2
|
import { ChevronDown, Ellipsis, Eye, Paperclip, RotateCw } from "lucide-react";
|
|
3
|
-
import { useLayoutEffect, useState } from "react";
|
|
3
|
+
import { Suspense, useLayoutEffect, useState } from "react";
|
|
4
4
|
import type { ReactNode } from "react";
|
|
5
5
|
|
|
6
6
|
import { DeliveryIndicator } from "./delivery-indicator";
|
|
@@ -20,6 +20,7 @@ import {
|
|
|
20
20
|
} from "./message-format";
|
|
21
21
|
import { MessageDetails, SenderLine } from "./message-header";
|
|
22
22
|
import { TranslationBar, useMessageTranslation } from "./message-translation";
|
|
23
|
+
import { attachmentContent, messageCards } from "./module-extensions";
|
|
23
24
|
import { PlainMessageText } from "./plain-message-text";
|
|
24
25
|
import {
|
|
25
26
|
SenderAvatar,
|
|
@@ -339,6 +340,7 @@ function ExpandedMessage({
|
|
|
339
340
|
actions={
|
|
340
341
|
<MessageActions
|
|
341
342
|
message={message}
|
|
343
|
+
mailboxId={mailbox?.id}
|
|
342
344
|
translation={translation}
|
|
343
345
|
resendPending={resendPending}
|
|
344
346
|
handlers={handlers}
|
|
@@ -393,6 +395,13 @@ function ExpandedMessage({
|
|
|
393
395
|
)}
|
|
394
396
|
|
|
395
397
|
<div className={messageBodyColumnClassName}>
|
|
398
|
+
{mailbox ? (
|
|
399
|
+
<MessageCards
|
|
400
|
+
mailboxId={mailbox.id}
|
|
401
|
+
messageId={message.id}
|
|
402
|
+
attachments={message.attachments}
|
|
403
|
+
/>
|
|
404
|
+
) : null}
|
|
396
405
|
<TranslationBar translation={translation} />
|
|
397
406
|
<MessageBody
|
|
398
407
|
subject={message.subject}
|
|
@@ -425,6 +434,33 @@ function ExpandedMessage({
|
|
|
425
434
|
);
|
|
426
435
|
}
|
|
427
436
|
|
|
437
|
+
/** Other modules' cards for the message's parts (`email.messageCards`). */
|
|
438
|
+
function MessageCards({
|
|
439
|
+
mailboxId,
|
|
440
|
+
messageId,
|
|
441
|
+
attachments,
|
|
442
|
+
}: {
|
|
443
|
+
mailboxId: string;
|
|
444
|
+
messageId: string;
|
|
445
|
+
attachments: MessageDetail["attachments"];
|
|
446
|
+
}) {
|
|
447
|
+
return messageCards(attachments).map(({ card, part }) => (
|
|
448
|
+
<Suspense key={card.id} fallback={null}>
|
|
449
|
+
<div className="mb-4">
|
|
450
|
+
<card.Component
|
|
451
|
+
mailboxId={mailboxId}
|
|
452
|
+
messageId={messageId}
|
|
453
|
+
part={{
|
|
454
|
+
contentType: part.contentType,
|
|
455
|
+
filename: part.filename,
|
|
456
|
+
content: () => attachmentContent(mailboxId, messageId, part.id),
|
|
457
|
+
}}
|
|
458
|
+
/>
|
|
459
|
+
</div>
|
|
460
|
+
</Suspense>
|
|
461
|
+
));
|
|
462
|
+
}
|
|
463
|
+
|
|
428
464
|
function RetryNotice({
|
|
429
465
|
message,
|
|
430
466
|
pending,
|
|
@@ -14,7 +14,6 @@ import {
|
|
|
14
14
|
Check,
|
|
15
15
|
ChevronDown,
|
|
16
16
|
LoaderCircle,
|
|
17
|
-
Paperclip,
|
|
18
17
|
Reply,
|
|
19
18
|
ReplyAll,
|
|
20
19
|
Send,
|
|
@@ -26,6 +25,7 @@ import type { Ref } from "react";
|
|
|
26
25
|
import { toast } from "sonner";
|
|
27
26
|
|
|
28
27
|
import { normalizeExternalEmailAddress } from "../../shared/mail";
|
|
28
|
+
import { ComposerAttachButton } from "./composer-attach-button";
|
|
29
29
|
import { ComposerAttachmentList } from "./composer-attachment-list";
|
|
30
30
|
import { ComposerEditor } from "./composer-editor";
|
|
31
31
|
import type { ComposerContent } from "./composer-editor";
|
|
@@ -527,16 +527,11 @@ export function ConversationReply({
|
|
|
527
527
|
event.target.value = "";
|
|
528
528
|
}}
|
|
529
529
|
/>
|
|
530
|
-
<
|
|
531
|
-
type="button"
|
|
532
|
-
variant="ghost"
|
|
533
|
-
size="icon-sm"
|
|
530
|
+
<ComposerAttachButton
|
|
534
531
|
disabled={busy}
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
<span className="sr-only">Add attachments</span>
|
|
539
|
-
</Button>
|
|
532
|
+
onChooseFromDevice={() => fileInput.current?.click()}
|
|
533
|
+
onPick={(files) => addFiles(files, "attachment")}
|
|
534
|
+
/>
|
|
540
535
|
<span
|
|
541
536
|
className={cn(
|
|
542
537
|
"min-w-0 flex-1 text-xs",
|
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
DropdownMenuShortcut,
|
|
14
14
|
DropdownMenuSubTrigger,
|
|
15
15
|
DropdownMenuTrigger,
|
|
16
|
+
moduleExtensions,
|
|
16
17
|
} from "@open-workspace/core/ui";
|
|
17
18
|
import {
|
|
18
19
|
Download,
|
|
@@ -36,6 +37,7 @@ import { ReplyActionIcon } from "./conversation-reply";
|
|
|
36
37
|
import { senderName } from "./message-format";
|
|
37
38
|
import { languageName } from "./message-translation";
|
|
38
39
|
import type { MessageTranslationState } from "./message-translation";
|
|
40
|
+
import { runModuleAction } from "./module-extensions";
|
|
39
41
|
import { printMessage } from "./print-message";
|
|
40
42
|
import { ToolbarTooltip } from "./toolbar-tooltip";
|
|
41
43
|
import type { MessageDetail, ReplyAction } from "./types";
|
|
@@ -98,11 +100,14 @@ export function actionButtonLabel(action: ReplyAction) {
|
|
|
98
100
|
/** A message's reply button and its "More actions" menu. */
|
|
99
101
|
export function MessageActions({
|
|
100
102
|
message,
|
|
103
|
+
mailboxId,
|
|
101
104
|
translation,
|
|
102
105
|
resendPending,
|
|
103
106
|
handlers,
|
|
104
107
|
}: {
|
|
105
108
|
message: MessageDetail;
|
|
109
|
+
/** The mailbox it is read in; other modules' actions need it. */
|
|
110
|
+
mailboxId?: string;
|
|
106
111
|
translation: MessageTranslationState;
|
|
107
112
|
resendPending: boolean;
|
|
108
113
|
handlers: MessageHandlers;
|
|
@@ -111,6 +116,17 @@ export function MessageActions({
|
|
|
111
116
|
const [primaryAction, ...otherActions] = message.replyPlan.actions;
|
|
112
117
|
const senderHandlers = handlers.sender;
|
|
113
118
|
|
|
119
|
+
const actionContext = mailboxId
|
|
120
|
+
? {
|
|
121
|
+
mailboxId,
|
|
122
|
+
messageId: message.id,
|
|
123
|
+
conversationId: message.conversationId,
|
|
124
|
+
subject: message.subject,
|
|
125
|
+
from: { name: message.fromName, address: message.fromAddress },
|
|
126
|
+
date: message.timelineAt,
|
|
127
|
+
}
|
|
128
|
+
: null;
|
|
129
|
+
|
|
114
130
|
return (
|
|
115
131
|
<div className="-mr-1.5 flex shrink-0 items-center">
|
|
116
132
|
{send && primaryAction && (
|
|
@@ -280,6 +296,20 @@ export function MessageActions({
|
|
|
280
296
|
</DropdownMenuSub>,
|
|
281
297
|
]
|
|
282
298
|
: [],
|
|
299
|
+
actionContext
|
|
300
|
+
? moduleExtensions("email.messageActions").map(
|
|
301
|
+
({ id, label, Icon, run }) => (
|
|
302
|
+
<DropdownMenuItem
|
|
303
|
+
key={`module-${id}`}
|
|
304
|
+
onClick={() =>
|
|
305
|
+
void runModuleAction(() => run(actionContext))
|
|
306
|
+
}
|
|
307
|
+
>
|
|
308
|
+
<Icon /> {label}
|
|
309
|
+
</DropdownMenuItem>
|
|
310
|
+
)
|
|
311
|
+
)
|
|
312
|
+
: [],
|
|
283
313
|
[
|
|
284
314
|
<DropdownMenuItem
|
|
285
315
|
key="print"
|
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Dialog,
|
|
3
3
|
DialogTrigger,
|
|
4
|
+
DropdownMenu,
|
|
5
|
+
DropdownMenuContent,
|
|
6
|
+
DropdownMenuItem,
|
|
7
|
+
DropdownMenuTrigger,
|
|
8
|
+
moduleExtensions,
|
|
4
9
|
Tooltip,
|
|
5
10
|
TooltipContent,
|
|
6
11
|
TooltipTrigger,
|
|
7
12
|
} from "@open-workspace/core/ui";
|
|
8
13
|
import {
|
|
9
14
|
Download,
|
|
15
|
+
Ellipsis,
|
|
10
16
|
File,
|
|
11
17
|
FileArchive,
|
|
12
18
|
FileImage,
|
|
@@ -20,6 +26,7 @@ import type { CSSProperties } from "react";
|
|
|
20
26
|
import { attachmentPreview } from "../../shared/attachment-preview";
|
|
21
27
|
import { AttachmentPreviewDialog } from "./attachment-preview-dialog";
|
|
22
28
|
import { formatBytes } from "./format-bytes";
|
|
29
|
+
import { attachmentContent, runModuleAction } from "./module-extensions";
|
|
23
30
|
import type { MessageAttachment } from "./types";
|
|
24
31
|
|
|
25
32
|
type FileKind = { label: string; Icon: LucideIcon; hue: number };
|
|
@@ -203,6 +210,61 @@ function AttachmentTile({
|
|
|
203
210
|
<Download className="size-4" />
|
|
204
211
|
</span>
|
|
205
212
|
)}
|
|
213
|
+
{mailboxId ? (
|
|
214
|
+
<AttachmentActions
|
|
215
|
+
mailboxId={mailboxId}
|
|
216
|
+
messageId={messageId}
|
|
217
|
+
attachment={attachment}
|
|
218
|
+
/>
|
|
219
|
+
) : null}
|
|
206
220
|
</li>
|
|
207
221
|
);
|
|
208
222
|
}
|
|
223
|
+
|
|
224
|
+
/** Other modules' actions on the attachment (`email.attachmentActions`). */
|
|
225
|
+
function AttachmentActions({
|
|
226
|
+
mailboxId,
|
|
227
|
+
messageId,
|
|
228
|
+
attachment,
|
|
229
|
+
}: {
|
|
230
|
+
mailboxId: string;
|
|
231
|
+
messageId: string;
|
|
232
|
+
attachment: MessageAttachment;
|
|
233
|
+
}) {
|
|
234
|
+
const actions = moduleExtensions("email.attachmentActions");
|
|
235
|
+
|
|
236
|
+
if (!actions.length) return null;
|
|
237
|
+
|
|
238
|
+
const context = {
|
|
239
|
+
mailboxId,
|
|
240
|
+
messageId,
|
|
241
|
+
attachment: {
|
|
242
|
+
id: attachment.id,
|
|
243
|
+
filename: attachment.filename,
|
|
244
|
+
contentType: attachment.contentType,
|
|
245
|
+
size: attachment.size,
|
|
246
|
+
},
|
|
247
|
+
content: () => attachmentContent(mailboxId, messageId, attachment.id),
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
return (
|
|
251
|
+
<DropdownMenu>
|
|
252
|
+
<DropdownMenuTrigger
|
|
253
|
+
aria-label={`More actions for ${attachment.filename}`}
|
|
254
|
+
className="text-muted-foreground hover:bg-accent hover:text-foreground focus-visible:ring-ring my-1.5 mr-1.5 -ml-1 grid w-8 shrink-0 place-items-center rounded-md transition-colors outline-none focus-visible:ring-2"
|
|
255
|
+
>
|
|
256
|
+
<Ellipsis className="size-4" />
|
|
257
|
+
</DropdownMenuTrigger>
|
|
258
|
+
<DropdownMenuContent align="end" className="w-56">
|
|
259
|
+
{actions.map(({ id, label, Icon, run }) => (
|
|
260
|
+
<DropdownMenuItem
|
|
261
|
+
key={id}
|
|
262
|
+
onClick={() => void runModuleAction(() => run(context))}
|
|
263
|
+
>
|
|
264
|
+
<Icon /> {label}
|
|
265
|
+
</DropdownMenuItem>
|
|
266
|
+
))}
|
|
267
|
+
</DropdownMenuContent>
|
|
268
|
+
</DropdownMenu>
|
|
269
|
+
);
|
|
270
|
+
}
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Button,
|
|
3
|
+
Sheet,
|
|
4
|
+
SheetContent,
|
|
5
|
+
SheetTitle,
|
|
6
|
+
Toggle,
|
|
7
|
+
moduleExtensions,
|
|
8
|
+
} from "@open-workspace/core/ui";
|
|
9
|
+
import { X } from "lucide-react";
|
|
10
|
+
import { Suspense, useEffect, useState, useSyncExternalStore } from "react";
|
|
11
|
+
|
|
12
|
+
import type { MessagePanel } from "../extensions";
|
|
13
|
+
import { ToolbarTooltip } from "./toolbar-tooltip";
|
|
14
|
+
import type { MessageDetail } from "./types";
|
|
15
|
+
|
|
16
|
+
/** A reading pane at least this wide shows a panel beside the conversation. */
|
|
17
|
+
const SIDE_PANEL_MIN_READER_WIDTH = 672;
|
|
18
|
+
|
|
19
|
+
/** Below Tailwind's `lg`, a panel's sheet rises from the bottom. */
|
|
20
|
+
const PHONE_QUERY = "(max-width: 1023.98px)";
|
|
21
|
+
|
|
22
|
+
/** The message panels are about: the latest incoming one, else the latest. */
|
|
23
|
+
export function panelMessage(messages: readonly MessageDetail[]) {
|
|
24
|
+
return (
|
|
25
|
+
messages.findLast((message) => message.direction === "incoming") ??
|
|
26
|
+
messages.at(-1)
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Other modules' message panels (`email.messagePanels`), and which is open. */
|
|
31
|
+
export function useMessagePanels(conversationOpen: boolean) {
|
|
32
|
+
const panels = moduleExtensions("email.messagePanels");
|
|
33
|
+
const [openId, setOpenId] = useState<string | null>(null);
|
|
34
|
+
|
|
35
|
+
// Closing the conversation closes its panel.
|
|
36
|
+
if (!conversationOpen && openId !== null) setOpenId(null);
|
|
37
|
+
|
|
38
|
+
return {
|
|
39
|
+
panels,
|
|
40
|
+
open: panels.find((panel) => panel.id === openId) ?? null,
|
|
41
|
+
toggle: (id: string) =>
|
|
42
|
+
setOpenId((current) => (current === id ? null : id)),
|
|
43
|
+
close: () => setOpenId(null),
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export type MessagePanels = ReturnType<typeof useMessagePanels>;
|
|
48
|
+
|
|
49
|
+
/** A toggle per panel, in the conversation's toolbar. */
|
|
50
|
+
export function MessagePanelToggles({
|
|
51
|
+
panels,
|
|
52
|
+
disabled,
|
|
53
|
+
}: {
|
|
54
|
+
panels: MessagePanels;
|
|
55
|
+
disabled: boolean;
|
|
56
|
+
}) {
|
|
57
|
+
if (!panels.panels.length) return null;
|
|
58
|
+
|
|
59
|
+
return (
|
|
60
|
+
<>
|
|
61
|
+
{panels.panels.map((panel) => (
|
|
62
|
+
<ToolbarTooltip key={panel.id} label={panel.label} side="bottom">
|
|
63
|
+
<Toggle
|
|
64
|
+
size="sm"
|
|
65
|
+
aria-label={panel.label}
|
|
66
|
+
disabled={disabled}
|
|
67
|
+
pressed={panels.open?.id === panel.id}
|
|
68
|
+
onPressedChange={() => panels.toggle(panel.id)}
|
|
69
|
+
className="text-foreground/80 size-8 min-w-8 px-0"
|
|
70
|
+
>
|
|
71
|
+
<panel.Icon />
|
|
72
|
+
</Toggle>
|
|
73
|
+
</ToolbarTooltip>
|
|
74
|
+
))}
|
|
75
|
+
<span aria-hidden="true" className="bg-border mx-1 h-4.5 w-px" />
|
|
76
|
+
</>
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function usePhoneLayout() {
|
|
81
|
+
return useSyncExternalStore(
|
|
82
|
+
(onChange) => {
|
|
83
|
+
const media = matchMedia(PHONE_QUERY);
|
|
84
|
+
media.addEventListener("change", onChange);
|
|
85
|
+
|
|
86
|
+
return () => media.removeEventListener("change", onChange);
|
|
87
|
+
},
|
|
88
|
+
() => matchMedia(PHONE_QUERY).matches,
|
|
89
|
+
() => false
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** Whether `element` is at least `min` pixels wide, as it resizes. */
|
|
94
|
+
function useWideEnough(element: HTMLElement | null, min: number) {
|
|
95
|
+
const [wide, setWide] = useState(false);
|
|
96
|
+
|
|
97
|
+
useEffect(() => {
|
|
98
|
+
if (!element) return;
|
|
99
|
+
|
|
100
|
+
const observer = new ResizeObserver(([entry]) => {
|
|
101
|
+
setWide((entry?.contentRect.width ?? 0) >= min);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
observer.observe(element);
|
|
105
|
+
|
|
106
|
+
return () => observer.disconnect();
|
|
107
|
+
}, [element, min]);
|
|
108
|
+
|
|
109
|
+
return wide;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function PanelContent({
|
|
113
|
+
panel,
|
|
114
|
+
mailboxId,
|
|
115
|
+
message,
|
|
116
|
+
}: {
|
|
117
|
+
panel: MessagePanel;
|
|
118
|
+
mailboxId: string;
|
|
119
|
+
message: MessageDetail;
|
|
120
|
+
}) {
|
|
121
|
+
return (
|
|
122
|
+
<Suspense fallback={null}>
|
|
123
|
+
<panel.Component
|
|
124
|
+
// A panel starts afresh for each message.
|
|
125
|
+
key={message.id}
|
|
126
|
+
mailboxId={mailboxId}
|
|
127
|
+
messageId={message.id}
|
|
128
|
+
conversationId={message.conversationId}
|
|
129
|
+
from={{ name: message.fromName, address: message.fromAddress }}
|
|
130
|
+
/>
|
|
131
|
+
</Suspense>
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* The open panel: beside the conversation when the reading pane has room
|
|
137
|
+
* (`reader` is the pane), else in a sheet, from the bottom on phones.
|
|
138
|
+
*/
|
|
139
|
+
export function OpenMessagePanel({
|
|
140
|
+
panels,
|
|
141
|
+
reader,
|
|
142
|
+
mailboxId,
|
|
143
|
+
message,
|
|
144
|
+
}: {
|
|
145
|
+
panels: MessagePanels;
|
|
146
|
+
reader: HTMLElement | null;
|
|
147
|
+
mailboxId: string | undefined;
|
|
148
|
+
message: MessageDetail | undefined;
|
|
149
|
+
}) {
|
|
150
|
+
const wide = useWideEnough(reader, SIDE_PANEL_MIN_READER_WIDTH);
|
|
151
|
+
const phone = usePhoneLayout();
|
|
152
|
+
const panel = panels.open;
|
|
153
|
+
|
|
154
|
+
if (!panel || !mailboxId || !message) return null;
|
|
155
|
+
|
|
156
|
+
if (wide) {
|
|
157
|
+
return (
|
|
158
|
+
<aside
|
|
159
|
+
aria-label={panel.label}
|
|
160
|
+
className="border-border flex w-80 shrink-0 flex-col border-l"
|
|
161
|
+
>
|
|
162
|
+
<div className="flex h-11 shrink-0 items-center gap-2 pr-1.5 pl-4">
|
|
163
|
+
<h2 className="min-w-0 flex-1 truncate text-[13px] font-semibold">
|
|
164
|
+
{panel.label}
|
|
165
|
+
</h2>
|
|
166
|
+
<Button
|
|
167
|
+
variant="ghost"
|
|
168
|
+
size="icon-sm"
|
|
169
|
+
aria-label={`Close ${panel.label}`}
|
|
170
|
+
onClick={panels.close}
|
|
171
|
+
>
|
|
172
|
+
<X />
|
|
173
|
+
</Button>
|
|
174
|
+
</div>
|
|
175
|
+
<div className="min-h-0 flex-1 overflow-y-auto px-4 pb-4">
|
|
176
|
+
<PanelContent panel={panel} mailboxId={mailboxId} message={message} />
|
|
177
|
+
</div>
|
|
178
|
+
</aside>
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
return (
|
|
183
|
+
<Sheet
|
|
184
|
+
open
|
|
185
|
+
onOpenChange={(open) => {
|
|
186
|
+
if (!open) panels.close();
|
|
187
|
+
}}
|
|
188
|
+
>
|
|
189
|
+
<SheetContent
|
|
190
|
+
side={phone ? "bottom" : "right"}
|
|
191
|
+
className={
|
|
192
|
+
phone
|
|
193
|
+
? "max-h-[min(85dvh,40rem)] gap-3 rounded-t-2xl px-4 pt-4 pb-[max(1rem,env(safe-area-inset-bottom))]"
|
|
194
|
+
: "gap-3 p-4"
|
|
195
|
+
}
|
|
196
|
+
>
|
|
197
|
+
<SheetTitle className="pr-10 text-[15px] font-semibold">
|
|
198
|
+
{panel.label}
|
|
199
|
+
</SheetTitle>
|
|
200
|
+
<div className="min-h-0 flex-1 overflow-y-auto">
|
|
201
|
+
<PanelContent panel={panel} mailboxId={mailboxId} message={message} />
|
|
202
|
+
</div>
|
|
203
|
+
</SheetContent>
|
|
204
|
+
</Sheet>
|
|
205
|
+
);
|
|
206
|
+
}
|