/** * Spreadsheet Domain Types * Defines spreadsheet-specific data structures and formula support */ import type { Timestamp, UUID } from './common'; /** * Spreadsheet/Grid document */ export interface Spreadsheet { id: UUID; documentId: UUID; sheets: Map; namedRanges: NamedRange[]; formulas: Formula[]; } /** * Sheet within a spreadsheet */ export interface Sheet { id: UUID; spreadsheetId: UUID; name: string; order: number; rows: number; columns: number; cells: Map; rowHeight: Map; columnWidth: Map; frozenRows: number; frozenColumns: number; filters: SheetFilter[]; sorts: SheetSort[]; hiddenRows: Set; hiddenColumns: Set; protected: boolean; protectionRules?: ProtectionRule[]; } /** * Cell in spreadsheet */ export interface Cell { row: number; col: number; value: CellValue; formula?: Formula; format: CellFormat; comment?: CellComment; validation?: DataValidation; locked: boolean; metadata?: Record; } /** * Cell value type */ export type CellValue = string | number | boolean | Date | null | CellError; /** * Cell error representation */ export interface CellError { type: 'error'; code: '#DIV/0!' | '#N/A' | '#NAME?' | '#NULL!' | '#NUM!' | '#REF!' | '#VALUE!'; message: string; } /** * Cell format (styling, alignment, number format) */ export interface CellFormat { fontSize: number; fontFamily: string; fontWeight: 'normal' | 'bold'; fontStyle: 'normal' | 'italic'; textDecoration: 'none' | 'underline' | 'line-through'; fontColor: string; backgroundColor: string; horizontalAlign: 'left' | 'center' | 'right' | 'justify'; verticalAlign: 'top' | 'middle' | 'bottom'; wrapText: boolean; borders: CellBorder; numberFormat?: string; mergeAcross?: number; mergeDown?: number; } /** * Cell border configuration */ export interface CellBorder { top?: BorderLine; bottom?: BorderLine; left?: BorderLine; right?: BorderLine; } /** * Individual border line */ export interface BorderLine { style: 'solid' | 'dashed' | 'dotted' | 'double'; width: number; color: string; } /** * Cell comment */ export interface CellComment { id: UUID; userId: UUID; content: string; createdAt: Timestamp; updatedAt: Timestamp; replies: CommentReply[]; } /** * Comment reply */ export interface CommentReply { id: UUID; userId: UUID; content: string; createdAt: Timestamp; } /** * Data validation rule for cell */ export interface DataValidation { type: 'list' | 'number' | 'decimal' | 'date' | 'time' | 'text_length' | 'custom'; operator?: 'equal' | 'not_equal' | 'greater_than' | 'less_than' | 'between'; value1?: string | number; value2?: string | number; allowBlank: boolean; showDropdown: boolean; showError: boolean; errorMessage?: string; errorTitle?: string; inputMessage?: string; showInputMessage: boolean; } /** * Formula in cell */ export interface Formula { id: UUID; sheetId: UUID; cellAddress: string; expression: string; result?: CellValue; error?: CellError; dependsOn: string[]; dependents: string[]; lastCalculated?: Timestamp; isDirty: boolean; } /** * Named range (e.g., "SalesData" = A1:C100) */ export interface NamedRange { id: UUID; spreadsheetId: UUID; name: string; range: CellRange; comment?: string; scope: 'spreadsheet' | 'sheet'; scopeId?: UUID; } /** * Cell range (e.g., A1:C10) */ export interface CellRange { sheetId: UUID; startRow: number; startCol: number; endRow: number; endCol: number; } /** * Sheet filter */ export interface SheetFilter { id: UUID; sheetId: UUID; name: string; range: CellRange; criteria: FilterCriteria[]; isActive: boolean; } /** * Filter criteria for column */ export interface FilterCriteria { column: number; operator: FilterOperator; values: (string | number)[]; condition?: 'and' | 'or'; } /** * Filter operator type */ export type FilterOperator = 'equals' | 'not_equals' | 'contains' | 'not_contains' | 'starts_with' | 'ends_with' | 'greater_than' | 'less_than' | 'greater_than_equal' | 'less_than_equal' | 'between' | 'not_between' | 'is_empty' | 'is_not_empty'; /** * Sheet sort configuration */ export interface SheetSort { id: UUID; sheetId: UUID; range: CellRange; sortBy: SortRule[]; } /** * Sort rule for column */ export interface SortRule { column: number; order: 'ascending' | 'descending'; type: 'text' | 'number' | 'date'; } /** * Protection rule for sheet */ export interface ProtectionRule { id: UUID; range?: CellRange; protection: { protectFormulas: boolean; protectCells: boolean; allowSelectLockedCells: boolean; allowSelectUnlockedCells: boolean; allowFormatCells: boolean; allowFormatColumns: boolean; allowFormatRows: boolean; allowInsertColumns: boolean; allowInsertRows: boolean; allowDeleteColumns: boolean; allowDeleteRows: boolean; allowSort: boolean; allowAutoFilter: boolean; allowPivotTables: boolean; }; protectedBy: UUID; createdAt: Timestamp; } /** * Calculated field (pivot-like calculation) */ export interface CalculatedField { id: UUID; spreadsheetId: UUID; name: string; expression: string; sourceRange: CellRange; } /** * Pivot table configuration */ export interface PivotTable { id: UUID; sheetId: UUID; sourceRange: CellRange; rows: PivotField[]; columns: PivotField[]; values: PivotField[]; filters: PivotField[]; resultRange: CellRange; } /** * Field in pivot table */ export interface PivotField { columnIndex: number; name: string; aggregation: 'sum' | 'avg' | 'count' | 'min' | 'max' | 'stddev' | 'var'; sortOrder?: 'ascending' | 'descending'; } /** * Chart based on spreadsheet data */ export interface Chart { id: UUID; spreadsheetId: UUID; title: string; type: ChartType; dataRange: CellRange; categories?: CellRange; series: ChartSeries[]; options: ChartOptions; } /** * Chart type */ export type ChartType = 'bar' | 'column' | 'line' | 'area' | 'scatter' | 'pie' | 'doughnut' | 'bubble' | 'histogram' | 'combo'; /** * Chart series */ export interface ChartSeries { name: string; dataRange: CellRange; color?: string; } /** * Chart options */ export interface ChartOptions { title?: string; subtitle?: string; width: number; height: number; showLegend: boolean; legendPosition?: 'top' | 'bottom' | 'left' | 'right'; showGridLines: boolean; showDataLabels: boolean; stacked?: boolean; chartArea?: ChartArea; } /** * Chart area configuration */ export interface ChartArea { left: number; top: number; width: number; height: number; } /** * Type guard to check if value is error */ export declare function isError(value: CellValue): value is CellError; /** * Parse cell address string (e.g., "A1", "B2:C5") */ export declare function parseCellAddress(address: string): CellRange; /** * Convert cell coordinates to address string */ export declare function getCellAddress(row: number, col: number): string; //# sourceMappingURL=spreadsheet.d.ts.map