import type { EventArgumentTypes, EventValueTypes } from "./FormComponent"; import type { defs } from "./FormHost"; export { Orientation, TitleLocation } from "./constants"; export type { Text } from "./elements/types"; /** * Details about an event to be fired when the value property is updated. * If `false`, no event is fired. * If `true`, the event is fired with the event object just containing the element's value. * If an object containing `"argument"` or `"item" properties, the event is fired and those properties are included in the event object. */ type EventOptions = Partial> | boolean; export interface ITranslateTextFunction { (content: string): string; (content: defs.MarkdownRef | defs.StatusRef): defs.MarkdownRef; (content: defs.Text | undefined): string | defs.MarkdownRef | undefined; } /** @public */ export interface FormElementProps extends FormElementSettableProps, FormElementGettableProps { className?: string; enabled: boolean; id: string; name: string | undefined; /** * A callback function to raise an event. The `custom` event accepts any * value as the eventValue. Use the Get Form Event Data to access the event * data in a sub-workflow of the Display Form activity. * @param eventName The name of the event to raise. Currently only `custom` * is permitted. * @param eventValue The value of the event. */ raiseEvent: (eventName: K, eventValue: EventValueTypes[K], argument?: EventArgumentTypes[K], item?: string, cancellationToken?: PromiseLike) => void; /** * Set a property on an item in the element. * @param property The name of the property to set. * @param value The new value to set. */ setItemProperty: (item: string, property: K, value: FormElementItemProps[K]) => void; /** * Set a property on the element. * @param property The name of the property to set. * @param value The new value to set. */ setProperty: >(property: K, value: this[K], event?: EventOptions) => void; /** * Sets the `value` property of the element. Equivalent to calling * `setProperty("value", value)`. * * Setting the value will raise the `change` event on the element. * * @param value The new value to set. */ setValue: (value: this["value"], event?: EventOptions) => void; } /** * Properties of a Form Element that can be read via the component's properties. */ declare type FormElementGettableProps = Pick; /** * Properties of a Form Element that can be set using `SetProperty()`. * Any properties defined here can also be read via the component's properties. * @public */ export interface FormElementSettableProps extends Pick { /** The value of the element. */ value: TValue; } /** @public */ export interface FormElementItemProps extends FormElementItemSettableProps, Pick { } /** @public */ declare type FormElementItemSettableProps = Pick; type SettablePropsFromProps = Omit & FormElementSettableProps; type Unionize = T[keyof T]; /** @public */ export type PropertyChangeEvent = Unionize<{ [K in keyof Required]: { properties: Readonly; property: K; setProperty: TSetProperty; }; }>; /** @public */ export interface FormElementRegistration = FormElementProps, TSettableProps extends SettablePropsFromProps = SettablePropsFromProps> { /** The React component definition of the form element. */ component: React.ComponentType; /** * Generate the initial properties of the form element. This will be assigned to * the element properties before first render. */ getInitialProperties?: () => Partial; /** The unique identifier of the element. */ id: string; /** * This function will be invoked prior to updating a property of the element * state. It will be invoked even if the element isn't currently visible. * * @returns Either a new value, an error message, or nothing. */ onPropertyChange?: (event: PropertyChangeEvent) => void; }