Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

feat(email): animate draft and thread expansion (#8313)

Jacob Beckermanf0519074d6d5
diff --git a/apps/web/AGENTS.md b/apps/web/AGENTS.md
index 90a169ab79..0c71a809a5 100644
--- a/apps/web/AGENTS.md
+++ b/apps/web/AGENTS.md
@@ -101,6 +101,8 @@ ownership. Cancel, logout, and the ten-minute timeout retire pending callbacks.
caches on save and the active cache on thread exit. Revalidate GraphQL thread
pages only when a save cannot patch the message list (missing snapshot or a
move between inboxes).
+- Keep email card resize motion on its content wrapper so message and inline
+ reply transitions preserve the card's focus target and return to natural height.
- Shared server-state queries and mutations live in `src/lib/queries`; keep
feature-specific query orchestration with its owning feature.
- Preserve loaded block content on initial access confirmation when its loader
diff --git a/apps/web/src/features/email-message/browser-test/motion.html b/apps/web/src/features/email-message/browser-test/motion.html
new file mode 100644
index 0000000000..23f3452a6c
--- /dev/null
+++ b/apps/web/src/features/email-message/browser-test/motion.html
@@ -0,0 +1,5 @@
+<!doctype html>
+<html lang="en">
+ <head><meta charset="UTF-8" /><meta name="viewport" content="width=device-width, initial-scale=1" /><title>Email motion preview</title></head>
+ <body><div id="root"></div><script type="module" src="./motion.tsx"></script></body>
+</html>
diff --git a/apps/web/src/features/email-message/browser-test/motion.tsx b/apps/web/src/features/email-message/browser-test/motion.tsx
new file mode 100644
index 0000000000..2a0191873f
--- /dev/null
+++ b/apps/web/src/features/email-message/browser-test/motion.tsx
@@ -0,0 +1,144 @@
+import '@app/index.css';
+import { CollapseTransition } from '@ui/components/CollapseTransition';
+import { createSignal, For, Show } from 'solid-js';
+import { render } from 'solid-js/web';
+import { MessageCard } from '../components/message-card';
+
+function MotionPreview() {
+ const [draftOpen, setDraftOpen] = createSignal(false);
+ const [expanded, setExpanded] = createSignal(false);
+ const [chainOpen, setChainOpen] = createSignal(false);
+ const [draft, setDraft] = createSignal(
+ 'Sounds good — I will send the updated proposal tomorrow.'
+ );
+ return (
+ <main class="min-h-screen bg-page text-ink p-6">
+ <div class="mx-auto max-w-3xl">
+ <h1 class="text-2xl font-semibold mb-2">Email motion preview</h1>
+ <p class="text-sm text-ink-muted mb-8">
+ Local sample content. Try opening and closing quickly.
+ </p>
+ <div class="flex flex-col gap-2">
+ <MessageCard
+ messageId="chain-start"
+ isSelected={false}
+ allowHover
+ isTouch={false}
+ >
+ <div class="flex justify-between gap-4">
+ <span class="font-medium">Alex</span>
+ <button
+ data-button
+ type="button"
+ aria-expanded={expanded()}
+ onClick={() => setExpanded(!expanded())}
+ >
+ {expanded() ? 'Collapse message' : 'Expand message'}
+ </button>
+ </div>
+ <Show
+ when={expanded()}
+ fallback={
+ <p class="truncate text-ink-muted">
+ Here is the updated proposal for next week.
+ </p>
+ }
+ >
+ <div class="space-y-4 pt-4">
+ <p>Here is the updated proposal for next week.</p>
+ <p>
+ We have incorporated the feedback from the last review. The
+ draft now includes the timeline, the new layout, and the
+ remaining questions.
+ </p>
+ <p>
+ Let me know what you think before we share it with the team.
+ </p>
+ <p>
+ Thanks,
+ <br />
+ Alex
+ </p>
+ </div>
+ </Show>
+ </MessageCard>
+ <button
+ class="py-2 text-sm text-ink-muted"
+ aria-expanded={chainOpen()}
+ onClick={() => setChainOpen(!chainOpen())}
+ >
+ {chainOpen() ? 'Hide earlier messages' : 'Show 3 hidden messages'}
+ </button>
+ <For each={['Tuesday', 'Wednesday', 'Thursday']}>
+ {(day) => (
+ <CollapseTransition open={chainOpen()}>
+ <div class="w-full shrink-0">
+ <MessageCard
+ messageId={day}
+ isSelected={false}
+ allowHover
+ isTouch={false}
+ >
+ <div class="font-medium">Alex · {day}</div>
+ <p class="text-ink-muted">
+ A follow-up about the proposal.
+ </p>
+ </MessageCard>
+ </div>
+ </CollapseTransition>
+ )}
+ </For>
+ <MessageCard
+ messageId="draft"
+ isSelected={false}
+ allowHover
+ isTouch={false}
+ >
+ <div class="font-medium">Sam</div>
+ <p class="py-4">
+ Looks good. Can you send the final version tomorrow?
+ </p>
+ <div class="border-t border-edge-muted pt-3">
+ <Show
+ when={draftOpen()}
+ fallback={
+ <button
+ data-button
+ type="button"
+ class="w-full text-left text-ink-muted"
+ onClick={() => setDraftOpen(true)}
+ >
+ <span class="font-medium text-warning">Draft</span> ·{' '}
+ {draft()}
+ </button>
+ }
+ >
+ <div class="flex justify-between text-sm text-ink-muted mb-3">
+ <span>To: Sam</span>
+ <button
+ data-button
+ type="button"
+ onClick={() => setDraftOpen(false)}
+ >
+ Collapse draft
+ </button>
+ </div>
+ <textarea
+ aria-label="Draft reply"
+ class="block w-full min-h-40 resize-y bg-transparent outline-none"
+ value={draft()}
+ onInput={(event) => setDraft(event.currentTarget.value)}
+ />
+ <p class="text-xs text-ink-muted">
+ Preview only — nothing is saved or sent.
+ </p>
+ </Show>
+ </div>
+ </MessageCard>
+ </div>
+ </div>
+ </main>
+ );
+}
+
+render(() => <MotionPreview />, document.getElementById('root')!);
diff --git a/apps/web/src/features/email-message/components/message-card.test.tsx b/apps/web/src/features/email-message/components/message-card.test.tsx
index aa7aa5cf23..c56cecad99 100644
--- a/apps/web/src/features/email-message/components/message-card.test.tsx
+++ b/apps/web/src/features/email-message/components/message-card.test.tsx
@@ -1,6 +1,6 @@
import { cleanup, fireEvent, render, screen } from '@solidjs/testing-library';
import { createSignal } from 'solid-js';
-import { afterEach, describe, expect, it, vi } from 'vitest';
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { MessageCard } from './message-card';
const device = vi.hoisted(() => ({ touch: false }));
@@ -13,7 +13,21 @@ vi.mock('@ui', async () => ({
.ComposerSurface,
}));
-afterEach(cleanup);
+beforeEach(() => {
+ vi.stubGlobal(
+ 'ResizeObserver',
+ class {
+ observe() {}
+ unobserve() {}
+ disconnect() {}
+ }
+ );
+});
+
+afterEach(() => {
+ cleanup();
+ vi.unstubAllGlobals();
+});
describe('MessageCard', () => {
it.each([false, true])(
@@ -48,7 +62,7 @@ describe('MessageCard', () => {
container.querySelector('[data-layer], [data-surface]')
).toBeNull();
const reply = screen.getByRole('button', { name: 'Reply' });
- expect(reply.parentElement).toBe(card);
+ expect(card.contains(reply)).toBe(true);
fireEvent.click(reply);
diff --git a/apps/web/src/features/email-message/components/message-card.tsx b/apps/web/src/features/email-message/components/message-card.tsx
index 837f4e6bb3..fa2810da9f 100644
--- a/apps/web/src/features/email-message/components/message-card.tsx
+++ b/apps/web/src/features/email-message/components/message-card.tsx
@@ -1,5 +1,6 @@
import { ComposerSurface, cn } from '@ui';
import type { JSX } from 'solid-js';
+import { createMessageResizeMotion } from './message-resize-motion';
interface MessageCardProps {
messageId: string | null | undefined;
@@ -29,10 +30,12 @@ interface MessageCardProps {
* Touch devices retain their existing card and selection treatment.
*/
export function MessageCard(props: MessageCardProps) {
+ const motion = createMessageResizeMotion();
return (
<div class="shrink-0 flex justify-center w-full">
<div class="@container/message macro-message-width macro-message-padding mobile:px-0 w-full">
<ComposerSurface
+ ref={motion.setCard}
as="div"
class={cn(
'relative p-4 outline-none',
@@ -76,7 +79,9 @@ export function MessageCard(props: MessageCardProps) {
props.onSelect?.();
}}
>
- {props.children}
+ <div ref={motion.setContent} class="flow-root">
+ {props.children}
+ </div>
</ComposerSurface>
</div>
</div>
diff --git a/apps/web/src/features/email-message/components/message-resize-motion.test.ts b/apps/web/src/features/email-message/components/message-resize-motion.test.ts
new file mode 100644
index 0000000000..46d9f4b9a8
--- /dev/null
+++ b/apps/web/src/features/email-message/components/message-resize-motion.test.ts
@@ -0,0 +1,84 @@
+import { createRoot } from 'solid-js';
+import { afterEach, expect, it, vi } from 'vitest';
+import { createMessageResizeMotion } from './message-resize-motion';
+
+let resize: (rect: { width: number; height: number }) => void;
+vi.mock('@solid-primitives/resize-observer', () => ({
+ createResizeObserver: (_target: unknown, callback: typeof resize) => {
+ resize = callback;
+ },
+}));
+
+afterEach(() => vi.unstubAllGlobals());
+
+function setup(reducedMotion = false) {
+ vi.stubGlobal('matchMedia', () => ({ matches: reducedMotion }));
+ const card = document.createElement('div');
+ const content = document.createElement('div');
+ card.style.padding = '16px';
+ card.style.border = '0px solid';
+ card.append(content);
+ const rect = vi.spyOn(card, 'getBoundingClientRect');
+ const animations: Array<{
+ cancel: ReturnType<typeof vi.fn>;
+ onfinish: (() => void) | null;
+ }> = [];
+ const animate = vi.fn(
+ (_frames: Keyframe[], _options: KeyframeAnimationOptions) => {
+ const animation = {
+ cancel: vi.fn(),
+ onfinish: null as (() => void) | null,
+ };
+ animations.push(animation);
+ return animation;
+ }
+ );
+ Object.defineProperty(card, 'animate', { value: animate });
+ const dispose = createRoot((dispose) => {
+ const motion = createMessageResizeMotion();
+ motion.setCard(card);
+ motion.setContent(content);
+ return dispose;
+ });
+ resize({ width: 500, height: 40 });
+ return { animate, animations, rect, dispose };
+}
+
+it('continues a reversed transition from the visible height and releases sizing at rest', () => {
+ const state = setup();
+ resize({ width: 500, height: 240 });
+ expect(state.animate.mock.calls[0]?.[0]).toEqual([
+ { height: '72px', overflow: 'clip', boxSizing: 'border-box' },
+ { height: '272px', overflow: 'clip', boxSizing: 'border-box' },
+ ]);
+ state.rect.mockReturnValue(new DOMRect(0, 0, 500, 150));
+ resize({ width: 500, height: 40 });
+ expect(state.animations[0].cancel).toHaveBeenCalledOnce();
+ expect(state.animate.mock.calls[1]?.[0]).toEqual([
+ { height: '150px', overflow: 'clip', boxSizing: 'border-box' },
+ { height: '72px', overflow: 'clip', boxSizing: 'border-box' },
+ ]);
+ state.animations[1].onfinish?.();
+ expect(state.animations[1].cancel).toHaveBeenCalledOnce();
+ state.dispose();
+});
+
+it('settles active motion when the viewport width changes', () => {
+ const state = setup();
+ resize({ width: 500, height: 240 });
+ resize({ width: 300, height: 240 });
+ expect(state.animations[0].cancel).toHaveBeenCalledOnce();
+ expect(state.animate).toHaveBeenCalledOnce();
+ state.dispose();
+});
+
+it('skips motion for reduced motion and cancels it on unmount', () => {
+ const reduced = setup(true);
+ resize({ width: 500, height: 240 });
+ expect(reduced.animate).not.toHaveBeenCalled();
+ reduced.dispose();
+ const active = setup();
+ resize({ width: 500, height: 240 });
+ active.dispose();
+ expect(active.animations[0].cancel).toHaveBeenCalledOnce();
+});
diff --git a/apps/web/src/features/email-message/components/message-resize-motion.ts b/apps/web/src/features/email-message/components/message-resize-motion.ts
new file mode 100644
index 0000000000..56bf742ddb
--- /dev/null
+++ b/apps/web/src/features/email-message/components/message-resize-motion.ts
@@ -0,0 +1,74 @@
+import { createAnimationGroup } from '@app/lib/utils/create-animation-group';
+import { createResizeObserver } from '@solid-primitives/resize-observer';
+import { createSignal, onCleanup, onMount } from 'solid-js';
+
+/** Keep the card in flow while its message or inline reply changes height. */
+export function createMessageResizeMotion() {
+ let card: HTMLDivElement | undefined;
+ const [content, setContent] = createSignal<HTMLDivElement>();
+ const motion = createAnimationGroup();
+ let previousHeight = 0;
+ let previousWidth = 0;
+
+ onMount(() => {
+ previousHeight = content()?.getBoundingClientRect().height ?? 0;
+ previousWidth = content()?.getBoundingClientRect().width ?? 0;
+ });
+ onCleanup(motion.cancel);
+
+ createResizeObserver(content, ({ height, width }) => {
+ if (!card) return;
+ const fromHeight = previousHeight;
+ const widthChanged = Math.abs(width - previousWidth) > 1;
+ previousHeight = height;
+ previousWidth = width;
+ if (widthChanged) {
+ motion.cancel();
+ return;
+ }
+ if (Math.abs(height - fromHeight) < 1) return;
+
+ const style = getComputedStyle(card);
+ const chrome =
+ Number.parseFloat(style.paddingTop) +
+ Number.parseFloat(style.paddingBottom) +
+ Number.parseFloat(style.borderTopWidth) +
+ Number.parseFloat(style.borderBottomWidth);
+ const from = motion.running()
+ ? card.getBoundingClientRect().height
+ : fromHeight + chrome;
+ motion.cancel();
+
+ if (
+ !card.animate ||
+ window.matchMedia('(prefers-reduced-motion: reduce)').matches
+ ) {
+ return;
+ }
+
+ motion.start(
+ [
+ {
+ target: card,
+ keyframes: [
+ { height: `${from}px`, overflow: 'clip', boxSizing: 'border-box' },
+ {
+ height: `${height + chrome}px`,
+ overflow: 'clip',
+ boxSizing: 'border-box',
+ },
+ ],
+ },
+ ],
+ { duration: 240, easing: 'cubic-bezier(0.22, 1, 0.36, 1)', fill: 'both' },
+ () => {}
+ );
+ });
+
+ return {
+ setCard: (element: HTMLDivElement) => {
+ card = element;
+ },
+ setContent,
+ };
+}
diff --git a/apps/web/src/features/email-thread/views/message-list.tsx b/apps/web/src/features/email-thread/views/message-list.tsx
index 06264557e5..20e9171557 100644
--- a/apps/web/src/features/email-thread/views/message-list.tsx
+++ b/apps/web/src/features/email-thread/views/message-list.tsx
@@ -2,6 +2,7 @@ import { StaticMarkdownContext } from '@core/component/LexicalMarkdown/component
import { fireAndForget } from '@core/util/fireAndForget';
import { Key } from '@solid-primitives/keyed';
import { cn, Layer } from '@ui';
+import { CollapseTransition } from '@ui/components/CollapseTransition';
import {
createEffect,
createMemo,
@@ -204,21 +205,23 @@ export function MessageList(props: MessageListProps) {
return (
<>
- <Show when={!hideMiddle()}>
- <MessageContainer
- isFirstMessage={normalizedIndex() === 0}
- isLastMessage={isLastMessage()}
- isSelected={isSelectedSelector(
- message().db_id ?? undefined
- )}
- allowHover={props.allowRowHover}
- message={message()}
- isExpanded={isExpanded()}
- markdownDomRef={
- isLastMessage() ? props.markdownDomRef : undefined
- }
- />
- </Show>
+ <CollapseTransition open={!hideMiddle()}>
+ <div class="w-full shrink-0">
+ <MessageContainer
+ isFirstMessage={normalizedIndex() === 0}
+ isLastMessage={isLastMessage()}
+ isSelected={isSelectedSelector(
+ message().db_id ?? undefined
+ )}
+ allowHover={props.allowRowHover}
+ message={message()}
+ isExpanded={isExpanded()}
+ markdownDomRef={
+ isLastMessage() ? props.markdownDomRef : undefined
+ }
+ />
+ </div>
+ </CollapseTransition>
<Show
when={
chronologicalIndex() === 0 &&
diff --git a/docs/agent-guide/email.md b/docs/agent-guide/email.md
index ca506cbf7a..b5f44fb9f3 100644
--- a/docs/agent-guide/email.md
+++ b/docs/agent-guide/email.md
@@ -1,5 +1,19 @@
# Email
+## Thread motion
+
+Message cards animate their height when expanding or collapsing a message or
+its inline reply draft. Hidden messages unfold with the shared collapse
+transition. Check repeated toggles during motion: the card should continue from
+its visible height and settle to natural sizing, with no clipped editor or
+attachments. Resizing the viewport and enabling reduced motion should settle
+immediately. Touch replies keep their existing drawer behavior.
+
+For an isolated check without account data, open
+`/src/features/email-message/browser-test/motion.html` on the Vite server. It
+uses the real message card and collapse transition with local sample content;
+it does not exercise draft persistence or delivery.
+
## Email reminder delivery
An email snooze returns its original conversation to the inbox and adds a