diff --git a/app/globals.css b/app/globals.css
index f9eb2c995..1bd57121d 100644
--- a/app/globals.css
+++ b/app/globals.css
@@ -628,6 +628,17 @@ html[data-window-controls] [data-window-row-right] {
padding-right: calc(var(--titlebar-right-inset) + 0.5rem) !important;
}
+/*
+ * The composer's header runs over its plugin panels. The head above the panel at the
+ * window's right takes that room inside itself, so it stays as wide as the panel and
+ * its Hide button stays at the panel's edge, with its window buttons left of the controls.
+ */
+html[data-window-controls]:not([dir="rtl"]) [data-window-row-right] > [data-composer-panel-head="right"],
+html[data-window-controls][dir="rtl"] [data-window-row-right] > [data-composer-panel-head="left"] {
+ margin-right: calc(-1 * (var(--titlebar-right-inset) + 0.5rem));
+ padding-right: calc(var(--titlebar-right-inset) + 0.5rem);
+}
+
/* Something floating at the top end of a page with no row: next to the controls, lined up. */
html[data-window-controls]:not([dir="rtl"]) [data-window-beside-controls] {
right: calc(var(--titlebar-right-inset) + 0.5rem);
diff --git a/components/email/__tests__/composer-plugin-surfaces.test.tsx b/components/email/__tests__/composer-plugin-surfaces.test.tsx
index 66357fe00..3af20e4f5 100644
--- a/components/email/__tests__/composer-plugin-surfaces.test.tsx
+++ b/components/email/__tests__/composer-plugin-surfaces.test.tsx
@@ -585,6 +585,7 @@ describe('composer-sidebar and composer-sidebar-right', () => {
Element.prototype.getBoundingClientRect = function (this: Element) {
if (this.matches('[data-testid="email-composer"]')) return rect(100, 800);
if (this.matches('[data-composer-header]')) return rect(100, 156);
+ if (this.matches('[data-composer-panels]')) return rect(156, 800);
if (this.matches('[data-composer-footer]')) return rect(740, 800);
return original.call(this);
};
@@ -593,7 +594,9 @@ describe('composer-sidebar and composer-sidebar-right', () => {
render();
fireEvent.click(document.querySelector('[data-composer-panel-toggle="right"]')!);
expect(panel('right').dataset.composerSidebarMode).toBe('overlay');
- expect(panel('right').style.top).toBe('56px');
+ // The header is above the row the panel is laid over: the panel starts at that row's top.
+ expect(document.querySelector('[data-composer-panels]')!.contains(document.querySelector('[data-composer-header]'))).toBe(false);
+ expect(panel('right').style.top).toBe('0px');
expect(panel('right').style.bottom).toBe('60px');
} finally {
Element.prototype.getBoundingClientRect = original;
@@ -718,7 +721,7 @@ describe('composer-sidebar and composer-sidebar-right', () => {
// Opened once: it stays open for the next composer.
render();
expect(panel('right').dataset.composerSidebarMode).toBe('docked');
- fireEvent.click(screen.getByRole('button', { name: 'plugin_panel_hide' }));
+ fireEvent.click(screen.getByRole('button', { name: 'hide_panel' }));
expect(panel('right').dataset.composerSidebarMode).toBe('folded');
});
@@ -742,11 +745,134 @@ describe('composer-sidebar and composer-sidebar-right', () => {
offerSlots('p1', ['composer-sidebar-right']);
render();
- fireEvent.click(screen.getByRole('button', { name: 'plugin_panel_show' }));
+ fireEvent.click(screen.getByRole('button', { name: 'show_panel' }));
expect(panel('right').dataset.composerSidebarMode).toBe('overlay');
expect(panel('right').className).toContain('absolute');
- fireEvent.click(screen.getByRole('button', { name: 'plugin_panel_hide' }));
+ fireEvent.click(screen.getByRole('button', { name: 'hide_panel' }));
expect(panel('right').dataset.composerSidebarMode).toBe('folded');
});
});
+
+// With a panel open, the composer's header runs over it: Full screen, Pop out
+// and Close end the whole composer, not the message column in the middle of
+// it. The panel's head (the header above it) has its own Hide button.
+describe('the composer header with a plugin panel open', () => {
+ function stubWidth(width: number) {
+ class FixedWidthObserver {
+ constructor(private cb: ResizeObserverCallback) {}
+ observe(el: Element) {
+ if ((el as HTMLElement).dataset.testid !== 'email-composer') return;
+ this.cb([{ target: el, contentRect: { width, height: 700 } } as unknown as ResizeObserverEntry], this as unknown as ResizeObserver);
+ }
+ unobserve() {}
+ disconnect() {}
+ }
+ vi.stubGlobal('ResizeObserver', FixedWidthObserver);
+ }
+ const panel = (side: 'left' | 'right') => document.querySelector(`[data-composer-sidebar="${side}"]`)!;
+ const header = () => document.querySelector('[data-composer-header]')!;
+ const head = (side: 'left' | 'right') => document.querySelector(`[data-composer-panel-head="${side}"]`);
+ const buttons = (el: HTMLElement) => Array.from(el.querySelectorAll('button'));
+
+ afterEach(() => {
+ vi.unstubAllGlobals();
+ for (const side of ['left', 'right']) {
+ localStorage.removeItem(`composerPluginSidebarCollapsed:${side}`);
+ localStorage.removeItem(`composerPluginSidebarWidth:${side}`);
+ }
+ });
+
+ it('keeps Close the last control, at the end of the row over the open panel', () => {
+ stubWidth(1400);
+ offerSlots('p1', ['composer-sidebar-right']);
+ render();
+ expect(panel('right').dataset.composerSidebarMode).toBe('docked');
+
+ // One row over the message and the panel: the panel is not beside the header.
+ expect(header().parentElement).toBe(screen.getByTestId('email-composer'));
+ expect(header().compareDocumentPosition(panel('right')) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();
+ // The part of it above the panel is as wide as the panel...
+ const right = head('right')!;
+ expect(header()).toContainElement(right);
+ expect(right.style.minWidth).toBe('260px');
+ // ...and ends with Full screen, Pop out and Close, Close last.
+ const all = buttons(header());
+ expect(all[all.length - 1]).toBe(screen.getByTestId('composer-close'));
+ expect(right).toContainElement(screen.getByTestId('composer-close'));
+ expect(right).toContainElement(screen.getByTestId('composer-maximize'));
+ });
+
+ it('gives the open panel a Hide button in its head, and the header a Show button while it is folded', () => {
+ stubWidth(1400);
+ offerSlots('p1', ['composer-sidebar', 'composer-sidebar-right']);
+ render();
+
+ for (const side of ['left', 'right'] as const) {
+ const hide = head(side)!.querySelector(`[data-composer-panel-hide="${side}"]`)!;
+ expect(hide).toBeTruthy();
+ expect(hide).toHaveAccessibleName('hide_panel');
+ expect(hide.getAttribute('title')).toBe('hide_panel');
+ expect(hide.getAttribute('aria-expanded')).toBe('true');
+ }
+ // At the panel's inner edge, where it meets the message: last in the left head, first in the right one.
+ expect(buttons(head('left')!).at(-1)!.dataset.composerPanelHide).toBe('left');
+ expect(buttons(head('right')!)[0].dataset.composerPanelHide).toBe('right');
+
+ fireEvent.click(head('right')!.querySelector('[data-composer-panel-hide]')!);
+ expect(panel('right').dataset.composerSidebarMode).toBe('folded');
+ expect(head('right')).toBeNull();
+ // Folded: one Show button in the header, before the window buttons; Close still last.
+ const show = screen.getByRole('button', { name: 'show_panel' });
+ expect(header()).toContainElement(show);
+ expect(show.getAttribute('aria-expanded')).toBe('false');
+ const all = buttons(header());
+ expect(all[all.length - 1]).toBe(screen.getByTestId('composer-close'));
+ expect(all.indexOf(show)).toBeLessThan(all.indexOf(screen.getByTestId('composer-maximize')));
+
+ fireEvent.click(show);
+ expect(panel('right').dataset.composerSidebarMode).toBe('docked');
+ expect(head('right')).toContainElement(screen.getByTestId('composer-close'));
+ });
+
+ it('hides the panel with Hide and closes the composer only with Close', () => {
+ stubWidth(1400);
+ offerSlots('p1', ['composer-sidebar-right']);
+ const onClose = vi.fn();
+ render();
+
+ const hide = head('right')!.querySelector('[data-composer-panel-hide]')!;
+ const close = screen.getByTestId('composer-close');
+ expect(hide).not.toBe(close);
+ expect(hide).not.toHaveAccessibleName(close.getAttribute('aria-label')!);
+
+ fireEvent.click(hide);
+ expect(panel('right').dataset.composerSidebarMode).toBe('folded');
+ expect(onClose).not.toHaveBeenCalled();
+ expect(screen.queryByRole('alertdialog')).toBeNull();
+ expect(screen.getByTestId('email-composer')).toBeInTheDocument();
+
+ fireEvent.click(screen.getByTestId('composer-close'));
+ expect(onClose.mock.calls.length > 0 || screen.queryByRole('alertdialog') !== null).toBe(true);
+ });
+
+ it('gives a panel laid over a narrow composer the same head', () => {
+ stubWidth(700);
+ offerSlots('p1', ['composer-sidebar-right']);
+ render();
+ fireEvent.click(screen.getByRole('button', { name: 'show_panel' }));
+ expect(panel('right').dataset.composerSidebarMode).toBe('overlay');
+ expect(head('right')).toContainElement(screen.getByTestId('composer-close'));
+ fireEvent.click(screen.getByRole('button', { name: 'hide_panel' }));
+ expect(panel('right').dataset.composerSidebarMode).toBe('folded');
+ });
+
+ it('keeps Close last in a composer that is its own window', () => {
+ stubWidth(1400);
+ offerSlots('p1', ['composer-sidebar-right']);
+ render();
+ const all = buttons(header());
+ expect(all[all.length - 1]).toBe(screen.getByTestId('composer-close'));
+ expect(head('right')).toContainElement(screen.getByTestId('composer-close'));
+ });
+});
diff --git a/components/email/composer-plugin-sidebars.tsx b/components/email/composer-plugin-sidebars.tsx
index 5616a099e..1c6adb14d 100644
--- a/components/email/composer-plugin-sidebars.tsx
+++ b/components/email/composer-plugin-sidebars.tsx
@@ -1,20 +1,25 @@
"use client";
// The composer-sidebar and composer-sidebar-right plugin panels. Each has a
-// width the user can drag (kept across composers) and a button in the
-// composer's header that shows and hides it (the left panel's at the start,
-// the right one's at the end, like the reader's). Folded, a panel takes no
-// room at all. When the composer is too narrow for an open panel next to
-// it, the panel folds by itself (right first); opening it anyway lays it
-// over the composer instead of squeezing the message into a column nobody
-// can write in. Laid over, it stays between the composer's header and its
-// bottom bar: the panel's own button, Close and Send stay in reach.
+// width the user can drag (kept across composers). The composer's header
+// runs across the whole composer, panels included, so its window buttons
+// (Full screen, Pop out, Close) stay at the far end of it, as Outlook and
+// Gmail have them. The part of that row above an open panel is the
+// panel's head: it holds "Hide ", at the panel's inner edge. A
+// folded panel takes no room at all, and a "Show " button in the
+// header brings it back (the left panel's at the start, the right one's
+// before the window buttons). When the composer is too narrow for an open
+// panel next to it, the panel folds by itself (right first); opening it
+// anyway lays it over the composer instead of squeezing the message into a
+// column nobody can write in. Laid over, it stays between the header and
+// the bottom bar: Hide, Close and Send stay in reach.
-import { useEffect, useLayoutEffect, useRef, useState, type RefObject } from "react";
+import { useEffect, useLayoutEffect, useRef, useState, type ReactNode, type RefObject } from "react";
import { useTranslations } from "next-intl";
import { PanelLeftClose, PanelLeftOpen, PanelRightClose, PanelRightOpen } from "@/components/icons";
import { PluginSlot } from "@/components/plugins/plugin-slot";
import { usePluginSlotOffers } from "@/hooks/use-plugin-slot-offers";
+import { get as getActivePlugin } from "@/lib/plugin-sandbox/registry";
import { onPanelRequest, type PanelRequest } from "@/lib/plugin-sandbox/panel-requests";
import { ResizeHandle } from "@/components/layout/resize-handle";
import { cn } from "@/lib/utils";
@@ -196,40 +201,123 @@ export function useComposerSidebars(root: HTMLElement | null, composerId: string
}
};
- return { modes, open, close, toggle, focusRequests, widths, setSideWidth };
+ // What the panels are called in their Show and Hide buttons: their plugins' names.
+ const nameOf = (offers: readonly { pluginId: string }[]) =>
+ offers.map((o) => getActivePlugin(o.pluginId)?.plugin.name).filter((n): n is string => !!n).join(", ") || null;
+ const names: Record = { left: nameOf(leftOffers), right: nameOf(rightOffers) };
+
+ return { modes, open, close, toggle, focusRequests, widths, setSideWidth, names };
}
-/** The button in the composer's header that shows and hides one panel (none on phones). */
-export function ComposerPanelToggle({
- side,
- mode,
- onToggle,
- className,
-}: {
+/** Open beside the composer or over it: on screen, with a head in the header row. */
+export function isPanelOpen(mode: ComposerSidebarMode | null): boolean {
+ return mode === "docked" || mode === "overlay";
+}
+
+/** The Show or Hide button of one panel. */
+function PanelButton({ side, open, name, onToggle, className }: {
side: ComposerSidebarSide;
- mode: ComposerSidebarMode | null;
+ open: boolean;
+ name: string | null;
onToggle: () => void;
className?: string;
}) {
- const t = useTranslations("email_viewer");
- if (!mode) return null;
- const isOpen = mode !== "folded";
- const Icon = side === "left" ? (isOpen ? PanelLeftClose : PanelLeftOpen) : (isOpen ? PanelRightClose : PanelRightOpen);
+ const t = useTranslations("composer_panel");
+ const tViewer = useTranslations("email_viewer");
+ const label = name
+ ? t(open ? "hide_panel" : "show_panel", { name })
+ : tViewer(open ? "plugin_panel_hide" : "plugin_panel_show");
+ const Icon = side === "left" ? (open ? PanelLeftClose : PanelLeftOpen) : (open ? PanelRightClose : PanelRightOpen);
return (
);
}
+/**
+ * The button in the composer's header that brings a folded panel back (none
+ * on phones). An open panel's Hide button is in its head instead
+ * (ComposerPanelHead).
+ */
+export function ComposerPanelToggle({
+ side,
+ mode,
+ name = null,
+ onToggle,
+ className,
+}: {
+ side: ComposerSidebarSide;
+ mode: ComposerSidebarMode | null;
+ name?: string | null;
+ onToggle: () => void;
+ className?: string;
+}) {
+ if (mode !== "folded") return null;
+ return ;
+}
+
+/**
+ * The part of the composer's header row above an open panel, as wide as the
+ * panel: its Hide button at the panel's inner edge, and for the right panel
+ * whatever else ends the row (the window buttons, Close last), so they stay
+ * at the far end of the composer. On phones there are no panels, and no head.
+ */
+export function ComposerPanelHead({
+ side,
+ mode,
+ width = COMPOSER_SIDEBAR_WIDTH,
+ name = null,
+ onToggle,
+ className,
+ childrenClassName,
+ children,
+}: {
+ side: ComposerSidebarSide;
+ mode: ComposerSidebarMode | null;
+ width?: number;
+ name?: string | null;
+ onToggle: () => void;
+ /** Padding of the row it is part of. */
+ className?: string;
+ /** The gap between what it holds besides Hide, as in the row it is part of. */
+ childrenClassName?: string;
+ children?: ReactNode;
+}) {
+ if (!isPanelOpen(mode)) return null;
+ const hide = ;
+ return (
+
+ {side === "right" && hide}
+
+ {/* No gap of the head's own around Hide and the space: a 260 px panel in the desktop app has just enough room for the buttons. */}
+ {children &&
{children}
}
+ {side === "left" && hide}
+
+ );
+}
+
const COMPOSER_HEADER = "[data-composer-header], [data-mv-compose-titlebar], [data-mv-compose-inline-bar]";
const COMPOSER_FOOTER = "[data-composer-footer]";
diff --git a/components/email/email-composer.tsx b/components/email/email-composer.tsx
index a1384e37c..82a3d72eb 100644
--- a/components/email/email-composer.tsx
+++ b/components/email/email-composer.tsx
@@ -92,7 +92,7 @@ import { useIdentityStore } from "@/stores/identity-store";
import { useProMultiAccountIdentities, stripCrossAccountIdentityPrefix } from "@/hooks/use-pro-multi-account-identities";
import { useAccountStore } from "@/stores/account-store";
import { useSettingsStore } from "@/stores/settings-store";
-import { ComposerPanelToggle, ComposerPluginSidebar, useComposerSidebars } from "./composer-plugin-sidebars";
+import { ComposerPanelHead, ComposerPanelToggle, ComposerPluginSidebar, isPanelOpen, useComposerSidebars } from "./composer-plugin-sidebars";
import { dragKindFromTypes } from "@/components/pro/pro-shell-drop";
import { useIsPaneScoped } from "@/hooks/use-pane-context";
import { ComposerSelectionMenu, useComposerSelectionMenu } from "./composer-selection-menu";
@@ -3621,13 +3621,28 @@ export function EmailComposer({
[pluginDraft, pluginSelection, pluginComposerId, pluginSidebars.focusRequests.right],
);
- // The buttons that show and hide the plugin panels, in the header.
- const leftPanelToggle = pluginSidebars.modes.left
- ? pluginSidebars.toggle('left')} />
+ // The plugin panels in the header row: a folded one's Show button, and an
+ // open one's head with its Hide button (see composer-plugin-sidebars.tsx).
+ const leftPanelToggle = pluginSidebars.modes.left === 'folded'
+ ? pluginSidebars.toggle('left')} />
: null;
- const rightPanelToggle = pluginSidebars.modes.right
- ? pluginSidebars.toggle('right')} />
+ const rightPanelToggle = pluginSidebars.modes.right === 'folded'
+ ? pluginSidebars.toggle('right')} />
: null;
+ const rightPanelOpen = isPanelOpen(pluginSidebars.modes.right);
+ const panelHead = (side: 'left' | 'right', className: string, children?: React.ReactNode, childrenClassName?: string) => (
+ pluginSidebars.toggle(side)}
+ className={className}
+ childrenClassName={childrenClassName}
+ >
+ {children}
+
+ );
// The right-click menu on selected text, when a plugin put entries in it.
const selectionMenu = useComposerSelectionMenu();
@@ -4737,6 +4752,86 @@ export function EmailComposer({
);
+ // What ends the header row: the window buttons, Close last. With the right
+ // panel open they end its head instead, at the far end of the composer.
+ const windowButtons = (
+ <>
+ {canMaximize && (
+
+ )}
+ {popOutButton(cn(phoneLayout ? "hidden md:grid" : "grid", "h-8 w-8 shrink-0 place-items-center rounded-md text-muted-foreground hover:bg-muted hover:text-foreground"), "w-4 h-4")}
+ {!closeBesideControls && composerCloseButton}
+ >
+ );
+ const mvInlineButtons = mvWindow && (
+ <>
+ {mvWindow.popOut && (
+
+ )}
+ {popOutButton("grid h-8 w-8 shrink-0 place-items-center rounded-full text-muted-foreground hover:bg-muted hover:text-foreground", "h-4 w-4")}
+
+ >
+ );
+ const mvWindowButtons = mvWindow && (
+ <>
+ {mvWindow.state !== "minimized" && popOutButton("grid h-7 w-7 shrink-0 place-items-center rounded-full text-muted-foreground hover:bg-foreground/10 hover:text-foreground", "h-4 w-4")}
+
+
+
+ >
+ );
+ // Files dropped on the header attach, as on the rest of the message.
+ const headerDropProps = { onDragEnter: handleDragEnter, onDragLeave: handleDragLeave, onDragOver: handleDragOver, onDrop: handleDrop };
+
// `keepDraft`: the bin's discard, which deletes the draft once its Undo is
// over, not here.
const handleDiscardAndClose = ({ keepDraft = false }: { keepDraft?: boolean } = {}) => {
@@ -5019,8 +5114,11 @@ export function EmailComposer({
data-testid="email-composer"
// Edits made while the draft moves wouldn't move with it.
inert={isPoppingOut || undefined}
+ // The header row on top, across the plugin panels too, so the window
+ // buttons and Close end the whole composer; panels and message below.
+ data-tour="composer"
className={cn(
- "flex h-full bg-background relative",
+ "flex flex-col h-full bg-background relative",
className,
// Over everything but dialogs (z-60) and toasts; below the desktop app's window controls.
// At the folder sidebar's z-50 and after it in the page, so over it (compose-p2-5).
@@ -5039,112 +5137,57 @@ export function EmailComposer({
{liveMessage && {liveMessage.text}}
- pluginSidebars.setSideWidth('left', w)} />
- {/* Right-side composer sidebar slot is rendered after the main content div below. */}
-
- {/* Drag overlay */}
- {isDraggingOver && (
-
-
-
- {t('drop_files')}
-
-
- )}
{/* Header - mobile: clean bar with close/send, desktop: title bar.
In Mountain View's window it is the window's title bar instead. */}
{mvWindow?.variant === "inline" ? (
-
{closeBesideControls && composerCloseButton}
- {/* The left panel's button at the start, the right one's at the end: where each panel is. */}
+ {/* A folded panel's Show button where the panel goes: the left one's at the start, the right one's before the window buttons. */}
{leftPanelToggle &&
)}
+ {/* The left panel, the message and the right panel, under the header. */}
+
+ pluginSidebars.setSideWidth('left', w)} />
+
+ {/* Drag overlay */}
+ {isDraggingOver && (
+
+
+
+ {t('drop_files')}
+
+
+ )}
{/* Fields + body. While pinFields holds, the fields sit outside the
body's scroll container so From/To/Cc/Bcc/Subject stay reachable
while scrolling long bodies, matching the pinned formatting toolbar
@@ -6305,6 +6356,7 @@ export function EmailComposer({
)}
pluginSidebars.setSideWidth('right', w)} />
+
);
diff --git a/lib/__tests__/plugin-ui-kit.test.tsx b/lib/__tests__/plugin-ui-kit.test.tsx
index 81057b238..cdff99ff2 100644
--- a/lib/__tests__/plugin-ui-kit.test.tsx
+++ b/lib/__tests__/plugin-ui-kit.test.tsx
@@ -22,6 +22,16 @@ const source = (file: string) => readFileSync(path.join(ROOT, file), 'utf8');
const classesOf = (el: Element) => el.getAttribute('class')!.split(/\s+/).filter((c) => c !== 'bk').sort();
describe('plugin UI kit components', () => {
+ it('starts a long LinkButton\'s lines at its icon, as a paragraph, not centred as a button would', () => {
+ // The AI assistant's examples in its panel ("Decline the invitation politely and suggest next month instead").
+ render(Decline the invitation politely and suggest next month instead);
+ const link = screen.getByRole('button');
+ expect(link.className).toMatch(/(^|\s)text-start(\s|$)/);
+ // The icon stays beside the first line rather than the middle of the text.
+ expect(link.className).toMatch(/(^|\s)items-start(\s|$)/);
+ expect(link.querySelector('svg')!.getAttribute('class')).toContain('mt-');
+ });
+
it('renders the app\'s own Button and Input', () => {
render(<>
Cancel
diff --git a/lib/plugin-sandbox/ui-kit/components.tsx b/lib/plugin-sandbox/ui-kit/components.tsx
index 9eea05bc0..328777195 100644
--- a/lib/plugin-sandbox/ui-kit/components.tsx
+++ b/lib/plugin-sandbox/ui-kit/components.tsx
@@ -103,11 +103,15 @@ export const Button = React.forwardRef(functi
);
});
-/** A text link styled like the app's inline links ("Add condition"). */
+/**
+ * A text link styled like the app's inline links ("Add condition"). A long one
+ * wraps like a paragraph: lines start at the icon's side (a button centres its
+ * text otherwise), with the icon beside the first line.
+ */
export function LinkButton({ icon, children, className, ...rest }: React.ButtonHTMLAttributes & { icon?: string }) {
return (
-