Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
feat(email): Drag and drop recipients in compose (#1910)
Evan Hutnik86b1f09d2100
diff --git a/js/app/packages/block-email/component/BaseInput.tsx b/js/app/packages/block-email/component/BaseInput.tsxindex 735812383d..c318af62d6 100644--- a/js/app/packages/block-email/component/BaseInput.tsx+++ b/js/app/packages/block-email/component/BaseInput.tsx@@ -78,6 +78,7 @@ import {createMemo,createSignal,For,+ type JSX,Match,onCleanup,onMount,@@ -151,6 +152,57 @@ const buildRecipientText = (return prefix + displayName + (showSeparator ? RECIPIENT_SEPARATOR : '');};+type RecipientFieldId = 'to' | 'cc' | 'bcc';++function RecipientDropRow(props: {+ field: RecipientFieldId;+ class?: string;+ children: JSX.Element;+ dragState: Accessor<{+ recipient: EmailRecipient;+ sourceField: RecipientFieldId;+ } | null>;+ onDrop: (+ targetField: RecipientFieldId,+ recipient: EmailRecipient,+ sourceField: RecipientFieldId+ ) => void;+}) {+ const [isDragOver, setIsDragOver] = createSignal(false);++ const handleDragOver = (e: DragEvent) => {+ const drag = props.dragState();+ if (!drag || drag.sourceField === props.field) return;+ e.preventDefault();+ if (e.dataTransfer) e.dataTransfer.dropEffect = 'move';+ setIsDragOver(true);+ };++ const handleDragLeave = () => {+ setIsDragOver(false);+ };++ const handleDrop = (e: DragEvent) => {+ e.preventDefault();+ setIsDragOver(false);+ const drag = props.dragState();+ if (!drag || drag.sourceField === props.field) return;+ props.onDrop(props.field, drag.recipient, drag.sourceField);+ };++ return (+ <div+ class={`flex flex-row items-center ${props.class ?? ''}`}+ classList={{ 'bg-accent/10': isDragOver() }}+ onDragOver={handleDragOver}+ onDragLeave={handleDragLeave}+ onDrop={handleDrop}+ >+ {props.children}+ </div>+ );+}+function TruncatedRecipientList(props: {toRecipients: EmailRecipient[];ccRecipients: EmailRecipient[];@@ -386,6 +438,10 @@ export function BaseInput(props: {const [bccRef, setBccRef] = createSignal<HTMLInputElement>();const [showCc, setShowCc] = createSignal<boolean>();const [showBcc, setShowBcc] = createSignal<boolean>();+ const [recipientDragState, setRecipientDragState] = createSignal<{+ recipient: EmailRecipient;+ sourceField: 'to' | 'cc' | 'bcc';+ } | null>(null);const [savedDraftId, setSavedDraftId] = createSignal<ApiDraftOutputDbId | undefined>(@@ -702,6 +758,40 @@ export function BaseInput(props: {}, DRAFT_DEBOUNCE_MS);}+ const handleChipDragStart = (+ field: 'to' | 'cc' | 'bcc',+ recipient: EmailRecipient,+ e: DragEvent+ ) => {+ if (!e.dataTransfer) return;+ setRecipientDragState({ recipient, sourceField: field });+ e.dataTransfer.effectAllowed = 'move';+ e.dataTransfer.setData('text/plain', '');+ };++ const handleChipDragEnd = () => {+ setRecipientDragState(null);+ };++ const handleRecipientDrop = (+ targetField: 'to' | 'cc' | 'bcc',+ recipient: EmailRecipient,+ sourceField: 'to' | 'cc' | 'bcc'+ ) => {+ const sourceList = form().recipients()[sourceField];+ form().setRecipients(+ sourceField,+ sourceList.filter((r) => r.id !== recipient.id)+ );+ const targetList = form().recipients()[targetField];+ if (!targetList.some((r) => r.id === recipient.id)) {+ form().setRecipients(targetField, [...targetList, recipient]);+ }+ if (targetField === 'cc') setShowCc(true);+ if (targetField === 'bcc') setShowBcc(true);+ scheduleDraftSave();+ };+const withDraftSave =<T,>(setter: (v: T) => void) =>(v: T) => {@@ -1217,7 +1307,12 @@ export function BaseInput(props: {</div>{/* Expanded TO */}- <div class="flex flex-row items-center -mt-0.5">+ <RecipientDropRow+ field="to"+ class="-mt-0.5"+ dragState={recipientDragState}+ onDrop={handleRecipientDrop}+ ><div class="min-w-8">to</div><RecipientSelector<EmailRecipient['kind']>inputRef={setToRef}@@ -1228,11 +1323,20 @@ export function BaseInput(props: {)}triggerMode="input"hideBorder+ onChipDragStart={(option, e) =>+ handleChipDragStart('to', option, e)+ }+ onChipDragEnd={handleChipDragEnd}/>- </div>+ </RecipientDropRow>{/* Expanded CC */}<Show when={showCc() || form().recipients().cc.length > 0}>- <div class="flex flex-row items-center -mt-1.5">+ <RecipientDropRow+ field="cc"+ class="-mt-1.5"+ dragState={recipientDragState}+ onDrop={handleRecipientDrop}+ ><div class="min-w-8">cc</div><RecipientSelector<EmailRecipient['kind']>inputRef={setCcRef}@@ -1243,12 +1347,21 @@ export function BaseInput(props: {)}triggerMode="input"hideBorder+ onChipDragStart={(option, e) =>+ handleChipDragStart('cc', option, e)+ }+ onChipDragEnd={handleChipDragEnd}/>- </div>+ </RecipientDropRow></Show>{/* Expanded BCC */}<Show when={showBcc() || form().recipients().bcc.length > 0}>- <div class="flex flex-row items-center -mt-1.5">+ <RecipientDropRow+ field="bcc"+ class="-mt-1.5"+ dragState={recipientDragState}+ onDrop={handleRecipientDrop}+ ><div class="min-w-8">bcc</div><RecipientSelector<EmailRecipient['kind']>inputRef={setBccRef}@@ -1259,8 +1372,12 @@ export function BaseInput(props: {)}triggerMode="input"hideBorder+ onChipDragStart={(option, e) =>+ handleChipDragStart('bcc', option, e)+ }+ onChipDragEnd={handleChipDragEnd}/>- </div>+ </RecipientDropRow></Show>{/* Show to, cc, bcc buttons */}<div class="flex flex-row justify-end space-x-2 pt-2">@@ -1327,7 +1444,7 @@ export function BaseInput(props: {editor()?.focus();}}use:fileFolderDrop={{- onDragStart: () => setIsDragging(true),+ onDragStart: (valid) => setIsDragging(valid),onDragEnd: () => setIsDragging(false),onDrop: (fileEntries, folderEntries, e) => {const editor_ = editor();diff --git a/js/app/packages/block-email/component/Compose.tsx b/js/app/packages/block-email/component/Compose.tsxindex dc454b4535..932acb28b6 100644--- a/js/app/packages/block-email/component/Compose.tsx+++ b/js/app/packages/block-email/component/Compose.tsx@@ -29,6 +29,7 @@ import {useUnscheduleMessageMutation,} from '@queries/email/thread';import {+ type Accessor,createMemo,createSignal,type JSX,@@ -66,7 +67,10 @@ import {useUploadDraftAttachmentsMutation,} from '@queries/email/attachment';import { MACRO_EMAIL_SIGNATURE } from '@block-email/constants';-import { useMaybeEmailContext } from '@block-email/component/EmailContext';+import {+ type EmailRecipient,+ useMaybeEmailContext,+} from '@block-email/component/EmailContext';import { decodeBase64Utf8 } from '@block-email/util/decodeBase64';import { plainTextToHtml } from '@block-email/util/plainTextToHtml';import { stickyGate } from '@core/util/debounce';@@ -119,10 +123,54 @@ type EmailComposeProps = {draftID?: string;};-function ComposeFieldRow(props: { label: string; children: JSX.Element }) {+type RecipientFieldId = 'to' | 'cc' | 'bcc';++type DragState = {+ recipient: EmailRecipient;+ sourceField: RecipientFieldId;+};++function ComposeFieldRow(props: {+ label: string;+ children: JSX.Element;+ fieldId?: RecipientFieldId;+ dragState?: Accessor<DragState | null>;+ onRecipientDrop?: (+ recipient: EmailRecipient,+ sourceField: RecipientFieldId+ ) => void;+}) {+ const [isDragOver, setIsDragOver] = createSignal(false);++ const handleDragOver = (e: DragEvent) => {+ const drag = props.dragState?.();+ if (!drag || !props.fieldId || drag.sourceField === props.fieldId) return;+ e.preventDefault();+ if (e.dataTransfer) e.dataTransfer.dropEffect = 'move';+ setIsDragOver(true);+ };++ const handleDragLeave = () => {+ setIsDragOver(false);+ };++ const handleDrop = (e: DragEvent) => {+ e.preventDefault();+ setIsDragOver(false);+ const drag = props.dragState?.();+ if (!drag || !props.fieldId || drag.sourceField === props.fieldId) return;+ props.onRecipientDrop?.(drag.recipient, drag.sourceField);+ };+return (- <div class="flex items-baseline gap-2 border-b border-edge-muted focus-within:border-accent">- <div class="text-sm w-4 shrink-0 text-ink-placeholder/70">+ <div+ class="flex items-center gap-2 border-b border-edge-muted focus-within:border-accent"+ classList={{ 'border-accent bg-accent/10': isDragOver() }}+ onDragOver={handleDragOver}+ onDragLeave={handleDragLeave}+ onDrop={handleDrop}+ >+ <div class="text-sm w-7 shrink-0 text-ink-placeholder/70">{props.label}</div><div class="flex-1">{props.children}</div>@@ -753,6 +801,46 @@ export function EmailCompose(props: EmailComposeProps) {return fromDraft ?? destinationOptions();};+ const [recipientDragState, setRecipientDragState] =+ createSignal<DragState | null>(null);++ const handleChipDragStart = (+ field: RecipientFieldId,+ recipient: EmailRecipient,+ e: DragEvent+ ) => {+ if (!e.dataTransfer) return;+ setRecipientDragState({ recipient, sourceField: field });+ e.dataTransfer.effectAllowed = 'move';+ e.dataTransfer.setData('text/plain', '');+ };++ const handleChipDragEnd = () => {+ setRecipientDragState(null);+ };++ const handleRecipientDrop = (+ targetField: RecipientFieldId,+ recipient: EmailRecipient,+ sourceField: RecipientFieldId+ ) => {+ // Remove from source+ const sourceList = form.recipients()[sourceField];+ form.setRecipients(+ sourceField,+ sourceList.filter((r) => r.id !== recipient.id)+ );+ // Add to target (avoid duplicates)+ const targetList = form.recipients()[targetField];+ if (!targetList.some((r) => r.id === recipient.id)) {+ form.setRecipients(targetField, [...targetList, recipient]);+ }+ // Auto-show cc/bcc if dropping into them+ if (targetField === 'cc') setShowCc(true);+ if (targetField === 'bcc') setShowBcc(true);+ scheduleDraftSave();+ };+const isDraftSaving = () => saveDraftMutation.isPending;const laggedIsDraftSaving = stickyGate(isDraftSaving, 250);@@ -879,7 +967,14 @@ export function EmailCompose(props: EmailComposeProps) {</div><div class="flex flex-col gap-2">- <ComposeFieldRow label="To">+ <ComposeFieldRow+ label="To"+ fieldId="to"+ dragState={recipientDragState}+ onRecipientDrop={(recipient, sourceField) =>+ handleRecipientDrop('to', recipient, sourceField)+ }+ ><RecipientSelectorinputRef={registerRef('directRecipientsSelector')}options={getRecipientOptions}@@ -892,6 +987,10 @@ export function EmailCompose(props: EmailComposeProps) {hideBordernoBracketsdisabled={hasLinkError()}+ onChipDragStart={(option, e) =>+ handleChipDragStart('to', option, e)+ }+ onChipDragEnd={handleChipDragEnd}/><Show when={withValidationError('no_recipient')}>{(err) => (@@ -903,7 +1002,14 @@ export function EmailCompose(props: EmailComposeProps) {</ComposeFieldRow><Show when={isCcVisible()}>- <ComposeFieldRow label="Cc">+ <ComposeFieldRow+ label="Cc"+ fieldId="cc"+ dragState={recipientDragState}+ onRecipientDrop={(recipient, sourceField) =>+ handleRecipientDrop('cc', recipient, sourceField)+ }+ ><RecipientSelectorinputRef={registerRef('ccRecipientsSelector')}options={getRecipientOptions}@@ -915,12 +1021,23 @@ export function EmailCompose(props: EmailComposeProps) {hideBordernoBracketsdisabled={hasLinkError()}+ onChipDragStart={(option, e) =>+ handleChipDragStart('cc', option, e)+ }+ onChipDragEnd={handleChipDragEnd}/></ComposeFieldRow></Show><Show when={isBccVisible()}>- <ComposeFieldRow label="Bcc">+ <ComposeFieldRow+ label="Bcc"+ fieldId="bcc"+ dragState={recipientDragState}+ onRecipientDrop={(recipient, sourceField) =>+ handleRecipientDrop('bcc', recipient, sourceField)+ }+ ><RecipientSelectorinputRef={registerRef('bccRecipientsSelector')}options={getRecipientOptions}@@ -932,6 +1049,10 @@ export function EmailCompose(props: EmailComposeProps) {hideBordernoBracketsdisabled={hasLinkError()}+ onChipDragStart={(option, e) =>+ handleChipDragStart('bcc', option, e)+ }+ onChipDragEnd={handleChipDragEnd}/></ComposeFieldRow></Show>diff --git a/js/app/packages/block-email/component/ComposeEmailInput.tsx b/js/app/packages/block-email/component/ComposeEmailInput.tsxindex 018e5b8f55..a7dfc67434 100644--- a/js/app/packages/block-email/component/ComposeEmailInput.tsx+++ b/js/app/packages/block-email/component/ComposeEmailInput.tsx@@ -229,7 +229,7 @@ export function ComposeEmailInput(props: ComposeEmailInputProps) {editor()?.focus();}}use:fileFolderDrop={{- onDragStart: () => setIsDragging(true),+ onDragStart: (valid) => setIsDragging(valid),onDragEnd: () => setIsDragging(false),onDrop: (files, dirs) => {handleFileFolderDrop(files, dirs, (u) =>diff --git a/js/app/packages/core/component/RecipientSelector.tsx b/js/app/packages/core/component/RecipientSelector.tsxindex b881ee976b..93d91fa840 100644--- a/js/app/packages/core/component/RecipientSelector.tsx+++ b/js/app/packages/core/component/RecipientSelector.tsx@@ -47,9 +47,18 @@ function RecipientChip(props: {icon?: JSX.Element;label: string;onRemove: () => void;+ draggable?: boolean;+ onDragStart?: (e: DragEvent) => void;+ onDragEnd?: (e: DragEvent) => void;}) {return (- <div class="flex flex-row py-1 pl-2 gap-1 pr-0.5 overflow-hidden items-center bg-hover">+ <div+ class="flex flex-row py-1 pl-2 gap-1 pr-0.5 overflow-hidden items-center bg-hover"+ classList={{ 'cursor-grab active:cursor-grabbing': props.draggable }}+ draggable={props.draggable}+ onDragStart={props.onDragStart}+ onDragEnd={props.onDragEnd}+ ><Show when={props.icon}>{props.icon}</Show><p class="text-sm">{truncateString(props.label, 20)}</p><XIcon@@ -224,6 +233,8 @@ type RecipientSelectorProps<K extends CombinedRecipientKind> = {noBrackets?: boolean;includeSelf?: boolean;disabled?: boolean;+ onChipDragStart?: (option: WithCustomUserInput<K>, e: DragEvent) => void;+ onChipDragEnd?: (e: DragEvent) => void;};export function RecipientSelector<K extends CombinedRecipientKind>(@@ -513,6 +524,14 @@ export function RecipientSelector<K extends CombinedRecipientKind>(}label={displayText() ?? ''}onRemove={() => state.remove(option)}+ draggable={!!props.onChipDragStart}+ onDragStart={(e) =>+ props.onChipDragStart?.(+ option as WithCustomUserInput<K>,+ e+ )+ }+ onDragEnd={props.onChipDragEnd}/></Tooltip>);@@ -562,6 +581,14 @@ export function RecipientSelector<K extends CombinedRecipientKind>(}label={email}onRemove={() => state.remove(option)}+ draggable={!!props.onChipDragStart}+ onDragStart={(e) =>+ props.onChipDragStart?.(+ option as WithCustomUserInput<K>,+ e+ )+ }+ onDragEnd={props.onChipDragEnd}/></Tooltip>);