import type { CSSObject, Theme } from '@mui/material/styles'; import type { RefObject } from '@mui/x-internals/types'; import type { GridRowId } from '@mui/x-data-grid-pro'; import type { GridPrivateApiPremium } from "../../../models/gridApiPremium.js"; import type { FormulaPositionContext, FormulaSourceSpan } from "./engine/index.js"; /** * A resolved highlight target. Identity-keyed: two references resolving to the * same target share a color. `unresolved` (`#REF!`, hidden column, filtered-out * row, self-reference) gets no color and no rectangle. */ export type FormulaReferenceTarget = { kind: 'cell'; field: string; rowId: GridRowId; } | { kind: 'range'; startField: string; endField: string; startRowId: GridRowId; endRowId: GridRowId; } | { kind: 'wholeColumn'; field: string; } | { kind: 'unresolved'; }; export interface FormulaReference { /** Offsets into the EDITOR text (the shown dialect, including the leading `=`). */ spans: FormulaSourceSpan[]; target: FormulaReferenceTarget; /** Same target ⇒ same key ⇒ same color. `null` for unresolved references. */ targetKey: string | null; /** Palette index, cycled over distinct targets in source order. `null` for unresolved. */ colorIndex: number | null; } export interface FormulaReferenceModel { references: FormulaReference[]; paletteSize: number; } /** * One run of editor text: a colored reference token (`colorIndex !== null`) or a * plain gap (`colorIndex === null`). Consumed by the editor to build its colored * ``s and text nodes. */ export interface FormulaTextSegment { text: string; colorIndex: number | null; /** * A run of operators/punctuation OUTSIDE any reference, rendered in the muted * foreground so the function names, identifiers and literals lead the line. * Never set on a reference token — a reference keeps its identity color across * its own inner parentheses and colons. */ syntax?: boolean; } /** * Shared reference palette: one hue per distinct target, cycled. Light/dark * variants keep ≥3:1 contrast against row backgrounds (the dashed rectangle's * color is the only thing tying it to its editor token). Both render halves read * this same constant, so a token's color and its rectangle's color can never * disagree. A typed override prop is a later addition. */ export declare const FORMULA_REFERENCE_PALETTE: readonly { light: string; dark: string; }[]; export declare const FORMULA_REFERENCE_PALETTE_SIZE: number; /** * The color for a reference, or `undefined` for an unresolved (`null`) index. */ export declare function getFormulaReferenceColor(colorIndex: number | null, mode: 'light' | 'dark'): string | undefined; /** * The palette as CSS custom properties with a dark-mode variant (via the grid's * own `applyStyles('dark')`). Spread onto each render half's root so a shared * `colorIndex` maps to one hue without depending on the JS theme mode — and the * two halves can never disagree. Override the `--DataGrid-formulaRefColor-*` * variables in a theme to recolor. */ export declare function getFormulaReferencePaletteStyles(theme: Theme): CSSObject; /** * The CSS `var(...)` for a resolved color index, cycled over the palette. */ export declare function getFormulaReferenceColorVar(colorIndex: number): string; /** * Builds the shared reference model both render halves consume. Pure: it reads * only the edit value, the position context and the owner cell, so the editor * backdrop and the grid overlay derive identical colors. Spans are shifted into * editor coordinates (the leading `=` the expression was stripped of). Colors * cycle the palette over distinct resolved targets, in source order. */ export declare function buildFormulaReferenceModel(value: unknown, positionContext: FormulaPositionContext, ownerCell: { id: GridRowId; field: string; }, a1Notation: boolean): FormulaReferenceModel; /** * Rebuilds the shared reference model on every change of the highlighted text. * The text is resolved in order: * * 1. `valueOverride`, when provided — a controlled editor (the shared * `GridFormulaEditable`) always colors exactly the text it displays. * 2. The active edit's `draft`, when `ownerCell` is the active-edit cell — text * edited outside the cell edit state, e.g. typed into the formula bar while * the cell stays in view mode. * 3. The cell's live edit-state value. * * The fallbacks read from grid *state*, not the editor component, so the grid * overlay keeps working when the editing cell is virtualized out. Returns the * empty model when no cell is given. */ export declare function useGridFormulaReferenceModel(apiRef: RefObject, ownerCell: { id: GridRowId; field: string; } | null, a1Notation: boolean, valueOverride?: unknown): FormulaReferenceModel; /** * Splits the editor text into colored reference runs and plain gaps, each gap * further split into muted syntax runs (operators, punctuation) and everything * else. References are non-overlapping distinct tokens; an out-of-order or * overlapping span is skipped defensively so the segment text always * reconstructs the value exactly — the invariant every caret offset depends on. * Shared by the editor's imperative DOM rebuild (`renderSegments`). */ export declare function buildFormulaTextSegments(value: string, references: FormulaReference[]): FormulaTextSegment[];