@open-workspace/email 0.2.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/README.md +23 -20
- package/alchemy/index.ts +273 -0
- package/drizzle/mailbox/0000_puzzling_dracula.sql +149 -0
- package/drizzle/mailbox/0001_mute_jack_flag.sql +12 -0
- package/drizzle/mailbox/meta/0000_snapshot.json +1002 -0
- package/drizzle/mailbox/meta/0001_snapshot.json +1002 -0
- package/drizzle/mailbox/meta/_journal.json +20 -0
- package/drizzle/mailbox/migrations.js +12 -0
- package/index.ts +3 -1
- package/migrations/0000_dry_moon_knight.sql +77 -0
- package/migrations/meta/0000_snapshot.json +248 -106
- package/migrations/meta/_journal.json +2 -2
- package/package.json +74 -68
- package/shared/attachment-preview.ts +37 -27
- package/shared/folder-order.ts +106 -0
- package/shared/mail-authentication.ts +8 -3
- package/shared/mail-feedback.ts +18 -25
- package/shared/mail-headers.ts +114 -39
- package/shared/mail-import.ts +38 -0
- package/shared/mail-path.ts +42 -0
- package/shared/mail-received.ts +174 -31
- package/shared/mail-remote.ts +59 -2
- package/shared/mail-sender-intel.ts +22 -4
- package/shared/mail.ts +78 -26
- package/shared/module.ts +33 -0
- package/shared/office-preview.ts +14 -2
- package/shared/pdfjs-assets.ts +35 -0
- package/shared/permissions.ts +73 -0
- package/shared/webhooks.ts +41 -0
- package/src/admin/blocked-senders.tsx +189 -0
- package/src/client.tsx +97 -0
- package/src/lib/mail-api.ts +9 -0
- package/src/mail/attachment-preview-dialog.tsx +161 -0
- package/src/mail/blocked-senders.tsx +138 -0
- package/src/mail/compose-window-chrome.tsx +194 -0
- package/src/mail/compose-window.tsx +486 -0
- package/src/mail/composer-asset-bookmarks.ts +409 -0
- package/src/mail/composer-asset.tsx +229 -0
- package/src/mail/composer-attachment-list.tsx +138 -0
- package/src/mail/composer-editor-document.ts +65 -0
- package/src/mail/composer-editor.tsx +284 -0
- package/src/mail/composer-linked-attachment-text.ts +12 -0
- package/src/mail/composer-recipient-fields.tsx +165 -0
- package/src/mail/composer-recipients.ts +208 -0
- package/src/mail/composer-session.ts +562 -0
- package/src/mail/composer-toolbar.tsx +303 -0
- package/src/mail/composer-upload-client.ts +105 -0
- package/src/mail/composer-upload-progress.ts +53 -0
- package/src/mail/conversation-list.tsx +550 -0
- package/src/mail/conversation-loading-skeleton.tsx +119 -0
- package/src/mail/conversation-message.tsx +346 -0
- package/src/mail/conversation-reply.tsx +470 -0
- package/src/mail/conversation-selection-toolbar.tsx +322 -0
- package/src/mail/conversation-view.tsx +437 -0
- package/src/mail/delivery-indicator.tsx +272 -0
- package/src/mail/email-html-body.tsx +203 -0
- package/src/mail/folder-glyph.tsx +46 -0
- package/src/mail/folder-manager.tsx +532 -0
- package/src/mail/format-bytes.ts +7 -0
- package/src/mail/mail-app-bar.tsx +253 -0
- package/src/mail/mail-background.tsx +12 -0
- package/src/mail/mail-dock.tsx +137 -0
- package/src/mail/mail-folders.ts +44 -0
- package/src/mail/mail-layout.css +236 -0
- package/src/mail/mail-location.ts +73 -0
- package/src/mail/mail-mailbox-sheet.tsx +275 -0
- package/src/mail/mail-nav-rail.tsx +129 -0
- package/src/mail/mail-nav.tsx +324 -0
- package/src/mail/mail-prefetch.ts +59 -0
- package/src/mail/mail-primitives.tsx +66 -0
- package/src/mail/mail-queries.ts +209 -0
- package/src/mail/mail-query-cache.ts +486 -0
- package/src/mail/mail-seed.ts +47 -0
- package/src/mail/mail-shell.tsx +126 -0
- package/src/mail/mailbox-ai-settings.tsx +185 -0
- package/src/mail/mailbox-realtime.tsx +251 -0
- package/src/mail/mailbox-route.tsx +15 -0
- package/src/mail/message-actions.tsx +353 -0
- package/src/mail/message-attachments.tsx +200 -0
- package/src/mail/message-format.ts +75 -0
- package/src/mail/message-header.tsx +260 -0
- package/src/mail/message-translation.tsx +225 -0
- package/src/mail/original-message-sheet.tsx +619 -0
- package/src/mail/original-message.ts +191 -0
- package/src/mail/outbound-notification.ts +53 -0
- package/src/mail/pane-splitter.tsx +117 -0
- package/src/mail/pdf-preview-toolbar.tsx +152 -0
- package/src/mail/pdf-preview.css +44 -0
- package/src/mail/pdf-preview.tsx +156 -0
- package/src/mail/pdf-translation-layout.ts +95 -0
- package/src/mail/print-message.ts +92 -0
- package/src/mail/reader-pane.tsx +535 -0
- package/src/mail/recipient-combobox.tsx +335 -0
- package/src/mail/recipient-field-row.tsx +34 -0
- package/src/mail/reply-to-warning.tsx +50 -0
- package/src/mail/sanitize-email-html.ts +430 -0
- package/src/mail/sender-actions.tsx +149 -0
- package/src/mail/sender-authentication.tsx +485 -0
- package/src/mail/sender-dialogs.tsx +384 -0
- package/src/mail/sender-security.tsx +545 -0
- package/src/mail/toolbar-tooltip.tsx +29 -0
- package/src/mail/translation-html.ts +49 -0
- package/src/mail/translation-language.ts +21 -0
- package/src/mail/types.ts +53 -0
- package/src/mail/unread-document-indicator.tsx +60 -0
- package/src/mail/use-compose-submission.ts +208 -0
- package/src/mail/use-composer-attachment-preflight.ts +184 -0
- package/src/mail/use-composer-submission.ts +117 -0
- package/src/mail/use-conversation-selection.ts +186 -0
- package/src/mail/use-mail-controller.ts +427 -0
- package/src/mail/use-mail-data.ts +279 -0
- package/src/mail/use-mail-safety.ts +155 -0
- package/src/mail/use-mail-send.ts +142 -0
- package/src/mail/use-pdf-translation-overlay.ts +156 -0
- package/src/mail/use-pdf-translation.ts +100 -0
- package/src/mail/use-pdf-viewer.ts +215 -0
- package/src/mail/use-reply-submission.ts +114 -0
- package/src/mail/use-sanitized-email-html.ts +20 -0
- package/src/mail/use-visible-message-read.ts +138 -0
- package/src/pwa/push-subscription.ts +151 -0
- package/src/settings/mail-apps-page.tsx +235 -0
- package/src/settings/notifications-page.tsx +291 -0
- package/worker/admin/blocked-sender-routes.ts +166 -0
- package/worker/admin/schemas.ts +11 -0
- package/worker/bindings.d.ts +14 -10
- package/worker/db/schema.ts +90 -34
- package/worker/jmap/eventsource.ts +169 -0
- package/worker/jmap/methods.ts +1716 -361
- package/worker/jmap/push-types.ts +27 -0
- package/worker/jmap/push.ts +207 -0
- package/worker/jmap/routes.ts +448 -86
- package/worker/mail/access.ts +258 -21
- package/worker/mail/ai-classification.ts +36 -20
- package/worker/mail/ai-translation.ts +13 -6
- package/worker/mail/auth-headers.ts +395 -137
- package/worker/mail/bimi.ts +200 -73
- package/worker/mail/bootstrap.ts +79 -0
- package/worker/mail/capped-body.ts +36 -0
- package/worker/mail/classification-signals.ts +35 -25
- package/worker/mail/conversation-cursor.ts +30 -19
- package/worker/mail/delivery-events.ts +88 -62
- package/worker/mail/delivery-facts.ts +46 -10
- package/worker/mail/demo-routes.ts +34 -10
- package/worker/mail/doh.ts +62 -23
- package/worker/mail/downloads.ts +75 -40
- package/worker/mail/edge-cache.ts +155 -0
- package/worker/mail/header-metadata.ts +84 -52
- package/worker/mail/impersonation.ts +160 -38
- package/worker/mail/import-routes.ts +313 -0
- package/worker/mail/inbound-delivery.ts +19 -9
- package/worker/mail/inbound-threading.ts +18 -8
- package/worker/mail/inbound.ts +82 -40
- package/worker/mail/ip-intel.ts +110 -27
- package/worker/mail/isolate-cache.ts +35 -0
- package/worker/mail/link-domains.ts +29 -7
- package/worker/mail/mailbox-deletion.ts +10 -4
- package/worker/mail/mailbox-directory.ts +16 -6
- package/worker/mail/mailing-list.ts +94 -39
- package/worker/mail/message-security.ts +90 -15
- package/worker/mail/message-view.ts +18 -6
- package/worker/mail/office-conversion.ts +31 -9
- package/worker/mail/office-preview-container.ts +40 -13
- package/worker/mail/office-preview-queue.ts +76 -32
- package/worker/mail/org-domain.ts +8 -1
- package/worker/mail/outbound-content.ts +71 -26
- package/worker/mail/outbound-delivery.ts +31 -17
- package/worker/mail/outbound-service.ts +48 -30
- package/worker/mail/outbound-threading.ts +30 -17
- package/worker/mail/outbound.ts +97 -70
- package/worker/mail/outgoing-context.ts +25 -15
- package/worker/mail/participants.ts +44 -29
- package/worker/mail/push-notifications.ts +283 -171
- package/worker/mail/quote-parser.ts +21 -10
- package/worker/mail/r2-presigned-urls.ts +31 -25
- package/worker/mail/receive.ts +23 -11
- package/worker/mail/recipients.ts +6 -1
- package/worker/mail/remote-proxy.ts +187 -31
- package/worker/mail/remote-routes.ts +87 -0
- package/worker/mail/remote-token.ts +104 -0
- package/worker/mail/repeat.ts +19 -0
- package/worker/mail/reply-plan.ts +62 -33
- package/worker/mail/rfc.ts +32 -7
- package/worker/mail/routes.ts +871 -542
- package/worker/mail/safety-routes.ts +329 -202
- package/worker/mail/schemas.ts +84 -105
- package/worker/mail/search.ts +1 -0
- package/worker/mail/security-settings.ts +41 -9
- package/worker/mail/sender-intel.ts +206 -51
- package/worker/mail/spamhaus.ts +92 -45
- package/worker/mail/unsubscribe.ts +76 -18
- package/worker/mail/uploads.ts +153 -91
- package/worker/mail/webhook-source.ts +35 -12
- package/worker/mail/workspace-safety.ts +97 -38
- package/worker/mailbox/demo-html.ts +7 -7
- package/worker/mailbox/demo-seed.ts +10 -44
- package/worker/mailbox/demo.ts +597 -227
- package/worker/mailbox/email-index.ts +53 -0
- package/worker/mailbox/folder-model.ts +53 -17
- package/worker/mailbox/import-placement.ts +88 -0
- package/worker/mailbox/inbox-counts.ts +106 -0
- package/worker/mailbox/index.ts +1761 -737
- package/worker/mailbox/jmap-store.ts +139 -35
- package/worker/mailbox/model.ts +7 -14
- package/worker/mailbox/office-preview-jobs.ts +56 -25
- package/worker/mailbox/schema.ts +87 -66
- package/worker/mailbox/senders.ts +176 -70
- package/worker/mcp/mail-action-tools.ts +128 -87
- package/worker/mcp/mail-compose-tools.ts +133 -82
- package/worker/mcp/mail-query-tools.ts +120 -71
- package/worker/mcp/mail-safety-tools.ts +321 -248
- package/worker/mcp/schemas.ts +43 -0
- package/worker/mcp/tools.ts +13 -10
- package/worker/module.ts +43 -18
- package/worker/sql.d.ts +8 -0
- package/alchemy.ts +0 -126
- package/containers/office-preview/Dockerfile +0 -10
- package/migrations/0000_email.sql +0 -53
- package/shared/mail-rules.ts +0 -156
- package/worker/admin/report-routes.ts +0 -164
- package/worker/mail/reported-messages.ts +0 -68
- package/worker/mailbox/legacy-migrations.ts +0 -41
- package/worker/mailbox/migrations.ts +0 -10
- package/worker/mailbox/rules.ts +0 -110
|
@@ -0,0 +1,486 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useEffect,
|
|
3
|
+
useEffectEvent,
|
|
4
|
+
useMemo,
|
|
5
|
+
useRef,
|
|
6
|
+
useState,
|
|
7
|
+
useSyncExternalStore,
|
|
8
|
+
} from "react";
|
|
9
|
+
import type { DragEvent, RefObject } from "react";
|
|
10
|
+
import { toast } from "sonner";
|
|
11
|
+
|
|
12
|
+
import { forwardSubject } from "../../shared/mail";
|
|
13
|
+
import {
|
|
14
|
+
ComposeWindowFooter,
|
|
15
|
+
ComposeWindowHeader,
|
|
16
|
+
ForwardedMessageNotice,
|
|
17
|
+
MinimizedComposer,
|
|
18
|
+
} from "./compose-window-chrome";
|
|
19
|
+
import { ComposerAttachmentList } from "./composer-attachment-list";
|
|
20
|
+
import { ComposerEditor } from "./composer-editor";
|
|
21
|
+
import type { ComposerContent, ComposerEditorHandle } from "./composer-editor";
|
|
22
|
+
import { ComposerRecipientFields } from "./composer-recipient-fields";
|
|
23
|
+
import { validateComposerRecipients } from "./composer-recipients";
|
|
24
|
+
import type { RecipientFieldValue } from "./composer-recipients";
|
|
25
|
+
import { useComposerSession } from "./composer-session";
|
|
26
|
+
import { isInlineComposerImage } from "./composer-upload-client";
|
|
27
|
+
import { ReplyToWarning } from "./reply-to-warning";
|
|
28
|
+
import type { Mailbox, MessageDetail } from "./types";
|
|
29
|
+
import { useComposeSubmission } from "./use-compose-submission";
|
|
30
|
+
import { useComposerAttachmentPreflight } from "./use-composer-attachment-preflight";
|
|
31
|
+
|
|
32
|
+
const EMPTY_RECIPIENT_FIELD: RecipientFieldValue = {
|
|
33
|
+
recipients: [],
|
|
34
|
+
input: "",
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const EMPTY_CONTENT: ComposerContent = {
|
|
38
|
+
bodyHtml: "",
|
|
39
|
+
bodyText: "",
|
|
40
|
+
inlineAssetIds: [],
|
|
41
|
+
linkedAssetIds: [],
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/** Below Tailwind's `sm`, the composer covers the screen. */
|
|
45
|
+
const PHONE_QUERY = "(max-width: 639.98px)";
|
|
46
|
+
|
|
47
|
+
function usePhoneLayout() {
|
|
48
|
+
return useSyncExternalStore(
|
|
49
|
+
(onChange) => {
|
|
50
|
+
const media = matchMedia(PHONE_QUERY);
|
|
51
|
+
media.addEventListener("change", onChange);
|
|
52
|
+
|
|
53
|
+
return () => media.removeEventListener("change", onChange);
|
|
54
|
+
},
|
|
55
|
+
() => matchMedia(PHONE_QUERY).matches,
|
|
56
|
+
() => false
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Makes everything outside `element` inert: each sibling of the element and
|
|
62
|
+
* of its ancestors up to <body>. Returns the undo. Elements that were inert
|
|
63
|
+
* already are left alone.
|
|
64
|
+
*/
|
|
65
|
+
function inertOutside(element: HTMLElement) {
|
|
66
|
+
const changed: HTMLElement[] = [];
|
|
67
|
+
|
|
68
|
+
for (
|
|
69
|
+
let node: HTMLElement | null = element;
|
|
70
|
+
node && node !== document.body;
|
|
71
|
+
node = node.parentElement
|
|
72
|
+
) {
|
|
73
|
+
for (const sibling of node.parentElement?.children ?? []) {
|
|
74
|
+
if (
|
|
75
|
+
sibling === node ||
|
|
76
|
+
!(sibling instanceof HTMLElement) ||
|
|
77
|
+
sibling.inert
|
|
78
|
+
) {
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (
|
|
83
|
+
sibling instanceof HTMLScriptElement ||
|
|
84
|
+
sibling instanceof HTMLStyleElement
|
|
85
|
+
) {
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
sibling.inert = true;
|
|
90
|
+
changed.push(sibling);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return () => {
|
|
95
|
+
for (const sibling of changed) sibling.inert = false;
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* On a phone the composer is a full-screen modal: the page behind is inert,
|
|
101
|
+
* focus starts inside, Escape closes it (unless a list or popup inside is
|
|
102
|
+
* open and takes the key), and focus goes back to what opened it. The
|
|
103
|
+
* floating desktop window stays non-modal.
|
|
104
|
+
*/
|
|
105
|
+
function useFullScreenComposer(
|
|
106
|
+
section: RefObject<HTMLElement | null>,
|
|
107
|
+
active: boolean,
|
|
108
|
+
onEscape: () => void
|
|
109
|
+
) {
|
|
110
|
+
const escape = useEffectEvent(onEscape);
|
|
111
|
+
// What had focus before the composer opened, to go back to when it closes.
|
|
112
|
+
const opener = useRef(document.activeElement);
|
|
113
|
+
useEffect(() => {
|
|
114
|
+
const element = section.current;
|
|
115
|
+
|
|
116
|
+
if (!active || !element) return;
|
|
117
|
+
const undo = inertOutside(element);
|
|
118
|
+
|
|
119
|
+
if (!element.contains(document.activeElement)) element.focus();
|
|
120
|
+
|
|
121
|
+
const onKeyDown = (event: KeyboardEvent) => {
|
|
122
|
+
if (event.key !== "Escape" || event.defaultPrevented) return;
|
|
123
|
+
|
|
124
|
+
if (
|
|
125
|
+
event.target instanceof Element &&
|
|
126
|
+
event.target.closest('[aria-expanded="true"]')
|
|
127
|
+
) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
event.preventDefault();
|
|
132
|
+
escape();
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
element.addEventListener("keydown", onKeyDown);
|
|
136
|
+
|
|
137
|
+
return () => {
|
|
138
|
+
element.removeEventListener("keydown", onKeyDown);
|
|
139
|
+
undo();
|
|
140
|
+
// Once the composer is gone, focus would fall to <body>.
|
|
141
|
+
const { current: returnTo } = opener;
|
|
142
|
+
|
|
143
|
+
requestAnimationFrame(() => {
|
|
144
|
+
const current = document.activeElement;
|
|
145
|
+
|
|
146
|
+
if (
|
|
147
|
+
(!current || current === document.body) &&
|
|
148
|
+
returnTo instanceof HTMLElement &&
|
|
149
|
+
returnTo.isConnected
|
|
150
|
+
) {
|
|
151
|
+
returnTo.focus();
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
};
|
|
155
|
+
}, [section, active]);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export function ComposeWindow({
|
|
159
|
+
mailbox,
|
|
160
|
+
forwardedMessage,
|
|
161
|
+
onClose,
|
|
162
|
+
}: {
|
|
163
|
+
mailbox: Mailbox;
|
|
164
|
+
forwardedMessage?: Pick<
|
|
165
|
+
MessageDetail,
|
|
166
|
+
| "id"
|
|
167
|
+
| "subject"
|
|
168
|
+
| "fromAddress"
|
|
169
|
+
| "fromName"
|
|
170
|
+
| "preview"
|
|
171
|
+
| "attachments"
|
|
172
|
+
| "security"
|
|
173
|
+
>;
|
|
174
|
+
onClose: () => void;
|
|
175
|
+
}) {
|
|
176
|
+
const form = useRef<HTMLFormElement>(null);
|
|
177
|
+
const editor = useRef<ComposerEditorHandle>(null);
|
|
178
|
+
const fileInput = useRef<HTMLInputElement>(null);
|
|
179
|
+
const inlineFileInput = useRef<HTMLInputElement>(null);
|
|
180
|
+
const [to, setTo] = useState<RecipientFieldValue>(EMPTY_RECIPIENT_FIELD);
|
|
181
|
+
const [cc, setCc] = useState<RecipientFieldValue>(EMPTY_RECIPIENT_FIELD);
|
|
182
|
+
const [bcc, setBcc] = useState<RecipientFieldValue>(EMPTY_RECIPIENT_FIELD);
|
|
183
|
+
const [replyTo, setReplyTo] = useState("");
|
|
184
|
+
|
|
185
|
+
const [subject, setSubject] = useState(() =>
|
|
186
|
+
forwardedMessage ? forwardSubject(forwardedMessage.subject) : ""
|
|
187
|
+
);
|
|
188
|
+
|
|
189
|
+
const [content, setContent] = useState<ComposerContent>(EMPTY_CONTENT);
|
|
190
|
+
const [documentAssetIds, setDocumentAssetIds] = useState<string[]>([]);
|
|
191
|
+
const [minimized, setMinimized] = useState(false);
|
|
192
|
+
const [dragging, setDragging] = useState(false);
|
|
193
|
+
const section = useRef<HTMLElement>(null);
|
|
194
|
+
const minimizeButton = useRef<HTMLButtonElement>(null);
|
|
195
|
+
const restoreButton = useRef<HTMLButtonElement>(null);
|
|
196
|
+
// Minimizing moves focus to Restore, and restoring back to Minimize.
|
|
197
|
+
const focusAfterToggle = useRef(false);
|
|
198
|
+
const phone = usePhoneLayout();
|
|
199
|
+
|
|
200
|
+
const { session, snapshot } = useComposerSession(
|
|
201
|
+
mailbox.id,
|
|
202
|
+
forwardedMessage?.attachments
|
|
203
|
+
);
|
|
204
|
+
|
|
205
|
+
const recipients = validateComposerRecipients({
|
|
206
|
+
to,
|
|
207
|
+
cc,
|
|
208
|
+
bcc,
|
|
209
|
+
replyTo,
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
const recipientCount = recipients.count;
|
|
213
|
+
|
|
214
|
+
const documentAssetIdSet = useMemo(
|
|
215
|
+
() => new Set(documentAssetIds),
|
|
216
|
+
[documentAssetIds]
|
|
217
|
+
);
|
|
218
|
+
|
|
219
|
+
const activeAssets = useMemo(
|
|
220
|
+
() => snapshot.assets.filter((asset) => documentAssetIdSet.has(asset.id)),
|
|
221
|
+
[documentAssetIdSet, snapshot.assets]
|
|
222
|
+
);
|
|
223
|
+
|
|
224
|
+
useComposerAttachmentPreflight(
|
|
225
|
+
session,
|
|
226
|
+
forwardedMessage
|
|
227
|
+
? {
|
|
228
|
+
kind: "forward",
|
|
229
|
+
mailboxId: mailbox.id,
|
|
230
|
+
sourceEmailId: forwardedMessage.id,
|
|
231
|
+
bodyText: content.bodyText,
|
|
232
|
+
bodyHtml: content.bodyHtml || undefined,
|
|
233
|
+
}
|
|
234
|
+
: {
|
|
235
|
+
kind: "compose",
|
|
236
|
+
mailboxId: mailbox.id,
|
|
237
|
+
subject,
|
|
238
|
+
bodyText: content.bodyText,
|
|
239
|
+
bodyHtml: content.bodyHtml || undefined,
|
|
240
|
+
},
|
|
241
|
+
activeAssets,
|
|
242
|
+
snapshot.phase === "editing"
|
|
243
|
+
);
|
|
244
|
+
const linkedIds = snapshot.linkedAssetIds;
|
|
245
|
+
const attachmentError = session.limitError();
|
|
246
|
+
|
|
247
|
+
const uploadsPending = activeAssets.some(
|
|
248
|
+
(asset) => asset.status === "uploading"
|
|
249
|
+
);
|
|
250
|
+
|
|
251
|
+
const uploadsFailed = activeAssets.some((asset) => asset.status === "error");
|
|
252
|
+
|
|
253
|
+
const submission = useComposeSubmission({
|
|
254
|
+
session,
|
|
255
|
+
phase: snapshot.phase,
|
|
256
|
+
mailbox,
|
|
257
|
+
forwardedMessage,
|
|
258
|
+
recipients,
|
|
259
|
+
subject,
|
|
260
|
+
content,
|
|
261
|
+
editor,
|
|
262
|
+
activeAssets,
|
|
263
|
+
uploadLimitError: attachmentError,
|
|
264
|
+
uploadsPending,
|
|
265
|
+
uploadsFailed,
|
|
266
|
+
onClose,
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
const { busy } = submission;
|
|
270
|
+
// Sending takes over the window: no drop target while it is busy.
|
|
271
|
+
const dropTarget = dragging && !busy;
|
|
272
|
+
|
|
273
|
+
function addInlineFiles(files: File[], position?: number) {
|
|
274
|
+
const assets = session.addFiles(files, "inline");
|
|
275
|
+
|
|
276
|
+
if (!assets) return;
|
|
277
|
+
editor.current?.insertAssets(assets, position);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
function addAttachmentFiles(files: File[], position?: number) {
|
|
281
|
+
const assets = session.addFiles(files, "attachment");
|
|
282
|
+
|
|
283
|
+
if (!assets) return;
|
|
284
|
+
editor.current?.insertAssets(assets, position);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
function handleComposerDrop(event: DragEvent<HTMLFormElement>) {
|
|
288
|
+
if (!event.dataTransfer.types.includes("Files")) return;
|
|
289
|
+
event.preventDefault();
|
|
290
|
+
setDragging(false);
|
|
291
|
+
|
|
292
|
+
if (busy) return;
|
|
293
|
+
|
|
294
|
+
// ProseMirror owns editor-body drops so it can preserve the insertion
|
|
295
|
+
// position. The form catches files dropped on every other composer area.
|
|
296
|
+
if (
|
|
297
|
+
event.target instanceof Element &&
|
|
298
|
+
event.target.closest("[data-composer-editor-content]")
|
|
299
|
+
) {
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
const inline: File[] = [];
|
|
304
|
+
const attachments: File[] = [];
|
|
305
|
+
|
|
306
|
+
for (const file of Array.from(event.dataTransfer.files)) {
|
|
307
|
+
(isInlineComposerImage(file) ? inline : attachments).push(file);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
if (inline.length) addInlineFiles(inline);
|
|
311
|
+
|
|
312
|
+
if (attachments.length) addAttachmentFiles(attachments);
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
function closeComposer() {
|
|
316
|
+
if (busy) {
|
|
317
|
+
toast.error("Wait for the message to finish sending");
|
|
318
|
+
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
session.close();
|
|
323
|
+
onClose();
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
function toggleMinimized(next: boolean) {
|
|
327
|
+
focusAfterToggle.current = true;
|
|
328
|
+
setMinimized(next);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
useEffect(() => {
|
|
332
|
+
if (!focusAfterToggle.current) return;
|
|
333
|
+
focusAfterToggle.current = false;
|
|
334
|
+
(minimized ? restoreButton : minimizeButton).current?.focus();
|
|
335
|
+
}, [minimized]);
|
|
336
|
+
|
|
337
|
+
useFullScreenComposer(section, phone && !minimized, closeComposer);
|
|
338
|
+
|
|
339
|
+
if (minimized) {
|
|
340
|
+
return (
|
|
341
|
+
<MinimizedComposer
|
|
342
|
+
subject={subject}
|
|
343
|
+
restoreRef={restoreButton}
|
|
344
|
+
onRestore={() => toggleMinimized(false)}
|
|
345
|
+
onClose={closeComposer}
|
|
346
|
+
/>
|
|
347
|
+
);
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
return (
|
|
351
|
+
<section
|
|
352
|
+
ref={section}
|
|
353
|
+
role="dialog"
|
|
354
|
+
aria-label="New message"
|
|
355
|
+
aria-modal={phone || undefined}
|
|
356
|
+
tabIndex={-1}
|
|
357
|
+
className="animate-rise bg-surface ring-border fixed inset-0 z-50 flex flex-col shadow-2xl ring-1 outline-none sm:inset-auto sm:right-6 sm:bottom-6 sm:h-[min(600px,calc(100dvh-3rem))] sm:w-[min(560px,calc(100vw-2.5rem))] sm:rounded-xl"
|
|
358
|
+
>
|
|
359
|
+
{/* oxlint-disable-next-line jsx-a11y/no-noninteractive-element-interactions -- files can be dropped anywhere on the form */}
|
|
360
|
+
<form
|
|
361
|
+
ref={form}
|
|
362
|
+
className="flex min-h-0 flex-1 flex-col"
|
|
363
|
+
aria-busy={busy}
|
|
364
|
+
onSubmit={submission.submit}
|
|
365
|
+
onDragEnter={(event) => {
|
|
366
|
+
if (!event.dataTransfer.types.includes("Files")) return;
|
|
367
|
+
event.preventDefault();
|
|
368
|
+
|
|
369
|
+
if (!busy) setDragging(true);
|
|
370
|
+
}}
|
|
371
|
+
onDragOver={(event) => {
|
|
372
|
+
if (!event.dataTransfer.types.includes("Files")) return;
|
|
373
|
+
event.preventDefault();
|
|
374
|
+
event.dataTransfer.dropEffect = busy ? "none" : "copy";
|
|
375
|
+
}}
|
|
376
|
+
onDragLeave={(event) => {
|
|
377
|
+
if (
|
|
378
|
+
!(
|
|
379
|
+
event.relatedTarget instanceof Node &&
|
|
380
|
+
event.currentTarget.contains(event.relatedTarget)
|
|
381
|
+
)
|
|
382
|
+
) {
|
|
383
|
+
setDragging(false);
|
|
384
|
+
}
|
|
385
|
+
}}
|
|
386
|
+
onDragEnd={() => setDragging(false)}
|
|
387
|
+
onDrop={handleComposerDrop}
|
|
388
|
+
>
|
|
389
|
+
<ComposeWindowHeader
|
|
390
|
+
from={mailbox.address}
|
|
391
|
+
minimizeRef={minimizeButton}
|
|
392
|
+
onMinimize={() => toggleMinimized(true)}
|
|
393
|
+
onClose={closeComposer}
|
|
394
|
+
/>
|
|
395
|
+
|
|
396
|
+
<ComposerRecipientFields
|
|
397
|
+
mailboxId={mailbox.id}
|
|
398
|
+
to={to}
|
|
399
|
+
cc={cc}
|
|
400
|
+
bcc={bcc}
|
|
401
|
+
replyTo={replyTo}
|
|
402
|
+
subject={subject}
|
|
403
|
+
subjectReadOnly={Boolean(forwardedMessage)}
|
|
404
|
+
disabled={busy}
|
|
405
|
+
onToChange={setTo}
|
|
406
|
+
onCcChange={setCc}
|
|
407
|
+
onBccChange={setBcc}
|
|
408
|
+
onReplyToChange={setReplyTo}
|
|
409
|
+
onSubjectChange={setSubject}
|
|
410
|
+
/>
|
|
411
|
+
|
|
412
|
+
{forwardedMessage ? (
|
|
413
|
+
<>
|
|
414
|
+
<ForwardedMessageNotice message={forwardedMessage} />
|
|
415
|
+
<ReplyToWarning
|
|
416
|
+
message={forwardedMessage}
|
|
417
|
+
recipients={[
|
|
418
|
+
...recipients.to,
|
|
419
|
+
...recipients.cc,
|
|
420
|
+
...recipients.bcc,
|
|
421
|
+
]}
|
|
422
|
+
/>
|
|
423
|
+
</>
|
|
424
|
+
) : null}
|
|
425
|
+
|
|
426
|
+
<ComposerEditor
|
|
427
|
+
ref={editor}
|
|
428
|
+
session={session}
|
|
429
|
+
onChange={setContent}
|
|
430
|
+
onAssetsChange={setDocumentAssetIds}
|
|
431
|
+
onAddInlineFiles={(files, position) => {
|
|
432
|
+
addInlineFiles(files, position);
|
|
433
|
+
}}
|
|
434
|
+
onAddAttachmentFiles={(files, position) => {
|
|
435
|
+
addAttachmentFiles(files, position);
|
|
436
|
+
}}
|
|
437
|
+
onChooseInlineImage={() => inlineFileInput.current?.click()}
|
|
438
|
+
onSubmitShortcut={() => form.current?.requestSubmit()}
|
|
439
|
+
dragging={dropTarget}
|
|
440
|
+
disabled={busy}
|
|
441
|
+
/>
|
|
442
|
+
|
|
443
|
+
<ComposerAttachmentList
|
|
444
|
+
uploads={activeAssets.filter(
|
|
445
|
+
(asset) => !linkedIds.has(asset.id) || asset.status !== "uploaded"
|
|
446
|
+
)}
|
|
447
|
+
linkedIds={linkedIds}
|
|
448
|
+
progress={session.progress}
|
|
449
|
+
disabled={busy}
|
|
450
|
+
onRemove={(asset) => {
|
|
451
|
+
if (editor.current?.removeAsset(asset.id)) return;
|
|
452
|
+
session.remove(asset.id);
|
|
453
|
+
}}
|
|
454
|
+
onRetry={(asset) => {
|
|
455
|
+
void session.retry(asset.id);
|
|
456
|
+
}}
|
|
457
|
+
/>
|
|
458
|
+
|
|
459
|
+
<ComposeWindowFooter
|
|
460
|
+
fileInput={fileInput}
|
|
461
|
+
inlineFileInput={inlineFileInput}
|
|
462
|
+
uploads={activeAssets}
|
|
463
|
+
error={
|
|
464
|
+
attachmentError ??
|
|
465
|
+
(activeAssets.length > 0 && snapshot.planError
|
|
466
|
+
? "Could not check attachment delivery"
|
|
467
|
+
: null)
|
|
468
|
+
}
|
|
469
|
+
sending={busy}
|
|
470
|
+
sendDisabled={
|
|
471
|
+
busy ||
|
|
472
|
+
recipientCount === 0 ||
|
|
473
|
+
!mailbox.canSend ||
|
|
474
|
+
Boolean(attachmentError) ||
|
|
475
|
+
uploadsPending ||
|
|
476
|
+
uploadsFailed
|
|
477
|
+
}
|
|
478
|
+
onAddAttachments={addAttachmentFiles}
|
|
479
|
+
onAddInlineImages={(files) => {
|
|
480
|
+
addInlineFiles(files);
|
|
481
|
+
}}
|
|
482
|
+
/>
|
|
483
|
+
</form>
|
|
484
|
+
</section>
|
|
485
|
+
);
|
|
486
|
+
}
|