import { StringOrFunction, ValueOrFunction } from '@moxb/util'; import { BindImpl, BindOptions } from '../bind/BindImpl'; import { Value } from './Value'; export interface ValueOptions extends BindOptions { inputType?: string; /** * Is this value required? * * If yes, you probably won't be able to save a form if not given. (See isGiven below) */ required?: boolean; /** * A function used to detect if this value is "given". (whatever that means in the context.) * This will be used to test the presence of required values. */ isGiven?: (value: T | undefined | null) => boolean; initialValue?: ValueOrFunction; /** * A function used to compare the initialValue with the current value. * It defaults to mobx.comparer.structural. * @param a * @param b */ valueCompareFunction?(a: T, b: T): boolean; setValue?(value: T): void; getValue?(): T | undefined; /** * If setValue is specified and this is specified, this is used to reset the value to * the initial value. */ resetToInitialValue?(): void; /** * If placeholder is a function it assumes that the function returns a translated placeholder. * If placeholder is a string, the assumption is that this is the default translation and the translation key is `id.placeholder` */ placeholder?: StringOrFunction; /** * Is called when Value.save() is called and Value.isInitialValue is false. * `done` must be called else the binding stays in saving state. * * @param {Value} bind * @param {(error: any) => void} done */ onSave?(bind: B, done: (error?: any) => void): void; onExitField?(bind: B): void; onEnterField?(bind: B): void; /** * This is called when the value is set. It can transform the value. * @param {T} value * @param {Value} bind */ onSetValue?(value: T, bind: B): T; /** * Called after the value has been set. * * @param {T} value * @param {Value} bind */ onAfterSetValue?(value: T, bind: B): void; } export declare class ValueImpl> extends BindImpl implements Value { /** * default value impl */ _value?: T; _isSaving: boolean; constructor(impl: Options); protected implValOrUndefined(key: string): any; private getInitialValue; get inputType(): string | undefined; get value(): T | undefined; private doGetValue; get placeholder(): string | undefined; private doPlaceholder; get required(): boolean | undefined; get isGiven(): boolean; setValue(value: T): void; private doSetValue; get isInitialValue(): boolean | undefined; protected compare(a: T | undefined, b: T | undefined): boolean; resetToInitialValue(): void; save(): void; private saveDone; get isSaving(): boolean; onEnterField(): void; onExitField(): void; }