@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,303 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Button,
|
|
3
|
+
Input,
|
|
4
|
+
Popover,
|
|
5
|
+
PopoverContent,
|
|
6
|
+
PopoverTrigger,
|
|
7
|
+
Toggle,
|
|
8
|
+
toggleVariants,
|
|
9
|
+
Tooltip,
|
|
10
|
+
TooltipContent,
|
|
11
|
+
TooltipTrigger,
|
|
12
|
+
} from "@open-workspace/core/ui";
|
|
13
|
+
import { useEditorState } from "@tiptap/react";
|
|
14
|
+
import type { Editor } from "@tiptap/react";
|
|
15
|
+
import {
|
|
16
|
+
Bold,
|
|
17
|
+
ImagePlus,
|
|
18
|
+
Italic,
|
|
19
|
+
Link2,
|
|
20
|
+
List,
|
|
21
|
+
ListOrdered,
|
|
22
|
+
Quote,
|
|
23
|
+
Redo2,
|
|
24
|
+
RemoveFormatting,
|
|
25
|
+
Undo2,
|
|
26
|
+
Underline,
|
|
27
|
+
X,
|
|
28
|
+
} from "lucide-react";
|
|
29
|
+
import { useRef, useState } from "react";
|
|
30
|
+
import type { ReactNode } from "react";
|
|
31
|
+
|
|
32
|
+
/** A formatting toggle: pressed while the selection has the format. */
|
|
33
|
+
function FormatToggle({
|
|
34
|
+
label,
|
|
35
|
+
pressed,
|
|
36
|
+
disabled,
|
|
37
|
+
onToggle,
|
|
38
|
+
children,
|
|
39
|
+
}: {
|
|
40
|
+
label: string;
|
|
41
|
+
pressed: boolean;
|
|
42
|
+
disabled: boolean;
|
|
43
|
+
onToggle: () => void;
|
|
44
|
+
children: ReactNode;
|
|
45
|
+
}) {
|
|
46
|
+
return (
|
|
47
|
+
<Tooltip>
|
|
48
|
+
<TooltipTrigger
|
|
49
|
+
render={
|
|
50
|
+
<Toggle
|
|
51
|
+
size="xs"
|
|
52
|
+
pressed={pressed}
|
|
53
|
+
disabled={disabled}
|
|
54
|
+
aria-label={label}
|
|
55
|
+
onPressedChange={onToggle}
|
|
56
|
+
/>
|
|
57
|
+
}
|
|
58
|
+
>
|
|
59
|
+
{children}
|
|
60
|
+
</TooltipTrigger>
|
|
61
|
+
<TooltipContent>{label}</TooltipContent>
|
|
62
|
+
</Tooltip>
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** A one-shot editor command, such as Undo. */
|
|
67
|
+
function EditorButton({
|
|
68
|
+
label,
|
|
69
|
+
disabled,
|
|
70
|
+
onClick,
|
|
71
|
+
children,
|
|
72
|
+
}: {
|
|
73
|
+
label: string;
|
|
74
|
+
disabled: boolean;
|
|
75
|
+
onClick: () => void;
|
|
76
|
+
children: ReactNode;
|
|
77
|
+
}) {
|
|
78
|
+
return (
|
|
79
|
+
<Tooltip>
|
|
80
|
+
<TooltipTrigger
|
|
81
|
+
render={
|
|
82
|
+
<Button
|
|
83
|
+
type="button"
|
|
84
|
+
variant="ghost"
|
|
85
|
+
size="icon-xs"
|
|
86
|
+
disabled={disabled}
|
|
87
|
+
aria-label={label}
|
|
88
|
+
onClick={onClick}
|
|
89
|
+
/>
|
|
90
|
+
}
|
|
91
|
+
>
|
|
92
|
+
{children}
|
|
93
|
+
</TooltipTrigger>
|
|
94
|
+
<TooltipContent>{label}</TooltipContent>
|
|
95
|
+
</Tooltip>
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export function ComposerToolbar({
|
|
100
|
+
editor,
|
|
101
|
+
onChooseInlineImage,
|
|
102
|
+
disabled,
|
|
103
|
+
}: {
|
|
104
|
+
editor: Editor;
|
|
105
|
+
onChooseInlineImage: () => void;
|
|
106
|
+
disabled: boolean;
|
|
107
|
+
}) {
|
|
108
|
+
const [linkOpen, setLinkOpen] = useState(false);
|
|
109
|
+
const [linkValue, setLinkValue] = useState("");
|
|
110
|
+
// Applying a link returns to the text; any other close returns to the Link button.
|
|
111
|
+
const returnToEditor = useRef(false);
|
|
112
|
+
|
|
113
|
+
const state = useEditorState({
|
|
114
|
+
editor,
|
|
115
|
+
selector: ({ editor: current }) => ({
|
|
116
|
+
bold: current.isActive("bold"),
|
|
117
|
+
italic: current.isActive("italic"),
|
|
118
|
+
underline: current.isActive("underline"),
|
|
119
|
+
link: current.isActive("link"),
|
|
120
|
+
bulletList: current.isActive("bulletList"),
|
|
121
|
+
orderedList: current.isActive("orderedList"),
|
|
122
|
+
blockquote: current.isActive("blockquote"),
|
|
123
|
+
}),
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
function closeLinkEditor(toEditor: boolean) {
|
|
127
|
+
returnToEditor.current = toEditor;
|
|
128
|
+
setLinkOpen(false);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function applyLink() {
|
|
132
|
+
const value = linkValue.trim();
|
|
133
|
+
|
|
134
|
+
if (!value) {
|
|
135
|
+
editor.chain().focus().extendMarkRange("link").unsetLink().run();
|
|
136
|
+
closeLinkEditor(true);
|
|
137
|
+
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const href = /^[a-z][a-z0-9+.-]*:/iu.test(value)
|
|
142
|
+
? value
|
|
143
|
+
: `https://${value}`;
|
|
144
|
+
|
|
145
|
+
editor.chain().focus().extendMarkRange("link").setLink({ href }).run();
|
|
146
|
+
setLinkValue("");
|
|
147
|
+
closeLinkEditor(true);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
return (
|
|
151
|
+
<div className="border-border/70 relative flex min-h-10 shrink-0 items-center gap-0.5 border-t px-3 py-1.5">
|
|
152
|
+
<FormatToggle
|
|
153
|
+
label="Bold"
|
|
154
|
+
pressed={state.bold}
|
|
155
|
+
disabled={disabled}
|
|
156
|
+
onToggle={() => editor.chain().focus().toggleBold().run()}
|
|
157
|
+
>
|
|
158
|
+
<Bold />
|
|
159
|
+
</FormatToggle>
|
|
160
|
+
<FormatToggle
|
|
161
|
+
label="Italic"
|
|
162
|
+
pressed={state.italic}
|
|
163
|
+
disabled={disabled}
|
|
164
|
+
onToggle={() => editor.chain().focus().toggleItalic().run()}
|
|
165
|
+
>
|
|
166
|
+
<Italic />
|
|
167
|
+
</FormatToggle>
|
|
168
|
+
<FormatToggle
|
|
169
|
+
label="Underline"
|
|
170
|
+
pressed={state.underline}
|
|
171
|
+
disabled={disabled}
|
|
172
|
+
onToggle={() => editor.chain().focus().toggleUnderline().run()}
|
|
173
|
+
>
|
|
174
|
+
<Underline />
|
|
175
|
+
</FormatToggle>
|
|
176
|
+
<Popover
|
|
177
|
+
open={linkOpen}
|
|
178
|
+
onOpenChange={(open) => {
|
|
179
|
+
if (open) {
|
|
180
|
+
returnToEditor.current = false;
|
|
181
|
+
setLinkValue(editor.getAttributes("link").href ?? "");
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
setLinkOpen(open);
|
|
185
|
+
}}
|
|
186
|
+
>
|
|
187
|
+
<Tooltip>
|
|
188
|
+
<TooltipTrigger
|
|
189
|
+
render={
|
|
190
|
+
<PopoverTrigger
|
|
191
|
+
// Looks pressed inside a link; the open editor shows the URL.
|
|
192
|
+
data-pressed={state.link || undefined}
|
|
193
|
+
className={toggleVariants({ size: "xs" })}
|
|
194
|
+
disabled={disabled}
|
|
195
|
+
aria-label="Link"
|
|
196
|
+
/>
|
|
197
|
+
}
|
|
198
|
+
>
|
|
199
|
+
<Link2 />
|
|
200
|
+
</TooltipTrigger>
|
|
201
|
+
<TooltipContent>Link</TooltipContent>
|
|
202
|
+
</Tooltip>
|
|
203
|
+
<PopoverContent
|
|
204
|
+
side="top"
|
|
205
|
+
align="start"
|
|
206
|
+
sideOffset={8}
|
|
207
|
+
className="flex w-72 items-center gap-1.5 p-2"
|
|
208
|
+
aria-label="Link editor"
|
|
209
|
+
finalFocus={() => !returnToEditor.current}
|
|
210
|
+
>
|
|
211
|
+
<Input
|
|
212
|
+
className="h-8 min-w-0 flex-1"
|
|
213
|
+
disabled={disabled}
|
|
214
|
+
value={linkValue}
|
|
215
|
+
placeholder="https://example.com"
|
|
216
|
+
aria-label="Link URL"
|
|
217
|
+
onChange={(event) => setLinkValue(event.target.value)}
|
|
218
|
+
onKeyDown={(event) => {
|
|
219
|
+
if (event.key === "Enter") {
|
|
220
|
+
event.preventDefault();
|
|
221
|
+
applyLink();
|
|
222
|
+
}
|
|
223
|
+
}}
|
|
224
|
+
/>
|
|
225
|
+
<Button
|
|
226
|
+
type="button"
|
|
227
|
+
size="sm"
|
|
228
|
+
disabled={disabled}
|
|
229
|
+
onClick={applyLink}
|
|
230
|
+
>
|
|
231
|
+
Apply
|
|
232
|
+
</Button>
|
|
233
|
+
<Button
|
|
234
|
+
type="button"
|
|
235
|
+
variant="ghost"
|
|
236
|
+
size="icon-sm"
|
|
237
|
+
aria-label="Close link editor"
|
|
238
|
+
disabled={disabled}
|
|
239
|
+
onClick={() => closeLinkEditor(false)}
|
|
240
|
+
>
|
|
241
|
+
<X />
|
|
242
|
+
</Button>
|
|
243
|
+
</PopoverContent>
|
|
244
|
+
</Popover>
|
|
245
|
+
<span className="bg-border mx-1 h-4 w-px" />
|
|
246
|
+
<FormatToggle
|
|
247
|
+
label="Bulleted list"
|
|
248
|
+
pressed={state.bulletList}
|
|
249
|
+
disabled={disabled}
|
|
250
|
+
onToggle={() => editor.chain().focus().toggleBulletList().run()}
|
|
251
|
+
>
|
|
252
|
+
<List />
|
|
253
|
+
</FormatToggle>
|
|
254
|
+
<FormatToggle
|
|
255
|
+
label="Numbered list"
|
|
256
|
+
pressed={state.orderedList}
|
|
257
|
+
disabled={disabled}
|
|
258
|
+
onToggle={() => editor.chain().focus().toggleOrderedList().run()}
|
|
259
|
+
>
|
|
260
|
+
<ListOrdered />
|
|
261
|
+
</FormatToggle>
|
|
262
|
+
<FormatToggle
|
|
263
|
+
label="Quote"
|
|
264
|
+
pressed={state.blockquote}
|
|
265
|
+
disabled={disabled}
|
|
266
|
+
onToggle={() => editor.chain().focus().toggleBlockquote().run()}
|
|
267
|
+
>
|
|
268
|
+
<Quote />
|
|
269
|
+
</FormatToggle>
|
|
270
|
+
<EditorButton
|
|
271
|
+
label="Insert inline image"
|
|
272
|
+
disabled={disabled}
|
|
273
|
+
onClick={onChooseInlineImage}
|
|
274
|
+
>
|
|
275
|
+
<ImagePlus />
|
|
276
|
+
</EditorButton>
|
|
277
|
+
<span className="bg-border mx-1 h-4 w-px" />
|
|
278
|
+
<EditorButton
|
|
279
|
+
label="Undo"
|
|
280
|
+
disabled={disabled}
|
|
281
|
+
onClick={() => editor.chain().focus().undo().run()}
|
|
282
|
+
>
|
|
283
|
+
<Undo2 />
|
|
284
|
+
</EditorButton>
|
|
285
|
+
<EditorButton
|
|
286
|
+
label="Redo"
|
|
287
|
+
disabled={disabled}
|
|
288
|
+
onClick={() => editor.chain().focus().redo().run()}
|
|
289
|
+
>
|
|
290
|
+
<Redo2 />
|
|
291
|
+
</EditorButton>
|
|
292
|
+
<EditorButton
|
|
293
|
+
label="Clear formatting"
|
|
294
|
+
disabled={disabled}
|
|
295
|
+
onClick={() =>
|
|
296
|
+
editor.chain().focus().unsetAllMarks().clearNodes().run()
|
|
297
|
+
}
|
|
298
|
+
>
|
|
299
|
+
<RemoveFormatting />
|
|
300
|
+
</EditorButton>
|
|
301
|
+
</div>
|
|
302
|
+
);
|
|
303
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { ApiError, responseJson } from "@open-workspace/core/ui";
|
|
2
|
+
|
|
3
|
+
import { isComposerInlineImageContentType } from "../../shared/mail";
|
|
4
|
+
import { mailApi } from "../lib/mail-api";
|
|
5
|
+
|
|
6
|
+
export function uploadContentType(file: File) {
|
|
7
|
+
return file.type || "application/octet-stream";
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function isInlineComposerImage(file: File) {
|
|
11
|
+
return isComposerInlineImageContentType(uploadContentType(file));
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export async function createComposerUploadIntent(
|
|
15
|
+
mailboxId: string,
|
|
16
|
+
file: { filename: string; contentType: string; size: number }
|
|
17
|
+
) {
|
|
18
|
+
return responseJson(
|
|
19
|
+
await mailApi.api.mail.uploads.$post({
|
|
20
|
+
query: { mailboxId },
|
|
21
|
+
json: file,
|
|
22
|
+
})
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export async function discardComposerUpload(
|
|
27
|
+
mailboxId: string,
|
|
28
|
+
uploadId: string
|
|
29
|
+
) {
|
|
30
|
+
await responseJson(
|
|
31
|
+
await mailApi.api.mail.uploads[":id"].$delete(
|
|
32
|
+
{
|
|
33
|
+
param: { id: uploadId },
|
|
34
|
+
query: { mailboxId },
|
|
35
|
+
},
|
|
36
|
+
{ init: { keepalive: true } }
|
|
37
|
+
)
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export async function completeComposerUpload(
|
|
42
|
+
mailboxId: string,
|
|
43
|
+
uploadId: string
|
|
44
|
+
) {
|
|
45
|
+
try {
|
|
46
|
+
return await requestComposerUploadCompletion(mailboxId, uploadId);
|
|
47
|
+
} catch (error) {
|
|
48
|
+
// Finalization is idempotent. Retry only failures where the server may
|
|
49
|
+
// have completed the first request but its response was lost.
|
|
50
|
+
if (error instanceof ApiError && error.status < 500) throw error;
|
|
51
|
+
|
|
52
|
+
return requestComposerUploadCompletion(mailboxId, uploadId);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async function requestComposerUploadCompletion(
|
|
57
|
+
mailboxId: string,
|
|
58
|
+
uploadId: string
|
|
59
|
+
) {
|
|
60
|
+
return responseJson(
|
|
61
|
+
await mailApi.api.mail.uploads[":id"].complete.$post({
|
|
62
|
+
param: { id: uploadId },
|
|
63
|
+
query: { mailboxId },
|
|
64
|
+
})
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function uploadComposerFile(
|
|
69
|
+
uploadUrl: string,
|
|
70
|
+
headers: Record<string, string>,
|
|
71
|
+
file: File,
|
|
72
|
+
onProgress: (progress: number) => void,
|
|
73
|
+
onRequest: (request: XMLHttpRequest) => void
|
|
74
|
+
) {
|
|
75
|
+
return new Promise<void>((resolve, reject) => {
|
|
76
|
+
const request = new XMLHttpRequest();
|
|
77
|
+
onRequest(request);
|
|
78
|
+
request.open("PUT", uploadUrl);
|
|
79
|
+
|
|
80
|
+
for (const [name, value] of Object.entries(headers)) {
|
|
81
|
+
request.setRequestHeader(name, value);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
request.upload.addEventListener("progress", (event) => {
|
|
85
|
+
if (event.lengthComputable && event.total > 0) {
|
|
86
|
+
onProgress(Math.min(1, event.loaded / event.total));
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
request.addEventListener("load", () => {
|
|
90
|
+
if (request.status >= 200 && request.status < 300) {
|
|
91
|
+
onProgress(1);
|
|
92
|
+
resolve();
|
|
93
|
+
} else {
|
|
94
|
+
reject(new Error(`Attachment upload failed (${request.status})`));
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
request.addEventListener("error", () => {
|
|
98
|
+
reject(new Error("Attachment upload failed"));
|
|
99
|
+
});
|
|
100
|
+
request.addEventListener("abort", () => {
|
|
101
|
+
reject(new DOMException("Attachment upload was cancelled", "AbortError"));
|
|
102
|
+
});
|
|
103
|
+
request.send(file);
|
|
104
|
+
});
|
|
105
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { useSyncExternalStore } from "react";
|
|
2
|
+
|
|
3
|
+
export type ComposerUploadProgressStore = {
|
|
4
|
+
get: (localId: string) => number;
|
|
5
|
+
subscribe: (localId: string, listener: () => void) => () => void;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
type MutableComposerUploadProgressStore = ComposerUploadProgressStore & {
|
|
9
|
+
delete: (localId: string) => void;
|
|
10
|
+
set: (localId: string, progress: number) => void;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export function createComposerUploadProgressStore(): MutableComposerUploadProgressStore {
|
|
14
|
+
const values = new Map<string, number>();
|
|
15
|
+
const listeners = new Map<string, Set<() => void>>();
|
|
16
|
+
|
|
17
|
+
return {
|
|
18
|
+
get: (localId) => values.get(localId) ?? 0,
|
|
19
|
+
subscribe: (localId, listener) => {
|
|
20
|
+
const current = listeners.get(localId) ?? new Set();
|
|
21
|
+
current.add(listener);
|
|
22
|
+
listeners.set(localId, current);
|
|
23
|
+
|
|
24
|
+
return () => {
|
|
25
|
+
current.delete(listener);
|
|
26
|
+
|
|
27
|
+
if (!current.size) listeners.delete(localId);
|
|
28
|
+
};
|
|
29
|
+
},
|
|
30
|
+
set: (localId, progress) => {
|
|
31
|
+
if (values.get(localId) === progress) return;
|
|
32
|
+
values.set(localId, progress);
|
|
33
|
+
|
|
34
|
+
for (const listener of listeners.get(localId) ?? []) listener();
|
|
35
|
+
},
|
|
36
|
+
delete: (localId) => {
|
|
37
|
+
values.delete(localId);
|
|
38
|
+
|
|
39
|
+
for (const listener of listeners.get(localId) ?? []) listener();
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function useComposerUploadProgress(
|
|
45
|
+
store: ComposerUploadProgressStore,
|
|
46
|
+
localId: string
|
|
47
|
+
) {
|
|
48
|
+
return useSyncExternalStore(
|
|
49
|
+
(listener) => store.subscribe(localId, listener),
|
|
50
|
+
() => store.get(localId),
|
|
51
|
+
() => 0
|
|
52
|
+
);
|
|
53
|
+
}
|