@react-aria/textfield 3.12.0 → 3.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/import.mjs CHANGED
@@ -27,9 +27,9 @@ import {useEffect as $kOq5K$useEffect, useRef as $kOq5K$useRef} from "react";
27
27
 
28
28
 
29
29
  function $2d73ec29415bd339$export$712718f7aec83d5(props, ref) {
30
- let { inputElementType: inputElementType = "input" , isDisabled: isDisabled = false , isRequired: isRequired = false , isReadOnly: isReadOnly = false , validationState: validationState , isInvalid: isInvalid = false , type: type = "text" , value: value , defaultValue: defaultValue , onChange: onChange = ()=>{} } = props;
31
- let { focusableProps: focusableProps } = (0, $kOq5K$useFocusable)(props, ref);
32
- let { labelProps: labelProps , fieldProps: fieldProps , descriptionProps: descriptionProps , errorMessageProps: errorMessageProps } = (0, $kOq5K$useField)(props);
30
+ let { inputElementType: inputElementType = "input", isDisabled: isDisabled = false, isRequired: isRequired = false, isReadOnly: isReadOnly = false, validationState: validationState, isInvalid: isInvalid = false, type: type = "text", value: value, defaultValue: defaultValue, onChange: onChange = ()=>{} } = props;
31
+ let { focusableProps: focusableProps } = (0, $kOq5K$useFocusable)(props, ref);
32
+ let { labelProps: labelProps, fieldProps: fieldProps, descriptionProps: descriptionProps, errorMessageProps: errorMessageProps } = (0, $kOq5K$useField)(props);
33
33
  let domProps = (0, $kOq5K$filterDOMProps)(props, {
34
34
  labelable: true
35
35
  });
@@ -159,7 +159,7 @@ function $d841c8010a73d545$export$4f384c9210e583c3(props, state, inputRef) {
159
159
  let nextValue = e.target.value.slice(0, e.target.selectionStart) + e.data + e.target.value.slice(e.target.selectionEnd);
160
160
  if (!state.validate(nextValue)) e.preventDefault();
161
161
  } : null;
162
- let { labelProps: labelProps , inputProps: textFieldProps , descriptionProps: descriptionProps , errorMessageProps: errorMessageProps } = (0, $2d73ec29415bd339$export$712718f7aec83d5)(props, inputRef);
162
+ let { labelProps: labelProps, inputProps: textFieldProps, descriptionProps: descriptionProps, errorMessageProps: errorMessageProps } = (0, $2d73ec29415bd339$export$712718f7aec83d5)(props, inputRef);
163
163
  let compositionStartState = (0, $kOq5K$useRef)(null);
164
164
  return {
165
165
  inputProps: (0, $kOq5K$mergeProps)(textFieldProps, {
@@ -177,7 +177,7 @@ function $d841c8010a73d545$export$4f384c9210e583c3(props, state, inputRef) {
177
177
  // Unfortunately, this messes up the undo/redo stack, but until insertFromComposition/deleteByComposition
178
178
  // are implemented, there is no other way to prevent composed input.
179
179
  // See https://bugs.chromium.org/p/chromium/issues/detail?id=1022204
180
- let { value: value , selectionStart: selectionStart , selectionEnd: selectionEnd } = inputRef.current;
180
+ let { value: value, selectionStart: selectionStart, selectionEnd: selectionEnd } = inputRef.current;
181
181
  compositionStartState.current = {
182
182
  value: value,
183
183
  selectionStart: selectionStart,
@@ -188,7 +188,7 @@ function $d841c8010a73d545$export$4f384c9210e583c3(props, state, inputRef) {
188
188
  if (!state.validate(inputRef.current.value)) {
189
189
  // Restore the input value in the DOM immediately so we can synchronously update the selection position.
190
190
  // But also update the value in React state as well so it is correct for future updates.
191
- let { value: value , selectionStart: selectionStart , selectionEnd: selectionEnd } = compositionStartState.current;
191
+ let { value: value, selectionStart: selectionStart, selectionEnd: selectionEnd } = compositionStartState.current;
192
192
  inputRef.current.value = value;
193
193
  inputRef.current.setSelectionRange(selectionStart, selectionEnd);
194
194
  state.setInputValue(value);
package/dist/main.js CHANGED
@@ -33,9 +33,9 @@ $parcel$export(module.exports, "useFormattedTextField", () => $56b68c3dab9bf16c$
33
33
 
34
34
 
35
35
  function $9076f978e02df845$export$712718f7aec83d5(props, ref) {
36
- let { inputElementType: inputElementType = "input" , isDisabled: isDisabled = false , isRequired: isRequired = false , isReadOnly: isReadOnly = false , validationState: validationState , isInvalid: isInvalid = false , type: type = "text" , value: value , defaultValue: defaultValue , onChange: onChange = ()=>{} } = props;
37
- let { focusableProps: focusableProps } = (0, $iITAC$reactariafocus.useFocusable)(props, ref);
38
- let { labelProps: labelProps , fieldProps: fieldProps , descriptionProps: descriptionProps , errorMessageProps: errorMessageProps } = (0, $iITAC$reactarialabel.useField)(props);
36
+ let { inputElementType: inputElementType = "input", isDisabled: isDisabled = false, isRequired: isRequired = false, isReadOnly: isReadOnly = false, validationState: validationState, isInvalid: isInvalid = false, type: type = "text", value: value, defaultValue: defaultValue, onChange: onChange = ()=>{} } = props;
37
+ let { focusableProps: focusableProps } = (0, $iITAC$reactariafocus.useFocusable)(props, ref);
38
+ let { labelProps: labelProps, fieldProps: fieldProps, descriptionProps: descriptionProps, errorMessageProps: errorMessageProps } = (0, $iITAC$reactarialabel.useField)(props);
39
39
  let domProps = (0, $iITAC$reactariautils.filterDOMProps)(props, {
40
40
  labelable: true
41
41
  });
@@ -165,7 +165,7 @@ function $56b68c3dab9bf16c$export$4f384c9210e583c3(props, state, inputRef) {
165
165
  let nextValue = e.target.value.slice(0, e.target.selectionStart) + e.data + e.target.value.slice(e.target.selectionEnd);
166
166
  if (!state.validate(nextValue)) e.preventDefault();
167
167
  } : null;
168
- let { labelProps: labelProps , inputProps: textFieldProps , descriptionProps: descriptionProps , errorMessageProps: errorMessageProps } = (0, $9076f978e02df845$export$712718f7aec83d5)(props, inputRef);
168
+ let { labelProps: labelProps, inputProps: textFieldProps, descriptionProps: descriptionProps, errorMessageProps: errorMessageProps } = (0, $9076f978e02df845$export$712718f7aec83d5)(props, inputRef);
169
169
  let compositionStartState = (0, $iITAC$react.useRef)(null);
170
170
  return {
171
171
  inputProps: (0, $iITAC$reactariautils.mergeProps)(textFieldProps, {
@@ -183,7 +183,7 @@ function $56b68c3dab9bf16c$export$4f384c9210e583c3(props, state, inputRef) {
183
183
  // Unfortunately, this messes up the undo/redo stack, but until insertFromComposition/deleteByComposition
184
184
  // are implemented, there is no other way to prevent composed input.
185
185
  // See https://bugs.chromium.org/p/chromium/issues/detail?id=1022204
186
- let { value: value , selectionStart: selectionStart , selectionEnd: selectionEnd } = inputRef.current;
186
+ let { value: value, selectionStart: selectionStart, selectionEnd: selectionEnd } = inputRef.current;
187
187
  compositionStartState.current = {
188
188
  value: value,
189
189
  selectionStart: selectionStart,
@@ -194,7 +194,7 @@ function $56b68c3dab9bf16c$export$4f384c9210e583c3(props, state, inputRef) {
194
194
  if (!state.validate(inputRef.current.value)) {
195
195
  // Restore the input value in the DOM immediately so we can synchronously update the selection position.
196
196
  // But also update the value in React state as well so it is correct for future updates.
197
- let { value: value , selectionStart: selectionStart , selectionEnd: selectionEnd } = compositionStartState.current;
197
+ let { value: value, selectionStart: selectionStart, selectionEnd: selectionEnd } = compositionStartState.current;
198
198
  inputRef.current.value = value;
199
199
  inputRef.current.setSelectionRange(selectionStart, selectionEnd);
200
200
  state.setInputValue(value);
package/dist/main.js.map CHANGED
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC;;;AA6FM,SAAS,yCACd,KAA8B,EAC9B,GAA0B;IAE1B,IAAI,oBACF,mBAAmB,sBACnB,aAAa,oBACb,aAAa,oBACb,aAAa,yBACb,gBAAe,aACf,YAAY,cACZ,OAAO,gBACP,MAAK,gBACL,aAAY,YACZ,WAAW,KAAO,IACnB,GAAqD;IACtD,IAAI,kBAAC,eAAc,EAAC,GAAG,CAAA,GAAA,kCAAW,EAAE,OAAO;IAC3C,IAAI,cAAC,WAAU,cAAE,WAAU,oBAAE,iBAAgB,qBAAE,kBAAiB,EAAC,GAAG,CAAA,GAAA,8BAAO,EAAE;IAC7E,IAAI,WAAW,CAAA,GAAA,oCAAa,EAAE,OAAO;QAAC,WAAW;IAAI;IAErD,MAAM,iBAAiB;cACrB;QACA,SAAS,MAAM;IACjB;QAEkB;IAAlB,CAAA,GAAA,kCAAW,EAAE,KAAK,CAAA,OAAA,kBAAA,mBAAA,QAAS,0BAAT,kBAAA,OAAyB,IAAI;IAE/C,OAAO;oBACL;QACA,YAAY,CAAA,GAAA,gCAAS,EACnB,UACA,qBAAqB,WAAW,gBAChC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IAEJ,IAAI,cAAC,WAAU,EAAE,YAAY,eAAc,oBAAE,iBAAgB,qBAAE,kBAAiB,EAAC,GAAG,CAAA,GAAA,wCAAW,EAAE,OAAO;IAExG,IAAI,wBAAwB,CAAA,GAAA,mBAAK,EAAE;IACnC,OAAO;QACL,YAAY,CAAA,GAAA,gCAAS,EACnB,gBACA;2BACE;YACA;gBACE,4FAA4F;gBAC5F,+FAA+F;gBAC/F,gGAAgG;gBAChG,kGAAkG;gBAClG,gGAAgG;gBAChG,mGAAmG;gBACnG,oGAAoG;gBACpG,kGAAkG;gBAClG,qGAAqG;gBACrG,yGAAyG;gBACzG,oEAAoE;gBACpE,oEAAoE;gBACpE,IAAI,SAAC,MAAK,kBAAE,eAAc,gBAAE,aAAY,EAAC,GAAG,SAAS;gBACrD,sBAAsB,UAAU;2BAAC;oCAAO;kCAAgB;gBAAY;YACtE;YACA;gBACE,IAAI,CAAC,MAAM,SAAS,SAAS,QAAQ,QAAQ;oBAC3C,wGAAwG;oBACxG,wFAAwF;oBACxF,IAAI,SAAC,MAAK,kBAAE,eAAc,gBAAE,aAAY,EAAC,GAAG,sBAAsB;oBAClE,SAAS,QAAQ,QAAQ;oBACzB,SAAS,QAAQ,kBAAkB,gBAAgB;oBACnD,MAAM,cAAc;gBACtB;YACF;QACF;oBAEF;0BACA;2BACA;IACF;AACF;","sources":["packages/@react-aria/textfield/src/index.ts","packages/@react-aria/textfield/src/useTextField.ts","packages/@react-aria/textfield/src/useFormattedTextField.ts"],"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 */\nexport type {TextFieldAria} from './useTextField';\nexport {useTextField} from './useTextField';\nexport {useFormattedTextField} from './useFormattedTextField';\nexport type {AriaTextFieldOptions} from './useTextField';\nexport type {AriaTextFieldProps} from '@react-types/textfield';\n","/*\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 isInvalid = false,\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': isInvalid || 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"],"names":[],"version":3,"file":"main.js.map"}
1
+ {"mappings":";;;;;;;;;;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC;;;AA6FM,SAAS,yCACd,KAA8B,EAC9B,GAA0B;IAE1B,IAAI,oBACF,mBAAmB,qBACnB,aAAa,mBACb,aAAa,mBACb,aAAa,wBACb,eAAe,aACf,YAAY,aACZ,OAAO,eACP,KAAK,gBACL,YAAY,YACZ,WAAW,KAAO,GACnB,GAAqD;IACtD,IAAI,kBAAC,cAAc,EAAC,GAAG,CAAA,GAAA,kCAAW,EAAE,OAAO;IAC3C,IAAI,cAAC,UAAU,cAAE,UAAU,oBAAE,gBAAgB,qBAAE,iBAAiB,EAAC,GAAG,CAAA,GAAA,8BAAO,EAAE;IAC7E,IAAI,WAAW,CAAA,GAAA,oCAAa,EAAE,OAAO;QAAC,WAAW;IAAI;IAErD,MAAM,iBAAiB;cACrB;QACA,SAAS,MAAM;IACjB;QAEkB;IAAlB,CAAA,GAAA,kCAAW,EAAE,KAAK,CAAA,OAAA,kBAAA,mBAAA,QAAS,0B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ACjC,EAAE,OACF,EAAE,OAAO,MAAM,MAAM,EAAE,OAAO;QAEhC,IAAI,CAAC,MAAM,SAAS,YAClB,EAAE;IAEN,IACE;IAEJ,IAAI,cAAC,UAAU,EAAE,YAAY,cAAc,oBAAE,gBAAgB,qBAAE,iBAAiB,EAAC,GAAG,CAAA,GAAA,wCAAW,EAAE,OAAO;IAExG,IAAI,wBAAwB,CAAA,GAAA,mBAAK,EAAE;IACnC,OAAO;QACL,YAAY,CAAA,GAAA,gCAAS,EACnB,gBACA;2BACE;YACA;gBACE,4FAA4F;gBAC5F,+FAA+F;gBAC/F,gGAAgG;gBAChG,kGAAkG;gBAClG,gGAAgG;gBAChG,mGAAmG;gBACnG,oGAAoG;gBACpG,kGAAkG;gBAClG,qGAAqG;gBACrG,yGAAyG;gBACzG,oEAAoE;gBACpE,oEAAoE;gBACpE,IAAI,SAAC,KAAK,kBAAE,cAAc,gBAAE,YAAY,EAAC,GAAG,SAAS;gBACrD,sBAAsB,UAAU;2BAAC;oCAAO;kCAAgB;gBAAY;YACtE;YACA;gBACE,IAAI,CAAC,MAAM,SAAS,SAAS,QAAQ,QAAQ;oBAC3C,wGAAwG;oBACxG,wFAAwF;oBACxF,IAAI,SAAC,KAAK,kBAAE,cAAc,gBAAE,YAAY,EAAC,GAAG,sBAAsB;oBAClE,SAAS,QAAQ,QAAQ;oBACzB,SAAS,QAAQ,kBAAkB,gBAAgB;oBACnD,MAAM,cAAc;gBACtB;YACF;QACF;oBAEF;0BACA;2BACA;IACF;AACF;","sources":["packages/@react-aria/textfield/src/index.ts","packages/@react-aria/textfield/src/useTextField.ts","packages/@react-aria/textfield/src/useFormattedTextField.ts"],"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 */\nexport type {TextFieldAria} from './useTextField';\nexport {useTextField} from './useTextField';\nexport {useFormattedTextField} from './useFormattedTextField';\nexport type {AriaTextFieldOptions} from './useTextField';\nexport type {AriaTextFieldProps} from '@react-types/textfield';\n","/*\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 isInvalid = false,\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': isInvalid || 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"],"names":[],"version":3,"file":"main.js.map"}
package/dist/module.js CHANGED
@@ -27,9 +27,9 @@ import {useEffect as $kOq5K$useEffect, useRef as $kOq5K$useRef} from "react";
27
27
 
28
28
 
29
29
  function $2d73ec29415bd339$export$712718f7aec83d5(props, ref) {
30
- let { inputElementType: inputElementType = "input" , isDisabled: isDisabled = false , isRequired: isRequired = false , isReadOnly: isReadOnly = false , validationState: validationState , isInvalid: isInvalid = false , type: type = "text" , value: value , defaultValue: defaultValue , onChange: onChange = ()=>{} } = props;
31
- let { focusableProps: focusableProps } = (0, $kOq5K$useFocusable)(props, ref);
32
- let { labelProps: labelProps , fieldProps: fieldProps , descriptionProps: descriptionProps , errorMessageProps: errorMessageProps } = (0, $kOq5K$useField)(props);
30
+ let { inputElementType: inputElementType = "input", isDisabled: isDisabled = false, isRequired: isRequired = false, isReadOnly: isReadOnly = false, validationState: validationState, isInvalid: isInvalid = false, type: type = "text", value: value, defaultValue: defaultValue, onChange: onChange = ()=>{} } = props;
31
+ let { focusableProps: focusableProps } = (0, $kOq5K$useFocusable)(props, ref);
32
+ let { labelProps: labelProps, fieldProps: fieldProps, descriptionProps: descriptionProps, errorMessageProps: errorMessageProps } = (0, $kOq5K$useField)(props);
33
33
  let domProps = (0, $kOq5K$filterDOMProps)(props, {
34
34
  labelable: true
35
35
  });
@@ -159,7 +159,7 @@ function $d841c8010a73d545$export$4f384c9210e583c3(props, state, inputRef) {
159
159
  let nextValue = e.target.value.slice(0, e.target.selectionStart) + e.data + e.target.value.slice(e.target.selectionEnd);
160
160
  if (!state.validate(nextValue)) e.preventDefault();
161
161
  } : null;
162
- let { labelProps: labelProps , inputProps: textFieldProps , descriptionProps: descriptionProps , errorMessageProps: errorMessageProps } = (0, $2d73ec29415bd339$export$712718f7aec83d5)(props, inputRef);
162
+ let { labelProps: labelProps, inputProps: textFieldProps, descriptionProps: descriptionProps, errorMessageProps: errorMessageProps } = (0, $2d73ec29415bd339$export$712718f7aec83d5)(props, inputRef);
163
163
  let compositionStartState = (0, $kOq5K$useRef)(null);
164
164
  return {
165
165
  inputProps: (0, $kOq5K$mergeProps)(textFieldProps, {
@@ -177,7 +177,7 @@ function $d841c8010a73d545$export$4f384c9210e583c3(props, state, inputRef) {
177
177
  // Unfortunately, this messes up the undo/redo stack, but until insertFromComposition/deleteByComposition
178
178
  // are implemented, there is no other way to prevent composed input.
179
179
  // See https://bugs.chromium.org/p/chromium/issues/detail?id=1022204
180
- let { value: value , selectionStart: selectionStart , selectionEnd: selectionEnd } = inputRef.current;
180
+ let { value: value, selectionStart: selectionStart, selectionEnd: selectionEnd } = inputRef.current;
181
181
  compositionStartState.current = {
182
182
  value: value,
183
183
  selectionStart: selectionStart,
@@ -188,7 +188,7 @@ function $d841c8010a73d545$export$4f384c9210e583c3(props, state, inputRef) {
188
188
  if (!state.validate(inputRef.current.value)) {
189
189
  // Restore the input value in the DOM immediately so we can synchronously update the selection position.
190
190
  // But also update the value in React state as well so it is correct for future updates.
191
- let { value: value , selectionStart: selectionStart , selectionEnd: selectionEnd } = compositionStartState.current;
191
+ let { value: value, selectionStart: selectionStart, selectionEnd: selectionEnd } = compositionStartState.current;
192
192
  inputRef.current.value = value;
193
193
  inputRef.current.setSelectionRange(selectionStart, selectionEnd);
194
194
  state.setInputValue(value);
@@ -1 +1 @@
1
- {"mappings":";;;;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC;;;AA6FM,SAAS,yCACd,KAA8B,EAC9B,GAA0B;IAE1B,IAAI,oBACF,mBAAmB,sBACnB,aAAa,oBACb,aAAa,oBACb,aAAa,yBACb,gBAAe,aACf,YAAY,cACZ,OAAO,gBACP,MAAK,gBACL,aAAY,YACZ,WAAW,KAAO,IACnB,GAAqD;IACtD,IAAI,kBAAC,eAAc,EAAC,GAAG,CAAA,GAAA,mBAAW,EAAE,OAAO;IAC3C,IAAI,cAAC,WAAU,cAAE,WAAU,oBAAE,iBAAgB,qBAAE,kBAAiB,EAAC,GAAG,CAAA,GAAA,eAAO,EAAE;IAC7E,IAAI,WAAW,CAAA,GAAA,qBAAa,EAAE,OAAO;QAAC,WAAW;IAAI;IAErD,MAAM,iBAAiB;cACrB;QACA,SAAS,MAAM;IACjB;QAEkB;IAAlB,CAAA,GAAA,mBAAW,EAAE,KAAK,CAAA,OAAA,kBAAA,mBAAA,QAAS,0BAAT,kBAAA,OAAyB,IAAI;IAE/C,OAAO;oBACL;QACA,YAAY,CAAA,GAAA,iBAAS,EACnB,UACA,qBAAqB,WAAW,gBAChC;YACE,UAAU;YACV,UAAU;YACV,iBAAiB,cAAc;YAC/B,gBAAgB,aAAa,oBAAoB,aAAa;YAC9D,qBAAqB,KAAK,CAAC,oBAAoB;YAC/C,yBAAyB,KAAK,CAAC,wBAAwB;YACvD,qBAAqB,KAAK,CAAC,oBAAoB;YAC/C,iBAAiB,KAAK,CAAC,gBAAgB;YACvC,OAAO,MAAM;YACb,cAAc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,+FAA+F;gBAC/F,gGAAgG;gBAChG,kGAAkG;gBAClG,gGAAgG;gBAChG,mGAAmG;gBACnG,oGAAoG;gBACpG,kGAAkG;gBAClG,qGAAqG;gBACrG,yGAAyG;gBACzG,oEAAoE;gBACpE,oEAAoE;gBACpE,IAAI,SAAC,MAAK,kBAAE,eAAc,gBAAE,aAAY,EAAC,GAAG,SAAS;gBACrD,sBAAsB,UAAU;2BAAC;oCAAO;kCAAgB;gBAAY;YACtE;YACA;gBACE,IAAI,CAAC,MAAM,SAAS,SAAS,QAAQ,QAAQ;oBAC3C,wGAAwG;oBACxG,wFAAwF;oBACxF,IAAI,SAAC,MAAK,kBAAE,eAAc,gBAAE,aAAY,EAAC,GAAG,sBAAsB;oBAClE,SAAS,QAAQ,QAAQ;oBACzB,SAAS,QAAQ,kBAAkB,gBAAgB;oBACnD,MAAM,cAAc;gBACtB;YACF;QACF;oBAEF;0BACA;2BACA;IACF;AACF;","sources":["packages/@react-aria/textfield/src/index.ts","packages/@react-aria/textfield/src/useTextField.ts","packages/@react-aria/textfield/src/useFormattedTextField.ts"],"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 */\nexport type {TextFieldAria} from './useTextField';\nexport {useTextField} from './useTextField';\nexport {useFormattedTextField} from './useFormattedTextField';\nexport type {AriaTextFieldOptions} from './useTextField';\nexport type {AriaTextFieldProps} from '@react-types/textfield';\n","/*\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 isInvalid = false,\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': isInvalid || 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"],"names":[],"version":3,"file":"module.js.map"}
1
+ {"mappings":";;;;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC;;;AA6FM,SAAS,yCACd,KAA8B,EAC9B,GAA0B;IAE1B,IAAI,oBACF,mBAAmB,qBACnB,aAAa,mBACb,aAAa,mBACb,aAAa,wBACb,eAAe,aACf,YAAY,aACZ,OAAO,eACP,KAAK,gBACL,YAAY,YACZ,WAAW,KAAO,GACnB,GAAqD;IACtD,IAAI,kBAAC,cAAc,EAAC,GAAG,CAAA,GAAA,mBAAW,EAAE,OAAO;IAC3C,IAAI,cAAC,UAAU,cAAE,UAAU,oBAAE,gBAAgB,qBAAE,iBAAiB,EAAC,GAAG,CAAA,GAAA,eAAO,EAAE;IAC7E,IAAI,WAAW,CAAA,GAAA,qBAAa,EAAE,OAAO;QAAC,WAAW;IAAI;IAErD,MAAM,iBAAiB;cACrB;QACA,SAAS,MAAM;IACjB;QAEkB;IAAlB,CAAA,GAAA,mBAAW,EAAE,KAAK,CAAA,OAAA,kBAAA,mBAAA,QAAS,0BAAT,kBAAA,OAAyB,IAAI;IAE/C,OAAO;oBACL;QACA,YAAY,CAAA,GAAA,iBAAS,EACnB,UACA,qBAAqB,WAAW,gBAChC;YACE,UAAU;YACV,UAAU;YACV,iBAAiB,cAAc;YAC/B,gBAAgB,aAAa,oBAAoB,aAAa;YAC9D,qBAAqB,KAAK,CAAC,oBAAoB;YAC/C,yBAAyB,KAAK,CAAC,wBAAwB;YAC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AK,EAAE;IACnC,OAAO;QACL,YAAY,CAAA,GAAA,iBAAS,EACnB,gBACA;2BACE;YACA;gBACE,4FAA4F;gBAC5F,+FAA+F;gBAC/F,gGAAgG;gBAChG,kGAAkG;gBAClG,gGAAgG;gBAChG,mGAAmG;gBACnG,oGAAoG;gBACpG,kGAAkG;gBAClG,qGAAqG;gBACrG,yGAAyG;gBACzG,oEAAoE;gBACpE,oEAAoE;gBACpE,IAAI,SAAC,KAAK,kBAAE,cAAc,gBAAE,YAAY,EAAC,GAAG,SAAS;gBACrD,sBAAsB,UAAU;2BAAC;oCAAO;kCAAgB;gBAAY;YACtE;YACA;gBACE,IAAI,CAAC,MAAM,SAAS,SAAS,QAAQ,QAAQ;oBAC3C,wGAAwG;oBACxG,wFAAwF;oBACxF,IAAI,SAAC,KAAK,kBAAE,cAAc,gBAAE,YAAY,EAAC,GAAG,sBAAsB;oBAClE,SAAS,QAAQ,QAAQ;oBACzB,SAAS,QAAQ,kBAAkB,gBAAgB;oBACnD,MAAM,cAAc;gBACtB;YACF;QACF;oBAEF;0BACA;2BACA;IACF;AACF;","sources":["packages/@react-aria/textfield/src/index.ts","packages/@react-aria/textfield/src/useTextField.ts","packages/@react-aria/textfield/src/useFormattedTextField.ts"],"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 */\nexport type {TextFieldAria} from './useTextField';\nexport {useTextField} from './useTextField';\nexport {useFormattedTextField} from './useFormattedTextField';\nexport type {AriaTextFieldOptions} from './useTextField';\nexport type {AriaTextFieldProps} from '@react-types/textfield';\n","/*\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 isInvalid = false,\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': isInvalid || 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"],"names":[],"version":3,"file":"module.js.map"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-aria/textfield",
3
- "version": "3.12.0",
3
+ "version": "3.12.1",
4
4
  "description": "Spectrum UI components in React",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/main.js",
@@ -22,11 +22,11 @@
22
22
  "url": "https://github.com/adobe/react-spectrum"
23
23
  },
24
24
  "dependencies": {
25
- "@react-aria/focus": "^3.14.1",
26
- "@react-aria/label": "^3.7.0",
27
- "@react-aria/utils": "^3.20.0",
28
- "@react-types/shared": "^3.20.0",
29
- "@react-types/textfield": "^3.8.0",
25
+ "@react-aria/focus": "^3.14.2",
26
+ "@react-aria/label": "^3.7.1",
27
+ "@react-aria/utils": "^3.21.0",
28
+ "@react-types/shared": "^3.21.0",
29
+ "@react-types/textfield": "^3.8.1",
30
30
  "@swc/helpers": "^0.5.0"
31
31
  },
32
32
  "peerDependencies": {
@@ -35,5 +35,5 @@
35
35
  "publishConfig": {
36
36
  "access": "public"
37
37
  },
38
- "gitHead": "54fbaa67cc56867506811819fef765546d403253"
38
+ "gitHead": "4122e44d1991c90507d630d35ed297f89db435d3"
39
39
  }