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.

3.4 KB
Raw Blame
import type { LexicalEditor } from 'lexical';
import type { Accessor, JSX } from 'solid-js';
import type { EmailCalendarEvents } from '../context/compose-capabilities';
import type { ComposeBodyActions } from '../context/editor-capabilities';
import type {
  EmailFormRecipients,
  EmailRecipient,
} from '../core/email-recipient';
import type { FromInboxOption } from '../core/email-sender';
import type { DraftFormAttachment } from './email-form-state';
import type { EmailScheduleState } from './email-send-schedule';

export type ComposeValidationError = {
  type: 'no_recipient' | 'no_message' | 'no_subject' | 'no_link';
  message: string;
};

export interface ComposeContextValue extends ComposeState {
  bodyActions: ComposeBodyActions;
  isMobile: Accessor<boolean>;
  scheduleEnabled: boolean;
  calendarEvents?: EmailCalendarEvents;
  onUpgrade?: () => void;
  viewerLoading?: Accessor<boolean>;
}

export interface ComposeState {
  // Form state (read)
  recipients: () => EmailFormRecipients;
  subject: () => string;
  attachments: () => DraftFormAttachment[];
  initialHtml: () => string | undefined;
  initialMarkdown?: () => string | undefined;

  // Form state (write)
  setRecipients: (
    field: keyof EmailFormRecipients,
    value: EmailRecipient[]
  ) => void;
  setSubject: (value: string) => void;
  onContentChange: (content: string) => void;
  /** Files the user picked or dropped; the controller decides what attaches. */
  onAddAttachments: (files: File[]) => void;
  onRemoveAttachment: (attachment: DraftFormAttachment) => void;

  // Editor
  captureEditor: (editor: LexicalEditor) => void;
  onEditorInitialized?: (editor: LexicalEditor) => void;

  // Actions
  onSend: () => void;
  onDelete?: () => void;
  schedule: {
    state: Accessor<EmailScheduleState>;
    selectedTime: Accessor<Date | undefined>;
    confirmedTime: Accessor<Date | undefined>;
    actionLabel: Accessor<string>;
    operation: Accessor<'idle' | 'committing' | 'updating' | 'cancelling'>;
    onSelect(date: Date | null): boolean;
    onCancel(): Promise<boolean>;
    onCheckStatus?(): Promise<void>;
    pickerDisabled: Accessor<boolean>;
  };

  // Status
  disabled: Accessor<boolean>;
  /** Discard can outlast editing; defaults to `disabled`. */
  deleteDisabled?: Accessor<boolean>;
  primaryActionDisabled: Accessor<boolean>;
  isSending: Accessor<boolean>;
  isSavingDraft?: Accessor<boolean>;
  hasDraft: Accessor<boolean>;
  sendUnavailableReason?: Accessor<string | undefined>;
  deliveryState?: Accessor<'draft' | 'scheduled' | 'sent' | 'missing'>;

  // Validation
  validationError: (
    type: ComposeValidationError['type']
  ) => ComposeValidationError | undefined;

  // Recipients config
  recipientOptions: () => Array<EmailRecipient>;
  focusRecipientsOnMount: boolean;
  includeSelf?: boolean;
  hideAttachments?: boolean;

  // Display
  fromAddress?: Accessor<string | undefined>;
  // From-inbox selection: the inboxes the user can send from, the active one,
  // and a setter to change it.
  fromInboxes?: Accessor<FromInboxOption[]>;
  inboxesLoading?: Accessor<boolean>;
  selectedInboxId?: Accessor<string | undefined>;
  onSelectInbox?: (inboxId: string, senderEmail?: string) => void;
  hasPaidAccess: Accessor<boolean>;

  // Signature preview slot — rendered below the body. Provided by the new-email
  // composer and the AI chat composer (ChatCompose); the reply/forward input
  // renders its own preview and omits this slot.
  signaturePreview?: () => JSX.Element;
}