@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
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-workspace/email",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Team mail for OpenWorkspace: personal and shared inboxes, mailing lists, previews, safety, and AI.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"alchemy",
|
|
@@ -32,7 +32,8 @@
|
|
|
32
32
|
"exports": {
|
|
33
33
|
".": "./index.ts",
|
|
34
34
|
"./alchemy": "./alchemy/index.ts",
|
|
35
|
-
"./client": "./src/
|
|
35
|
+
"./client": "./src/extensions.ts",
|
|
36
|
+
"./module": "./worker/module-api.ts",
|
|
36
37
|
"./shared/*": "./shared/*",
|
|
37
38
|
"./src/lib/mail-api.ts": "./src/lib/mail-api.ts",
|
|
38
39
|
"./src/mail/*": "./src/mail/*",
|
|
@@ -86,8 +87,8 @@
|
|
|
86
87
|
"@alchemy.run/test": "2.0.0-beta.87",
|
|
87
88
|
"@effect/platform-bun": "4.1.7",
|
|
88
89
|
"@effect/platform-node": "4.1.7",
|
|
89
|
-
"@open-workspace/core": "0.
|
|
90
|
-
"@open-workspace/create": "0.
|
|
90
|
+
"@open-workspace/core": "0.6.0",
|
|
91
|
+
"@open-workspace/create": "0.6.0",
|
|
91
92
|
"@types/bun": "1.4.5",
|
|
92
93
|
"@types/html-to-text": "9.0.4",
|
|
93
94
|
"@types/jsdom": "30.0.0",
|
|
@@ -108,7 +109,7 @@
|
|
|
108
109
|
},
|
|
109
110
|
"peerDependencies": {
|
|
110
111
|
"@alchemy.run/cloudflare": "2.0.0-beta.87",
|
|
111
|
-
"@open-workspace/core": "0.
|
|
112
|
+
"@open-workspace/core": "0.6.0",
|
|
112
113
|
"alchemy": "2.0.0-beta.87",
|
|
113
114
|
"effect": "4.1.7"
|
|
114
115
|
}
|
package/shared/mail.ts
CHANGED
|
@@ -112,9 +112,10 @@ export type MailboxPushJob =
|
|
|
112
112
|
| (MailboxPushJobBase &
|
|
113
113
|
(
|
|
114
114
|
| { type: "dispatch" }
|
|
115
|
+
/** One person's notification, sent to their devices with `sendPush`. */
|
|
115
116
|
| {
|
|
116
|
-
type: "
|
|
117
|
-
|
|
117
|
+
type: "notify";
|
|
118
|
+
userId: string;
|
|
118
119
|
mailboxDisplayName: string;
|
|
119
120
|
}
|
|
120
121
|
))
|
package/shared/module.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The mail module's id: its `Email()` infrastructure (its migrations are
|
|
3
|
-
* recorded
|
|
3
|
+
* recorded in `__alchemy_migrations_email`, so it never changes), its server part
|
|
4
4
|
* (`WorkspaceModule.name`, the key of its bootstrap data) and its part of the
|
|
5
5
|
* browser app (`ClientModule.name`).
|
|
6
6
|
*/
|
package/src/client.tsx
CHANGED
|
@@ -6,11 +6,11 @@ import type {
|
|
|
6
6
|
} from "@open-workspace/core/ui";
|
|
7
7
|
import {
|
|
8
8
|
Archive,
|
|
9
|
-
Bell,
|
|
10
9
|
Mail,
|
|
11
10
|
MonitorSmartphone,
|
|
12
11
|
PenLine,
|
|
13
12
|
Plane,
|
|
13
|
+
Send,
|
|
14
14
|
ShieldBan,
|
|
15
15
|
} from "lucide-react";
|
|
16
16
|
import { lazy, Suspense } from "react";
|
|
@@ -27,8 +27,6 @@ import {
|
|
|
27
27
|
adminBlockedSendersQuery,
|
|
28
28
|
autoReplyMailboxesQuery,
|
|
29
29
|
mailArchiveQuery,
|
|
30
|
-
notificationPreferencesQuery,
|
|
31
|
-
pushConfigQuery,
|
|
32
30
|
signatureQuery,
|
|
33
31
|
} from "./settings/settings-queries";
|
|
34
32
|
|
|
@@ -79,27 +77,18 @@ function AddressAutoReplySection({
|
|
|
79
77
|
);
|
|
80
78
|
}
|
|
81
79
|
|
|
80
|
+
const MailNotifications = lazy(() =>
|
|
81
|
+
import("./settings/mail-notifications").then((module) => ({
|
|
82
|
+
default: module.MailNotifications,
|
|
83
|
+
}))
|
|
84
|
+
);
|
|
85
|
+
|
|
82
86
|
const mail: ClientModule = {
|
|
83
87
|
name: EMAIL_MODULE,
|
|
84
88
|
home: { label: "mail", Component: MailboxRoute },
|
|
85
89
|
app: { label: "Mail", Icon: Mail, path: "/" },
|
|
86
90
|
routes: [{ path: MAIL_ROUTE, Component: MailboxRoute }],
|
|
87
91
|
settings: [
|
|
88
|
-
{
|
|
89
|
-
id: "notifications",
|
|
90
|
-
label: "Notifications",
|
|
91
|
-
description: "New mail alerts for this device and your mailboxes.",
|
|
92
|
-
Icon: Bell,
|
|
93
|
-
...preloadable(() =>
|
|
94
|
-
import("./settings/notifications-page").then(
|
|
95
|
-
(module) => module.NotificationsSettings
|
|
96
|
-
)
|
|
97
|
-
),
|
|
98
|
-
prefetch: (queryClient) => {
|
|
99
|
-
void queryClient.prefetchQuery(pushConfigQuery);
|
|
100
|
-
void queryClient.prefetchQuery(notificationPreferencesQuery);
|
|
101
|
-
},
|
|
102
|
-
},
|
|
103
92
|
{
|
|
104
93
|
id: "signature",
|
|
105
94
|
label: "Signature",
|
|
@@ -184,6 +173,19 @@ const mail: ClientModule = {
|
|
|
184
173
|
{ id: "auto-reply", Component: AddressAutoReplySection },
|
|
185
174
|
{ id: "forward-destinations", Component: ForwardDestinations },
|
|
186
175
|
],
|
|
176
|
+
notifications: [{ id: "mailboxes", Component: MailNotifications }],
|
|
177
|
+
shareTargets: [
|
|
178
|
+
{
|
|
179
|
+
id: "email.new-message",
|
|
180
|
+
label: "New message",
|
|
181
|
+
Icon: Send,
|
|
182
|
+
accepts: { files: ["*/*"], text: true },
|
|
183
|
+
open: async (shared, app) =>
|
|
184
|
+
(await import("./mail/shared-compose")).composeShared(shared, app),
|
|
185
|
+
},
|
|
186
|
+
],
|
|
187
|
+
personErasure:
|
|
188
|
+
"Their mailboxes with all their mail, their drafts and signature are deleted.",
|
|
187
189
|
webhookEvents: emailWebhookEvents,
|
|
188
190
|
background: mailBackground.Component,
|
|
189
191
|
preload: async () => {
|
|
@@ -196,18 +198,6 @@ const mail: ClientModule = {
|
|
|
196
198
|
},
|
|
197
199
|
seed: seedMail,
|
|
198
200
|
prefetch: prefetchMail,
|
|
199
|
-
afterSignIn: async () => {
|
|
200
|
-
const { syncCurrentPushSubscription } =
|
|
201
|
-
await import("./pwa/push-subscription");
|
|
202
|
-
|
|
203
|
-
await syncCurrentPushSubscription();
|
|
204
|
-
},
|
|
205
|
-
beforeSignOut: async () => {
|
|
206
|
-
const { removePushSubscriptionForSignOut } =
|
|
207
|
-
await import("./pwa/push-subscription");
|
|
208
|
-
|
|
209
|
-
await removePushSubscriptionForSignOut();
|
|
210
|
-
},
|
|
211
201
|
};
|
|
212
202
|
|
|
213
203
|
export default mail;
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@open-workspace/email/client`: the slots mail offers other modules' client
|
|
3
|
+
* parts, as `ClientModule.extensions` entries:
|
|
4
|
+
*
|
|
5
|
+
* import type { MessageAction } from "@open-workspace/email/client";
|
|
6
|
+
*
|
|
7
|
+
* extensions: { "email.messageActions": [createNote] }
|
|
8
|
+
*
|
|
9
|
+
* Types only: importing it declares the slots and adds no code to the app.
|
|
10
|
+
* Mail's other files are not an API.
|
|
11
|
+
*/
|
|
12
|
+
import type { LucideIcon } from "lucide-react";
|
|
13
|
+
import type { ComponentType } from "react";
|
|
14
|
+
|
|
15
|
+
/** An attachment of a stored message. */
|
|
16
|
+
export type MailAttachment = {
|
|
17
|
+
id: string;
|
|
18
|
+
filename: string;
|
|
19
|
+
/** Without parameters, e.g. "text/calendar". */
|
|
20
|
+
contentType: string;
|
|
21
|
+
/** In bytes. */
|
|
22
|
+
size: number;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/** What an attachment action runs with. */
|
|
26
|
+
export type AttachmentActionContext = {
|
|
27
|
+
mailboxId: string;
|
|
28
|
+
messageId: string;
|
|
29
|
+
attachment: MailAttachment;
|
|
30
|
+
/** Downloads the attachment; rejects if it can't. */
|
|
31
|
+
content: () => Promise<Blob>;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/** An entry in an attachment's menu, under a message. */
|
|
35
|
+
export type AttachmentAction = {
|
|
36
|
+
/** Unique within the module. */
|
|
37
|
+
id: string;
|
|
38
|
+
label: string;
|
|
39
|
+
Icon: LucideIcon;
|
|
40
|
+
/** A rejection is shown to the person as an error. */
|
|
41
|
+
run: (context: AttachmentActionContext) => void | Promise<void>;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/** What a message card gets: the message and the part it is for. */
|
|
45
|
+
export type MessageCardProps = {
|
|
46
|
+
mailboxId: string;
|
|
47
|
+
messageId: string;
|
|
48
|
+
part: {
|
|
49
|
+
contentType: string;
|
|
50
|
+
filename?: string;
|
|
51
|
+
/** Downloads the part; rejects if it can't. */
|
|
52
|
+
content: () => Promise<Blob>;
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* A card above a message's text, shown when the message has a part of one
|
|
58
|
+
* of `contentTypes` (compared without parameters, e.g. "text/calendar" for
|
|
59
|
+
* an invitation), once for its first such part.
|
|
60
|
+
*/
|
|
61
|
+
export type MessageCard = {
|
|
62
|
+
id: string;
|
|
63
|
+
contentTypes: string[];
|
|
64
|
+
Component: ComponentType<MessageCardProps>;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
/** What a composer source gets while it is open. */
|
|
68
|
+
export type ComposerSourceProps = {
|
|
69
|
+
/** Attaches the files to the message, like files from this device. */
|
|
70
|
+
onPick: (files: File[]) => void;
|
|
71
|
+
onClose: () => void;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Another place to attach files from, next to "This device" in the
|
|
76
|
+
* composer's attach menu. Its component opens in a dialog titled `label`.
|
|
77
|
+
*/
|
|
78
|
+
export type ComposerSource = {
|
|
79
|
+
id: string;
|
|
80
|
+
label: string;
|
|
81
|
+
Icon: LucideIcon;
|
|
82
|
+
Component: ComponentType<ComposerSourceProps>;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
/** What a message action runs with. */
|
|
86
|
+
export type MessageActionContext = {
|
|
87
|
+
mailboxId: string;
|
|
88
|
+
messageId: string;
|
|
89
|
+
conversationId: string;
|
|
90
|
+
subject: string;
|
|
91
|
+
from: { name: string | null; address: string };
|
|
92
|
+
/** When it was sent or received, as an ISO 8601 string. */
|
|
93
|
+
date: string;
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
/** An entry in a message's "More actions" menu. */
|
|
97
|
+
export type MessageAction = {
|
|
98
|
+
id: string;
|
|
99
|
+
label: string;
|
|
100
|
+
Icon: LucideIcon;
|
|
101
|
+
/** A rejection is shown to the person as an error. */
|
|
102
|
+
run: (context: MessageActionContext) => void | Promise<void>;
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
/** An address a recipient source suggests. */
|
|
106
|
+
export type RecipientSuggestion = { name?: string; address: string };
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* More suggestions in the recipient fields, after mail's own, e.g. a CRM's
|
|
110
|
+
* contacts. `search` gets what is typed; `signal` aborts when the text
|
|
111
|
+
* changes. A source that fails or is slow never holds mail's suggestions.
|
|
112
|
+
*/
|
|
113
|
+
export type RecipientSource = {
|
|
114
|
+
id: string;
|
|
115
|
+
search: (
|
|
116
|
+
query: string,
|
|
117
|
+
options: { signal: AbortSignal }
|
|
118
|
+
) => Promise<RecipientSuggestion[]>;
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
/** What a message panel gets: the open message and its sender. */
|
|
122
|
+
export type MessagePanelProps = {
|
|
123
|
+
mailboxId: string;
|
|
124
|
+
messageId: string;
|
|
125
|
+
conversationId: string;
|
|
126
|
+
from: { name: string | null; address: string };
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* A side panel next to the open conversation, about the latest incoming
|
|
131
|
+
* message's sender (else the latest message's), e.g. meetings with them.
|
|
132
|
+
* Its toggle is in the conversation's toolbar; one panel is open at a time,
|
|
133
|
+
* in a sheet on phones.
|
|
134
|
+
*/
|
|
135
|
+
export type MessagePanel = {
|
|
136
|
+
id: string;
|
|
137
|
+
label: string;
|
|
138
|
+
Icon: LucideIcon;
|
|
139
|
+
Component: ComponentType<MessagePanelProps>;
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
/** What a composer insert puts at the cursor. */
|
|
143
|
+
export type ComposerInsertContent =
|
|
144
|
+
| { text: string }
|
|
145
|
+
| { link: { url: string; text: string } };
|
|
146
|
+
|
|
147
|
+
/** What a composer insert gets while it is open. */
|
|
148
|
+
export type ComposerInsertProps = {
|
|
149
|
+
/** Puts the content at the cursor and closes the dialog. */
|
|
150
|
+
insert: (content: ComposerInsertContent) => void;
|
|
151
|
+
onClose: () => void;
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* An entry in the composer's toolbar (the new message window's and the
|
|
156
|
+
* reply's), opened in a dialog titled `label`, that inserts text or a link.
|
|
157
|
+
*/
|
|
158
|
+
export type ComposerInsert = {
|
|
159
|
+
id: string;
|
|
160
|
+
label: string;
|
|
161
|
+
Icon: LucideIcon;
|
|
162
|
+
Component: ComponentType<ComposerInsertProps>;
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
declare module "@open-workspace/core/ui" {
|
|
166
|
+
// oxlint-disable-next-line typescript/consistent-type-definitions -- declaration merging
|
|
167
|
+
interface ClientExtensions {
|
|
168
|
+
"email.attachmentActions": AttachmentAction;
|
|
169
|
+
"email.messageCards": MessageCard;
|
|
170
|
+
"email.composerSources": ComposerSource;
|
|
171
|
+
"email.messageActions": MessageAction;
|
|
172
|
+
"email.recipientSources": RecipientSource;
|
|
173
|
+
"email.messagePanels": MessagePanel;
|
|
174
|
+
"email.composerInserts": ComposerInsert;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
@@ -4,13 +4,13 @@ import {
|
|
|
4
4
|
ImagePlus,
|
|
5
5
|
LoaderCircle,
|
|
6
6
|
Minus,
|
|
7
|
-
Paperclip,
|
|
8
7
|
Send,
|
|
9
8
|
Trash2,
|
|
10
9
|
X,
|
|
11
10
|
} from "lucide-react";
|
|
12
11
|
import type { Ref, RefObject } from "react";
|
|
13
12
|
|
|
13
|
+
import { ComposerAttachButton } from "./composer-attach-button";
|
|
14
14
|
import { formatBytes } from "./format-bytes";
|
|
15
15
|
import type { MessageDetail } from "./types";
|
|
16
16
|
|
|
@@ -168,16 +168,11 @@ export function ComposeWindowFooter({
|
|
|
168
168
|
{sending ? <LoaderCircle className="animate-spin" /> : <Send />}
|
|
169
169
|
Send
|
|
170
170
|
</Button>
|
|
171
|
-
<
|
|
172
|
-
type="button"
|
|
173
|
-
variant="ghost"
|
|
174
|
-
size="icon-sm"
|
|
175
|
-
aria-label="Add attachments"
|
|
171
|
+
<ComposerAttachButton
|
|
176
172
|
disabled={sending}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
</Button>
|
|
173
|
+
onChooseFromDevice={() => fileInput.current?.click()}
|
|
174
|
+
onPick={onAddAttachments}
|
|
175
|
+
/>
|
|
181
176
|
<Button
|
|
182
177
|
type="button"
|
|
183
178
|
variant="ghost"
|
|
@@ -33,6 +33,7 @@ import {
|
|
|
33
33
|
import type { RecipientFieldValue } from "./composer-recipients";
|
|
34
34
|
import { notifyOutboundResult } from "./outbound-notification";
|
|
35
35
|
import { ReplyToWarning } from "./reply-to-warning";
|
|
36
|
+
import { forgetSharedMessage, sharedMessage } from "./shared-compose";
|
|
36
37
|
import type { Mailbox } from "./types";
|
|
37
38
|
import { useComposerAttachmentPreflight } from "./use-composer-attachment-preflight";
|
|
38
39
|
import { useComposerCore } from "./use-composer-core";
|
|
@@ -98,6 +99,14 @@ export function ComposeWindow({
|
|
|
98
99
|
/** It closed; `ended` when its draft is gone (sent or discarded), not just put away. */
|
|
99
100
|
onClose: (ended?: boolean) => void;
|
|
100
101
|
}) {
|
|
102
|
+
// What another app shared, when the composer opened for it (/share).
|
|
103
|
+
// oxlint-disable-next-line react/hook-use-state -- read once; nothing sets it
|
|
104
|
+
const [shared] = useState(() => (draft ? undefined : sharedMessage(draftId)));
|
|
105
|
+
|
|
106
|
+
useEffect(() => {
|
|
107
|
+
forgetSharedMessage(draftId);
|
|
108
|
+
}, [draftId]);
|
|
109
|
+
|
|
101
110
|
const [to, setTo] = useState<RecipientFieldValue>(() =>
|
|
102
111
|
draft ? recipientField(draft.to) : EMPTY_RECIPIENT_FIELD
|
|
103
112
|
);
|
|
@@ -115,7 +124,9 @@ export function ComposeWindow({
|
|
|
115
124
|
const [subject, setSubject] = useState(
|
|
116
125
|
() =>
|
|
117
126
|
draft?.subject ??
|
|
118
|
-
(forwardedMessage
|
|
127
|
+
(forwardedMessage
|
|
128
|
+
? forwardSubject(forwardedMessage.subject)
|
|
129
|
+
: (shared?.subject ?? ""))
|
|
119
130
|
);
|
|
120
131
|
|
|
121
132
|
const [minimized, setMinimized] = useState(false);
|
|
@@ -476,7 +487,7 @@ export function ComposeWindow({
|
|
|
476
487
|
</>
|
|
477
488
|
) : null}
|
|
478
489
|
|
|
479
|
-
<ComposerEditor ref={editor} {...editorProps} />
|
|
490
|
+
<ComposerEditor ref={editor} {...editorProps} shared={shared} />
|
|
480
491
|
|
|
481
492
|
<ComposerAttachmentList
|
|
482
493
|
{...attachmentListProps}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Button,
|
|
3
|
+
Dialog,
|
|
4
|
+
DialogContent,
|
|
5
|
+
DialogHeader,
|
|
6
|
+
DialogTitle,
|
|
7
|
+
DropdownMenu,
|
|
8
|
+
DropdownMenuContent,
|
|
9
|
+
DropdownMenuItem,
|
|
10
|
+
DropdownMenuTrigger,
|
|
11
|
+
moduleExtensions,
|
|
12
|
+
} from "@open-workspace/core/ui";
|
|
13
|
+
import { HardDrive, Paperclip } from "lucide-react";
|
|
14
|
+
import { Suspense, useState } from "react";
|
|
15
|
+
|
|
16
|
+
import type { ComposerSource } from "../extensions";
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The composer's "Add attachments": files from this device, or, with other
|
|
20
|
+
* modules' sources (`email.composerSources`), a menu of them too. A source
|
|
21
|
+
* opens in a dialog, and the files it picks attach like the device's.
|
|
22
|
+
*/
|
|
23
|
+
export function ComposerAttachButton({
|
|
24
|
+
disabled,
|
|
25
|
+
onChooseFromDevice,
|
|
26
|
+
onPick,
|
|
27
|
+
}: {
|
|
28
|
+
disabled: boolean;
|
|
29
|
+
onChooseFromDevice: () => void;
|
|
30
|
+
onPick: (files: File[]) => void;
|
|
31
|
+
}) {
|
|
32
|
+
const sources = moduleExtensions("email.composerSources");
|
|
33
|
+
const [source, setSource] = useState<ComposerSource | null>(null);
|
|
34
|
+
|
|
35
|
+
if (!sources.length) {
|
|
36
|
+
return (
|
|
37
|
+
<Button
|
|
38
|
+
type="button"
|
|
39
|
+
variant="ghost"
|
|
40
|
+
size="icon-sm"
|
|
41
|
+
aria-label="Add attachments"
|
|
42
|
+
disabled={disabled}
|
|
43
|
+
onClick={onChooseFromDevice}
|
|
44
|
+
>
|
|
45
|
+
<Paperclip />
|
|
46
|
+
</Button>
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
<>
|
|
52
|
+
<DropdownMenu>
|
|
53
|
+
<DropdownMenuTrigger
|
|
54
|
+
render={
|
|
55
|
+
<Button
|
|
56
|
+
type="button"
|
|
57
|
+
variant="ghost"
|
|
58
|
+
size="icon-sm"
|
|
59
|
+
aria-label="Add attachments"
|
|
60
|
+
disabled={disabled}
|
|
61
|
+
/>
|
|
62
|
+
}
|
|
63
|
+
>
|
|
64
|
+
<Paperclip />
|
|
65
|
+
</DropdownMenuTrigger>
|
|
66
|
+
<DropdownMenuContent align="start" side="top" className="w-56">
|
|
67
|
+
<DropdownMenuItem onClick={onChooseFromDevice}>
|
|
68
|
+
<HardDrive /> This device
|
|
69
|
+
</DropdownMenuItem>
|
|
70
|
+
{sources.map((entry) => (
|
|
71
|
+
<DropdownMenuItem key={entry.id} onClick={() => setSource(entry)}>
|
|
72
|
+
<entry.Icon /> {entry.label}
|
|
73
|
+
</DropdownMenuItem>
|
|
74
|
+
))}
|
|
75
|
+
</DropdownMenuContent>
|
|
76
|
+
</DropdownMenu>
|
|
77
|
+
<Dialog
|
|
78
|
+
open={source !== null}
|
|
79
|
+
onOpenChange={(open) => {
|
|
80
|
+
if (!open) setSource(null);
|
|
81
|
+
}}
|
|
82
|
+
>
|
|
83
|
+
{source ? (
|
|
84
|
+
<DialogContent anchor="top" className="sm:max-w-md">
|
|
85
|
+
<DialogHeader>
|
|
86
|
+
<DialogTitle>{source.label}</DialogTitle>
|
|
87
|
+
</DialogHeader>
|
|
88
|
+
{/* The dialog is a portal, but React still bubbles its events
|
|
89
|
+
to the composer's form: a source's own form mustn't send. */}
|
|
90
|
+
<div onSubmit={(event) => event.stopPropagation()}>
|
|
91
|
+
<Suspense fallback={null}>
|
|
92
|
+
<source.Component
|
|
93
|
+
onPick={(files) => {
|
|
94
|
+
setSource(null);
|
|
95
|
+
onPick(files);
|
|
96
|
+
}}
|
|
97
|
+
onClose={() => setSource(null)}
|
|
98
|
+
/>
|
|
99
|
+
</Suspense>
|
|
100
|
+
</div>
|
|
101
|
+
</DialogContent>
|
|
102
|
+
) : null}
|
|
103
|
+
</Dialog>
|
|
104
|
+
</>
|
|
105
|
+
);
|
|
106
|
+
}
|
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
} from "./composer-asset-bookmarks";
|
|
17
17
|
import { composerContent } from "./composer-editor-document";
|
|
18
18
|
import type { ComposerContent } from "./composer-editor-document";
|
|
19
|
+
import { textNodes } from "./composer-inserts";
|
|
19
20
|
import type {
|
|
20
21
|
ComposerAsset as ComposerAssetRecord,
|
|
21
22
|
ComposerSession,
|
|
@@ -56,6 +57,8 @@ export const ComposerEditor = forwardRef<
|
|
|
56
57
|
label?: string;
|
|
57
58
|
/** Read once. */
|
|
58
59
|
placeholder?: string;
|
|
60
|
+
/** Shared from another app: text put first, files attached; read once. */
|
|
61
|
+
shared?: { text: string; files: File[] };
|
|
59
62
|
}
|
|
60
63
|
>(function ComposerEditor(
|
|
61
64
|
{
|
|
@@ -72,6 +75,7 @@ export const ComposerEditor = forwardRef<
|
|
|
72
75
|
originalBody,
|
|
73
76
|
label = "Message body",
|
|
74
77
|
placeholder = "Write a message",
|
|
78
|
+
shared,
|
|
75
79
|
},
|
|
76
80
|
ref
|
|
77
81
|
) {
|
|
@@ -223,6 +227,19 @@ export const ComposerEditor = forwardRef<
|
|
|
223
227
|
[]
|
|
224
228
|
);
|
|
225
229
|
|
|
230
|
+
// As edits, so the composer counts as written and saves a draft.
|
|
231
|
+
const sharedAdded = useRef(false);
|
|
232
|
+
useEffect(() => {
|
|
233
|
+
if (!shared || sharedAdded.current) return;
|
|
234
|
+
sharedAdded.current = true;
|
|
235
|
+
|
|
236
|
+
if (shared.text) {
|
|
237
|
+
editor.commands.insertContentAt(1, textNodes(shared.text));
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
if (shared.files.length) onAddAttachmentFiles(shared.files);
|
|
241
|
+
});
|
|
242
|
+
|
|
226
243
|
useImperativeHandle(
|
|
227
244
|
ref,
|
|
228
245
|
() => ({
|