{"version":3,"names":["createEffect","createMemo","useFieldMessagesContext","useFieldRootContext","fieldStateAttrs","useAriaLabelledBy","useLabelableId","makeSlotRefDirective","readOption","mergeRootProps","SNAPSHOT_KEYS","snapshotKeys","useFieldControlValidation","createInput","options","field","messages","id","disabled","name","state","getInputValidationProps","inputRef","commit","value","controlRef","validation","getValue","current","externalValue","hasExternal","input","setFilled","ariaLabelledBy","ariaDescribedBy","ids","getMessageIds","length","undefined","join","controlInternal","aria-labelledby","aria-describedby","data-disabled","onFocus","setFocused","onBlur","event","setTouched","validationMode","currentTarget","onInput","setDirty","validityData","initialValue","onKeyDown","tagName","key","validationProps","control","userProps","merged","bindControl","el","baseDirective","api","INPUT_SNAPSHOT_KEYS"],"sources":["create-input.tsx"],"sourcesContent":["import { type Accessor, createEffect, createMemo } from \"solid-js\";\nimport { useFieldMessagesContext } from \"../field/field-messages-context.ts\";\nimport {\n\ttype FieldRootState,\n\tuseFieldRootContext,\n} from \"../internals/field-context.ts\";\nimport { fieldStateAttrs } from \"../internals/field-state-attrs\";\nimport { useAriaLabelledBy } from \"../internals/labelable-provider/use-aria-labelled-by.ts\";\nimport { useLabelableId } from \"../internals/labelable-provider/use-labelable-id.ts\";\nimport { makeSlotRefDirective } from \"../internals/make-slot-ref-directive\";\nimport { type MaybeAccessor, readOption } from \"../internals/maybe-accessor\";\nimport { mergeRootProps } from \"../internals/merge-root-props\";\nimport {\n\tSNAPSHOT_KEYS,\n\ttype Snapshottable,\n\tsnapshotKeys,\n} from \"../internals/observability/snapshot\";\nimport { useFieldControlValidation } from \"../internals/use-field-control-validation/use-field-control-validation.ts\";\n\n/** State surface exposed to slot consumers. Mirrors the surrounding field. */\nexport interface InputState extends FieldRootState {}\n\n/**\n * Options for {@link createInput}. Every reactive input is `MaybeAccessor<T>`\n * — pass an accessor to make the value reactive (or a bare value; Solid's\n * JSX-proxy makes wrapper props reactive either way, and `readOption` is\n * identity on non-functions).\n *\n * **Solid-native shape.** Like the other field controls, `createInput` owns\n * no value/validation state of its own — that lives in the surrounding\n * `<Field.Root>`. The primitive reads the field/labelable/messages contexts\n * internally and projects a control prop-bag. Outside a `<Field.Root>` every\n * context resolves to its NOOP form and the control still renders a plain\n * `<input>`.\n */\nexport interface CreateInputOptions {\n\t/**\n\t * The control's live value. Used for field-control registration and to\n\t * drive the surrounding field's `filled` state. Not written back onto the\n\t * element by the primitive — spread it (or pass it through `control()`'s\n\t * `userProps`) yourself.\n\t */\n\tvalue?: MaybeAccessor<string | number | readonly string[] | undefined>;\n\t/**\n\t * Whether the control is disabled. Composed with the field's `disabled`\n\t * (either being true disables the control).\n\t * @default false\n\t */\n\tdisabled?: MaybeAccessor<boolean | undefined>;\n\t/**\n\t * Explicit id for the control. Read once during setup (matches\n\t * `useBaseUiId`'s stable-id semantics); generated when omitted.\n\t */\n\tid?: string | undefined;\n\t/** Form-submission name. Falls back to the field's `name`. */\n\tname?: MaybeAccessor<string | undefined>;\n}\n\n/** Shape of attributes emitted by `c.control()`. */\nexport interface InputControlSlotProps {\n\tid: string;\n\tdisabled: boolean;\n\tname: string | undefined;\n\t\"aria-labelledby\": string;\n\t\"aria-describedby\": string;\n\t\"data-disabled\": \"\" | undefined;\n\tonFocus: (event: FocusEvent) => void;\n\tonBlur: (event: FocusEvent & { currentTarget: HTMLInputElement }) => void;\n\tonInput: (event: InputEvent & { currentTarget: HTMLInputElement }) => void;\n\tonKeyDown: (\n\t\tevent: KeyboardEvent & { currentTarget: HTMLInputElement },\n\t) => void;\n}\n\n/**\n * Public API returned by {@link createInput}. Flat accessors at the root; the\n * control prop-bag (`control`) and its directive form (`controlRef`) carry the\n * field wiring. No `Provider`/`useInput` — an `<input>` is a leaf with no\n * descendant subtree that would read the api back (same call as Toggle's\n * skipped provider).\n */\nexport interface InputApi {\n\t/** Composed `disabled` (field's OR the option's). */\n\tdisabled: Accessor<boolean>;\n\t/** The field-derived state (field state + composed `disabled`). */\n\tstate: Accessor<InputState>;\n\t/** The resolved control id. Stable for the primitive's lifetime. */\n\tid: string;\n\t/**\n\t * Control slot — getter-bag of attributes + handlers ready for spreading\n\t * onto a native `<input>`. Does NOT include `ref`; bind the element via\n\t * {@link bindControl} (or use {@link controlRef} for the directive form).\n\t */\n\tcontrol: <U extends object | undefined = undefined>(\n\t\tuserProps?: U,\n\t) => InputControlSlotProps & (U extends object ? U : object);\n\t/**\n\t * Plain setter that binds the live `<input>` element into the field's\n\t * validation pipeline (`element.validity` reads, `setCustomValidity`\n\t * writes). Compose with the consumer's ref via `composeRefs`. Use this\n\t * when the element already receives `control()`'s prop bag via spread.\n\t */\n\tbindControl: (el: HTMLInputElement | null) => void;\n\t/**\n\t * Directive form — a `ref` callback that spreads the control bag onto the\n\t * element AND binds it into the validation pipeline. For cva-style\n\t * consumers that own the element's prop surface and don't spread\n\t * `control()`.\n\t */\n\tcontrolRef: () => (el: HTMLInputElement | null) => void;\n}\n\n/**\n * Solid 2.0-native field-control primitive for a native `<input>` that\n * integrates with a surrounding `<Field.Root>`. Wires (when inside a field):\n *\n *   - id registration into the labelable provider so `<Field.Label>`'s\n *     `htmlFor` can target this input.\n *   - value registration into the field (and any `<Form>` above) via\n *     `useFieldControlValidation`.\n *   - `aria-labelledby` composed from registered labels.\n *   - `aria-describedby` composed from `<Field.Description>` / `<Field.Error>`\n *     ids via the field-messages registry.\n *   - `aria-invalid` — flipped to literal `\"true\"` once validation latches\n *     invalid (via `getInputValidationProps()`).\n *   - `onInput` / `onBlur` / `onFocus` / `onKeyDown` into the field's\n *     touched / dirty / filled / focused setters and the validation pipeline.\n *\n * Must be called in an owner scope (component body or `createRoot`) — it\n * reads contexts and installs effects / cleanups.\n */\nexport function createInput(options: CreateInputOptions = {}): InputApi {\n\tconst field = useFieldRootContext();\n\tconst messages = useFieldMessagesContext();\n\n\tconst { id } = useLabelableId({ id: options.id });\n\n\tconst disabled = createMemo(\n\t\t(): boolean => field.disabled() || readOption(options.disabled) === true,\n\t\t{ name: \"input.disabled\" },\n\t);\n\n\tconst state = createMemo(\n\t\t(): InputState => ({\n\t\t\t...field.state(),\n\t\t\tdisabled: disabled(),\n\t\t}),\n\t\t{ name: \"input.state\" },\n\t);\n\n\tconst { getInputValidationProps, inputRef, commit } =\n\t\tuseFieldControlValidation({\n\t\t\tvalue: () => readOption(options.value),\n\t\t\tid: () => id,\n\t\t\tcontrolRef: field.validation.inputRef,\n\t\t\tgetValue: () => field.validation.inputRef.current?.value,\n\t\t});\n\n\t// Mirror the live value into the field's `filled` state. A non-empty\n\t// external value (or a non-empty element value) marks filled; an explicit\n\t// empty string clears it.\n\tcreateEffect(\n\t\t() => readOption(options.value),\n\t\t(externalValue) => {\n\t\t\tconst hasExternal = externalValue != null;\n\t\t\tconst input = field.validation.inputRef.current;\n\t\t\tif (input?.value || (hasExternal && externalValue !== \"\")) {\n\t\t\t\tfield.setFilled(true);\n\t\t\t} else if (hasExternal && externalValue === \"\") {\n\t\t\t\tfield.setFilled(false);\n\t\t\t}\n\t\t},\n\t);\n\n\tconst ariaLabelledBy = useAriaLabelledBy();\n\n\tconst ariaDescribedBy = createMemo(\n\t\t(): string | undefined => {\n\t\t\tconst ids = messages.getMessageIds();\n\t\t\tif (ids.length === 0) return undefined;\n\t\t\treturn ids.join(\" \");\n\t\t},\n\t\t{ name: \"input.ariaDescribedBy\" },\n\t);\n\n\tconst controlInternal = {\n\t\tget id() {\n\t\t\treturn id;\n\t\t},\n\t\tget disabled() {\n\t\t\treturn disabled();\n\t\t},\n\t\tget name() {\n\t\t\treturn field.name() ?? readOption(options.name);\n\t\t},\n\t\tget \"aria-labelledby\"() {\n\t\t\treturn ariaLabelledBy() ?? \"\";\n\t\t},\n\t\tget \"aria-describedby\"() {\n\t\t\treturn ariaDescribedBy() ?? \"\";\n\t\t},\n\t\tget \"data-disabled\"(): \"\" | undefined {\n\t\t\treturn disabled() ? \"\" : undefined;\n\t\t},\n\t\tonFocus: () => {\n\t\t\tfield.setFocused(true);\n\t\t},\n\t\tonBlur: (event: FocusEvent & { currentTarget: HTMLInputElement }) => {\n\t\t\tfield.setTouched(true);\n\t\t\tfield.setFocused(false);\n\t\t\tif (field.validationMode() === \"onBlur\") {\n\t\t\t\tvoid commit(event.currentTarget.value);\n\t\t\t}\n\t\t},\n\t\tonInput: (event: InputEvent & { currentTarget: HTMLInputElement }) => {\n\t\t\tconst value = event.currentTarget.value;\n\t\t\tfield.setDirty(value !== field.validityData().initialValue);\n\t\t\tfield.setFilled(value !== \"\");\n\t\t},\n\t\tonKeyDown: (event: KeyboardEvent & { currentTarget: HTMLInputElement }) => {\n\t\t\tif (event.currentTarget.tagName === \"INPUT\" && event.key === \"Enter\") {\n\t\t\t\tfield.setTouched(true);\n\t\t\t\tvoid commit(event.currentTarget.value);\n\t\t\t}\n\t\t},\n\t};\n\n\t// `getInputValidationProps()` is built from getters that re-read field\n\t// state, so materialize the bag once and merge it — the keys stay\n\t// reactive through `mergeRootProps`.\n\tconst validationProps = getInputValidationProps();\n\n\tconst control = <U extends object | undefined>(userProps?: U) => {\n\t\tlet merged: Record<string, unknown> = mergeRootProps(\n\t\t\tcontrolInternal,\n\t\t\tfieldStateAttrs(state),\n\t\t);\n\t\tmerged = mergeRootProps(merged, validationProps);\n\t\tmerged = mergeRootProps(merged, userProps);\n\t\treturn merged as InputControlSlotProps & (U extends object ? U : object);\n\t};\n\n\tconst bindControl = (el: HTMLInputElement | null): void => {\n\t\tinputRef.current = el;\n\t};\n\n\tconst controlRef = (): ((el: HTMLInputElement | null) => void) => {\n\t\tconst baseDirective = makeSlotRefDirective(\n\t\t\t() => control() as Record<string, unknown>,\n\t\t);\n\t\treturn (el: HTMLInputElement | null): void => {\n\t\t\tbindControl(el);\n\t\t\tbaseDirective(el);\n\t\t};\n\t};\n\n\tconst api: InputApi = {\n\t\tdisabled,\n\t\tstate,\n\t\tid,\n\t\tcontrol,\n\t\tbindControl,\n\t\tcontrolRef,\n\t};\n\t(api as InputApi & Snapshottable)[SNAPSHOT_KEYS] = INPUT_SNAPSHOT_KEYS;\n\treturn api;\n}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