{"version":3,"names":["useFieldRootContext","mergePropsN","ariaInvalid","useFieldControlRegistration","useFieldControlValidation","params","field","source","value","id","controlRef","getValue","enabled","getValidationProps","externalProps","validation","getInputValidationProps","getAriaInvalidProps","present","undefined","state","valid","inputRef","commit"],"sources":["use-field-control-validation.ts"],"sourcesContent":["import type { JSX } from \"@solidjs/web\";\nimport type { Accessor } from \"solid-js\";\nimport type { FieldValidationProps, MutableRef } from \"../field-context\";\nimport { useFieldRootContext } from \"../field-context\";\nimport { mergePropsN, type PropsLike } from \"../merge-props-n\";\nimport { ariaInvalid } from \"../seed-aria-attr\";\nimport { useFieldControlRegistration } from \"../use-field-control-registration/use-field-control-registration\";\n\nexport interface UseFieldControlValidationParameters {\n\t/** Accessor for the control's live value (checkbox `checked`, etc). */\n\tvalue: Accessor<unknown>;\n\t/** Accessor for the id to register under `<Field.Root>`. */\n\tid: Accessor<string | undefined>;\n\t/**\n\t * Ref to the visible control element (the `<button>` that renders the\n\t * checkbox UI, not the hidden input).\n\t */\n\tcontrolRef: MutableRef<HTMLElement | null>;\n\t/** Optional explicit value getter — when the value lives on a hidden input. */\n\tgetValue?: (() => unknown) | undefined;\n\t/**\n\t * `false` disables registration. Threaded through to\n\t * `useFieldControlRegistration` for checkbox-in-checkbox-group cases.\n\t */\n\tenabled?: Accessor<boolean | undefined> | undefined;\n}\n\nexport interface UseFieldControlValidationReturn {\n\t/**\n\t * Adds a11y hooks (`aria-invalid`, `aria-describedby`) to a props bag.\n\t * Thin wrapper around `validation.getValidationProps` from the parent\n\t * field — delegates so tier-2 controls don't have to reach into the\n\t * context directly.\n\t */\n\tgetValidationProps: (\n\t\texternalProps?: JSX.HTMLAttributes<HTMLElement>,\n\t) => JSX.HTMLAttributes<HTMLElement>;\n\t/**\n\t * Same as {@link getValidationProps} but adds the `onInput` -> `commit`\n\t * bridge expected on a native `<input>` element.\n\t */\n\tgetInputValidationProps: (\n\t\texternalProps?: JSX.InputHTMLAttributes<HTMLInputElement>,\n\t) => JSX.InputHTMLAttributes<HTMLInputElement>;\n\t/**\n\t * Minimal props bag containing only the derived `aria-invalid` attribute.\n\t * Useful when the caller wants to splat just the a11y flag without the\n\t * aria-describedby plumbing that lives in `getValidationProps` (currently\n\t * a no-op for tier-2 widgets — kept as a parity surface for when the\n\t * description context lands).\n\t */\n\tgetAriaInvalidProps: () => PropsLike;\n\t/** Ref the native validation machinery uses to read `element.validity`. */\n\tinputRef: MutableRef<HTMLInputElement | null>;\n\t/**\n\t * Imperative trigger for the validation pipeline. Calls the parent's\n\t * `validation.commit(value, revalidate?)`.\n\t */\n\tcommit: FieldValidationProps[\"commit\"];\n\t/**\n\t * Opaque symbol used to key the control's registration — surfaced for\n\t * parity with React but rarely needed by callers.\n\t */\n\tsource: symbol;\n}\n\n/**\n * Compose `<Field.Root>`'s existing `useFieldValidation` machinery with\n * per-control registration for tier-2 widgets (checkbox, switch, radio, …).\n *\n * React parity: the React port splits this work across `useRegisterFieldControl`\n * and manual use of `validation` from the field-root context. Solid's\n * version collapses the two into a single hook so tier-2 components have a\n * single call site and don't need to pull `useFieldRootContext` themselves.\n *\n * Solid 2 notes:\n *\n * - Registration uses `useFieldControlRegistration` (P4), which installs\n *   its own `onCleanup` and `useValueChanged` bridge.\n * - `getValidationProps` / `getInputValidationProps` delegate to the parent\n *   field's pre-built props-factories — they already encode the correct\n *   `aria-invalid` semantics (literal `\"true\"` / `undefined` per RFC 07).\n * - When there's no `<Field.Root>` above, the hook still works: the noop\n *   field context returns pass-through props factories and a noop commit.\n */\nexport function useFieldControlValidation(\n\tparams: UseFieldControlValidationParameters,\n): UseFieldControlValidationReturn {\n\tconst field = useFieldRootContext();\n\n\tconst { source } = useFieldControlRegistration({\n\t\tvalue: params.value,\n\t\tid: params.id,\n\t\tcontrolRef: params.controlRef,\n\t\tgetValue: params.getValue,\n\t\tenabled: params.enabled,\n\t});\n\n\tconst getValidationProps: UseFieldControlValidationReturn[\"getValidationProps\"] =\n\t\t(externalProps) => field.validation.getValidationProps(externalProps);\n\n\tconst getInputValidationProps: UseFieldControlValidationReturn[\"getInputValidationProps\"] =\n\t\t(externalProps) => field.validation.getInputValidationProps(externalProps);\n\n\t// Minimal aria-only projection. Re-reads the underlying field state on\n\t// every access so consumers splatting this into a reactive proxy (e.g.\n\t// `mergePropsN`) see the latest value. Outside a real `<Field.Root>` the\n\t// noop context has `present: false`; emit `undefined` so the key doesn't\n\t// appear on consumers that render standalone. WAI-ARIA 1.2 treats\n\t// `aria-invalid=\"false\"` as equivalent to absent, so AT behavior is\n\t// unchanged.\n\tconst getAriaInvalidProps: UseFieldControlValidationReturn[\"getAriaInvalidProps\"] =\n\t\t() =>\n\t\t\tmergePropsN([\n\t\t\t\tariaInvalid(() => {\n\t\t\t\t\tif (!field.present) return undefined;\n\t\t\t\t\treturn field.state().valid === false;\n\t\t\t\t}),\n\t\t\t]);\n\n\treturn {\n\t\tgetValidationProps,\n\t\tgetInputValidationProps,\n\t\tgetAriaInvalidProps,\n\t\tinputRef: field.validation.inputRef,\n\t\tcommit: field.validation.commit,\n\t\tsource,\n\t};\n}\n"],"mappings":"AAGA,SAASA,mBAAmB,QAAQ,kBAAkB;AACtD,SAASC,WAAW,QAAwB,kBAAkB;AAC9D,SAASC,WAAW,QAAQ,mBAAmB;AAC/C,SAASC,2BAA2B,QAAQ,kEAAkE;AA4D9G;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,yBAAyBA,CACxCC,MAA2C,EACT;EAClC,MAAMC,KAAK,GAAGN,mBAAmB,CAAC,CAAC;EAEnC,MAAM;IAAEO;EAAO,CAAC,GAAGJ,2BAA2B,CAAC;IAC9CK,KAAK,EAAEH,MAAM,CAACG,KAAK;IACnBC,EAAE,EAAEJ,MAAM,CAACI,EAAE;IACbC,UAAU,EAAEL,MAAM,CAACK,UAAU;IAC7BC,QAAQ,EAAEN,MAAM,CAACM,QAAQ;IACzBC,OAA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