/** * The rules a field states, as the attributes an input carries. * * A constraint declared once — `maxLength(50)` in a schema, `"maxLength": 50` in a document — should * reach the keyboard, not only the error list. Until now it reached neither for most of the family: * every renderer wrote `min`/`max` by hand for numbers and nothing wrote `maxlength` or `pattern` at * all, so a fifty-character field let someone type five hundred and told them afterwards. * * The translation lives here, once, because three renderers writing it separately is how they come * to disagree — and a fourth renderer would have to rediscover which attribute belongs to which * kind. * * **The boundary is the model.** These attributes constrain typing. A value arriving from anywhere * else — a draft, a server, `set()` — is kept whole and judged by the rules, exactly as * ADR 0029 requires of a widget: nothing here truncates, rounds or rewrites what a form holds. */ import type { MdyFieldConstraints } from "@modyra/core"; import type { MdyWidgetKind } from "./catalog.js"; /** An attribute an input carries, or `null` to leave it off. */ export type MdyNativeAttributes = Readonly>; /** * The track a slider is drawn on, given what bounds it and what it holds. * * A slider has to span something to be drawn at all, and where nothing states a range it takes the * one a bare `` assumes. That default is the kind's, not a rule — and a default * is not a licence to misrepresent: a form holding `150` with no bound declared drew a track ending * at `100` and put the thumb there, so the page showed a number the form did not hold, with nothing * said. Both renderers had invented the same `?? 100` separately, which is how they came to agree * about a lie. * * **Widened only where nothing was declared.** A document that *did* declare `max: 50` keeps it: * the attribute is the native guard, it must not promise less than the rules it came from * (`VAL-004`), and since [ADR 0066](../../../docs/architecture/0066-a-bound-beside-the-field-is-a-rule.md) * a value past it is refused with a message — so the page explains the difference instead of hiding * it. Where nothing was declared there is no rule to explain anything, and showing the value is the * only honest answer left. * * **`step` is dropped where it would move the thumb.** The platform snaps a range input to a * multiple, so a value of `7` with `step: 5` was drawn at `5`. There is no step rule to appeal to — * the validator vocabulary has none — so the affordance gives way to the value. */ export declare function sliderTrack(constraints: Pick, value: number | null): { readonly min: number; readonly max: number; readonly step: number | null; }; /** * What `kind` can carry of `constraints`. * * Only what the kind's own control understands: a `maxlength` on a number input is ignored by the * platform, and offering it would be a promise the widget does not keep. `inputType` is deliberately * absent — the kind decides what the input *is*, and a rule may not change it. */ export declare function nativeConstraintAttributes(kind: MdyWidgetKind | string, constraints: MdyFieldConstraints, /** What the field holds, where the kind draws it — a slider's track spans it. */ value?: number | null): MdyNativeAttributes; export declare function narrowConstraints(rules: MdyFieldConstraints, narrowing: Partial | undefined): MdyFieldConstraints;