@odoo/o-spreadsheet
Version:
A spreadsheet component
45 lines (44 loc) • 2.21 kB
TypeScript
import { CellValue } from "../types/cells";
import { EvaluatedCriterion, GenericCriterion, GenericCriterionType } from "../types/generic_criterion";
import { Getters } from "../types/getters";
import { UID } from "../types/misc";
import { Range } from "../types/range";
import { Registry } from "./registry";
export type CriterionEvaluator<T = unknown> = {
type: GenericCriterionType;
/**
* Checks if a value is valid for the given criterion.
*
* The value and the criterion values should be in canonical form (non-localized), and formulas should
* be evaluated.
*
* For more complex criteria (like "top10"), a computation cache may be returned to avoid recomputing the entire criterion
* on every value it applies to.
*/
isValueValid: (value: CellValue, criterion: EvaluatedCriterion, preComputedCriterion?: T) => boolean;
/**
* For more complex criteria (like "top10"), we might want to pre-compute some data before evaluating the criterion for
* each cell, to avoid recomputing everything each time.
*/
preComputeCriterion?: (criterion: GenericCriterion, criterionRanges: Range[], getters: Getters) => T;
/**
* Returns the error string to display when the value is not valid.
*
* The criterion values should be in canonical form (non-localized), and formulas should be evaluated.
*/
getErrorString: (criterion: EvaluatedCriterion, getters: Getters, sheetId: UID) => string;
/**
* Checks if a criterion value is valid.
*
* The value should be in canonical form (non-localized).
*/
isCriterionValueValid: (value: string) => boolean;
/** Return the number of values that the criterion must contains. Return undefined if the criterion can have any number of values */
numberOfValues: (criterion: GenericCriterion) => number | undefined;
name: string;
getPreview: (criterion: GenericCriterion, getters: Getters) => string;
/** Error string when a criterion value is invalid */
criterionValueErrorString: string;
allowedValues?: "onlyLiterals" | "onlyFormulas";
};
export declare const criterionEvaluatorRegistry: Registry<CriterionEvaluator<unknown>>;