import type { IFieldBase } from './field.types'; import { FieldBase } from './field.types'; export interface INumber extends IFieldBase { placeholder?: string; min?: number; max?: number; step?: number; debounceFor: number; customVisual?: any; } export class NumberModel extends FieldBase implements INumber { type = "number"; min = -10000; max = 10000; step = 1; debounceFor = 200; customVisual = null; constructor(number: Partial) { super(number); this.min = number.min ?? this.min; this.max = number.max ?? this.max; this.step = number.step ?? this.step; this.debounceFor = number.debounceFor ?? this.debounceFor; this.customVisual = number.customVisual ?? this.customVisual; } } // SCHEMA export interface NumberStateScaffold { value: { initial: string, states: { idle: {}; typing: {}; } }, hasDecimal: { initial: '', states: { false: {}, true: {} } } } export interface NumberStates extends NumberStateScaffold { value: { initial: '', states: { idle: {}; typing: {}; } }, hasDecimal: { initial: '', states: { false: {}, true: {} } } } // EVENTS that the machine handles export type Number_Event_Keystroke = { type: 'KEYSTROKE'; value: any }; export type Number_Event_Stopped = { type: 'STOPPED'; value: any }; export type Number_Event_Focus = { type: 'FOCUS'; value: any }; export type Number_Event_ToggleDecimal = { type: 'TOGGLE_DECIMAL' }; export type NumberEvent = Number_Event_Keystroke | Number_Event_Stopped | Number_Event_Focus | Number_Event_ToggleDecimal export interface NumberEventsScaffold { 'KEYSTROKE': Function, 'STOPPED': Function, 'FOCUS': Function, 'TOGGLE_DECIMAL': Function, } // CONTEXT export interface NumberContext { debounceMachine: any; field: INumber; } interface NumberContextUndefined { debounceMachine: any; field: undefined; } export interface NumberStateSchema { initial: string; context: NumberContext; states: NumberStates }; export type NumberState = { value: 'idle'; context: NumberContext & NumberContextUndefined; } | { value: 'typing'; context: NumberContext & NumberContextUndefined; };