import { InputContext, InputOptions } from "../createInput/index.mjs"; import { NumericContext, NumericOptions } from "../createNumeric/index.mjs"; import { MaybeRefOrGetter, Ref } from "vue"; //#region src/composables/createNumberField/index.d.ts interface NumberFieldOptions extends NumericOptions { /** Value source — defaults to ref(null). */ value?: Ref; /** BCP 47 locale tag. @default 'en-US' */ locale?: string; /** Intl.NumberFormat options. */ format?: Intl.NumberFormatOptions; /** Whether commit() clamps to min/max. @default true */ clamp?: boolean; /** * When to write typed input into `value`. `'change'` (default) only * writes on `commit()` (blur/Enter). `'input'` also writes on every * keystroke via `write()`, without clamping or snapping — clamping * mid-type would jump a value like `1` to `min` before the user finishes * typing `15`. Clamping/snapping still happens on the next `commit()`. * * @default 'change' * * @example * ```ts * const field = createNumberField({ min: 10, max: 100, commitOn: 'input' }) * field.write('1') * field.value.value // 1 — no jump to min while typing * ``` */ commitOn?: 'input' | 'change'; /** Disabled state. */ disabled?: MaybeRefOrGetter; /** Readonly state. */ readonly?: MaybeRefOrGetter; /** Unique identifier. */ id?: InputOptions['id']; /** Display label. */ label?: string; /** Form field name. */ name?: string; /** * Form injection key. Must match the parent Form's `namespace`. * * @default 'v0:form' */ formNamespace?: string; /** * Whether required. When true, a presence rule is registered so Form * submit fails on empty values even with `novalidate`. */ required?: boolean; /** Validation rules. */ rules?: InputOptions['rules']; /** Manual error state override — forces invalid. */ error?: InputOptions['error']; /** Manual error messages — merged with rule-based errors. */ errorMessages?: InputOptions['errorMessages']; } interface NumberFieldContext { /** The numeric value (null when empty). */ value: Ref; /** Formatted display string (empty for null). */ display: Readonly>; /** Whether the value can be incremented. */ canIncrement: Readonly>; /** Whether the value can be decremented. */ canDecrement: Readonly>; /** The underlying numeric context. */ numeric: NumericContext; /** The underlying input context. */ input: InputContext; /** Increment value by step * multiplier. */ increment: (multiplier?: number) => void; /** Decrement value by step * multiplier. */ decrement: (multiplier?: number) => void; /** Set value to min. */ floor: () => void; /** Set value to max. */ ceil: () => void; /** Format a number using Intl.NumberFormat. */ formatValue: (value: number) => string; /** Parse locale-formatted text to a number or null. */ parse: (text: string) => number | null; /** Snap and optionally clamp the current value. Pass `next` to avoid reading the stale model on the same tick as a write. */ commit: (next?: number | null) => void; /** When typed input is written into `value` — see {@link NumberFieldOptions.commitOn}. */ readonly commitOn: 'input' | 'change'; /** * Parse `text` and write it straight into `value`, without clamping or * snapping. Used by `commitOn: 'input'` consumers to get per-keystroke * updates without the min/max jump `commit()` would cause mid-type. * * @example * ```ts * const field = createNumberField({ min: 10, max: 100 }) * field.write('1') * field.value.value // 1 — clamped only on the next commit() * ``` */ write: (text: string) => void; } declare function createNumberField(options?: NumberFieldOptions): NumberFieldContext; //#endregion export { NumberFieldContext, NumberFieldOptions, createNumberField };