import { AnyComponentSchema } from '@open-formulieren/types'; import { NestedObject } from './components/utils'; import { VisibilityContext } from './registry/types'; import { JSONObject } from './types'; /** * The possible errors in the Formik state. * * @note We don't use the `FormikErrors` type here because it's too limited with a * generic JSONObject `Values` type argument - it simplifies to `{[k: string]: string}`, * but the actual error structure mimicks the values structure that can string keys * and values of type: * * - string * - string[] (for components with multiple: true, for example) * - nested error structure (object), for `foo.bar` like component keys * - arrays of nested error structures or strings, like for edit grids, where the * error may be about the item as a whole (string) or an object (item field errors) * * The errors structure itself may also be `undefined`, when there's *no* error for a * particular field at all. */ export type Errors = NestedObject | string | string[] | undefined; /** * The return value of `processVisibility`. */ interface ProcessVisibilityResult { /** * The subset of provided components that are visible with the currently provided * `values`. * * There are no guarantees about object identity - not for the array itself nor the * components inside. */ visibleComponents: AnyComponentSchema[]; /** * Updated `values` because of `clearOnHide` side-effects, or side-effects because * the component became visible (again). Unmodified values are guaranteed to have a * stable identity, for both the top-level and nested objects. */ updatedValues: JSONObject; /** * Updated `errors` because of visibility logic. A component can be invalid when it is * not hidden. The key of a hidden component should not be in the object even if it * "used" to be invalid. */ updatedErrors: Errors; } /** * Given an array of components (like a form definition) and (current) component values, * evaluate the visibility of each component and its children. The return value is an * array of visible components and values updated by visibility/hidden side-effects. * * Only the visible components are returned so that the rendering logic can be kept * simple. The `updatedValues` are the result of applying side effects like * `clearOnHide` on each component (including nested components!). * * Layout components must implement the `applyVisibility` callback to ensure all child * components can apply their side-effects. You can call `processVisibility` inside * `applyVisibility` to recursively process the entire component tree. */ export declare const processVisibility: ( /** * Form definition/subtree of components to test for visibility. */ components: AnyComponentSchema[], /** * Submission (or item) values for the current scope. The root scope is equal to the * values for the _whole_ submission, but that's not always the case. Edit grids * essentially have a nested, isolated scope for each item with a nested subform tree * of components, with access to the outer sope. See the context parameter * `getEvaluationScope` for such situations. * * A component becoming visible or hidden produces side effects, which are applied to * the provided `values` - make sure the shape of `values` matches the component * definitions provided in `components`. */ values: JSONObject, /** * Validation errors for the current scope. The root scope is equal to the * errors for the _whole_ submission, but that's not always the case. Edit grids * essentially have a nested, isolated scope for each item with a nested subform tree * of components, with access to the outer sope. See the context parameter * `getEvaluationScope` for such situations. * * A component becoming hidden produces side effects - the validation errors for that * component must be cleared to not block submission. Make sure the shape of `errors` * matches the component definitions provided in `components`. */ errors: Errors, /** * Form definition/subtree context, used to pass callbacks to avoid circular * dependencies but also more fine-grained context set by one or more parent * components. */ context: VisibilityContext) => ProcessVisibilityResult; export {};