@rapidmx/web-client 0.2.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/LICENSE +382 -0
- package/apps/admin/_404.tsx +9 -0
- package/apps/admin/_500.tsx +9 -0
- package/apps/admin/_layout.tsx +41 -0
- package/apps/admin/audit-log/index.tsx +187 -0
- package/apps/admin/branding/index.tsx +404 -0
- package/apps/admin/distribution-lists/[uid].tsx +70 -0
- package/apps/admin/distribution-lists/index.tsx +115 -0
- package/apps/admin/distribution-lists/new/index.tsx +114 -0
- package/apps/admin/domains/[uid].tsx +259 -0
- package/apps/admin/domains/index.tsx +125 -0
- package/apps/admin/domains/new/index.tsx +84 -0
- package/apps/admin/index.tsx +82 -0
- package/apps/admin/ingest-queue/index.tsx +116 -0
- package/apps/admin/mailboxes/[uid].tsx +126 -0
- package/apps/admin/mailboxes/new/index.tsx +291 -0
- package/apps/admin/quarantine/index.tsx +171 -0
- package/apps/admin/transport-rules/[uid].tsx +143 -0
- package/apps/admin/transport-rules/_transportRuleConfig.tsx +75 -0
- package/apps/admin/transport-rules/index.tsx +117 -0
- package/apps/admin/transport-rules/new/index.tsx +105 -0
- package/apps/shared/components/admin/distributionLists/MemberListCard.tsx +117 -0
- package/apps/shared/components/admin/layout/AdminShell.tsx +186 -0
- package/apps/shared/components/admin/mailboxes/MailboxTable.tsx +73 -0
- package/apps/shared/components/admin/mailboxes/ResourceSettingsCard.tsx +154 -0
- package/apps/shared/components/admin/mailboxes/ShareAccessCard.tsx +124 -0
- package/apps/shared/components/booking/AvailabilityEditor.tsx +118 -0
- package/apps/shared/components/calendar/CalendarListSidebar.tsx +119 -0
- package/apps/shared/components/calendar/EventModal.tsx +513 -0
- package/apps/shared/components/calendar/MonthView.tsx +139 -0
- package/apps/shared/components/calendar/RecurrenceEditor.tsx +180 -0
- package/apps/shared/components/calendar/ResourcePicker.tsx +80 -0
- package/apps/shared/components/calendar/SplitDayView.tsx +137 -0
- package/apps/shared/components/calendar/TimeGridView.tsx +198 -0
- package/apps/shared/components/calendar/layout/CalendarShell.tsx +211 -0
- package/apps/shared/components/contacts/ContactDetailPane.tsx +99 -0
- package/apps/shared/components/contacts/ContactForm.tsx +314 -0
- package/apps/shared/components/contacts/ContactsSidebar.tsx +242 -0
- package/apps/shared/components/contacts/ContactsToolbar.tsx +115 -0
- package/apps/shared/components/contacts/layout/ContactsShell.tsx +197 -0
- package/apps/shared/components/layout/AppShell.tsx +165 -0
- package/apps/shared/components/layout/BrandingChrome.tsx +25 -0
- package/apps/shared/components/layout/MailboxProvisioning.tsx +110 -0
- package/apps/shared/components/layout/UserMenu.tsx +150 -0
- package/apps/shared/components/mail/ConversationList.tsx +61 -0
- package/apps/shared/components/mail/ConversationThreadPane.tsx +174 -0
- package/apps/shared/components/mail/MessageDetailPane.tsx +390 -0
- package/apps/shared/components/mail/compose/ComposeContext.tsx +114 -0
- package/apps/shared/components/mail/compose/ComposeToolbar.tsx +418 -0
- package/apps/shared/components/mail/compose/ComposeWindow.tsx +518 -0
- package/apps/shared/components/mail/compose/EmojiPicker.tsx +64 -0
- package/apps/shared/components/mail/compose/GifPicker.tsx +82 -0
- package/apps/shared/components/mail/compose/RichTextEditor.tsx +83 -0
- package/apps/shared/components/mail/compose/ScheduleSendPicker.tsx +64 -0
- package/apps/shared/components/mail/layout/MailShell.tsx +287 -0
- package/apps/shared/components/rules/RuleBuilder.tsx +276 -0
- package/apps/shared/components/settings/layout/SettingsShell.tsx +223 -0
- package/apps/shared/components/tasks/TasksSidebar.tsx +201 -0
- package/apps/shared/components/tasks/TasksToolbar.tsx +68 -0
- package/apps/shared/components/tasks/layout/TasksShell.tsx +199 -0
- package/apps/shared/styles/app.css +265 -0
- package/apps/www/_404.tsx +9 -0
- package/apps/www/_500.tsx +9 -0
- package/apps/www/_layout.tsx +45 -0
- package/apps/www/calendar/index.tsx +407 -0
- package/apps/www/contacts/[uid].tsx +88 -0
- package/apps/www/contacts/index.tsx +436 -0
- package/apps/www/index.tsx +375 -0
- package/apps/www/messages/[uid].tsx +70 -0
- package/apps/www/settings/auto-reply/index.tsx +129 -0
- package/apps/www/settings/booking-types/[uid].tsx +300 -0
- package/apps/www/settings/booking-types/index.tsx +98 -0
- package/apps/www/settings/booking-types/new/index.tsx +212 -0
- package/apps/www/settings/filters/[uid].tsx +155 -0
- package/apps/www/settings/filters/_mailFilterRuleConfig.tsx +102 -0
- package/apps/www/settings/filters/index.tsx +99 -0
- package/apps/www/settings/filters/new/index.tsx +126 -0
- package/apps/www/settings/focused-inbox/index.tsx +148 -0
- package/apps/www/settings/read-receipts/index.tsx +125 -0
- package/apps/www/settings/signatures/[uid].tsx +167 -0
- package/apps/www/settings/signatures/index.tsx +85 -0
- package/apps/www/settings/signatures/new/index.tsx +129 -0
- package/apps/www/settings/signatures/signatureDefaults.ts +36 -0
- package/apps/www/tasks/index.tsx +530 -0
- package/dist/apps/admin/_404.js +4 -0
- package/dist/apps/admin/_500.js +4 -0
- package/dist/apps/admin/_layout.js +10 -0
- package/dist/apps/admin/audit-log/index.js +66 -0
- package/dist/apps/admin/branding/index.js +126 -0
- package/dist/apps/admin/distribution-lists/[uid].js +34 -0
- package/dist/apps/admin/distribution-lists/index.js +31 -0
- package/dist/apps/admin/distribution-lists/new/index.js +51 -0
- package/dist/apps/admin/domains/[uid].js +102 -0
- package/dist/apps/admin/domains/index.js +31 -0
- package/dist/apps/admin/domains/new/index.js +41 -0
- package/dist/apps/admin/index.js +32 -0
- package/dist/apps/admin/ingest-queue/index.js +48 -0
- package/dist/apps/admin/mailboxes/[uid].js +59 -0
- package/dist/apps/admin/mailboxes/new/index.js +93 -0
- package/dist/apps/admin/quarantine/index.js +66 -0
- package/dist/apps/admin/transport-rules/[uid].js +87 -0
- package/dist/apps/admin/transport-rules/_transportRuleConfig.js +37 -0
- package/dist/apps/admin/transport-rules/index.js +32 -0
- package/dist/apps/admin/transport-rules/new/index.js +50 -0
- package/dist/apps/shared/components/admin/distributionLists/MemberListCard.js +64 -0
- package/dist/apps/shared/components/admin/layout/AdminShell.js +94 -0
- package/dist/apps/shared/components/admin/mailboxes/MailboxTable.js +16 -0
- package/dist/apps/shared/components/admin/mailboxes/ResourceSettingsCard.js +59 -0
- package/dist/apps/shared/components/admin/mailboxes/ShareAccessCard.js +67 -0
- package/dist/apps/shared/components/booking/AvailabilityEditor.js +45 -0
- package/dist/apps/shared/components/calendar/CalendarListSidebar.js +44 -0
- package/dist/apps/shared/components/calendar/EventModal.js +167 -0
- package/dist/apps/shared/components/calendar/MonthView.js +38 -0
- package/dist/apps/shared/components/calendar/RecurrenceEditor.js +55 -0
- package/dist/apps/shared/components/calendar/ResourcePicker.js +36 -0
- package/dist/apps/shared/components/calendar/SplitDayView.js +44 -0
- package/dist/apps/shared/components/calendar/TimeGridView.js +58 -0
- package/dist/apps/shared/components/calendar/layout/CalendarShell.js +96 -0
- package/dist/apps/shared/components/contacts/ContactDetailPane.js +11 -0
- package/dist/apps/shared/components/contacts/ContactForm.js +85 -0
- package/dist/apps/shared/components/contacts/ContactsSidebar.js +105 -0
- package/dist/apps/shared/components/contacts/ContactsToolbar.js +32 -0
- package/dist/apps/shared/components/contacts/layout/ContactsShell.js +93 -0
- package/dist/apps/shared/components/layout/AppShell.js +68 -0
- package/dist/apps/shared/components/layout/BrandingChrome.js +18 -0
- package/dist/apps/shared/components/layout/MailboxProvisioning.js +75 -0
- package/dist/apps/shared/components/layout/UserMenu.js +59 -0
- package/dist/apps/shared/components/mail/ConversationList.js +17 -0
- package/dist/apps/shared/components/mail/ConversationThreadPane.js +112 -0
- package/dist/apps/shared/components/mail/MessageDetailPane.js +153 -0
- package/dist/apps/shared/components/mail/compose/ComposeContext.js +55 -0
- package/dist/apps/shared/components/mail/compose/ComposeToolbar.js +88 -0
- package/dist/apps/shared/components/mail/compose/ComposeWindow.js +261 -0
- package/dist/apps/shared/components/mail/compose/EmojiPicker.js +25 -0
- package/dist/apps/shared/components/mail/compose/GifPicker.js +36 -0
- package/dist/apps/shared/components/mail/compose/RichTextEditor.js +60 -0
- package/dist/apps/shared/components/mail/compose/ScheduleSendPicker.js +33 -0
- package/dist/apps/shared/components/mail/layout/MailShell.js +139 -0
- package/dist/apps/shared/components/rules/RuleBuilder.js +78 -0
- package/dist/apps/shared/components/settings/layout/SettingsShell.js +100 -0
- package/dist/apps/shared/components/tasks/TasksSidebar.js +81 -0
- package/dist/apps/shared/components/tasks/TasksToolbar.js +15 -0
- package/dist/apps/shared/components/tasks/layout/TasksShell.js +92 -0
- package/dist/apps/shared/styles/app.css +265 -0
- package/dist/apps/www/_404.js +4 -0
- package/dist/apps/www/_500.js +4 -0
- package/dist/apps/www/_layout.js +8 -0
- package/dist/apps/www/calendar/index.js +228 -0
- package/dist/apps/www/contacts/[uid].js +62 -0
- package/dist/apps/www/contacts/index.js +262 -0
- package/dist/apps/www/index.js +228 -0
- package/dist/apps/www/messages/[uid].js +47 -0
- package/dist/apps/www/settings/auto-reply/index.js +54 -0
- package/dist/apps/www/settings/booking-types/[uid].js +129 -0
- package/dist/apps/www/settings/booking-types/index.js +29 -0
- package/dist/apps/www/settings/booking-types/new/index.js +86 -0
- package/dist/apps/www/settings/filters/[uid].js +94 -0
- package/dist/apps/www/settings/filters/_mailFilterRuleConfig.js +65 -0
- package/dist/apps/www/settings/filters/index.js +30 -0
- package/dist/apps/www/settings/filters/new/index.js +61 -0
- package/dist/apps/www/settings/focused-inbox/index.js +69 -0
- package/dist/apps/www/settings/read-receipts/index.js +51 -0
- package/dist/apps/www/settings/signatures/[uid].js +96 -0
- package/dist/apps/www/settings/signatures/index.js +34 -0
- package/dist/apps/www/settings/signatures/new/index.js +63 -0
- package/dist/apps/www/settings/signatures/signatureDefaults.js +30 -0
- package/dist/apps/www/tasks/index.js +280 -0
- package/package.json +87 -0
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
2
|
+
// Copyright (C) 2026 Jean-Philippe Steinmetz
|
|
3
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
4
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
5
|
+
import React, { PropsWithChildren, createContext, useContext, useMemo, useState } from "react";
|
|
6
|
+
import useIsMobile from "@rapidmx/react-shared/util/useIsMobile.js";
|
|
7
|
+
import ComposeWindow from "./ComposeWindow.js";
|
|
8
|
+
|
|
9
|
+
export interface ComposeSession {
|
|
10
|
+
id: string;
|
|
11
|
+
mailboxUid: string;
|
|
12
|
+
initialTo?: string;
|
|
13
|
+
initialCc?: string;
|
|
14
|
+
initialSubject?: string;
|
|
15
|
+
/** Pre-built HTML (already includes its own quote-attribution wrapper — see `composeQuoting.ts`)
|
|
16
|
+
* inserted below the resolved default signature. Absent for a fresh, non-reply/forward compose. */
|
|
17
|
+
initialQuotedHtml?: string;
|
|
18
|
+
/** Which of a signature's two "default" flags to resolve against — `"new"` (the default) uses
|
|
19
|
+
* `isDefaultForNewMessages`, `"reply_forward"` uses `isDefaultForReplyForward`. */
|
|
20
|
+
signatureContext: "new" | "reply_forward";
|
|
21
|
+
minimized: boolean;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface OpenComposeInput {
|
|
25
|
+
mailboxUid: string;
|
|
26
|
+
/** Prefills the To field — e.g. Contacts' "Email" toolbar action, or Reply/Reply All/Forward. */
|
|
27
|
+
to?: string;
|
|
28
|
+
/** Prefills the Cc field and reveals the Cc/Bcc row — Reply All only. */
|
|
29
|
+
cc?: string;
|
|
30
|
+
/** Prefills the Subject field — Reply/Reply All/Forward. */
|
|
31
|
+
subject?: string;
|
|
32
|
+
/** See `ComposeSession.initialQuotedHtml`'s own doc comment. */
|
|
33
|
+
quotedHtml?: string;
|
|
34
|
+
/** See `ComposeSession.signatureContext`'s own doc comment. Defaults to `"new"` — every existing
|
|
35
|
+
* caller (Contacts' "Email" action, the folder-sidebar "Compose" button) is a fresh compose. */
|
|
36
|
+
signatureContext?: "new" | "reply_forward";
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface ComposeContextValue {
|
|
40
|
+
/** Opens a new compose window, stacked alongside any already open (Gmail allows several at once). */
|
|
41
|
+
openCompose: (input: OpenComposeInput) => void;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const ComposeContext = createContext<ComposeContextValue>({ openCompose: () => undefined });
|
|
45
|
+
|
|
46
|
+
/** Opens the floating Compose window from anywhere inside `AppShell` (any of the four webmail apps). */
|
|
47
|
+
export function useCompose(): ComposeContextValue {
|
|
48
|
+
return useContext(ComposeContext);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Owns every currently-open Compose window and renders them stacked bottom-right, Gmail-style — see
|
|
53
|
+
* `ComposeWindow`'s own doc comment for why this replaced the old dedicated `/compose` page. Mounted
|
|
54
|
+
* once in `AppShell`, so every webmail app (Mail/Calendar/Contacts/Tasks) shares the same instance:
|
|
55
|
+
* opening Compose from Contacts' "Email" action, for instance, overlays the window on top of whatever
|
|
56
|
+
* app is currently showing, exactly like opening it from Mail's own sidebar button.
|
|
57
|
+
*/
|
|
58
|
+
export default function ComposeProvider({ children }: PropsWithChildren) {
|
|
59
|
+
const [sessions, setSessions] = useState<ComposeSession[]>([]);
|
|
60
|
+
const isMobile = useIsMobile();
|
|
61
|
+
|
|
62
|
+
function openCompose({ mailboxUid, to, cc, subject, quotedHtml, signatureContext = "new" }: OpenComposeInput) {
|
|
63
|
+
setSessions((prev) => [
|
|
64
|
+
...prev,
|
|
65
|
+
{
|
|
66
|
+
id: crypto.randomUUID(),
|
|
67
|
+
mailboxUid,
|
|
68
|
+
initialTo: to,
|
|
69
|
+
initialCc: cc,
|
|
70
|
+
initialSubject: subject,
|
|
71
|
+
initialQuotedHtml: quotedHtml,
|
|
72
|
+
signatureContext,
|
|
73
|
+
minimized: false,
|
|
74
|
+
},
|
|
75
|
+
]);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function closeCompose(id: string) {
|
|
79
|
+
setSessions((prev) => prev.filter((s) => s.id !== id));
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function toggleMinimize(id: string) {
|
|
83
|
+
setSessions((prev) => prev.map((s) => (s.id === id ? { ...s, minimized: !s.minimized } : s)));
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const value = useMemo<ComposeContextValue>(() => ({ openCompose }), []);
|
|
87
|
+
|
|
88
|
+
// On mobile, a non-minimized `ComposeWindow` renders full-screen (see that component's own doc
|
|
89
|
+
// comment) — Gmail-style stacking of several full-screen overlays at once makes no sense there, so
|
|
90
|
+
// at most one non-minimized session is ever rendered: the most recently opened one. Minimized
|
|
91
|
+
// sessions are small chips regardless of device, so every one of those still renders — an earlier
|
|
92
|
+
// session becomes visible again (as its own chip, or full-screen if it's the new most-recent
|
|
93
|
+
// non-minimized one) once whatever's currently "on top" is closed or minimized.
|
|
94
|
+
const lastNonMinimizedId = isMobile ? [...sessions].reverse().find((s) => !s.minimized)?.id : undefined;
|
|
95
|
+
const visibleSessions = isMobile ? sessions.filter((s) => s.minimized || s.id === lastNonMinimizedId) : sessions;
|
|
96
|
+
|
|
97
|
+
return (
|
|
98
|
+
<ComposeContext.Provider value={value}>
|
|
99
|
+
{children}
|
|
100
|
+
{visibleSessions.length > 0 && (
|
|
101
|
+
<div className="fixed bottom-0 right-6 flex items-end gap-3 z-50">
|
|
102
|
+
{visibleSessions.map((session) => (
|
|
103
|
+
<ComposeWindow
|
|
104
|
+
key={session.id}
|
|
105
|
+
session={session}
|
|
106
|
+
onClose={() => closeCompose(session.id)}
|
|
107
|
+
onToggleMinimize={() => toggleMinimize(session.id)}
|
|
108
|
+
/>
|
|
109
|
+
))}
|
|
110
|
+
</div>
|
|
111
|
+
)}
|
|
112
|
+
</ComposeContext.Provider>
|
|
113
|
+
);
|
|
114
|
+
}
|
|
@@ -0,0 +1,418 @@
|
|
|
1
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
2
|
+
// Copyright (C) 2026 Jean-Philippe Steinmetz
|
|
3
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
4
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
5
|
+
import React, { ReactNode, useRef, useState } from "react";
|
|
6
|
+
import type { Editor } from "@tiptap/react";
|
|
7
|
+
import type { IconType } from "react-icons";
|
|
8
|
+
import {
|
|
9
|
+
BsArrowClockwise,
|
|
10
|
+
BsArrowCounterclockwise,
|
|
11
|
+
BsEraser,
|
|
12
|
+
BsHighlighter,
|
|
13
|
+
BsImage,
|
|
14
|
+
BsIndent,
|
|
15
|
+
BsJustify,
|
|
16
|
+
BsLink45Deg,
|
|
17
|
+
BsListOl,
|
|
18
|
+
BsListUl,
|
|
19
|
+
BsPaletteFill,
|
|
20
|
+
BsTable,
|
|
21
|
+
BsTextCenter,
|
|
22
|
+
BsTextLeft,
|
|
23
|
+
BsTextRight,
|
|
24
|
+
BsTypeBold,
|
|
25
|
+
BsTypeItalic,
|
|
26
|
+
BsTypeStrikethrough,
|
|
27
|
+
BsTypeUnderline,
|
|
28
|
+
BsUnindent,
|
|
29
|
+
} from "react-icons/bs";
|
|
30
|
+
import EmojiPicker from "./EmojiPicker.js";
|
|
31
|
+
import GifPicker from "./GifPicker.js";
|
|
32
|
+
|
|
33
|
+
export interface ComposeToolbarProps {
|
|
34
|
+
/** `null` before the editor has mounted client-side (see `RichTextEditor`'s `immediatelyRender: false`
|
|
35
|
+
* doc comment) — every button is disabled in that state rather than the toolbar rendering nothing, so
|
|
36
|
+
* its layout doesn't shift the instant the editor becomes ready. */
|
|
37
|
+
editor: Editor | null;
|
|
38
|
+
/** Uploads `file` as an attachment on the current draft and resolves to a URL the browser can
|
|
39
|
+
* preview it at while composing — see `BaseMailComposeRoute.rewriteInlineImageSources()`'s doc
|
|
40
|
+
* comment for why that's not the final URL the message actually ships with. Resolves to `null`
|
|
41
|
+
* (rather than rejecting) on failure — `ComposeWindow`'s own implementation is responsible for
|
|
42
|
+
* surfacing the error itself, so a failed upload here just quietly doesn't insert an image. */
|
|
43
|
+
onUploadImage: (file: File) => Promise<string | null>;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const FONT_FAMILIES = [
|
|
47
|
+
{ label: "Default", value: "" },
|
|
48
|
+
{ label: "Sans Serif", value: "Arial, Helvetica, sans-serif" },
|
|
49
|
+
{ label: "Serif", value: "Georgia, 'Times New Roman', serif" },
|
|
50
|
+
{ label: "Monospace", value: "'Courier New', monospace" },
|
|
51
|
+
];
|
|
52
|
+
|
|
53
|
+
const FONT_SIZES = [
|
|
54
|
+
{ label: "Small", value: "12px" },
|
|
55
|
+
{ label: "Normal", value: "" },
|
|
56
|
+
{ label: "Large", value: "18px" },
|
|
57
|
+
{ label: "Huge", value: "24px" },
|
|
58
|
+
];
|
|
59
|
+
|
|
60
|
+
function ToolbarButton({
|
|
61
|
+
label,
|
|
62
|
+
icon: Icon,
|
|
63
|
+
active,
|
|
64
|
+
disabled,
|
|
65
|
+
onClick,
|
|
66
|
+
}: {
|
|
67
|
+
label: string;
|
|
68
|
+
icon: IconType;
|
|
69
|
+
active?: boolean;
|
|
70
|
+
disabled?: boolean;
|
|
71
|
+
onClick: () => void;
|
|
72
|
+
}) {
|
|
73
|
+
return (
|
|
74
|
+
<button
|
|
75
|
+
type="button"
|
|
76
|
+
aria-label={label}
|
|
77
|
+
aria-pressed={active ?? false}
|
|
78
|
+
title={label}
|
|
79
|
+
disabled={disabled}
|
|
80
|
+
onClick={onClick}
|
|
81
|
+
className={[
|
|
82
|
+
"w-8 h-8 flex items-center justify-center rounded-sm disabled:opacity-40 disabled:cursor-not-allowed",
|
|
83
|
+
active ? "bg-primary/10 text-primary-dark" : "text-text-muted hover:bg-surface-alt hover:text-text",
|
|
84
|
+
].join(" ")}
|
|
85
|
+
>
|
|
86
|
+
<Icon size={16} aria-hidden="true" />
|
|
87
|
+
</button>
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function Divider() {
|
|
92
|
+
return <div className="w-px self-stretch my-1.5 bg-border" aria-hidden="true" />;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* The compose page's rich-text formatting toolbar — a practical single Outlook-Home-tab-style bar
|
|
97
|
+
* (font/size, bold/italic/underline/strikethrough, text/highlight color, alignment, lists/indent, insert
|
|
98
|
+
* link/image/table, clear formatting, undo/redo), not a full multi-tab ribbon replica. Every command is a
|
|
99
|
+
* plain `editor.chain().focus().<command>().run()` call against the `Editor` instance `RichTextEditor`
|
|
100
|
+
* creates; active-state styling comes from `editor.isActive(...)`.
|
|
101
|
+
*/
|
|
102
|
+
type Popup = "link" | "emoji" | "gif" | null;
|
|
103
|
+
|
|
104
|
+
export default function ComposeToolbar({ editor, onUploadImage }: ComposeToolbarProps) {
|
|
105
|
+
const [openPopup, setOpenPopup] = useState<Popup>(null);
|
|
106
|
+
const [linkUrl, setLinkUrl] = useState("");
|
|
107
|
+
const imageInputRef = useRef<HTMLInputElement>(null);
|
|
108
|
+
const emojiButtonRef = useRef<HTMLButtonElement>(null);
|
|
109
|
+
const gifButtonRef = useRef<HTMLButtonElement>(null);
|
|
110
|
+
|
|
111
|
+
const disabled = !editor;
|
|
112
|
+
|
|
113
|
+
// Every control that calls `run()` is itself `disabled` while `editor` is null (see `disabled` above),
|
|
114
|
+
// and `editor` never reverts to null once TipTap actually creates it (only `immediatelyRender: false`'s
|
|
115
|
+
// one-render gap before mount produces a null `editor` at all) — so `run()` is never reachable with a
|
|
116
|
+
// null `editor` through any real UI interaction; asserted non-null rather than guarded, matching this
|
|
117
|
+
// codebase's established pattern for the same class of "always non-null by the time it's called" value.
|
|
118
|
+
function run(fn: (editor: Editor) => void) {
|
|
119
|
+
fn(editor!);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
async function handleImageFileSelected(e: React.ChangeEvent<HTMLInputElement>) {
|
|
123
|
+
const file = e.target.files?.[0];
|
|
124
|
+
e.target.value = "";
|
|
125
|
+
if (!file) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
const url = await onUploadImage(file);
|
|
129
|
+
if (url) {
|
|
130
|
+
run((ed) => ed.chain().focus().setImage({ src: url }).run());
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function handleInsertEmoji(native: string) {
|
|
135
|
+
run((e) => e.chain().focus().insertContent(native).run());
|
|
136
|
+
setOpenPopup(null);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function handleInsertGif(url: string) {
|
|
140
|
+
run((e) => e.chain().focus().setImage({ src: url }).run());
|
|
141
|
+
setOpenPopup(null);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function openLinkPrompt() {
|
|
145
|
+
setLinkUrl(editor?.getAttributes("link").href ?? "");
|
|
146
|
+
setOpenPopup("link");
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function submitLink(e: React.FormEvent) {
|
|
150
|
+
e.preventDefault();
|
|
151
|
+
if (linkUrl.trim().length === 0) {
|
|
152
|
+
run((ed) => ed.chain().focus().extendMarkRange("link").unsetLink().run());
|
|
153
|
+
} else {
|
|
154
|
+
run((ed) => ed.chain().focus().extendMarkRange("link").setLink({ href: linkUrl.trim() }).run());
|
|
155
|
+
}
|
|
156
|
+
setOpenPopup(null);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
let linkPrompt: ReactNode = null;
|
|
160
|
+
if (openPopup === "link") {
|
|
161
|
+
linkPrompt = (
|
|
162
|
+
<form onSubmit={submitLink} className="flex items-center gap-1.5 px-2 py-1.5 border-t border-border">
|
|
163
|
+
<input
|
|
164
|
+
type="text"
|
|
165
|
+
autoFocus
|
|
166
|
+
aria-label="Link URL"
|
|
167
|
+
placeholder="https://example.com"
|
|
168
|
+
value={linkUrl}
|
|
169
|
+
onChange={(e) => setLinkUrl(e.target.value)}
|
|
170
|
+
className="flex-1 text-sm py-1 px-2 border border-border rounded-sm bg-surface"
|
|
171
|
+
/>
|
|
172
|
+
<button type="submit" className="text-xs font-semibold text-primary-dark hover:underline">
|
|
173
|
+
Apply
|
|
174
|
+
</button>
|
|
175
|
+
<button
|
|
176
|
+
type="button"
|
|
177
|
+
onClick={() => setOpenPopup(null)}
|
|
178
|
+
className="text-xs font-medium text-text-muted hover:underline"
|
|
179
|
+
>
|
|
180
|
+
Cancel
|
|
181
|
+
</button>
|
|
182
|
+
</form>
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return (
|
|
187
|
+
<div className="border-b border-border bg-surface-alt">
|
|
188
|
+
<div className="flex flex-wrap items-center gap-0.5 px-2 py-1.5">
|
|
189
|
+
<select
|
|
190
|
+
aria-label="Font family"
|
|
191
|
+
disabled={disabled}
|
|
192
|
+
value={editor?.getAttributes("textStyle").fontFamily ?? ""}
|
|
193
|
+
onChange={(e) =>
|
|
194
|
+
run((ed) =>
|
|
195
|
+
e.target.value
|
|
196
|
+
? ed.chain().focus().setFontFamily(e.target.value).run()
|
|
197
|
+
: ed.chain().focus().unsetFontFamily().run(),
|
|
198
|
+
)
|
|
199
|
+
}
|
|
200
|
+
className="text-xs py-1 px-1.5 border border-border rounded-sm bg-surface disabled:opacity-40"
|
|
201
|
+
>
|
|
202
|
+
{FONT_FAMILIES.map((f) => (
|
|
203
|
+
<option key={f.label} value={f.value}>
|
|
204
|
+
{f.label}
|
|
205
|
+
</option>
|
|
206
|
+
))}
|
|
207
|
+
</select>
|
|
208
|
+
|
|
209
|
+
<select
|
|
210
|
+
aria-label="Font size"
|
|
211
|
+
disabled={disabled}
|
|
212
|
+
value={editor?.getAttributes("textStyle").fontSize ?? ""}
|
|
213
|
+
onChange={(e) =>
|
|
214
|
+
run((ed) =>
|
|
215
|
+
e.target.value
|
|
216
|
+
? ed.chain().focus().setFontSize(e.target.value).run()
|
|
217
|
+
: ed.chain().focus().unsetFontSize().run(),
|
|
218
|
+
)
|
|
219
|
+
}
|
|
220
|
+
className="text-xs py-1 px-1.5 border border-border rounded-sm bg-surface disabled:opacity-40"
|
|
221
|
+
>
|
|
222
|
+
{FONT_SIZES.map((f) => (
|
|
223
|
+
<option key={f.label} value={f.value}>
|
|
224
|
+
{f.label}
|
|
225
|
+
</option>
|
|
226
|
+
))}
|
|
227
|
+
</select>
|
|
228
|
+
|
|
229
|
+
<Divider />
|
|
230
|
+
|
|
231
|
+
<ToolbarButton
|
|
232
|
+
label="Bold"
|
|
233
|
+
icon={BsTypeBold}
|
|
234
|
+
disabled={disabled}
|
|
235
|
+
active={editor?.isActive("bold")}
|
|
236
|
+
onClick={() => run((e) => e.chain().focus().toggleBold().run())}
|
|
237
|
+
/>
|
|
238
|
+
<ToolbarButton
|
|
239
|
+
label="Italic"
|
|
240
|
+
icon={BsTypeItalic}
|
|
241
|
+
disabled={disabled}
|
|
242
|
+
active={editor?.isActive("italic")}
|
|
243
|
+
onClick={() => run((e) => e.chain().focus().toggleItalic().run())}
|
|
244
|
+
/>
|
|
245
|
+
<ToolbarButton
|
|
246
|
+
label="Underline"
|
|
247
|
+
icon={BsTypeUnderline}
|
|
248
|
+
disabled={disabled}
|
|
249
|
+
active={editor?.isActive("underline")}
|
|
250
|
+
onClick={() => run((e) => e.chain().focus().toggleUnderline().run())}
|
|
251
|
+
/>
|
|
252
|
+
<ToolbarButton
|
|
253
|
+
label="Strikethrough"
|
|
254
|
+
icon={BsTypeStrikethrough}
|
|
255
|
+
disabled={disabled}
|
|
256
|
+
active={editor?.isActive("strike")}
|
|
257
|
+
onClick={() => run((e) => e.chain().focus().toggleStrike().run())}
|
|
258
|
+
/>
|
|
259
|
+
|
|
260
|
+
<Divider />
|
|
261
|
+
|
|
262
|
+
<label className="w-8 h-8 flex items-center justify-center rounded-sm text-text-muted hover:bg-surface-alt hover:text-text cursor-pointer has-[:disabled]:opacity-40 has-[:disabled]:cursor-not-allowed">
|
|
263
|
+
<BsPaletteFill size={16} aria-hidden="true" />
|
|
264
|
+
<span className="sr-only">Text color</span>
|
|
265
|
+
<input
|
|
266
|
+
type="color"
|
|
267
|
+
disabled={disabled}
|
|
268
|
+
value={editor?.getAttributes("textStyle").color ?? "#000000"}
|
|
269
|
+
onChange={(e) => run((ed) => ed.chain().focus().setColor(e.target.value).run())}
|
|
270
|
+
className="sr-only"
|
|
271
|
+
/>
|
|
272
|
+
</label>
|
|
273
|
+
<ToolbarButton
|
|
274
|
+
label="Highlight"
|
|
275
|
+
icon={BsHighlighter}
|
|
276
|
+
disabled={disabled}
|
|
277
|
+
active={editor?.isActive("highlight")}
|
|
278
|
+
onClick={() => run((e) => e.chain().focus().toggleHighlight().run())}
|
|
279
|
+
/>
|
|
280
|
+
|
|
281
|
+
<Divider />
|
|
282
|
+
|
|
283
|
+
<ToolbarButton
|
|
284
|
+
label="Align left"
|
|
285
|
+
icon={BsTextLeft}
|
|
286
|
+
disabled={disabled}
|
|
287
|
+
active={editor?.isActive({ textAlign: "left" })}
|
|
288
|
+
onClick={() => run((e) => e.chain().focus().setTextAlign("left").run())}
|
|
289
|
+
/>
|
|
290
|
+
<ToolbarButton
|
|
291
|
+
label="Align center"
|
|
292
|
+
icon={BsTextCenter}
|
|
293
|
+
disabled={disabled}
|
|
294
|
+
active={editor?.isActive({ textAlign: "center" })}
|
|
295
|
+
onClick={() => run((e) => e.chain().focus().setTextAlign("center").run())}
|
|
296
|
+
/>
|
|
297
|
+
<ToolbarButton
|
|
298
|
+
label="Align right"
|
|
299
|
+
icon={BsTextRight}
|
|
300
|
+
disabled={disabled}
|
|
301
|
+
active={editor?.isActive({ textAlign: "right" })}
|
|
302
|
+
onClick={() => run((e) => e.chain().focus().setTextAlign("right").run())}
|
|
303
|
+
/>
|
|
304
|
+
<ToolbarButton
|
|
305
|
+
label="Justify"
|
|
306
|
+
icon={BsJustify}
|
|
307
|
+
disabled={disabled}
|
|
308
|
+
active={editor?.isActive({ textAlign: "justify" })}
|
|
309
|
+
onClick={() => run((e) => e.chain().focus().setTextAlign("justify").run())}
|
|
310
|
+
/>
|
|
311
|
+
|
|
312
|
+
<Divider />
|
|
313
|
+
|
|
314
|
+
<ToolbarButton
|
|
315
|
+
label="Bulleted list"
|
|
316
|
+
icon={BsListUl}
|
|
317
|
+
disabled={disabled}
|
|
318
|
+
active={editor?.isActive("bulletList")}
|
|
319
|
+
onClick={() => run((e) => e.chain().focus().toggleBulletList().run())}
|
|
320
|
+
/>
|
|
321
|
+
<ToolbarButton
|
|
322
|
+
label="Numbered list"
|
|
323
|
+
icon={BsListOl}
|
|
324
|
+
disabled={disabled}
|
|
325
|
+
active={editor?.isActive("orderedList")}
|
|
326
|
+
onClick={() => run((e) => e.chain().focus().toggleOrderedList().run())}
|
|
327
|
+
/>
|
|
328
|
+
<ToolbarButton
|
|
329
|
+
label="Decrease indent"
|
|
330
|
+
icon={BsUnindent}
|
|
331
|
+
disabled={disabled}
|
|
332
|
+
onClick={() => run((e) => e.chain().focus().liftListItem("listItem").run())}
|
|
333
|
+
/>
|
|
334
|
+
<ToolbarButton
|
|
335
|
+
label="Increase indent"
|
|
336
|
+
icon={BsIndent}
|
|
337
|
+
disabled={disabled}
|
|
338
|
+
onClick={() => run((e) => e.chain().focus().sinkListItem("listItem").run())}
|
|
339
|
+
/>
|
|
340
|
+
|
|
341
|
+
<Divider />
|
|
342
|
+
|
|
343
|
+
<ToolbarButton
|
|
344
|
+
label="Insert link"
|
|
345
|
+
icon={BsLink45Deg}
|
|
346
|
+
disabled={disabled}
|
|
347
|
+
active={editor?.isActive("link")}
|
|
348
|
+
onClick={openLinkPrompt}
|
|
349
|
+
/>
|
|
350
|
+
<ToolbarButton label="Insert image" icon={BsImage} disabled={disabled} onClick={() => imageInputRef.current?.click()} />
|
|
351
|
+
<input
|
|
352
|
+
ref={imageInputRef}
|
|
353
|
+
type="file"
|
|
354
|
+
accept="image/*"
|
|
355
|
+
onChange={handleImageFileSelected}
|
|
356
|
+
className="sr-only"
|
|
357
|
+
aria-label="Insert image file"
|
|
358
|
+
/>
|
|
359
|
+
<ToolbarButton
|
|
360
|
+
label="Insert table"
|
|
361
|
+
icon={BsTable}
|
|
362
|
+
disabled={disabled}
|
|
363
|
+
onClick={() => run((e) => e.chain().focus().insertTable({ rows: 3, cols: 3, withHeaderRow: true }).run())}
|
|
364
|
+
/>
|
|
365
|
+
|
|
366
|
+
<button
|
|
367
|
+
ref={emojiButtonRef}
|
|
368
|
+
type="button"
|
|
369
|
+
aria-label="Insert emoji"
|
|
370
|
+
title="Insert emoji"
|
|
371
|
+
disabled={disabled}
|
|
372
|
+
onClick={() => setOpenPopup((p) => (p === "emoji" ? null : "emoji"))}
|
|
373
|
+
className="w-8 h-8 flex items-center justify-center text-base rounded-sm disabled:opacity-40 disabled:cursor-not-allowed text-text-muted hover:bg-surface-alt hover:text-text"
|
|
374
|
+
>
|
|
375
|
+
😀
|
|
376
|
+
</button>
|
|
377
|
+
{openPopup === "emoji" && (
|
|
378
|
+
<EmojiPicker anchorRef={emojiButtonRef} onSelect={handleInsertEmoji} onClose={() => setOpenPopup(null)} />
|
|
379
|
+
)}
|
|
380
|
+
|
|
381
|
+
<button
|
|
382
|
+
ref={gifButtonRef}
|
|
383
|
+
type="button"
|
|
384
|
+
aria-label="Insert GIF"
|
|
385
|
+
title="Insert GIF"
|
|
386
|
+
disabled={disabled}
|
|
387
|
+
onClick={() => setOpenPopup((p) => (p === "gif" ? null : "gif"))}
|
|
388
|
+
className="w-8 h-8 flex items-center justify-center text-[10px] font-extrabold tracking-tight rounded-sm disabled:opacity-40 disabled:cursor-not-allowed text-text-muted hover:bg-surface-alt hover:text-text"
|
|
389
|
+
>
|
|
390
|
+
GIF
|
|
391
|
+
</button>
|
|
392
|
+
{openPopup === "gif" && <GifPicker anchorRef={gifButtonRef} onSelect={handleInsertGif} onClose={() => setOpenPopup(null)} />}
|
|
393
|
+
|
|
394
|
+
<Divider />
|
|
395
|
+
|
|
396
|
+
<ToolbarButton
|
|
397
|
+
label="Clear formatting"
|
|
398
|
+
icon={BsEraser}
|
|
399
|
+
disabled={disabled}
|
|
400
|
+
onClick={() => run((e) => e.chain().focus().unsetAllMarks().clearNodes().run())}
|
|
401
|
+
/>
|
|
402
|
+
<ToolbarButton
|
|
403
|
+
label="Undo"
|
|
404
|
+
icon={BsArrowCounterclockwise}
|
|
405
|
+
disabled={disabled || !editor?.can().undo()}
|
|
406
|
+
onClick={() => run((e) => e.chain().focus().undo().run())}
|
|
407
|
+
/>
|
|
408
|
+
<ToolbarButton
|
|
409
|
+
label="Redo"
|
|
410
|
+
icon={BsArrowClockwise}
|
|
411
|
+
disabled={disabled || !editor?.can().redo()}
|
|
412
|
+
onClick={() => run((e) => e.chain().focus().redo().run())}
|
|
413
|
+
/>
|
|
414
|
+
</div>
|
|
415
|
+
{linkPrompt}
|
|
416
|
+
</div>
|
|
417
|
+
);
|
|
418
|
+
}
|