import * as React from 'react'; import type { GridRowId } from '@mui/x-data-grid-pro'; /** * The font formula text is rendered in — monospace, so a formula reads as the * code it is and cannot be mistaken for a plain cell value (the formula bar * shows both). Override the `--DataGrid-formulaFontFamily` CSS variable in a * theme to change it, the same escape hatch the reference palette uses. * * Applied as `font-family` alone, never through the `font` shorthand: the * hosting surfaces set `font: vars.typography.font.body`, and keeping their font * size and unitless line height is what makes the line box — and with it the * floating editor's wrap measurements — identical to the proportional font's. */ export declare const FORMULA_FONT_FAMILY = "var(--DataGrid-formulaFontFamily, ui-monospace, SFMono-Regular, \"SF Mono\", Menlo, Consolas, \"Liberation Mono\", monospace)"; /** * The edit value as the string the editor displays. Non-string values (e.g. a * number parsed from a plain edit) render through their string form; the * reference model treats them as non-formulas (no coloring). */ export declare function valueToText(value: unknown): string; /** * Imperative access the hosting component needs to the editable — entry focus, * caret placement, session bookkeeping, and closing the suggestion popup from * outside (e.g. when a column drag-resize starts). */ export interface GridFormulaEditableHandle { getRoot: () => HTMLDivElement | null; focus: (options?: FocusOptions) => void; /** * @returns {number | null} Character offset of the collapsed caret, or `null` when there is none. */ getCaret: () => number | null; /** * Places the caret and scrolls it into view. * @param {number | null} offset The character offset, or `null` for the end of the text. */ placeCaret: (offset: number | null) => void; /** * @returns {boolean} The engaged flag: `false` until the first real edit (seeding parks the caret at the end). */ isEngaged: () => boolean; setEngaged: (engaged: boolean) => void; closeSuggestions: () => void; } export interface GridFormulaEditableProps { /** The text the editable displays — the single source of truth (controlled). */ value: string; /** * The cell the text belongs to, for reference highlighting (self-references * are never highlighted) and the shared model. `null` disables highlighting. */ ownerCell: { id: GridRowId; field: string; } | null; /** Whether references are shown in A1 notation rather than the canonical dialect. */ a1Notation: boolean; /** Whether the autocomplete suggestion popup is enabled. */ suggestionsEnabled: boolean; /** * Hides the popup without touching its state — e.g. while the floating editor * is unfocused (row edit mode) or its row is virtualized out of the viewport. */ popupDisabled?: boolean; /** * Renders the text non-editable (and not focusable) — the formula bar's state * for non-editable cells. Coloring still applies. */ readOnly?: boolean; /** Stable DOM id prefix for the popup's listbox/options (aria wiring). */ popupId: string; ariaLabel: string; className?: string; /** * Called on every user edit (typing, paste, IME commit, accepted suggestion). * The host writes the text to its store; the new text flows back through * `value`, and the rebuild effect restores the caret. * @param {string} text The normalized single-line text. * @param {number | null} caret The caret offset to restore after the rebuild. * @param {React.SyntheticEvent} event The originating event. */ onValueChange: (text: string, caret: number | null, event: React.SyntheticEvent) => void; /** * Consulted before an INSERTION (typing, paste, IME commit) is accepted: * return `true` to neglect it — the editable restores the previous text and * selection, the way a native number input ignores characters it cannot * represent. Deletions are never filtered. * @param {string} nextText The text the insertion would produce. * @param {string} previousText The text currently rendered. * @returns {boolean} `true` to reject the insertion. */ shouldIgnoreInput?: (nextText: string, previousText: string) => boolean; /** * Enter pressed while the popup is closed (or the accept was a no-op). The * newline is always prevented; when this is not provided the event keeps * propagating so an enclosing grid cell commits the edit. * @param {React.KeyboardEvent} event The keyboard event. */ onCommitKey?: (event: React.KeyboardEvent) => void; /** * Escape pressed while the popup is closed. * @param {React.KeyboardEvent} event The keyboard event. */ onCancelKey?: (event: React.KeyboardEvent) => void; /** * Runs inside the rebuild layout effect, after the colored children are * rendered and before the caret is restored — the hook for content-driven * geometry (the floating editor's grow-to-fit). * @param {HTMLDivElement} root The editable element. */ onAfterRebuild?: (root: HTMLDivElement) => void; /** * Any user interaction that may have moved the caret (input, accept, keyup, * mouseup) — the floating editor mirrors these into its remount session. * @param {number | null} caret The caret offset after the interaction. */ onInteraction?: (caret: number | null) => void; onBlur?: (event: React.FocusEvent) => void; } /** * The single-layer formula text editor: a `contenteditable` whose children are * the colored reference token ``s themselves, so the caret, the native * selection, and the colors share one element (nothing to keep aligned). It is a * controlled component — the host owns the value — and layers the autocomplete * popup (suggestions from `useGridFormulaAutocomplete`, highlight colors from * `useGridFormulaReferenceModel`). Caret save/restore around each rebuild, * IME-composition guarding and explicit paste/newline handling are the cost of * `contenteditable`; each is handled below. Shared by the in-cell floating * editor (`GridFormulaEditor`) and the formula bar. */ declare const GridFormulaEditable: React.ForwardRefExoticComponent>; export { GridFormulaEditable };