@open-workspace/email 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/README.md +22 -22
- 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_email.sql → 0000_dry_moon_knight.sql} +26 -20
- package/migrations/meta/0000_snapshot.json +125 -109
- 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 +77 -28
- 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 +63 -40
- package/worker/jmap/eventsource.ts +84 -16
- package/worker/jmap/methods.ts +1630 -524
- package/worker/jmap/push-types.ts +27 -0
- package/worker/jmap/push.ts +140 -56
- package/worker/jmap/routes.ts +366 -105
- 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 +88 -22
- 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 +271 -173
- 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 +870 -541
- package/worker/mail/safety-routes.ts +328 -200
- 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 +126 -93
- 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 +595 -225
- 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 +1734 -721
- package/worker/mailbox/jmap-store.ts +139 -35
- package/worker/mailbox/model.ts +8 -6
- 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 -142
- package/containers/office-preview/Dockerfile +0 -10
- 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/migrations.ts +0 -10
- package/worker/mailbox/rules.ts +0 -110
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { Badge, Button } from "@open-workspace/core/ui";
|
|
2
|
+
import {
|
|
3
|
+
AlertCircle,
|
|
4
|
+
Image,
|
|
5
|
+
Link2,
|
|
6
|
+
LoaderCircle,
|
|
7
|
+
Paperclip,
|
|
8
|
+
RotateCcw,
|
|
9
|
+
X,
|
|
10
|
+
} from "lucide-react";
|
|
11
|
+
|
|
12
|
+
import type { ComposerAsset } from "./composer-session";
|
|
13
|
+
import { useComposerUploadProgress } from "./composer-upload-progress";
|
|
14
|
+
import type { ComposerUploadProgressStore } from "./composer-upload-progress";
|
|
15
|
+
import { formatBytes } from "./format-bytes";
|
|
16
|
+
|
|
17
|
+
export function ComposerAttachmentList({
|
|
18
|
+
uploads,
|
|
19
|
+
linkedIds,
|
|
20
|
+
progress,
|
|
21
|
+
onRemove,
|
|
22
|
+
onRetry,
|
|
23
|
+
disabled = false,
|
|
24
|
+
}: {
|
|
25
|
+
uploads: readonly ComposerAsset[];
|
|
26
|
+
linkedIds: ReadonlySet<string>;
|
|
27
|
+
progress: ComposerUploadProgressStore;
|
|
28
|
+
onRemove: (upload: ComposerAsset) => void;
|
|
29
|
+
onRetry: (upload: ComposerAsset) => void;
|
|
30
|
+
disabled?: boolean;
|
|
31
|
+
}) {
|
|
32
|
+
if (!uploads.length) return null;
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
<div className="border-border/70 max-h-32 shrink-0 overflow-y-auto border-t px-3 py-2">
|
|
36
|
+
{uploads.map((upload) => (
|
|
37
|
+
<ComposerAttachmentRow
|
|
38
|
+
key={upload.id}
|
|
39
|
+
upload={upload}
|
|
40
|
+
linked={linkedIds.has(upload.id)}
|
|
41
|
+
progressStore={progress}
|
|
42
|
+
disabled={disabled}
|
|
43
|
+
onRemove={onRemove}
|
|
44
|
+
onRetry={onRetry}
|
|
45
|
+
/>
|
|
46
|
+
))}
|
|
47
|
+
</div>
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function ComposerAttachmentRow({
|
|
52
|
+
upload,
|
|
53
|
+
linked,
|
|
54
|
+
progressStore,
|
|
55
|
+
disabled,
|
|
56
|
+
onRemove,
|
|
57
|
+
onRetry,
|
|
58
|
+
}: {
|
|
59
|
+
upload: ComposerAsset;
|
|
60
|
+
linked: boolean;
|
|
61
|
+
progressStore: ComposerUploadProgressStore;
|
|
62
|
+
disabled: boolean;
|
|
63
|
+
onRemove: (upload: ComposerAsset) => void;
|
|
64
|
+
onRetry: (upload: ComposerAsset) => void;
|
|
65
|
+
}) {
|
|
66
|
+
const progress = useComposerUploadProgress(progressStore, upload.id);
|
|
67
|
+
|
|
68
|
+
return (
|
|
69
|
+
<div className="relative flex min-h-9 items-center gap-2 overflow-hidden rounded-lg px-1.5 text-xs">
|
|
70
|
+
{upload.intent === "inline" ? (
|
|
71
|
+
<Image className="text-muted-foreground size-3.5 shrink-0" />
|
|
72
|
+
) : (
|
|
73
|
+
<Paperclip className="text-muted-foreground size-3.5 shrink-0" />
|
|
74
|
+
)}
|
|
75
|
+
<span className="min-w-0 flex-1 truncate font-medium">
|
|
76
|
+
{upload.filename}
|
|
77
|
+
</span>
|
|
78
|
+
<span className="text-muted-foreground shrink-0 tabular-nums">
|
|
79
|
+
{formatBytes(upload.size)}
|
|
80
|
+
</span>
|
|
81
|
+
{upload.status === "uploading" ? (
|
|
82
|
+
<Badge variant="secondary">
|
|
83
|
+
<LoaderCircle className="animate-spin" />
|
|
84
|
+
{Math.round(progress * 100)}%
|
|
85
|
+
</Badge>
|
|
86
|
+
) : null}
|
|
87
|
+
{upload.status === "error" ? (
|
|
88
|
+
<Badge variant="destructive" title={upload.error ?? undefined}>
|
|
89
|
+
<AlertCircle />
|
|
90
|
+
Failed
|
|
91
|
+
</Badge>
|
|
92
|
+
) : null}
|
|
93
|
+
{upload.status === "uploaded" && linked ? (
|
|
94
|
+
<Badge
|
|
95
|
+
variant="warning"
|
|
96
|
+
title="A 30-day download link will be added to the message"
|
|
97
|
+
>
|
|
98
|
+
<Link2 />
|
|
99
|
+
30-day link
|
|
100
|
+
</Badge>
|
|
101
|
+
) : null}
|
|
102
|
+
{upload.status === "uploaded" && !linked ? (
|
|
103
|
+
<Badge variant="success">
|
|
104
|
+
{upload.intent === "inline" ? <Image /> : <Paperclip />}
|
|
105
|
+
{upload.intent === "inline" ? "Inline" : "Attached"}
|
|
106
|
+
</Badge>
|
|
107
|
+
) : null}
|
|
108
|
+
{upload.status === "error" ? (
|
|
109
|
+
<Button
|
|
110
|
+
type="button"
|
|
111
|
+
variant="ghost"
|
|
112
|
+
size="icon-xs"
|
|
113
|
+
aria-label={`Retry ${upload.filename}`}
|
|
114
|
+
disabled={disabled}
|
|
115
|
+
onClick={() => onRetry(upload)}
|
|
116
|
+
>
|
|
117
|
+
<RotateCcw />
|
|
118
|
+
</Button>
|
|
119
|
+
) : null}
|
|
120
|
+
<Button
|
|
121
|
+
type="button"
|
|
122
|
+
variant="ghost"
|
|
123
|
+
size="icon-xs"
|
|
124
|
+
aria-label={`Remove ${upload.filename}`}
|
|
125
|
+
disabled={disabled}
|
|
126
|
+
onClick={() => onRemove(upload)}
|
|
127
|
+
>
|
|
128
|
+
<X />
|
|
129
|
+
</Button>
|
|
130
|
+
{upload.status === "uploading" ? (
|
|
131
|
+
<span
|
|
132
|
+
className="bg-primary absolute inset-x-1.5 bottom-0 h-0.5 origin-left rounded-full transition-transform"
|
|
133
|
+
style={{ transform: `scaleX(${progress})` }}
|
|
134
|
+
/>
|
|
135
|
+
) : null}
|
|
136
|
+
</div>
|
|
137
|
+
);
|
|
138
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { Editor } from "@tiptap/react";
|
|
2
|
+
|
|
3
|
+
import type { ComposerSession } from "./composer-session";
|
|
4
|
+
|
|
5
|
+
export type ComposerContent = {
|
|
6
|
+
bodyHtml: string;
|
|
7
|
+
bodyText: string;
|
|
8
|
+
inlineAssetIds: string[];
|
|
9
|
+
linkedAssetIds: string[];
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Serializes the editor from stable asset references. Upload metadata stays in
|
|
14
|
+
* ComposerSession and never has to be copied back into ProseMirror attributes.
|
|
15
|
+
*/
|
|
16
|
+
export function composerContent(
|
|
17
|
+
editor: Editor,
|
|
18
|
+
session: ComposerSession
|
|
19
|
+
): ComposerContent {
|
|
20
|
+
const wrapper = document.createElement("div");
|
|
21
|
+
wrapper.innerHTML = editor.getHTML();
|
|
22
|
+
const inlineAssetIds: string[] = [];
|
|
23
|
+
const linkedAssetIds: string[] = [];
|
|
24
|
+
|
|
25
|
+
for (const reference of wrapper.querySelectorAll<HTMLElement>(
|
|
26
|
+
"[data-composer-asset]"
|
|
27
|
+
)) {
|
|
28
|
+
const assetId = reference.dataset.composerAsset ?? "";
|
|
29
|
+
const asset = session.getAsset(assetId);
|
|
30
|
+
|
|
31
|
+
if (!asset?.uploadId) {
|
|
32
|
+
reference.remove();
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (session.isLinked(asset.id)) {
|
|
37
|
+
linkedAssetIds.push(asset.id);
|
|
38
|
+
const placeholder = document.createElement("span");
|
|
39
|
+
placeholder.dataset.linkedAttachment = asset.uploadId;
|
|
40
|
+
placeholder.dataset.linkedAttachmentFilename = asset.filename;
|
|
41
|
+
placeholder.textContent = asset.filename;
|
|
42
|
+
reference.replaceWith(placeholder);
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (asset.intent === "inline" && asset.contentId) {
|
|
47
|
+
inlineAssetIds.push(asset.id);
|
|
48
|
+
const image = document.createElement("img");
|
|
49
|
+
image.src = `cid:${asset.contentId}`;
|
|
50
|
+
image.alt = asset.filename;
|
|
51
|
+
image.title = asset.filename;
|
|
52
|
+
reference.replaceWith(image);
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
reference.remove();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return {
|
|
60
|
+
bodyHtml: wrapper.innerHTML,
|
|
61
|
+
bodyText: editor.getText({ blockSeparator: "\n\n" }),
|
|
62
|
+
inlineAssetIds,
|
|
63
|
+
linkedAssetIds,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
import { cn } from "@open-workspace/core/ui";
|
|
2
|
+
import Placeholder from "@tiptap/extension-placeholder";
|
|
3
|
+
import { Slice } from "@tiptap/pm/model";
|
|
4
|
+
import { EditorContent, useEditor } from "@tiptap/react";
|
|
5
|
+
import StarterKit from "@tiptap/starter-kit";
|
|
6
|
+
import {
|
|
7
|
+
forwardRef,
|
|
8
|
+
useEffect,
|
|
9
|
+
useImperativeHandle,
|
|
10
|
+
useLayoutEffect,
|
|
11
|
+
useRef,
|
|
12
|
+
} from "react";
|
|
13
|
+
|
|
14
|
+
import { ComposerAsset } from "./composer-asset";
|
|
15
|
+
import {
|
|
16
|
+
composerAssetIds,
|
|
17
|
+
insertComposerAssets,
|
|
18
|
+
reconcileComposerAssetNodes,
|
|
19
|
+
removeComposerAsset,
|
|
20
|
+
withoutComposerAssetNodes,
|
|
21
|
+
} from "./composer-asset-bookmarks";
|
|
22
|
+
import { composerContent } from "./composer-editor-document";
|
|
23
|
+
import type { ComposerContent } from "./composer-editor-document";
|
|
24
|
+
import type {
|
|
25
|
+
ComposerAsset as ComposerAssetRecord,
|
|
26
|
+
ComposerSession,
|
|
27
|
+
} from "./composer-session";
|
|
28
|
+
import { ComposerToolbar } from "./composer-toolbar";
|
|
29
|
+
import { isInlineComposerImage } from "./composer-upload-client";
|
|
30
|
+
|
|
31
|
+
export type { ComposerContent } from "./composer-editor-document";
|
|
32
|
+
|
|
33
|
+
export type ComposerEditorHandle = {
|
|
34
|
+
content: () => ComposerContent;
|
|
35
|
+
assetIds: () => string[];
|
|
36
|
+
insertAssets: (assets: ComposerAssetRecord[], position?: number) => void;
|
|
37
|
+
reconcileAssets: () => void;
|
|
38
|
+
removeAsset: (assetId: string) => boolean;
|
|
39
|
+
focus: () => void;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export const ComposerEditor = forwardRef<
|
|
43
|
+
ComposerEditorHandle,
|
|
44
|
+
{
|
|
45
|
+
session: ComposerSession;
|
|
46
|
+
onChange: (content: ComposerContent) => void;
|
|
47
|
+
/** Must be stable (e.g. a state setter): the editor keeps the first. */
|
|
48
|
+
onAssetsChange: (assetIds: string[]) => void;
|
|
49
|
+
onAddInlineFiles: (files: File[], position?: number) => void;
|
|
50
|
+
onAddAttachmentFiles: (files: File[], position?: number) => void;
|
|
51
|
+
onChooseInlineImage: () => void;
|
|
52
|
+
onSubmitShortcut: () => void;
|
|
53
|
+
dragging: boolean;
|
|
54
|
+
disabled: boolean;
|
|
55
|
+
}
|
|
56
|
+
>(function ComposerEditor(
|
|
57
|
+
{
|
|
58
|
+
session,
|
|
59
|
+
onChange,
|
|
60
|
+
onAssetsChange,
|
|
61
|
+
onAddInlineFiles,
|
|
62
|
+
onAddAttachmentFiles,
|
|
63
|
+
onChooseInlineImage,
|
|
64
|
+
onSubmitShortcut,
|
|
65
|
+
dragging,
|
|
66
|
+
disabled,
|
|
67
|
+
},
|
|
68
|
+
ref
|
|
69
|
+
) {
|
|
70
|
+
const callbacks = useRef({
|
|
71
|
+
onChange,
|
|
72
|
+
onAddInlineFiles,
|
|
73
|
+
onAddAttachmentFiles,
|
|
74
|
+
onChooseInlineImage,
|
|
75
|
+
onSubmitShortcut,
|
|
76
|
+
disabled,
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
// The editor's handlers are created once; they read this render's props.
|
|
80
|
+
useLayoutEffect(() => {
|
|
81
|
+
callbacks.current = {
|
|
82
|
+
onChange,
|
|
83
|
+
onAddInlineFiles,
|
|
84
|
+
onAddAttachmentFiles,
|
|
85
|
+
onChooseInlineImage,
|
|
86
|
+
onSubmitShortcut,
|
|
87
|
+
disabled,
|
|
88
|
+
};
|
|
89
|
+
});
|
|
90
|
+
const contentTimer = useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
91
|
+
|
|
92
|
+
const editor = useEditor({
|
|
93
|
+
extensions: [
|
|
94
|
+
StarterKit.configure({
|
|
95
|
+
code: false,
|
|
96
|
+
codeBlock: false,
|
|
97
|
+
heading: false,
|
|
98
|
+
horizontalRule: false,
|
|
99
|
+
link: {
|
|
100
|
+
openOnClick: false,
|
|
101
|
+
defaultProtocol: "https",
|
|
102
|
+
},
|
|
103
|
+
strike: false,
|
|
104
|
+
}),
|
|
105
|
+
Placeholder.configure({ placeholder: "Write a message" }),
|
|
106
|
+
// Read once, when the editor is created: pass a stable function.
|
|
107
|
+
ComposerAsset.configure({ session, onAssetsChanged: onAssetsChange }),
|
|
108
|
+
],
|
|
109
|
+
content: "",
|
|
110
|
+
editorProps: {
|
|
111
|
+
attributes: {
|
|
112
|
+
class: [
|
|
113
|
+
"min-h-full px-4 py-4 text-[0.9375rem] leading-[1.65] caret-primary outline-none",
|
|
114
|
+
"[&_p]:my-0 [&_p+p]:mt-3",
|
|
115
|
+
"[&_ul]:my-2 [&_ul]:list-disc [&_ul]:pl-6",
|
|
116
|
+
"[&_ol]:my-2 [&_ol]:list-decimal [&_ol]:pl-6",
|
|
117
|
+
"[&_blockquote]:my-3 [&_blockquote]:border-l-2 [&_blockquote]:border-border [&_blockquote]:pl-3 [&_blockquote]:text-muted-foreground",
|
|
118
|
+
"[&_a]:text-info [&_a]:underline [&_a]:underline-offset-2",
|
|
119
|
+
"[&_img]:my-3 [&_img]:max-h-72 [&_img]:max-w-full [&_img]:rounded-lg [&_img]:object-contain",
|
|
120
|
+
"[&_img.ProseMirror-selectednode]:outline-2 [&_img.ProseMirror-selectednode]:outline-primary/70",
|
|
121
|
+
"[&_.is-editor-empty:first-child::before]:pointer-events-none [&_.is-editor-empty:first-child::before]:float-left [&_.is-editor-empty:first-child::before]:h-0 [&_.is-editor-empty:first-child::before]:text-muted-foreground [&_.is-editor-empty:first-child::before]:content-[attr(data-placeholder)]",
|
|
122
|
+
].join(" "),
|
|
123
|
+
role: "textbox",
|
|
124
|
+
"aria-label": "Message body",
|
|
125
|
+
"aria-multiline": "true",
|
|
126
|
+
"data-composer-editor-content": "",
|
|
127
|
+
},
|
|
128
|
+
handleKeyDown: (_view, event) => {
|
|
129
|
+
if (callbacks.current.disabled) return true;
|
|
130
|
+
|
|
131
|
+
if ((event.metaKey || event.ctrlKey) && event.key === "Enter") {
|
|
132
|
+
event.preventDefault();
|
|
133
|
+
callbacks.current.onSubmitShortcut();
|
|
134
|
+
|
|
135
|
+
return true;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return false;
|
|
139
|
+
},
|
|
140
|
+
handlePaste: (view, event, slice) => {
|
|
141
|
+
if (callbacks.current.disabled) return true;
|
|
142
|
+
const files = Array.from(event.clipboardData?.files ?? []);
|
|
143
|
+
const images = files.filter(isInlineComposerImage);
|
|
144
|
+
|
|
145
|
+
const attachments = files.filter(
|
|
146
|
+
(file) => !isInlineComposerImage(file)
|
|
147
|
+
);
|
|
148
|
+
|
|
149
|
+
const content = withoutComposerAssetNodes(slice.content);
|
|
150
|
+
const removedComposerAssets = content.size !== slice.content.size;
|
|
151
|
+
|
|
152
|
+
if (!images.length && !attachments.length && !removedComposerAssets) {
|
|
153
|
+
return false;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
event.preventDefault();
|
|
157
|
+
|
|
158
|
+
const pastedContent = new Slice(
|
|
159
|
+
content,
|
|
160
|
+
slice.openStart,
|
|
161
|
+
slice.openEnd
|
|
162
|
+
);
|
|
163
|
+
|
|
164
|
+
if (pastedContent.content.size > 0) {
|
|
165
|
+
view.dispatch(
|
|
166
|
+
view.state.tr.replaceSelection(pastedContent).scrollIntoView()
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
if (images.length) callbacks.current.onAddInlineFiles(images);
|
|
171
|
+
|
|
172
|
+
if (attachments.length) {
|
|
173
|
+
callbacks.current.onAddAttachmentFiles(attachments);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
return true;
|
|
177
|
+
},
|
|
178
|
+
handleDrop: (view, event) => {
|
|
179
|
+
if (callbacks.current.disabled) return true;
|
|
180
|
+
const files = Array.from(event.dataTransfer?.files ?? []);
|
|
181
|
+
|
|
182
|
+
if (!files.length) return false;
|
|
183
|
+
event.preventDefault();
|
|
184
|
+
const images: File[] = [];
|
|
185
|
+
const attachments: File[] = [];
|
|
186
|
+
|
|
187
|
+
for (const file of files) {
|
|
188
|
+
(isInlineComposerImage(file) ? images : attachments).push(file);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
const position = view.posAtCoords({
|
|
192
|
+
left: event.clientX,
|
|
193
|
+
top: event.clientY,
|
|
194
|
+
})?.pos;
|
|
195
|
+
|
|
196
|
+
if (images.length) {
|
|
197
|
+
callbacks.current.onAddInlineFiles(images, position);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
if (attachments.length) {
|
|
201
|
+
callbacks.current.onAddAttachmentFiles(attachments, position);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
return true;
|
|
205
|
+
},
|
|
206
|
+
},
|
|
207
|
+
onUpdate: ({ editor: current }) => {
|
|
208
|
+
if (contentTimer.current) clearTimeout(contentTimer.current);
|
|
209
|
+
contentTimer.current = setTimeout(() => {
|
|
210
|
+
callbacks.current.onChange(composerContent(current, session));
|
|
211
|
+
}, 180);
|
|
212
|
+
},
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
useEffect(() => {
|
|
216
|
+
editor.setEditable(!disabled);
|
|
217
|
+
}, [disabled, editor]);
|
|
218
|
+
|
|
219
|
+
useEffect(
|
|
220
|
+
() => () => {
|
|
221
|
+
if (contentTimer.current) clearTimeout(contentTimer.current);
|
|
222
|
+
},
|
|
223
|
+
[]
|
|
224
|
+
);
|
|
225
|
+
|
|
226
|
+
useImperativeHandle(
|
|
227
|
+
ref,
|
|
228
|
+
() => ({
|
|
229
|
+
content: () => composerContent(editor, session),
|
|
230
|
+
assetIds: () => composerAssetIds(editor.state),
|
|
231
|
+
insertAssets: (assets, position) => {
|
|
232
|
+
const transaction = insertComposerAssets(
|
|
233
|
+
editor.state,
|
|
234
|
+
assets,
|
|
235
|
+
position
|
|
236
|
+
);
|
|
237
|
+
|
|
238
|
+
if (!transaction) return;
|
|
239
|
+
editor.view.dispatch(transaction.scrollIntoView());
|
|
240
|
+
editor.commands.focus();
|
|
241
|
+
},
|
|
242
|
+
reconcileAssets: () => reconcileComposerAssetNodes(editor.view, session),
|
|
243
|
+
removeAsset: (assetId) => {
|
|
244
|
+
const transaction = removeComposerAsset(editor.state, assetId);
|
|
245
|
+
|
|
246
|
+
if (!transaction) return false;
|
|
247
|
+
editor.view.dispatch(transaction);
|
|
248
|
+
|
|
249
|
+
return true;
|
|
250
|
+
},
|
|
251
|
+
focus: () => editor.commands.focus(),
|
|
252
|
+
}),
|
|
253
|
+
[editor, session]
|
|
254
|
+
);
|
|
255
|
+
|
|
256
|
+
return (
|
|
257
|
+
<div
|
|
258
|
+
className={cn(
|
|
259
|
+
"relative flex min-h-0 flex-1 flex-col overflow-hidden",
|
|
260
|
+
dragging && "bg-primary/5"
|
|
261
|
+
)}
|
|
262
|
+
>
|
|
263
|
+
<div
|
|
264
|
+
className="min-h-0 flex-1 overflow-y-auto"
|
|
265
|
+
data-composer-editor-surface
|
|
266
|
+
>
|
|
267
|
+
<EditorContent
|
|
268
|
+
className={cn("min-h-full", disabled && "pointer-events-none")}
|
|
269
|
+
editor={editor}
|
|
270
|
+
/>
|
|
271
|
+
</div>
|
|
272
|
+
<ComposerToolbar
|
|
273
|
+
editor={editor}
|
|
274
|
+
onChooseInlineImage={onChooseInlineImage}
|
|
275
|
+
disabled={disabled}
|
|
276
|
+
/>
|
|
277
|
+
{dragging ? (
|
|
278
|
+
<div className="border-primary/60 bg-surface/90 pointer-events-none absolute inset-2 z-40 flex items-center justify-center rounded-xl border border-dashed text-sm font-medium shadow-inner">
|
|
279
|
+
Drop images into the message · other files attach below
|
|
280
|
+
</div>
|
|
281
|
+
) : null}
|
|
282
|
+
</div>
|
|
283
|
+
);
|
|
284
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { linkedAttachmentTextToken } from "../../shared/mail";
|
|
2
|
+
|
|
3
|
+
export function linkedAttachmentPlainText(
|
|
4
|
+
uploadId: string | null,
|
|
5
|
+
filename: string
|
|
6
|
+
) {
|
|
7
|
+
const text = uploadId ? linkedAttachmentTextToken(uploadId) : filename;
|
|
8
|
+
|
|
9
|
+
// Tiptap concatenates inline serializers without separators. Keep the
|
|
10
|
+
// plain-text alternative readable when a card sits between prose.
|
|
11
|
+
return `\n\n${text}\n\n`;
|
|
12
|
+
}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Button,
|
|
3
|
+
InputGroup,
|
|
4
|
+
InputGroupAddon,
|
|
5
|
+
InputGroupInput,
|
|
6
|
+
InputGroupText,
|
|
7
|
+
} from "@open-workspace/core/ui";
|
|
8
|
+
import { useMemo, useState } from "react";
|
|
9
|
+
|
|
10
|
+
import { normalizeExternalEmailAddress } from "../../shared/mail";
|
|
11
|
+
import type { RecipientFieldValue } from "./composer-recipients";
|
|
12
|
+
import { RecipientCombobox } from "./recipient-combobox";
|
|
13
|
+
import { RecipientFieldRow } from "./recipient-field-row";
|
|
14
|
+
|
|
15
|
+
function committedAddresses(value: RecipientFieldValue) {
|
|
16
|
+
return new Set(
|
|
17
|
+
value.recipients.map((recipient) =>
|
|
18
|
+
normalizeExternalEmailAddress(recipient.address)
|
|
19
|
+
)
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function ComposerRecipientFields({
|
|
24
|
+
mailboxId,
|
|
25
|
+
to,
|
|
26
|
+
cc,
|
|
27
|
+
bcc,
|
|
28
|
+
replyTo,
|
|
29
|
+
subject,
|
|
30
|
+
subjectReadOnly,
|
|
31
|
+
disabled,
|
|
32
|
+
onToChange,
|
|
33
|
+
onCcChange,
|
|
34
|
+
onBccChange,
|
|
35
|
+
onReplyToChange,
|
|
36
|
+
onSubjectChange,
|
|
37
|
+
}: {
|
|
38
|
+
mailboxId: string;
|
|
39
|
+
to: RecipientFieldValue;
|
|
40
|
+
cc: RecipientFieldValue;
|
|
41
|
+
bcc: RecipientFieldValue;
|
|
42
|
+
replyTo: string;
|
|
43
|
+
subject: string;
|
|
44
|
+
subjectReadOnly: boolean;
|
|
45
|
+
disabled: boolean;
|
|
46
|
+
onToChange: (value: RecipientFieldValue) => void;
|
|
47
|
+
onCcChange: (value: RecipientFieldValue) => void;
|
|
48
|
+
onBccChange: (value: RecipientFieldValue) => void;
|
|
49
|
+
onReplyToChange: (value: string) => void;
|
|
50
|
+
onSubjectChange: (value: string) => void;
|
|
51
|
+
}) {
|
|
52
|
+
const [showCc, setShowCc] = useState(false);
|
|
53
|
+
const [showBcc, setShowBcc] = useState(false);
|
|
54
|
+
const [showReplyTo, setShowReplyTo] = useState(false);
|
|
55
|
+
|
|
56
|
+
const excludedFromTo = useMemo(
|
|
57
|
+
() => new Set([...committedAddresses(cc), ...committedAddresses(bcc)]),
|
|
58
|
+
[cc, bcc]
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
const excludedFromCc = useMemo(
|
|
62
|
+
() => new Set([...committedAddresses(to), ...committedAddresses(bcc)]),
|
|
63
|
+
[to, bcc]
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
const excludedFromBcc = useMemo(
|
|
67
|
+
() => new Set([...committedAddresses(to), ...committedAddresses(cc)]),
|
|
68
|
+
[to, cc]
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
return (
|
|
72
|
+
<div className="divide-border/70 border-border/70 shrink-0 divide-y border-b px-4">
|
|
73
|
+
<RecipientCombobox
|
|
74
|
+
mailboxId={mailboxId}
|
|
75
|
+
label="To"
|
|
76
|
+
value={to}
|
|
77
|
+
excludedAddresses={excludedFromTo}
|
|
78
|
+
autoFocus
|
|
79
|
+
disabled={disabled}
|
|
80
|
+
onChange={onToChange}
|
|
81
|
+
actions={
|
|
82
|
+
<div className="flex shrink-0 items-center gap-0.5 pt-0.5">
|
|
83
|
+
{showCc ? null : (
|
|
84
|
+
<Button
|
|
85
|
+
type="button"
|
|
86
|
+
variant="ghost"
|
|
87
|
+
size="xs"
|
|
88
|
+
disabled={disabled}
|
|
89
|
+
onClick={() => setShowCc(true)}
|
|
90
|
+
>
|
|
91
|
+
Cc
|
|
92
|
+
</Button>
|
|
93
|
+
)}
|
|
94
|
+
{showBcc ? null : (
|
|
95
|
+
<Button
|
|
96
|
+
type="button"
|
|
97
|
+
variant="ghost"
|
|
98
|
+
size="xs"
|
|
99
|
+
disabled={disabled}
|
|
100
|
+
onClick={() => setShowBcc(true)}
|
|
101
|
+
>
|
|
102
|
+
Bcc
|
|
103
|
+
</Button>
|
|
104
|
+
)}
|
|
105
|
+
{showReplyTo ? null : (
|
|
106
|
+
<Button
|
|
107
|
+
type="button"
|
|
108
|
+
variant="ghost"
|
|
109
|
+
size="xs"
|
|
110
|
+
disabled={disabled}
|
|
111
|
+
onClick={() => setShowReplyTo(true)}
|
|
112
|
+
>
|
|
113
|
+
Reply-to
|
|
114
|
+
</Button>
|
|
115
|
+
)}
|
|
116
|
+
</div>
|
|
117
|
+
}
|
|
118
|
+
/>
|
|
119
|
+
{showCc ? (
|
|
120
|
+
<RecipientCombobox
|
|
121
|
+
mailboxId={mailboxId}
|
|
122
|
+
label="Cc"
|
|
123
|
+
value={cc}
|
|
124
|
+
excludedAddresses={excludedFromCc}
|
|
125
|
+
disabled={disabled}
|
|
126
|
+
onChange={onCcChange}
|
|
127
|
+
/>
|
|
128
|
+
) : null}
|
|
129
|
+
{showBcc ? (
|
|
130
|
+
<RecipientCombobox
|
|
131
|
+
mailboxId={mailboxId}
|
|
132
|
+
label="Bcc"
|
|
133
|
+
value={bcc}
|
|
134
|
+
excludedAddresses={excludedFromBcc}
|
|
135
|
+
disabled={disabled}
|
|
136
|
+
onChange={onBccChange}
|
|
137
|
+
/>
|
|
138
|
+
) : null}
|
|
139
|
+
{showReplyTo ? (
|
|
140
|
+
<RecipientFieldRow
|
|
141
|
+
label="Reply-to"
|
|
142
|
+
value={replyTo}
|
|
143
|
+
disabled={disabled}
|
|
144
|
+
onChange={onReplyToChange}
|
|
145
|
+
/>
|
|
146
|
+
) : null}
|
|
147
|
+
<InputGroup className="h-11 rounded-none border-0 bg-transparent shadow-none has-[[data-slot=input-group-control]:focus-visible]:border-0 has-[[data-slot=input-group-control]:focus-visible]:ring-0 dark:bg-transparent">
|
|
148
|
+
<InputGroupAddon className="w-14 justify-start pl-0">
|
|
149
|
+
<InputGroupText className="text-xs font-medium">
|
|
150
|
+
Subject
|
|
151
|
+
</InputGroupText>
|
|
152
|
+
</InputGroupAddon>
|
|
153
|
+
<InputGroupInput
|
|
154
|
+
className="px-2 dark:hover:bg-transparent"
|
|
155
|
+
value={subject}
|
|
156
|
+
readOnly={subjectReadOnly}
|
|
157
|
+
disabled={disabled}
|
|
158
|
+
aria-label="Subject"
|
|
159
|
+
onChange={(event) => onSubjectChange(event.target.value)}
|
|
160
|
+
placeholder="Subject"
|
|
161
|
+
/>
|
|
162
|
+
</InputGroup>
|
|
163
|
+
</div>
|
|
164
|
+
);
|
|
165
|
+
}
|