{"ast":null,"code":"import _defineProperty from \"@babel/runtime/helpers/defineProperty\";\nfunction ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }\nfunction _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }\nimport { filterDOMProps as $kOq5K$filterDOMProps, useFormReset as $kOq5K$useFormReset, mergeProps as $kOq5K$mergeProps, useEffectEvent as $kOq5K$useEffectEvent } from \"@react-aria/utils\";\nimport { useField as $kOq5K$useField } from \"@react-aria/label\";\nimport { useFocusable as $kOq5K$useFocusable } from \"@react-aria/focus\";\nimport { useEffect as $kOq5K$useEffect, useRef as $kOq5K$useRef } from \"react\";\nfunction $2d73ec29415bd339$export$712718f7aec83d5(props, ref) {\n  var _props$inputElementTy = props.inputElementType,\n    inputElementType = _props$inputElementTy === void 0 ? \"input\" : _props$inputElementTy,\n    _props$isDisabled = props.isDisabled,\n    isDisabled = _props$isDisabled === void 0 ? false : _props$isDisabled,\n    _props$isRequired = props.isRequired,\n    isRequired = _props$isRequired === void 0 ? false : _props$isRequired,\n    _props$isReadOnly = props.isReadOnly,\n    isReadOnly = _props$isReadOnly === void 0 ? false : _props$isReadOnly,\n    validationState = props.validationState,\n    _props$type = props.type,\n    type = _props$type === void 0 ? \"text\" : _props$type,\n    value = props.value,\n    defaultValue = props.defaultValue,\n    _props$onChange = props.onChange,\n    _onChange = _props$onChange === void 0 ? function () {} : _props$onChange;\n  var _ref2 = (0, $kOq5K$useFocusable)(props, ref),\n    focusableProps = _ref2.focusableProps;\n  var _ref3 = (0, $kOq5K$useField)(props),\n    labelProps = _ref3.labelProps,\n    fieldProps = _ref3.fieldProps,\n    descriptionProps = _ref3.descriptionProps,\n    errorMessageProps = _ref3.errorMessageProps;\n  var domProps = (0, $kOq5K$filterDOMProps)(props, {\n    labelable: true\n  });\n  var inputOnlyProps = {\n    type: type,\n    pattern: props.pattern\n  };\n  var _ref;\n  (0, $kOq5K$useFormReset)(ref, (_ref = value !== null && value !== void 0 ? value : defaultValue) !== null && _ref !== void 0 ? _ref : \"\", _onChange);\n  return {\n    labelProps: labelProps,\n    inputProps: (0, $kOq5K$mergeProps)(domProps, inputElementType === \"input\" && inputOnlyProps, _objectSpread(_objectSpread({\n      disabled: isDisabled,\n      readOnly: isReadOnly,\n      \"aria-required\": isRequired || undefined,\n      \"aria-invalid\": validationState === \"invalid\" || undefined,\n      \"aria-errormessage\": props[\"aria-errormessage\"],\n      \"aria-activedescendant\": props[\"aria-activedescendant\"],\n      \"aria-autocomplete\": props[\"aria-autocomplete\"],\n      \"aria-haspopup\": props[\"aria-haspopup\"],\n      value: props.value,\n      defaultValue: props.value ? undefined : props.defaultValue,\n      onChange: function onChange(e) {\n        return _onChange(e.target.value);\n      },\n      autoComplete: props.autoComplete,\n      maxLength: props.maxLength,\n      minLength: props.minLength,\n      name: props.name,\n      placeholder: props.placeholder,\n      inputMode: props.inputMode,\n      onCopy: props.onCopy,\n      onCut: props.onCut,\n      onPaste: props.onPaste,\n      onCompositionEnd: props.onCompositionEnd,\n      onCompositionStart: props.onCompositionStart,\n      onCompositionUpdate: props.onCompositionUpdate,\n      onSelect: props.onSelect,\n      onBeforeInput: props.onBeforeInput,\n      onInput: props.onInput\n    }, focusableProps), fieldProps)),\n    descriptionProps: descriptionProps,\n    errorMessageProps: errorMessageProps\n  };\n}\nfunction $d841c8010a73d545$var$supportsNativeBeforeInputEvent() {\n  return typeof window !== \"undefined\" && window.InputEvent && typeof InputEvent.prototype.getTargetRanges === \"function\";\n}\nfunction $d841c8010a73d545$export$4f384c9210e583c3(props, state, inputRef) {\n  var onBeforeInputFallback = (0, $kOq5K$useEffectEvent)(function (e) {\n    var input = inputRef.current;\n    var nextValue;\n    switch (e.inputType) {\n      case \"historyUndo\":\n      case \"historyRedo\":\n        return;\n      case \"deleteContent\":\n      case \"deleteByCut\":\n      case \"deleteByDrag\":\n        nextValue = input.value.slice(0, input.selectionStart) + input.value.slice(input.selectionEnd);\n        break;\n      case \"deleteContentForward\":\n        nextValue = input.selectionEnd === input.selectionStart ? input.value.slice(0, input.selectionStart) + input.value.slice(input.selectionEnd + 1) : input.value.slice(0, input.selectionStart) + input.value.slice(input.selectionEnd);\n        break;\n      case \"deleteContentBackward\":\n        nextValue = input.selectionEnd === input.selectionStart ? input.value.slice(0, input.selectionStart - 1) + input.value.slice(input.selectionStart) : input.value.slice(0, input.selectionStart) + input.value.slice(input.selectionEnd);\n        break;\n      case \"deleteSoftLineBackward\":\n      case \"deleteHardLineBackward\":\n        nextValue = input.value.slice(input.selectionStart);\n        break;\n      default:\n        if (e.data != null) nextValue = input.value.slice(0, input.selectionStart) + e.data + input.value.slice(input.selectionEnd);\n        break;\n    }\n    if (nextValue == null || !state.validate(nextValue)) e.preventDefault();\n  });\n  (0, $kOq5K$useEffect)(function () {\n    if (!$d841c8010a73d545$var$supportsNativeBeforeInputEvent()) return;\n    var input = inputRef.current;\n    input.addEventListener(\"beforeinput\", onBeforeInputFallback, false);\n    return function () {\n      input.removeEventListener(\"beforeinput\", onBeforeInputFallback, false);\n    };\n  }, [inputRef, onBeforeInputFallback]);\n  var onBeforeInput = !$d841c8010a73d545$var$supportsNativeBeforeInputEvent() ? function (e) {\n    var nextValue = e.target.value.slice(0, e.target.selectionStart) + e.data + e.target.value.slice(e.target.selectionEnd);\n    if (!state.validate(nextValue)) e.preventDefault();\n  } : null;\n  var _ref4 = (0, $2d73ec29415bd339$export$712718f7aec83d5)(props, inputRef),\n    labelProps = _ref4.labelProps,\n    textFieldProps = _ref4.inputProps,\n    descriptionProps = _ref4.descriptionProps,\n    errorMessageProps = _ref4.errorMessageProps;\n  var compositionStartState = (0, $kOq5K$useRef)(null);\n  return {\n    inputProps: (0, $kOq5K$mergeProps)(textFieldProps, {\n      onBeforeInput: onBeforeInput,\n      onCompositionStart: function onCompositionStart() {\n        var _inputRef$current = inputRef.current,\n          value = _inputRef$current.value,\n          selectionStart = _inputRef$current.selectionStart,\n          selectionEnd = _inputRef$current.selectionEnd;\n        compositionStartState.current = {\n          value: value,\n          selectionStart: selectionStart,\n          selectionEnd: selectionEnd\n        };\n      },\n      onCompositionEnd: function onCompositionEnd() {\n        if (!state.validate(inputRef.current.value)) {\n          var _compositionStartStat = compositionStartState.current,\n            value = _compositionStartStat.value,\n            selectionStart = _compositionStartStat.selectionStart,\n            selectionEnd = _compositionStartStat.selectionEnd;\n          inputRef.current.value = value;\n          inputRef.current.setSelectionRange(selectionStart, selectionEnd);\n          state.setInputValue(value);\n        }\n      }\n    }),\n    labelProps: labelProps,\n    descriptionProps: descriptionProps,\n    errorMessageProps: errorMessageProps\n  };\n}\nexport { $2d73ec29415bd339$export$712718f7aec83d5 as useTextField, $d841c8010a73d545$export$4f384c9210e583c3 as useFormattedTextField };","map":{"version":3,"sources":["packages/@react-aria/textfield/src/useTextField.ts","packages/@react-aria/textfield/src/useFormattedTextField.ts"],"names":[],"mappings":";;;;;;;AAuGO,SAAS,wCAAA,CACd,KAA8B,EAC9B,GAA0B,EAAA;EAE1B,IAAA,qBAAA,GAUsD,KAAA,CAVlD,gBAAA;IACF,gBAAA,GAAA,qBAAA,cAAmB,OAAA,GAAA,qBAAA;IAAA,iBAAA,GASiC,KAAA,CATjC,UAAA;IACnB,UAAA,GAAA,iBAAA,cAAa,KAAA,GAAA,iBAAA;IAAA,iBAAA,GAQuC,KAAA,CARvC,UAAA;IACb,UAAA,GAAA,iBAAA,cAAa,KAAA,GAAA,iBAAA;IAAA,iBAAA,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,iBAAA,CAAkB,cAAA,EAAgB,YAAA,CAAA;UACnD,KAAA,CAAM,aAAA,CAAc,KAAA,CAAA;QACtB;MACF;IACF,CAAA,CAAA;gBAEF,UAAA;sBACA,gBAAA;uBACA;EACF,CAAA;AACF","sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaTextFieldProps} from '@react-types/textfield';\nimport {\n  ChangeEvent,\n  DOMFactory,\n  HTMLAttributes,\n  LabelHTMLAttributes,\n  ReactDOM,\n  RefObject\n} from 'react';\nimport {DOMAttributes} from '@react-types/shared';\nimport {filterDOMProps, mergeProps, useFormReset} from '@react-aria/utils';\nimport {useField} from '@react-aria/label';\nimport {useFocusable} from '@react-aria/focus';\n\n/**\n * A map of HTML element names and their interface types.\n * For example `'a'` -> `HTMLAnchorElement`.\n */\ntype IntrinsicHTMLElements = {\n  [K in keyof IntrinsicHTMLAttributes]: IntrinsicHTMLAttributes[K] extends HTMLAttributes<infer T> ? T : never\n};\n\n/**\n * A map of HTML element names and their attribute interface types.\n * For example `'a'` -> `AnchorHTMLAttributes<HTMLAnchorElement>`.\n */\ntype IntrinsicHTMLAttributes = {\n  [K in keyof ReactDOM]: ReactDOM[K] extends DOMFactory<infer T, any> ? T : never\n};\n\ntype DefaultElementType = 'input';\n\n/**\n * The intrinsic HTML element names that `useTextField` supports; e.g. `input`,\n * `textarea`.\n */\ntype TextFieldIntrinsicElements = keyof Pick<IntrinsicHTMLElements, 'input' | 'textarea'>;\n\n/**\n * The HTML element interfaces that `useTextField` supports based on what is\n * defined for `TextFieldIntrinsicElements`; e.g. `HTMLInputElement`,\n * `HTMLTextAreaElement`.\n */\ntype TextFieldHTMLElementType = Pick<IntrinsicHTMLElements, TextFieldIntrinsicElements>;\n\n/**\n * The HTML attributes interfaces that `useTextField` supports based on what\n * is defined for `TextFieldIntrinsicElements`; e.g. `InputHTMLAttributes`,\n * `TextareaHTMLAttributes`.\n */\ntype TextFieldHTMLAttributesType = Pick<IntrinsicHTMLAttributes, TextFieldIntrinsicElements>;\n\n/**\n * The type of `inputProps` returned by `useTextField`; e.g. `InputHTMLAttributes`,\n * `TextareaHTMLAttributes`.\n */\ntype TextFieldInputProps<T extends TextFieldIntrinsicElements> = TextFieldHTMLAttributesType[T];\n\nexport interface AriaTextFieldOptions<T extends TextFieldIntrinsicElements> extends AriaTextFieldProps {\n  /**\n   * The HTML element used to render the input, e.g. 'input', or 'textarea'.\n   * It determines whether certain HTML attributes will be included in `inputProps`.\n   * For example, [`type`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attr-type).\n   * @default 'input'\n   */\n  inputElementType?: T\n}\n\n/**\n * The type of `ref` object that can be passed to `useTextField` based on the given\n * intrinsic HTML element name; e.g.`RefObject<HTMLInputElement>`,\n * `RefObject<HTMLTextAreaElement>`.\n */\ntype TextFieldRefObject<T extends TextFieldIntrinsicElements> = RefObject<TextFieldHTMLElementType[T]>;\n\nexport interface TextFieldAria<T extends TextFieldIntrinsicElements = DefaultElementType> {\n  /** Props for the input element. */\n  inputProps: TextFieldInputProps<T>,\n  /** Props for the text field's visible label element, if any. */\n  labelProps: DOMAttributes | LabelHTMLAttributes<HTMLLabelElement>,\n  /** Props for the text field's description element, if any. */\n  descriptionProps: DOMAttributes,\n  /** Props for the text field's error message element, if any. */\n  errorMessageProps: DOMAttributes\n}\n\n/**\n * Provides the behavior and accessibility implementation for a text field.\n * @param props - Props for the text field.\n * @param ref - Ref to the HTML input or textarea element.\n */\nexport function useTextField<T extends TextFieldIntrinsicElements = DefaultElementType>(\n  props: AriaTextFieldOptions<T>,\n  ref: TextFieldRefObject<T>\n): TextFieldAria<T> {\n  let {\n    inputElementType = 'input',\n    isDisabled = false,\n    isRequired = false,\n    isReadOnly = false,\n    validationState,\n    type = 'text',\n    value,\n    defaultValue,\n    onChange = () => {}\n  }: AriaTextFieldOptions<TextFieldIntrinsicElements> = props;\n  let {focusableProps} = useFocusable(props, ref);\n  let {labelProps, fieldProps, descriptionProps, errorMessageProps} = useField(props);\n  let domProps = filterDOMProps(props, {labelable: true});\n\n  const inputOnlyProps = {\n    type,\n    pattern: props.pattern\n  };\n\n  useFormReset(ref, value ?? defaultValue ?? '', onChange);\n\n  return {\n    labelProps,\n    inputProps: mergeProps(\n      domProps,\n      inputElementType === 'input' && inputOnlyProps,\n      {\n        disabled: isDisabled,\n        readOnly: isReadOnly,\n        'aria-required': isRequired || undefined,\n        'aria-invalid': validationState === 'invalid' || undefined,\n        'aria-errormessage': props['aria-errormessage'],\n        'aria-activedescendant': props['aria-activedescendant'],\n        'aria-autocomplete': props['aria-autocomplete'],\n        'aria-haspopup': props['aria-haspopup'],\n        value: props.value,\n        defaultValue: props.value ? undefined : props.defaultValue,\n        onChange: (e: ChangeEvent<HTMLInputElement>) => onChange(e.target.value),\n        autoComplete: props.autoComplete,\n        maxLength: props.maxLength,\n        minLength: props.minLength,\n        name: props.name,\n        placeholder: props.placeholder,\n        inputMode: props.inputMode,\n\n        // Clipboard events\n        onCopy: props.onCopy,\n        onCut: props.onCut,\n        onPaste: props.onPaste,\n\n        // Composition events\n        onCompositionEnd: props.onCompositionEnd,\n        onCompositionStart: props.onCompositionStart,\n        onCompositionUpdate: props.onCompositionUpdate,\n\n        // Selection events\n        onSelect: props.onSelect,\n\n        // Input events\n        onBeforeInput: props.onBeforeInput,\n        onInput: props.onInput,\n        ...focusableProps,\n        ...fieldProps\n      }\n    ),\n    descriptionProps,\n    errorMessageProps\n  };\n}\n","/*\n * Copyright 2021 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaTextFieldProps} from '@react-types/textfield';\nimport {mergeProps, useEffectEvent} from '@react-aria/utils';\nimport {RefObject, useEffect, useRef} from 'react';\nimport {TextFieldAria, useTextField} from './useTextField';\n\ninterface FormattedTextFieldState {\n  validate: (val: string) => boolean,\n  setInputValue: (val: string) => void\n}\n\n\nfunction supportsNativeBeforeInputEvent() {\n  return typeof window !== 'undefined' &&\n    window.InputEvent &&\n    // @ts-ignore\n    typeof InputEvent.prototype.getTargetRanges === 'function';\n}\n\nexport function useFormattedTextField(props: AriaTextFieldProps, state: FormattedTextFieldState, inputRef: RefObject<HTMLInputElement>): TextFieldAria {\n  // All browsers implement the 'beforeinput' event natively except Firefox\n  // (currently behind a flag as of Firefox 84). React's polyfill does not\n  // run in all cases that the native event fires, e.g. when deleting text.\n  // Use the native event if available so that we can prevent invalid deletions.\n  // We do not attempt to polyfill this in Firefox since it would be very complicated,\n  // the benefit of doing so is fairly minor, and it's going to be natively supported soon.\n  let onBeforeInputFallback = useEffectEvent((e: InputEvent) => {\n    let input = inputRef.current;\n\n    // Compute the next value of the input if the event is allowed to proceed.\n    // See https://www.w3.org/TR/input-events-2/#interface-InputEvent-Attributes for a full list of input types.\n    let nextValue: string;\n    switch (e.inputType) {\n      case 'historyUndo':\n      case 'historyRedo':\n        // Explicitly allow undo/redo. e.data is null in this case, but there's no need to validate,\n        // because presumably the input would have already been validated previously.\n        return;\n      case 'deleteContent':\n      case 'deleteByCut':\n      case 'deleteByDrag':\n        nextValue = input.value.slice(0, input.selectionStart) + input.value.slice(input.selectionEnd);\n        break;\n      case 'deleteContentForward':\n        // This is potentially incorrect, since the browser may actually delete more than a single UTF-16\n        // character. In reality, a full Unicode grapheme cluster consisting of multiple UTF-16 characters\n        // or code points may be deleted. However, in our currently supported locales, there are no such cases.\n        // If we support additional locales in the future, this may need to change.\n        nextValue = input.selectionEnd === input.selectionStart\n          ? input.value.slice(0, input.selectionStart) + input.value.slice(input.selectionEnd + 1)\n          : input.value.slice(0, input.selectionStart) + input.value.slice(input.selectionEnd);\n        break;\n      case 'deleteContentBackward':\n        nextValue = input.selectionEnd === input.selectionStart\n          ? input.value.slice(0, input.selectionStart - 1) + input.value.slice(input.selectionStart)\n          : input.value.slice(0, input.selectionStart) + input.value.slice(input.selectionEnd);\n        break;\n      case 'deleteSoftLineBackward':\n      case 'deleteHardLineBackward':\n        nextValue = input.value.slice(input.selectionStart);\n        break;\n      default:\n        if (e.data != null) {\n          nextValue =\n            input.value.slice(0, input.selectionStart) +\n            e.data +\n            input.value.slice(input.selectionEnd);\n        }\n        break;\n    }\n\n    // If we did not compute a value, or the new value is invalid, prevent the event\n    // so that the browser does not update the input text, move the selection, or add to\n    // the undo/redo stack.\n    if (nextValue == null || !state.validate(nextValue)) {\n      e.preventDefault();\n    }\n  });\n\n  useEffect(() => {\n    if (!supportsNativeBeforeInputEvent()) {\n      return;\n    }\n\n    let input = inputRef.current;\n    input.addEventListener('beforeinput', onBeforeInputFallback, false);\n    return () => {\n      input.removeEventListener('beforeinput', onBeforeInputFallback, false);\n    };\n  }, [inputRef, onBeforeInputFallback]);\n\n  let onBeforeInput = !supportsNativeBeforeInputEvent()\n    ? e => {\n      let nextValue =\n        e.target.value.slice(0, e.target.selectionStart) +\n        e.data +\n        e.target.value.slice(e.target.selectionEnd);\n\n      if (!state.validate(nextValue)) {\n        e.preventDefault();\n      }\n    }\n    : null;\n\n  let {labelProps, inputProps: textFieldProps, descriptionProps, errorMessageProps} = useTextField(props, inputRef);\n\n  let compositionStartState = useRef(null);\n  return {\n    inputProps: mergeProps(\n      textFieldProps,\n      {\n        onBeforeInput,\n        onCompositionStart() {\n          // Chrome does not implement Input Events Level 2, which specifies the insertFromComposition\n          // and deleteByComposition inputType values for the beforeinput event. These are meant to occur\n          // at the end of a composition (e.g. Pinyin IME, Android auto correct, etc.), and crucially, are\n          // cancelable. The insertCompositionText and deleteCompositionText input types are not cancelable,\n          // nor would we want to cancel them because the input from the user is incomplete at that point.\n          // In Safari, insertFromComposition/deleteFromComposition will fire, however, allowing us to cancel\n          // the final composition result if it is invalid. As a fallback for Chrome and Firefox, which either\n          // don't support Input Events Level 2, or beforeinput at all, we store the state of the input when\n          // the compositionstart event fires, and undo the changes in compositionend (below) if it is invalid.\n          // Unfortunately, this messes up the undo/redo stack, but until insertFromComposition/deleteByComposition\n          // are implemented, there is no other way to prevent composed input.\n          // See https://bugs.chromium.org/p/chromium/issues/detail?id=1022204\n          let {value, selectionStart, selectionEnd} = inputRef.current;\n          compositionStartState.current = {value, selectionStart, selectionEnd};\n        },\n        onCompositionEnd() {\n          if (!state.validate(inputRef.current.value)) {\n            // Restore the input value in the DOM immediately so we can synchronously update the selection position.\n            // But also update the value in React state as well so it is correct for future updates.\n            let {value, selectionStart, selectionEnd} = compositionStartState.current;\n            inputRef.current.value = value;\n            inputRef.current.setSelectionRange(selectionStart, selectionEnd);\n            state.setInputValue(value);\n          }\n        }\n      }\n    ),\n    labelProps,\n    descriptionProps,\n    errorMessageProps\n  };\n}\n"]},"metadata":{},"sourceType":"module"}