import { map } from "rxjs"; import { inputPipe } from '../utils/input-pipe'; import { autoValue } from "../utils/auto-value"; /** * An Event Operator that emits the value of the underlying <input> element into a target observer * * @category Event Adapter Operators * @returns OperatorFunction * * For simple, one-step input pipelines, see the {@link Cut | Cut (uppercase)} Event Adapter * * ## Examples * * ### ValidInfo * * Create a custom Event Operator that feeds a stream with validated data, once a custom validator passes * * ```ts * import { Subject, filter } from 'rxjs'; * import { rml, inputPipe, value } from 'rimmel'; * * const isValid = filter((s: string) => IS_VALID_IMPL(s) ); * const ValidInfo = inputPipe(value, isValid); * * const Component = () => { * const stream = new Subject(); * * return rml` * * [ ${stream} ] * `; * }; * ``` */ export const value = map((e: Event) => autoValue(e.target)); /** * An Event Adapter emitting the value of the underlying <input> element instead of a regular DOM Event object * * ## Example * Copy the value of a text box on change * * ```ts * import { Subject } from 'rxjs'; * import { rml, Value } from 'rimmel'; * * const Component = () => { * const stream = new Subject(); * * return rml` * * [ ${stream} ] * `; * }; * ``` */ export const Value = inputPipe( value ); /** * An Event Adapter emitting the type-detected value of the underlying <input> element instead of a regular DOM Event object * * ## Example * Copy the value of a text box on change * * ```ts * import { Subject } from 'rxjs'; * import { rml, AutoValue } from 'rimmel'; * * const Component = () => { * const stream = new Subject; * * return rml` * * [ ${stream} ] * `; * }; * ``` */ export const AutoValue = Value; /** * An Event Source Operator emitting the value of the underlying <input> element instead of a regular DOM Event object * @returns OperatorFunction */ export const valueAsString = map((e: Event) => (e.target).value); /** * An Event Adapter emitting the value of the underlying <input> element instead of a regular DOM Event object * @param handler A handler function or observer to send events to * @returns EventSource */ export const ValueAsString = inputPipe( valueAsString ); /** * An Event Source Operator for valueAsNumber * Emits the numeric value of the underlying <input type="number"> or <input type="range"> instead of a regular DOM Event object * @returns OperatorFunction */ export const valueAsNumber = map((e: Event) => (e.target).valueAsNumber); /** * An Event Source for valueAsNumber * Emits the numeric value of the underlying <input type="number"> or <input type="range"> instead of a regular DOM Event object * @returns EventSource */ export const ValueAsNumber = inputPipe( valueAsNumber, ); /** * An Event Source Operator for valueAsDate * Emits the numeric value of the underlying `` instead of a regular DOM Event object * @returns OperatorFunction */ export const valueAsDate = map((e: Event) => (e.target).valueAsDate); /** * An Event Adapter for valueAsDate * Emits the numeric value of the underlying `` instead of a regular DOM Event object * @returns EventSource */ export const ValueAsDate = inputPipe( valueAsDate ); export const asValue = value; export const AsValue = Value; export const asStringValue = valueAsString; export const AsStringValue = ValueAsString; export const asNumericValue = valueAsNumber; export const AsNumericValue = ValueAsNumber; export const asDateValue = valueAsDate; export const AsDateValue = ValueAsDate;