/** * Shared type definitions for the Atmosphere Sheets module. * * These types are used across multiple sheets source files. */ // --- Cell Reference Types --- export interface CellRef { col: number; row: number; } // --- Cell Style Types --- export interface BorderStyle { top?: string; bottom?: string; left?: string; right?: string; } export type InteractiveCellType = 'boolean' | 'rating' | 'progress'; export interface CellStyle { bold?: boolean; italic?: boolean; underline?: boolean; strikethrough?: boolean; color?: string; bg?: string; align?: 'left' | 'center' | 'right'; verticalAlign?: 'top' | 'middle' | 'bottom'; fontSize?: number; fontFamily?: 'sans-serif' | 'serif' | 'monospace'; format?: 'auto' | 'number' | 'currency' | 'percent' | 'date' | 'text'; borders?: BorderStyle; wrap?: boolean; cellType?: InteractiveCellType; } // --- Cell Data Types --- export type CellValue = string | number | boolean | Date | undefined; export interface CellData { v: CellValue | ''; f: string; s: CellStyle; } // --- Formula Types --- export type TokenType = | 'NUMBER' | 'STRING' | 'BOOLEAN' | 'CELL_REF' | 'CROSS_SHEET_REF' | 'RANGE' | 'FUNCTION' | 'IDENTIFIER' | 'OPERATOR' | 'LPAREN' | 'RPAREN' | 'COMMA' | 'COLON' | 'BANG' | 'EOF'; export interface CrossSheetRefValue { sheetName: string; ref: string; } export interface Token { type: TokenType; value?: string | number | boolean | CrossSheetRefValue; } export type FormulaResult = CellValue | CellValue[] | string; export type GetCellValue = (ref: string) => CellValue | ''; export interface CrossSheetResolver { sheetExists(sheetName: string): boolean; getSheetCellValue(sheetName: string, cellRef: string): CellValue | ''; } export type FormatType = 'auto' | 'number' | 'currency' | 'percent' | 'date' | 'text'; // --- Range Array with dimensions --- export interface RangeArray extends Array { _rangeRows?: number; _rangeCols?: number; } // --- Named Ranges --- export interface NamedRangeEntry { name: string; range: string; sheet: string; } export type NamedRangesMap = Record; // --- Recalc Engine Types --- export interface RecalcCellData { v: CellValue | ''; f: string; } export interface CellStore { get(id: string): RecalcCellData | null; set(id: string, cell: RecalcCellData): void; has(id: string): boolean; entries(): IterableIterator<[string, RecalcCellData]>; getAllFormulaCells(): Array<[string, RecalcCellData]>; } export interface RecalcOptions { onEvaluate?: (cellId: string) => void; namedRanges?: NamedRangesMap; crossSheetResolver?: CrossSheetResolver; /** * Resolve cross-sheet formula dependencies for cycle detection. * Given a fully-qualified cell key (e.g. "Sheet2!B1"), returns the set of * fully-qualified cell keys that cell's formula depends on. * Returns null/undefined if the cell has no formula or the sheet doesn't exist. */ crossSheetFormulaDeps?: (qualifiedCellId: string) => Set | null | undefined; /** * The name of the current sheet. Used to map local cell IDs to fully-qualified * keys when detecting cross-sheet circular dependencies. */ currentSheetName?: string; } // --- Chart Types --- export type ChartType = 'bar' | 'line' | 'pie' | 'scatter' | 'area' | 'doughnut' | 'radar' | 'stackedBar' | 'stackedLine'; export interface ChartConfig { type: ChartType; range: string; title?: string; xAxisLabel?: string; yAxisLabel?: string; } export interface ChartValidationResult { valid: boolean; errors: string[]; } export interface DataRange { startCol: number; startRow: number; endCol: number; endRow: number; } export interface ChartDataset { label: string; data: (CellValue | '' | { x: CellValue | ''; y: CellValue | '' })[]; backgroundColor?: string | string[]; borderColor?: string | string[]; borderWidth?: number; fill?: boolean; tension?: number; pointRadius?: number; } export interface TransformedChartData { labels: (CellValue | '' | number)[]; datasets: ChartDataset[]; } // --- Selection Types --- export interface SelectionRange { startCol: number; startRow: number; endCol: number; endRow: number; } // --- Conditional Formatting Types --- export type CfRuleType = | 'greaterThan' | 'lessThan' | 'equalTo' | 'between' | 'textContains' | 'isEmpty' | 'isNotEmpty' | 'colorScale' | 'dataBar' | 'iconSet'; export interface CfRule { type: CfRuleType; value?: string | number; value2?: string | number; bgColor?: string; textColor?: string; name?: string; /** Color scale: low-end color (default: #f8696b red) */ minColor?: string; /** Color scale: midpoint color (default: #ffeb84 yellow, omit for 2-color) */ midColor?: string; /** Color scale: high-end color (default: #63be7b green) */ maxColor?: string; /** Data bar: fill color (default: #4472c4 blue) */ barColor?: string; /** Icon set: which icon set to use (default: traffic3) */ iconSetName?: string; } export interface DataBarResult { barWidthPct: number; barColor: string; negative: boolean; } export interface IconSetResult { iconIndex: number; iconSetName: string; } export interface CfStyleResult { bgColor?: string; textColor?: string; } // --- Data Validation Types --- export type ValidationRuleType = 'list' | 'numberBetween' | 'textLength'; export interface ValidationRule { type: ValidationRuleType; value?: string; value2?: string; items?: string[]; } export interface ValidationResult { valid: boolean; message?: string; } // --- Filter Types --- export interface FilterRow { _row: number; [col: number]: CellValue | ''; } export type FilterState = Record>; // --- Sort Types --- export type SortOrder = 'asc' | 'desc'; export interface SortKey { col: number | string; order: SortOrder; } // --- Formula Autocomplete Types --- export interface FormulaFunction { name: string; signature: string; } // --- Formula Highlighter Types --- export type HighlightTokenType = | 'operator' | 'whitespace' | 'error' | 'string' | 'number' | 'boolean' | 'cell_ref' | 'function' | 'paren' | 'identifier' | 'unknown'; export interface HighlightToken { text: string; type: HighlightTokenType; start: number; end: number; } // --- Formula Tooltip Types --- export interface FunctionParam { name: string; desc: string; required: boolean; } export interface FunctionMetadataEntry { desc: string; params: FunctionParam[]; } export interface DetectedFunction { functionName: string; paramIndex: number; } // --- Range Highlight Types --- export interface FormulaRange { ref: string; startIndex: number; endIndex: number; } export interface ColoredRange extends FormulaRange { color: string; } export interface HighlightBorders { top: boolean; bottom: boolean; left: boolean; right: boolean; } // --- Drag Fill Types --- export interface FillPattern { type: string; step?: number; stepMs?: number; } export type FillDirection = 'forward' | 'backward'; // --- Paste Special Types --- export interface PasteCellData { v: CellValue | '' | null; f: string; s: Record; } // --- Named Range Store --- export interface NamedRangeStore { get(key: string): string | undefined; set(key: string, value: string): void; has(key: string): boolean; delete(key: string): void; forEach(callback: (value: string, key: string) => void): void; } // --- XLSX Import Types --- export interface XlsxCellStyle { bold?: boolean; italic?: boolean; underline?: boolean; strikethrough?: boolean; fontSize?: number; color?: string; bg?: string; align?: 'left' | 'center' | 'right'; verticalAlign?: 'top' | 'middle' | 'bottom'; wrap?: boolean; format?: string; borders?: BorderStyle; } export interface XlsxCellData { v: string | number | ''; f: string; s: XlsxCellStyle; } export interface ParsedSheet { name: string; cells: Map; rowCount: number; colCount: number; merges: string[]; colWidths: Record; rowHeights: Record; } export interface ImportXlsxOptions { ydoc: { transact(fn: () => void): void }; getActiveSheet: () => { get(key: string): unknown; set(key: string, value: unknown): void; }; setCellData: (id: string, data: Partial) => void; getCells?: () => unknown; renderGrid: () => void; showToast: (message: string, duration?: number) => void; evalCache: Map; DEFAULT_ROWS: number; DEFAULT_COLS: number; } // --- Tab Handler Types --- export type TabAction = 'moveRight' | 'moveLeft'; export interface TabContext { sheetKey: boolean; } // --- Notes Types --- export type NotesMap = Record; // --- Merge Types --- export interface MergeData { startCol: number; startRow: number; endCol: number; endRow: number; } export interface MergeMapEntry { hidden: boolean; merge: MergeData; colspan?: number; rowspan?: number; } // --- Shortcut Types --- export interface ShortcutEntry { keys: string[]; label: string; } export interface ShortcutCategory { category: string; shortcuts: ShortcutEntry[]; }