@react-aria/textfield 3.18.4 → 3.19.0

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.
@@ -1,130 +0,0 @@
1
- import {useTextField as $2d73ec29415bd339$export$712718f7aec83d5} from "./useTextField.module.js";
2
- import {useEffectEvent as $jyGKS$useEffectEvent, mergeProps as $jyGKS$mergeProps} from "@react-aria/utils";
3
- import {useEffect as $jyGKS$useEffect, useRef as $jyGKS$useRef} from "react";
4
-
5
- /*
6
- * Copyright 2021 Adobe. All rights reserved.
7
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
8
- * you may not use this file except in compliance with the License. You may obtain a copy
9
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software distributed under
12
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
13
- * OF ANY KIND, either express or implied. See the License for the specific language
14
- * governing permissions and limitations under the License.
15
- */
16
-
17
-
18
- function $d841c8010a73d545$var$supportsNativeBeforeInputEvent() {
19
- return typeof window !== 'undefined' && window.InputEvent && typeof InputEvent.prototype.getTargetRanges === 'function';
20
- }
21
- function $d841c8010a73d545$export$4f384c9210e583c3(props, state, inputRef) {
22
- // All browsers implement the 'beforeinput' event natively except Firefox
23
- // (currently behind a flag as of Firefox 84). React's polyfill does not
24
- // run in all cases that the native event fires, e.g. when deleting text.
25
- // Use the native event if available so that we can prevent invalid deletions.
26
- // We do not attempt to polyfill this in Firefox since it would be very complicated,
27
- // the benefit of doing so is fairly minor, and it's going to be natively supported soon.
28
- let onBeforeInputFallback = (0, $jyGKS$useEffectEvent)((e)=>{
29
- let input = inputRef.current;
30
- if (!input) return;
31
- // Compute the next value of the input if the event is allowed to proceed.
32
- // See https://www.w3.org/TR/input-events-2/#interface-InputEvent-Attributes for a full list of input types.
33
- let nextValue = null;
34
- switch(e.inputType){
35
- case 'historyUndo':
36
- case 'historyRedo':
37
- // Explicitly allow undo/redo. e.data is null in this case, but there's no need to validate,
38
- // because presumably the input would have already been validated previously.
39
- return;
40
- case 'insertLineBreak':
41
- // Explicitly allow "insertLineBreak" event, to allow onSubmit for "enter" key. e.data is null in this case.
42
- return;
43
- case 'deleteContent':
44
- case 'deleteByCut':
45
- case 'deleteByDrag':
46
- nextValue = input.value.slice(0, input.selectionStart) + input.value.slice(input.selectionEnd);
47
- break;
48
- case 'deleteContentForward':
49
- // This is potentially incorrect, since the browser may actually delete more than a single UTF-16
50
- // character. In reality, a full Unicode grapheme cluster consisting of multiple UTF-16 characters
51
- // or code points may be deleted. However, in our currently supported locales, there are no such cases.
52
- // If we support additional locales in the future, this may need to change.
53
- 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);
54
- break;
55
- case 'deleteContentBackward':
56
- 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);
57
- break;
58
- case 'deleteSoftLineBackward':
59
- case 'deleteHardLineBackward':
60
- nextValue = input.value.slice(input.selectionStart);
61
- break;
62
- default:
63
- if (e.data != null) nextValue = input.value.slice(0, input.selectionStart) + e.data + input.value.slice(input.selectionEnd);
64
- break;
65
- }
66
- // If we did not compute a value, or the new value is invalid, prevent the event
67
- // so that the browser does not update the input text, move the selection, or add to
68
- // the undo/redo stack.
69
- if (nextValue == null || !state.validate(nextValue)) e.preventDefault();
70
- });
71
- (0, $jyGKS$useEffect)(()=>{
72
- if (!$d841c8010a73d545$var$supportsNativeBeforeInputEvent() || !inputRef.current) return;
73
- let input = inputRef.current;
74
- input.addEventListener('beforeinput', onBeforeInputFallback, false);
75
- return ()=>{
76
- input.removeEventListener('beforeinput', onBeforeInputFallback, false);
77
- };
78
- }, [
79
- inputRef
80
- ]);
81
- let onBeforeInput = !$d841c8010a73d545$var$supportsNativeBeforeInputEvent() ? (e)=>{
82
- let nextValue = e.target.value.slice(0, e.target.selectionStart) + e.data + e.target.value.slice(e.target.selectionEnd);
83
- if (!state.validate(nextValue)) e.preventDefault();
84
- } : null;
85
- let { labelProps: labelProps, inputProps: textFieldProps, descriptionProps: descriptionProps, errorMessageProps: errorMessageProps, ...validation } = (0, $2d73ec29415bd339$export$712718f7aec83d5)(props, inputRef);
86
- let compositionStartState = (0, $jyGKS$useRef)(null);
87
- return {
88
- inputProps: (0, $jyGKS$mergeProps)(textFieldProps, {
89
- onBeforeInput: onBeforeInput,
90
- onCompositionStart () {
91
- // Chrome does not implement Input Events Level 2, which specifies the insertFromComposition
92
- // and deleteByComposition inputType values for the beforeinput event. These are meant to occur
93
- // at the end of a composition (e.g. Pinyin IME, Android auto correct, etc.), and crucially, are
94
- // cancelable. The insertCompositionText and deleteCompositionText input types are not cancelable,
95
- // nor would we want to cancel them because the input from the user is incomplete at that point.
96
- // In Safari, insertFromComposition/deleteFromComposition will fire, however, allowing us to cancel
97
- // the final composition result if it is invalid. As a fallback for Chrome and Firefox, which either
98
- // don't support Input Events Level 2, or beforeinput at all, we store the state of the input when
99
- // the compositionstart event fires, and undo the changes in compositionend (below) if it is invalid.
100
- // Unfortunately, this messes up the undo/redo stack, but until insertFromComposition/deleteByComposition
101
- // are implemented, there is no other way to prevent composed input.
102
- // See https://bugs.chromium.org/p/chromium/issues/detail?id=1022204
103
- let { value: value, selectionStart: selectionStart, selectionEnd: selectionEnd } = inputRef.current;
104
- compositionStartState.current = {
105
- value: value,
106
- selectionStart: selectionStart,
107
- selectionEnd: selectionEnd
108
- };
109
- },
110
- onCompositionEnd () {
111
- if (inputRef.current && !state.validate(inputRef.current.value)) {
112
- // Restore the input value in the DOM immediately so we can synchronously update the selection position.
113
- // But also update the value in React state as well so it is correct for future updates.
114
- let { value: value, selectionStart: selectionStart, selectionEnd: selectionEnd } = compositionStartState.current;
115
- inputRef.current.value = value;
116
- inputRef.current.setSelectionRange(selectionStart, selectionEnd);
117
- state.setInputValue(value);
118
- }
119
- }
120
- }),
121
- labelProps: labelProps,
122
- descriptionProps: descriptionProps,
123
- errorMessageProps: errorMessageProps,
124
- ...validation
125
- };
126
- }
127
-
128
-
129
- export {$d841c8010a73d545$export$4f384c9210e583c3 as useFormattedTextField};
130
- //# sourceMappingURL=useFormattedTextField.module.js.map
@@ -1 +0,0 @@
1
- {"mappings":";;;;AAAA;;;;;;;;;;CAUC;;;AAcD,SAAS;IACP,OAAO,OAAO,WAAW,eACvB,OAAO,UAAU,IACjB,OAAO,WAAW,SAAS,CAAC,eAAe,KAAK;AACpD;AAEO,SAAS,0CAAsB,KAAyB,EAAE,KAA8B,EAAE,QAA4C;IAC3I,yEAAyE;IACzE,wEAAwE;IACxE,yEAAyE;IACzE,8EAA8E;IAC9E,oFAAoF;IACpF,yFAAyF;IACzF,IAAI,wBAAwB,CAAA,GAAA,qBAAa,EAAE,CAAC;QAC1C,IAAI,QAAQ,SAAS,OAAO;QAC5B,IAAI,CAAC,OACH;QAGF,0EAA0E;QAC1E,4GAA4G;QAC5G,IAAI,YAA2B;QAC/B,OAAQ,EAAE,SAAS;YACjB,KAAK;YACL,KAAK;gBACH,4FAA4F;gBAC5F,6EAA6E;gBAC7E;YACF,KAAK;gBACH,4GAA4G;gBAC5G;YACF,KAAK;YACL,KAAK;YACL,KAAK;gBACH,YAAY,MAAM,KAAK,CAAC,KAAK,CAAC,GAAG,MAAM,cAAc,IAAK,MAAM,KAAK,CAAC,KAAK,CAAC,MAAM,YAAY;gBAC9F;YACF,KAAK;gBACH,iGAAiG;gBACjG,kGAAkG;gBAClG,uGAAuG;gBACvG,2EAA2E;gBAC3E,YAAY,MAAM,YAAY,KAAK,MAAM,cAAc,GACnD,MAAM,KAAK,CAAC,KAAK,CAAC,GAAG,MAAM,cAAc,IAAK,MAAM,KAAK,CAAC,KAAK,CAAC,MAAM,YAAY,GAAI,KACtF,MAAM,KAAK,CAAC,KAAK,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Ac;IAEpB,IACE;IAEJ,IAAI,cAAC,UAAU,EAAE,YAAY,cAAc,oBAAE,gBAAgB,qBAAE,iBAAiB,EAAE,GAAG,YAAW,GAAG,CAAA,GAAA,wCAAW,EAAE,OAAO;IAEvH,IAAI,wBAAwB,CAAA,GAAA,aAAK,EAAsF;IACvH,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,OAAO;gBAC5D,sBAAsB,OAAO,GAAG;2BAAC;oCAAO;kCAAgB;gBAAY;YACtE;YACA;gBACE,IAAI,SAAS,OAAO,IAAI,CAAC,MAAM,QAAQ,CAAC,SAAS,OAAO,CAAC,KAAK,GAAG;oBAC/D,wGAAwG;oBACxG,wFAAwF;oBACxF,IAAI,SAAC,KAAK,kBAAE,cAAc,gBAAE,YAAY,EAAC,GAAG,sBAAsB,OAAO;oBACzE,SAAS,OAAO,CAAC,KAAK,GAAG;oBACzB,SAAS,OAAO,CAAC,iBAAiB,CAAC,gBAAgB;oBACnD,MAAM,aAAa,CAAC;gBACtB;YACF;QACF;oBAEF;0BACA;2BACA;QACA,GAAG,UAAU;IACf;AACF","sources":["packages/@react-aria/textfield/src/useFormattedTextField.ts"],"sourcesContent":["/*\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} from '@react-types/shared';\nimport {TextFieldAria, useTextField} from './useTextField';\nimport {useEffect, useRef} from 'react';\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 typeof InputEvent.prototype.getTargetRanges === 'function';\n}\n\nexport function useFormattedTextField(props: AriaTextFieldProps, state: FormattedTextFieldState, inputRef: RefObject<HTMLInputElement | null>): 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 if (!input) {\n return;\n }\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 | null = null;\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 'insertLineBreak':\n // Explicitly allow \"insertLineBreak\" event, to allow onSubmit for \"enter\" key. e.data is null in this case.\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() || !inputRef.current) {\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]);\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, ...validation} = useTextField(props, inputRef);\n\n let compositionStartState = useRef<{value: string, selectionStart: number | null, selectionEnd: number | null} | null>(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 (inputRef.current && !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 ...validation\n };\n}\n"],"names":[],"version":3,"file":"useFormattedTextField.module.js.map"}
@@ -1,112 +0,0 @@
1
- var $4Z7CR$reactariautils = require("@react-aria/utils");
2
- var $4Z7CR$react = require("react");
3
- var $4Z7CR$reactstatelyutils = require("@react-stately/utils");
4
- var $4Z7CR$reactarialabel = require("@react-aria/label");
5
- var $4Z7CR$reactariainteractions = require("@react-aria/interactions");
6
- var $4Z7CR$reactariaform = require("@react-aria/form");
7
- var $4Z7CR$reactstatelyform = require("@react-stately/form");
8
-
9
-
10
- function $parcel$interopDefault(a) {
11
- return a && a.__esModule ? a.default : a;
12
- }
13
-
14
- function $parcel$export(e, n, v, s) {
15
- Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
16
- }
17
-
18
- $parcel$export(module.exports, "useTextField", () => $9076f978e02df845$export$712718f7aec83d5);
19
- /*
20
- * Copyright 2020 Adobe. All rights reserved.
21
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
22
- * you may not use this file except in compliance with the License. You may obtain a copy
23
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
24
- *
25
- * Unless required by applicable law or agreed to in writing, software distributed under
26
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
27
- * OF ANY KIND, either express or implied. See the License for the specific language
28
- * governing permissions and limitations under the License.
29
- */
30
-
31
-
32
-
33
-
34
-
35
-
36
- function $9076f978e02df845$export$712718f7aec83d5(props, ref) {
37
- let { inputElementType: inputElementType = 'input', isDisabled: isDisabled = false, isRequired: isRequired = false, isReadOnly: isReadOnly = false, type: type = 'text', validationBehavior: validationBehavior = 'aria' } = props;
38
- let [value, setValue] = (0, $4Z7CR$reactstatelyutils.useControlledState)(props.value, props.defaultValue || '', props.onChange);
39
- let { focusableProps: focusableProps } = (0, $4Z7CR$reactariainteractions.useFocusable)(props, ref);
40
- let validationState = (0, $4Z7CR$reactstatelyform.useFormValidationState)({
41
- ...props,
42
- value: value
43
- });
44
- let { isInvalid: isInvalid, validationErrors: validationErrors, validationDetails: validationDetails } = validationState.displayValidation;
45
- let { labelProps: labelProps, fieldProps: fieldProps, descriptionProps: descriptionProps, errorMessageProps: errorMessageProps } = (0, $4Z7CR$reactarialabel.useField)({
46
- ...props,
47
- isInvalid: isInvalid,
48
- errorMessage: props.errorMessage || validationErrors
49
- });
50
- let domProps = (0, $4Z7CR$reactariautils.filterDOMProps)(props, {
51
- labelable: true
52
- });
53
- const inputOnlyProps = {
54
- type: type,
55
- pattern: props.pattern
56
- };
57
- let [initialValue] = (0, $4Z7CR$react.useState)(value);
58
- var _props_defaultValue;
59
- (0, $4Z7CR$reactariautils.useFormReset)(ref, (_props_defaultValue = props.defaultValue) !== null && _props_defaultValue !== void 0 ? _props_defaultValue : initialValue, setValue);
60
- (0, $4Z7CR$reactariaform.useFormValidation)(props, validationState, ref);
61
- return {
62
- labelProps: labelProps,
63
- inputProps: (0, $4Z7CR$reactariautils.mergeProps)(domProps, inputElementType === 'input' ? inputOnlyProps : undefined, {
64
- disabled: isDisabled,
65
- readOnly: isReadOnly,
66
- required: isRequired && validationBehavior === 'native',
67
- 'aria-required': isRequired && validationBehavior === 'aria' || undefined,
68
- 'aria-invalid': isInvalid || undefined,
69
- 'aria-errormessage': props['aria-errormessage'],
70
- 'aria-activedescendant': props['aria-activedescendant'],
71
- 'aria-autocomplete': props['aria-autocomplete'],
72
- 'aria-haspopup': props['aria-haspopup'],
73
- 'aria-controls': props['aria-controls'],
74
- value: value,
75
- onChange: (e)=>setValue(e.target.value),
76
- autoComplete: props.autoComplete,
77
- autoCapitalize: props.autoCapitalize,
78
- maxLength: props.maxLength,
79
- minLength: props.minLength,
80
- name: props.name,
81
- form: props.form,
82
- placeholder: props.placeholder,
83
- inputMode: props.inputMode,
84
- autoCorrect: props.autoCorrect,
85
- spellCheck: props.spellCheck,
86
- [parseInt((0, ($parcel$interopDefault($4Z7CR$react))).version, 10) >= 17 ? 'enterKeyHint' : 'enterkeyhint']: props.enterKeyHint,
87
- // Clipboard events
88
- onCopy: props.onCopy,
89
- onCut: props.onCut,
90
- onPaste: props.onPaste,
91
- // Composition events
92
- onCompositionEnd: props.onCompositionEnd,
93
- onCompositionStart: props.onCompositionStart,
94
- onCompositionUpdate: props.onCompositionUpdate,
95
- // Selection events
96
- onSelect: props.onSelect,
97
- // Input events
98
- onBeforeInput: props.onBeforeInput,
99
- onInput: props.onInput,
100
- ...focusableProps,
101
- ...fieldProps
102
- }),
103
- descriptionProps: descriptionProps,
104
- errorMessageProps: errorMessageProps,
105
- isInvalid: isInvalid,
106
- validationErrors: validationErrors,
107
- validationDetails: validationDetails
108
- };
109
- }
110
-
111
-
112
- //# sourceMappingURL=useTextField.main.js.map
@@ -1 +0,0 @@
1
- {"mappings":";;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;AAuGM,SA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AAwB;YACvD,qBAAqB,KAAK,CAAC,oBAAoB;YAC/C,iBAAiB,KAAK,CAAC,gBAAgB;YACvC,iBAAiB,KAAK,CAAC,gBAAgB;mBACvC;YACA,UAAU,CAAC,IAAqC,SAAS,EAAE,MAAM,CAAC,KAAK;YACvE,cAAc,MAAM,YAAY;YAChC,gBAAgB,MAAM,cAAc;YACpC,WAAW,MAAM,SAAS;YAC1B,WAAW,MAAM,SAAS;YAC1B,MAAM,MAAM,IAAI;YAChB,MAAM,MAAM,IAAI;YAChB,aAAa,MAAM,WAAW;YAC9B,WAAW,MAAM,SAAS;YAC1B,aAAa,MAAM,WAAW;YAC9B,YAAY,MAAM,UAAU;YAC5B,CAAC,SAAS,CAAA,GAAA,sCAAI,EAAE,OAAO,EAAE,OAAO,KAAK,iBAAiB,eAAe,EAAE,MAAM,YAAY;YAEzF,mBAAmB;YACnB,QAAQ,MAAM,MAAM;YACpB,OAAO,MAAM,KAAK;YAClB,SAAS,MAAM,OAAO;YAEtB,qBAAqB;YACrB,kBAAkB,MAAM,gBAAgB;YACxC,oBAAoB,MAAM,kBAAkB;YAC5C,qBAAqB,MAAM,mBAAmB;YAE9C,mBAAmB;YACnB,UAAU,MAAM,QAAQ;YAExB,eAAe;YACf,eAAe,MAAM,aAAa;YAClC,SAAS,MAAM,OAAO;YACtB,GAAG,cAAc;YACjB,GAAG,UAAU;QACf;0BAEF;2BACA;mBACA;0BACA;2BACA;IACF;AACF","sources":["packages/@react-aria/textfield/src/useTextField.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 */\n\nimport {AriaTextFieldProps} from '@react-types/textfield';\nimport {DOMAttributes, ValidationResult} from '@react-types/shared';\nimport {filterDOMProps, mergeProps, useFormReset} from '@react-aria/utils';\nimport React, {\n ChangeEvent,\n HTMLAttributes,\n type JSX,\n LabelHTMLAttributes,\n RefObject,\n useState\n} from 'react';\nimport {useControlledState} from '@react-stately/utils';\nimport {useField} from '@react-aria/label';\nimport {useFocusable} from '@react-aria/interactions';\nimport {useFormValidation} from '@react-aria/form';\nimport {useFormValidationState} from '@react-stately/form';\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 = JSX.IntrinsicElements;\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<TextFieldHTMLElementType[T]> {\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 * Controls whether inputted text is automatically capitalized and, if so, in what manner.\n * See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/autocapitalize).\n */\n autoCapitalize?: 'off' | 'none' | 'on' | 'sentences' | 'words' | 'characters',\n /**\n * An enumerated attribute that defines what action label or icon to preset for the enter key on virtual keyboards. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/enterkeyhint).\n */\n enterKeyHint?: 'enter' | 'done' | 'go' | 'next' | 'previous' | 'search' | 'send'\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] | null>;\n\nexport interface TextFieldAria<T extends TextFieldIntrinsicElements = DefaultElementType> extends ValidationResult {\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 type = 'text',\n validationBehavior = 'aria'\n } = props;\n let [value, setValue] = useControlledState<string>(props.value, props.defaultValue || '', props.onChange);\n let {focusableProps} = useFocusable<TextFieldHTMLElementType[T]>(props, ref);\n let validationState = useFormValidationState({\n ...props,\n value\n });\n let {isInvalid, validationErrors, validationDetails} = validationState.displayValidation;\n let {labelProps, fieldProps, descriptionProps, errorMessageProps} = useField({\n ...props,\n isInvalid,\n errorMessage: props.errorMessage || validationErrors\n });\n let domProps = filterDOMProps(props, {labelable: true});\n\n const inputOnlyProps = {\n type,\n pattern: props.pattern\n };\n\n let [initialValue] = useState(value);\n useFormReset(ref, props.defaultValue ?? initialValue, setValue);\n useFormValidation(props, validationState, ref);\n\n return {\n labelProps,\n inputProps: mergeProps(\n domProps,\n inputElementType === 'input' ? inputOnlyProps : undefined,\n {\n disabled: isDisabled,\n readOnly: isReadOnly,\n required: isRequired && validationBehavior === 'native',\n 'aria-required': (isRequired && validationBehavior === 'aria') || undefined,\n 'aria-invalid': isInvalid || 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 'aria-controls': props['aria-controls'],\n value,\n onChange: (e: ChangeEvent<HTMLInputElement>) => setValue(e.target.value),\n autoComplete: props.autoComplete,\n autoCapitalize: props.autoCapitalize,\n maxLength: props.maxLength,\n minLength: props.minLength,\n name: props.name,\n form: props.form,\n placeholder: props.placeholder,\n inputMode: props.inputMode,\n autoCorrect: props.autoCorrect,\n spellCheck: props.spellCheck,\n [parseInt(React.version, 10) >= 17 ? 'enterKeyHint' : 'enterkeyhint']: props.enterKeyHint,\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 isInvalid,\n validationErrors,\n validationDetails\n };\n}\n"],"names":[],"version":3,"file":"useTextField.main.js.map"}
@@ -1,103 +0,0 @@
1
- import {filterDOMProps as $ig234$filterDOMProps, useFormReset as $ig234$useFormReset, mergeProps as $ig234$mergeProps} from "@react-aria/utils";
2
- import $ig234$react, {useState as $ig234$useState} from "react";
3
- import {useControlledState as $ig234$useControlledState} from "@react-stately/utils";
4
- import {useField as $ig234$useField} from "@react-aria/label";
5
- import {useFocusable as $ig234$useFocusable} from "@react-aria/interactions";
6
- import {useFormValidation as $ig234$useFormValidation} from "@react-aria/form";
7
- import {useFormValidationState as $ig234$useFormValidationState} from "@react-stately/form";
8
-
9
- /*
10
- * Copyright 2020 Adobe. All rights reserved.
11
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
12
- * you may not use this file except in compliance with the License. You may obtain a copy
13
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
14
- *
15
- * Unless required by applicable law or agreed to in writing, software distributed under
16
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
17
- * OF ANY KIND, either express or implied. See the License for the specific language
18
- * governing permissions and limitations under the License.
19
- */
20
-
21
-
22
-
23
-
24
-
25
-
26
- function $2d73ec29415bd339$export$712718f7aec83d5(props, ref) {
27
- let { inputElementType: inputElementType = 'input', isDisabled: isDisabled = false, isRequired: isRequired = false, isReadOnly: isReadOnly = false, type: type = 'text', validationBehavior: validationBehavior = 'aria' } = props;
28
- let [value, setValue] = (0, $ig234$useControlledState)(props.value, props.defaultValue || '', props.onChange);
29
- let { focusableProps: focusableProps } = (0, $ig234$useFocusable)(props, ref);
30
- let validationState = (0, $ig234$useFormValidationState)({
31
- ...props,
32
- value: value
33
- });
34
- let { isInvalid: isInvalid, validationErrors: validationErrors, validationDetails: validationDetails } = validationState.displayValidation;
35
- let { labelProps: labelProps, fieldProps: fieldProps, descriptionProps: descriptionProps, errorMessageProps: errorMessageProps } = (0, $ig234$useField)({
36
- ...props,
37
- isInvalid: isInvalid,
38
- errorMessage: props.errorMessage || validationErrors
39
- });
40
- let domProps = (0, $ig234$filterDOMProps)(props, {
41
- labelable: true
42
- });
43
- const inputOnlyProps = {
44
- type: type,
45
- pattern: props.pattern
46
- };
47
- let [initialValue] = (0, $ig234$useState)(value);
48
- var _props_defaultValue;
49
- (0, $ig234$useFormReset)(ref, (_props_defaultValue = props.defaultValue) !== null && _props_defaultValue !== void 0 ? _props_defaultValue : initialValue, setValue);
50
- (0, $ig234$useFormValidation)(props, validationState, ref);
51
- return {
52
- labelProps: labelProps,
53
- inputProps: (0, $ig234$mergeProps)(domProps, inputElementType === 'input' ? inputOnlyProps : undefined, {
54
- disabled: isDisabled,
55
- readOnly: isReadOnly,
56
- required: isRequired && validationBehavior === 'native',
57
- 'aria-required': isRequired && validationBehavior === 'aria' || undefined,
58
- 'aria-invalid': isInvalid || undefined,
59
- 'aria-errormessage': props['aria-errormessage'],
60
- 'aria-activedescendant': props['aria-activedescendant'],
61
- 'aria-autocomplete': props['aria-autocomplete'],
62
- 'aria-haspopup': props['aria-haspopup'],
63
- 'aria-controls': props['aria-controls'],
64
- value: value,
65
- onChange: (e)=>setValue(e.target.value),
66
- autoComplete: props.autoComplete,
67
- autoCapitalize: props.autoCapitalize,
68
- maxLength: props.maxLength,
69
- minLength: props.minLength,
70
- name: props.name,
71
- form: props.form,
72
- placeholder: props.placeholder,
73
- inputMode: props.inputMode,
74
- autoCorrect: props.autoCorrect,
75
- spellCheck: props.spellCheck,
76
- [parseInt((0, $ig234$react).version, 10) >= 17 ? 'enterKeyHint' : 'enterkeyhint']: props.enterKeyHint,
77
- // Clipboard events
78
- onCopy: props.onCopy,
79
- onCut: props.onCut,
80
- onPaste: props.onPaste,
81
- // Composition events
82
- onCompositionEnd: props.onCompositionEnd,
83
- onCompositionStart: props.onCompositionStart,
84
- onCompositionUpdate: props.onCompositionUpdate,
85
- // Selection events
86
- onSelect: props.onSelect,
87
- // Input events
88
- onBeforeInput: props.onBeforeInput,
89
- onInput: props.onInput,
90
- ...focusableProps,
91
- ...fieldProps
92
- }),
93
- descriptionProps: descriptionProps,
94
- errorMessageProps: errorMessageProps,
95
- isInvalid: isInvalid,
96
- validationErrors: validationErrors,
97
- validationDetails: validationDetails
98
- };
99
- }
100
-
101
-
102
- export {$2d73ec29415bd339$export$712718f7aec83d5 as useTextField};
103
- //# sourceMappingURL=useTextField.module.js.map
@@ -1,103 +0,0 @@
1
- import {filterDOMProps as $ig234$filterDOMProps, useFormReset as $ig234$useFormReset, mergeProps as $ig234$mergeProps} from "@react-aria/utils";
2
- import $ig234$react, {useState as $ig234$useState} from "react";
3
- import {useControlledState as $ig234$useControlledState} from "@react-stately/utils";
4
- import {useField as $ig234$useField} from "@react-aria/label";
5
- import {useFocusable as $ig234$useFocusable} from "@react-aria/interactions";
6
- import {useFormValidation as $ig234$useFormValidation} from "@react-aria/form";
7
- import {useFormValidationState as $ig234$useFormValidationState} from "@react-stately/form";
8
-
9
- /*
10
- * Copyright 2020 Adobe. All rights reserved.
11
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
12
- * you may not use this file except in compliance with the License. You may obtain a copy
13
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
14
- *
15
- * Unless required by applicable law or agreed to in writing, software distributed under
16
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
17
- * OF ANY KIND, either express or implied. See the License for the specific language
18
- * governing permissions and limitations under the License.
19
- */
20
-
21
-
22
-
23
-
24
-
25
-
26
- function $2d73ec29415bd339$export$712718f7aec83d5(props, ref) {
27
- let { inputElementType: inputElementType = 'input', isDisabled: isDisabled = false, isRequired: isRequired = false, isReadOnly: isReadOnly = false, type: type = 'text', validationBehavior: validationBehavior = 'aria' } = props;
28
- let [value, setValue] = (0, $ig234$useControlledState)(props.value, props.defaultValue || '', props.onChange);
29
- let { focusableProps: focusableProps } = (0, $ig234$useFocusable)(props, ref);
30
- let validationState = (0, $ig234$useFormValidationState)({
31
- ...props,
32
- value: value
33
- });
34
- let { isInvalid: isInvalid, validationErrors: validationErrors, validationDetails: validationDetails } = validationState.displayValidation;
35
- let { labelProps: labelProps, fieldProps: fieldProps, descriptionProps: descriptionProps, errorMessageProps: errorMessageProps } = (0, $ig234$useField)({
36
- ...props,
37
- isInvalid: isInvalid,
38
- errorMessage: props.errorMessage || validationErrors
39
- });
40
- let domProps = (0, $ig234$filterDOMProps)(props, {
41
- labelable: true
42
- });
43
- const inputOnlyProps = {
44
- type: type,
45
- pattern: props.pattern
46
- };
47
- let [initialValue] = (0, $ig234$useState)(value);
48
- var _props_defaultValue;
49
- (0, $ig234$useFormReset)(ref, (_props_defaultValue = props.defaultValue) !== null && _props_defaultValue !== void 0 ? _props_defaultValue : initialValue, setValue);
50
- (0, $ig234$useFormValidation)(props, validationState, ref);
51
- return {
52
- labelProps: labelProps,
53
- inputProps: (0, $ig234$mergeProps)(domProps, inputElementType === 'input' ? inputOnlyProps : undefined, {
54
- disabled: isDisabled,
55
- readOnly: isReadOnly,
56
- required: isRequired && validationBehavior === 'native',
57
- 'aria-required': isRequired && validationBehavior === 'aria' || undefined,
58
- 'aria-invalid': isInvalid || undefined,
59
- 'aria-errormessage': props['aria-errormessage'],
60
- 'aria-activedescendant': props['aria-activedescendant'],
61
- 'aria-autocomplete': props['aria-autocomplete'],
62
- 'aria-haspopup': props['aria-haspopup'],
63
- 'aria-controls': props['aria-controls'],
64
- value: value,
65
- onChange: (e)=>setValue(e.target.value),
66
- autoComplete: props.autoComplete,
67
- autoCapitalize: props.autoCapitalize,
68
- maxLength: props.maxLength,
69
- minLength: props.minLength,
70
- name: props.name,
71
- form: props.form,
72
- placeholder: props.placeholder,
73
- inputMode: props.inputMode,
74
- autoCorrect: props.autoCorrect,
75
- spellCheck: props.spellCheck,
76
- [parseInt((0, $ig234$react).version, 10) >= 17 ? 'enterKeyHint' : 'enterkeyhint']: props.enterKeyHint,
77
- // Clipboard events
78
- onCopy: props.onCopy,
79
- onCut: props.onCut,
80
- onPaste: props.onPaste,
81
- // Composition events
82
- onCompositionEnd: props.onCompositionEnd,
83
- onCompositionStart: props.onCompositionStart,
84
- onCompositionUpdate: props.onCompositionUpdate,
85
- // Selection events
86
- onSelect: props.onSelect,
87
- // Input events
88
- onBeforeInput: props.onBeforeInput,
89
- onInput: props.onInput,
90
- ...focusableProps,
91
- ...fieldProps
92
- }),
93
- descriptionProps: descriptionProps,
94
- errorMessageProps: errorMessageProps,
95
- isInvalid: isInvalid,
96
- validationErrors: validationErrors,
97
- validationDetails: validationDetails
98
- };
99
- }
100
-
101
-
102
- export {$2d73ec29415bd339$export$712718f7aec83d5 as useTextField};
103
- //# sourceMappingURL=useTextField.module.js.map
@@ -1 +0,0 @@
1
- {"mappings":";;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;AAuGM,SAAS,yCACd,KAA8B,EAC9B,GAA0B;IAE1B,IAAI,oBACF,mBAAmB,qBACnB,aAAa,mBACb,aAAa,mBACb,aAAa,aACb,OAAO,4BACP,qBAAqB,QACtB,GAAG;IACJ,IAAI,CAAC,OAAO,SAAS,GAAG,CAAA,GAAA,yBAAiB,EAAU,MAAM,KAAK,EAAE,MAAM,YAAY,IAAI,IAAI,MAAM,QAAQ;IACxG,IAAI,kBAAC,cAAc,EAAC,GAAG,CAAA,GAAA,mBAAW,EAA+B,OAAO;IACxE,IAAI,kBAAkB,CAAA,GAAA,6BAAqB,EAAE;QAC3C,GAAG,KAAK;eACR;IACF;IACA,IAAI,aAAC,SAAS,oBAAE,gBAAgB,qBAAE,iBAAiB,EAAC,GAAG,gBAAgB,iBAAiB;IACxF,IAAI,cAAC,UAAU,cAAE,UAAU,oBAAE,gBAAgB,qBAAE,iBAAiB,EAAC,GAAG,CAAA,GAAA,eAAO,EAAE;QAC3E,GAAG,KAAK;mBACR;QACA,cAAc,MA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B;YACrB,kBAAkB,MAAM,gBAAgB;YACxC,oBAAoB,MAAM,kBAAkB;YAC5C,qBAAqB,MAAM,mBAAmB;YAE9C,mBAAmB;YACnB,UAAU,MAAM,QAAQ;YAExB,eAAe;YACf,eAAe,MAAM,aAAa;YAClC,SAAS,MAAM,OAAO;YACtB,GAAG,cAAc;YACjB,GAAG,UAAU;QACf;0BAEF;2BACA;mBACA;0BACA;2BACA;IACF;AACF","sources":["packages/@react-aria/textfield/src/useTextField.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 */\n\nimport {AriaTextFieldProps} from '@react-types/textfield';\nimport {DOMAttributes, ValidationResult} from '@react-types/shared';\nimport {filterDOMProps, mergeProps, useFormReset} from '@react-aria/utils';\nimport React, {\n ChangeEvent,\n HTMLAttributes,\n type JSX,\n LabelHTMLAttributes,\n RefObject,\n useState\n} from 'react';\nimport {useControlledState} from '@react-stately/utils';\nimport {useField} from '@react-aria/label';\nimport {useFocusable} from '@react-aria/interactions';\nimport {useFormValidation} from '@react-aria/form';\nimport {useFormValidationState} from '@react-stately/form';\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 = JSX.IntrinsicElements;\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<TextFieldHTMLElementType[T]> {\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 * Controls whether inputted text is automatically capitalized and, if so, in what manner.\n * See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/autocapitalize).\n */\n autoCapitalize?: 'off' | 'none' | 'on' | 'sentences' | 'words' | 'characters',\n /**\n * An enumerated attribute that defines what action label or icon to preset for the enter key on virtual keyboards. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/enterkeyhint).\n */\n enterKeyHint?: 'enter' | 'done' | 'go' | 'next' | 'previous' | 'search' | 'send'\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] | null>;\n\nexport interface TextFieldAria<T extends TextFieldIntrinsicElements = DefaultElementType> extends ValidationResult {\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 type = 'text',\n validationBehavior = 'aria'\n } = props;\n let [value, setValue] = useControlledState<string>(props.value, props.defaultValue || '', props.onChange);\n let {focusableProps} = useFocusable<TextFieldHTMLElementType[T]>(props, ref);\n let validationState = useFormValidationState({\n ...props,\n value\n });\n let {isInvalid, validationErrors, validationDetails} = validationState.displayValidation;\n let {labelProps, fieldProps, descriptionProps, errorMessageProps} = useField({\n ...props,\n isInvalid,\n errorMessage: props.errorMessage || validationErrors\n });\n let domProps = filterDOMProps(props, {labelable: true});\n\n const inputOnlyProps = {\n type,\n pattern: props.pattern\n };\n\n let [initialValue] = useState(value);\n useFormReset(ref, props.defaultValue ?? initialValue, setValue);\n useFormValidation(props, validationState, ref);\n\n return {\n labelProps,\n inputProps: mergeProps(\n domProps,\n inputElementType === 'input' ? inputOnlyProps : undefined,\n {\n disabled: isDisabled,\n readOnly: isReadOnly,\n required: isRequired && validationBehavior === 'native',\n 'aria-required': (isRequired && validationBehavior === 'aria') || undefined,\n 'aria-invalid': isInvalid || 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 'aria-controls': props['aria-controls'],\n value,\n onChange: (e: ChangeEvent<HTMLInputElement>) => setValue(e.target.value),\n autoComplete: props.autoComplete,\n autoCapitalize: props.autoCapitalize,\n maxLength: props.maxLength,\n minLength: props.minLength,\n name: props.name,\n form: props.form,\n placeholder: props.placeholder,\n inputMode: props.inputMode,\n autoCorrect: props.autoCorrect,\n spellCheck: props.spellCheck,\n [parseInt(React.version, 10) >= 17 ? 'enterKeyHint' : 'enterkeyhint']: props.enterKeyHint,\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 isInvalid,\n validationErrors,\n validationDetails\n };\n}\n"],"names":[],"version":3,"file":"useTextField.module.js.map"}