import type { defs } from "../../forms/FormHost"; import type { FormElementRegistration } from "../../forms/index"; /** * Describes the position of something relative to something else. * We use "before" and "after" instead of "left" and "right" to still make sense * in a right-to-left environment. */ export type RelativePosition = "above" | "below" | "before" | "after"; /** * Details of where to position an element when adding it to the form. */ export interface ElementPosition { /** The direction we move from the target element to determine the new position. */ relativePosition: RelativePosition; /** The name of the element to use as a starting position. */ targetElementName: string; } /** Defines what the renderer exposes. */ export default interface FormActor { /** * Adds the supplied element to the form. * @param elementName The unique name for the element. * @param type The type of element to add. * @param element The contents of the element to add. */ addElement(elementName: string, type: string, element: defs.Element, elementPosition?: ElementPosition): defs.Element; /** Assigns a property to an element item, or overwrites an existing property. */ assignElementItemProperty(elementName: string, itemKey: string, propertyName: string, propertyValue: any, markdown?: boolean): void; /** * Assigns a property to an element, or overwrites an existing property. * @param elementName The name of the element to be updated. * @param propertyName The name of the property of the element to be updated. * @param propertyValue The new value for the element's property. * @param markdown (optional) True if the value should be treated as markdown, false otherwise. The default value is false. * @param event (optional) Only relevant when `propertyName` is `"value"`. If a boolean value, indicates whether or not to post a "changed" event. If a `Partial` specifies some of the properties of the event to be posted. Any `name` and `value` provided here are ignored. The default value is true. */ assignElementProperty(elementName: string, propertyName: string, propertyValue: any, markdown?: boolean, event?: Partial | boolean): void; /** Assigns an items property to an element. */ assignItemsToElement(elementName: string, items: Record, reset?: boolean): void; /** Filters the items of an element based on heuristics. */ filterItems(elementName: string, phrase: string): boolean; /** Returns the element with the given name. If the element does not exist an error will be thrown. */ getElement(element: string | defs.Element | undefined, event?: defs.Event): defs.Element; /** Returns the name of the given element. If the element does not exist an error will be thrown. */ getElementName(element: defs.Element | string | undefined, event?: defs.Event): string; getElementRegistration(element: defs.Element): FormElementRegistration | undefined; /** Sets element visibility to false. */ hideElement(element: defs.Element): void; /** Finds the specified item and sets it as the current one. Returns true if a match was found, false otherwise. */ setCurrentItem(elementName: string, value: defs.Value | defs.Text | defs.Item, matchType: defs.ItemMatchType): boolean; /** Assigns an error message to an element. */ setElementError(elementName: string, error: string | undefined, markdown?: boolean): void; /** Sets element visibility to true. */ showElement(element: defs.Element): void; }