@react-aria/textfield 3.18.5 → 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.
package/dist/import.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import {useTextField as $2d73ec29415bd339$export$712718f7aec83d5} from "./useTextField.mjs";
2
- import {useFormattedTextField as $d841c8010a73d545$export$4f384c9210e583c3} from "./useFormattedTextField.mjs";
1
+ import {useTextField as $0fa547b14c3cee43$re_export$useTextField} from "react-aria/useTextField";
2
+ import {useFormattedTextField as $0fa547b14c3cee43$re_export$useFormattedTextField} from "react-aria/private/textfield/useFormattedTextField";
3
3
 
4
4
  /*
5
5
  * Copyright 2020 Adobe. All rights reserved.
@@ -15,5 +15,5 @@ import {useFormattedTextField as $d841c8010a73d545$export$4f384c9210e583c3} from
15
15
 
16
16
 
17
17
 
18
- export {$2d73ec29415bd339$export$712718f7aec83d5 as useTextField, $d841c8010a73d545$export$4f384c9210e583c3 as useFormattedTextField};
18
+ export {$0fa547b14c3cee43$re_export$useTextField as useTextField, $0fa547b14c3cee43$re_export$useFormattedTextField as useFormattedTextField};
19
19
  //# sourceMappingURL=module.js.map
package/dist/main.js CHANGED
@@ -1,13 +1,13 @@
1
- var $9076f978e02df845$exports = require("./useTextField.main.js");
2
- var $56b68c3dab9bf16c$exports = require("./useFormattedTextField.main.js");
1
+ var $jAs05$reactariauseTextField = require("react-aria/useTextField");
2
+ var $jAs05$reactariaprivatetextfielduseFormattedTextField = require("react-aria/private/textfield/useFormattedTextField");
3
3
 
4
4
 
5
5
  function $parcel$export(e, n, v, s) {
6
6
  Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
7
7
  }
8
8
 
9
- $parcel$export(module.exports, "useTextField", () => $9076f978e02df845$exports.useTextField);
10
- $parcel$export(module.exports, "useFormattedTextField", () => $56b68c3dab9bf16c$exports.useFormattedTextField);
9
+ $parcel$export(module.exports, "useTextField", function () { return $jAs05$reactariauseTextField.useTextField; });
10
+ $parcel$export(module.exports, "useFormattedTextField", function () { return $jAs05$reactariaprivatetextfielduseFormattedTextField.useFormattedTextField; });
11
11
  /*
12
12
  * Copyright 2020 Adobe. All rights reserved.
13
13
  * This file is licensed to you under the Apache License, Version 2.0 (the "License");
package/dist/main.js.map CHANGED
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-aria/textfield/src/index.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"],"names":[],"version":3,"file":"main.js.map"}
1
+ {"mappings":";;;;;;;;;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-aria/textfield/src/index.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 {useTextField} from 'react-aria/useTextField';\n\nexport {useFormattedTextField} from 'react-aria/private/textfield/useFormattedTextField';\nexport type {TextFieldAria, AriaTextFieldOptions, TextFieldProps, AriaTextFieldProps} from 'react-aria/useTextField';\n"],"names":[],"version":3,"file":"main.js.map"}
package/dist/module.js CHANGED
@@ -1,5 +1,5 @@
1
- import {useTextField as $2d73ec29415bd339$export$712718f7aec83d5} from "./useTextField.module.js";
2
- import {useFormattedTextField as $d841c8010a73d545$export$4f384c9210e583c3} from "./useFormattedTextField.module.js";
1
+ import {useTextField as $0fa547b14c3cee43$re_export$useTextField} from "react-aria/useTextField";
2
+ import {useFormattedTextField as $0fa547b14c3cee43$re_export$useFormattedTextField} from "react-aria/private/textfield/useFormattedTextField";
3
3
 
4
4
  /*
5
5
  * Copyright 2020 Adobe. All rights reserved.
@@ -15,5 +15,5 @@ import {useFormattedTextField as $d841c8010a73d545$export$4f384c9210e583c3} from
15
15
 
16
16
 
17
17
 
18
- export {$2d73ec29415bd339$export$712718f7aec83d5 as useTextField, $d841c8010a73d545$export$4f384c9210e583c3 as useFormattedTextField};
18
+ export {$0fa547b14c3cee43$re_export$useTextField as useTextField, $0fa547b14c3cee43$re_export$useFormattedTextField as useFormattedTextField};
19
19
  //# sourceMappingURL=module.js.map
@@ -1 +1 @@
1
- {"mappings":";;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-aria/textfield/src/index.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"],"names":[],"version":3,"file":"module.js.map"}
1
+ {"mappings":";;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-aria/textfield/src/index.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 {useTextField} from 'react-aria/useTextField';\n\nexport {useFormattedTextField} from 'react-aria/private/textfield/useFormattedTextField';\nexport type {TextFieldAria, AriaTextFieldOptions, TextFieldProps, AriaTextFieldProps} from 'react-aria/useTextField';\n"],"names":[],"version":3,"file":"module.js.map"}
@@ -0,0 +1,3 @@
1
+ export { useTextField } from 'react-aria/useTextField';
2
+ export { useFormattedTextField } from 'react-aria/private/textfield/useFormattedTextField';
3
+ export type { TextFieldAria, AriaTextFieldOptions, TextFieldProps, AriaTextFieldProps } from 'react-aria/useTextField';
package/package.json CHANGED
@@ -1,20 +1,20 @@
1
1
  {
2
2
  "name": "@react-aria/textfield",
3
- "version": "3.18.5",
3
+ "version": "3.19.0",
4
4
  "description": "Spectrum UI components in React",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/main.js",
7
7
  "module": "dist/module.js",
8
8
  "exports": {
9
- "source": "./src/index.ts",
10
- "types": [
11
- "./dist/types.d.ts",
12
- "./src/index.ts"
13
- ],
14
- "import": "./dist/import.mjs",
15
- "require": "./dist/main.js"
9
+ ".": {
10
+ "source": "./src/index.ts",
11
+ "types": "./dist/types/src/index.d.ts",
12
+ "import": "./dist/import.mjs",
13
+ "require": "./dist/main.js"
14
+ },
15
+ "./package.json": "./package.json"
16
16
  },
17
- "types": "dist/types.d.ts",
17
+ "types": "dist/types/src/index.d.ts",
18
18
  "source": "src/index.ts",
19
19
  "files": [
20
20
  "dist",
@@ -26,15 +26,8 @@
26
26
  "url": "https://github.com/adobe/react-spectrum"
27
27
  },
28
28
  "dependencies": {
29
- "@react-aria/form": "^3.1.5",
30
- "@react-aria/interactions": "^3.27.1",
31
- "@react-aria/label": "^3.7.25",
32
- "@react-aria/utils": "^3.33.1",
33
- "@react-stately/form": "^3.2.4",
34
- "@react-stately/utils": "^3.11.0",
35
- "@react-types/shared": "^3.33.1",
36
- "@react-types/textfield": "^3.12.8",
37
- "@swc/helpers": "^0.5.0"
29
+ "@swc/helpers": "^0.5.0",
30
+ "react-aria": "3.48.0"
38
31
  },
39
32
  "peerDependencies": {
40
33
  "react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1",
@@ -43,5 +36,8 @@
43
36
  "publishConfig": {
44
37
  "access": "public"
45
38
  },
46
- "gitHead": "8df187370053aa35f553cb388ad670f65e1ab371"
39
+ "targets": {
40
+ "types": false
41
+ },
42
+ "gitHead": "a6999bdf494a2e9c0381a5881908328bdd22ddae"
47
43
  }
package/src/index.ts CHANGED
@@ -9,8 +9,7 @@
9
9
  * OF ANY KIND, either express or implied. See the License for the specific language
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
- export type {TextFieldAria} from './useTextField';
13
- export {useTextField} from './useTextField';
14
- export {useFormattedTextField} from './useFormattedTextField';
15
- export type {AriaTextFieldOptions} from './useTextField';
16
- export type {AriaTextFieldProps} from '@react-types/textfield';
12
+ export {useTextField} from 'react-aria/useTextField';
13
+
14
+ export {useFormattedTextField} from 'react-aria/private/textfield/useFormattedTextField';
15
+ export type {TextFieldAria, AriaTextFieldOptions, TextFieldProps, AriaTextFieldProps} from 'react-aria/useTextField';
package/dist/types.d.ts DELETED
@@ -1,86 +0,0 @@
1
- import { AriaTextFieldProps } from "@react-types/textfield";
2
- import { DOMAttributes, ValidationResult, RefObject as _RefObject1 } from "@react-types/shared";
3
- import { HTMLAttributes, JSX, LabelHTMLAttributes, RefObject } from "react";
4
- /**
5
- * A map of HTML element names and their interface types.
6
- * For example `'a'` -> `HTMLAnchorElement`.
7
- */
8
- type IntrinsicHTMLElements = {
9
- [K in keyof IntrinsicHTMLAttributes]: IntrinsicHTMLAttributes[K] extends HTMLAttributes<infer T> ? T : never;
10
- };
11
- /**
12
- * A map of HTML element names and their attribute interface types.
13
- * For example `'a'` -> `AnchorHTMLAttributes<HTMLAnchorElement>`.
14
- */
15
- type IntrinsicHTMLAttributes = JSX.IntrinsicElements;
16
- type DefaultElementType = 'input';
17
- /**
18
- * The intrinsic HTML element names that `useTextField` supports; e.g. `input`,
19
- * `textarea`.
20
- */
21
- type TextFieldIntrinsicElements = keyof Pick<IntrinsicHTMLElements, 'input' | 'textarea'>;
22
- /**
23
- * The HTML element interfaces that `useTextField` supports based on what is
24
- * defined for `TextFieldIntrinsicElements`; e.g. `HTMLInputElement`,
25
- * `HTMLTextAreaElement`.
26
- */
27
- type TextFieldHTMLElementType = Pick<IntrinsicHTMLElements, TextFieldIntrinsicElements>;
28
- /**
29
- * The HTML attributes interfaces that `useTextField` supports based on what
30
- * is defined for `TextFieldIntrinsicElements`; e.g. `InputHTMLAttributes`,
31
- * `TextareaHTMLAttributes`.
32
- */
33
- type TextFieldHTMLAttributesType = Pick<IntrinsicHTMLAttributes, TextFieldIntrinsicElements>;
34
- /**
35
- * The type of `inputProps` returned by `useTextField`; e.g. `InputHTMLAttributes`,
36
- * `TextareaHTMLAttributes`.
37
- */
38
- type TextFieldInputProps<T extends TextFieldIntrinsicElements> = TextFieldHTMLAttributesType[T];
39
- export interface AriaTextFieldOptions<T extends TextFieldIntrinsicElements> extends AriaTextFieldProps<TextFieldHTMLElementType[T]> {
40
- /**
41
- * The HTML element used to render the input, e.g. 'input', or 'textarea'.
42
- * It determines whether certain HTML attributes will be included in `inputProps`.
43
- * For example, [`type`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attr-type).
44
- * @default 'input'
45
- */
46
- inputElementType?: T;
47
- /**
48
- * Controls whether inputted text is automatically capitalized and, if so, in what manner.
49
- * See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/autocapitalize).
50
- */
51
- autoCapitalize?: 'off' | 'none' | 'on' | 'sentences' | 'words' | 'characters';
52
- /**
53
- * 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).
54
- */
55
- enterKeyHint?: 'enter' | 'done' | 'go' | 'next' | 'previous' | 'search' | 'send';
56
- }
57
- /**
58
- * The type of `ref` object that can be passed to `useTextField` based on the given
59
- * intrinsic HTML element name; e.g.`RefObject<HTMLInputElement>`,
60
- * `RefObject<HTMLTextAreaElement>`.
61
- */
62
- type TextFieldRefObject<T extends TextFieldIntrinsicElements> = RefObject<TextFieldHTMLElementType[T] | null>;
63
- export interface TextFieldAria<T extends TextFieldIntrinsicElements = DefaultElementType> extends ValidationResult {
64
- /** Props for the input element. */
65
- inputProps: TextFieldInputProps<T>;
66
- /** Props for the text field's visible label element, if any. */
67
- labelProps: DOMAttributes | LabelHTMLAttributes<HTMLLabelElement>;
68
- /** Props for the text field's description element, if any. */
69
- descriptionProps: DOMAttributes;
70
- /** Props for the text field's error message element, if any. */
71
- errorMessageProps: DOMAttributes;
72
- }
73
- /**
74
- * Provides the behavior and accessibility implementation for a text field.
75
- * @param props - Props for the text field.
76
- * @param ref - Ref to the HTML input or textarea element.
77
- */
78
- export function useTextField<T extends TextFieldIntrinsicElements = DefaultElementType>(props: AriaTextFieldOptions<T>, ref: TextFieldRefObject<T>): TextFieldAria<T>;
79
- interface FormattedTextFieldState {
80
- validate: (val: string) => boolean;
81
- setInputValue: (val: string) => void;
82
- }
83
- export function useFormattedTextField(props: AriaTextFieldProps, state: FormattedTextFieldState, inputRef: _RefObject1<HTMLInputElement | null>): TextFieldAria;
84
- export type { AriaTextFieldProps } from '@react-types/textfield';
85
-
86
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"mappings":";;;AA6BA;;;GAGG;AACH,6BAA6B;KAC1B,CAAC,IAAI,MAAM,uBAAuB,GAAG,uBAAuB,CAAC,CAAC,CAAC,SAAS,eAAe,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK;CAC7G,CAAC;AAEF;;;GAGG;AACH,+BAA+B,IAAI,iBAAiB,CAAC;AAErD,0BAA0B,OAAO,CAAC;AAElC;;;GAGG;AACH,kCAAkC,MAAM,IAAI,CAAC,qBAAqB,EAAE,OAAO,GAAG,UAAU,CAAC,CAAC;AAE1F;;;;GAIG;AACH,gCAAgC,IAAI,CAAC,qBAAqB,EAAE,0BAA0B,CAAC,CAAC;AAExF;;;;GAIG;AACH,mCAAmC,IAAI,CAAC,uBAAuB,EAAE,0BAA0B,CAAC,CAAC;AAE7F;;;GAGG;AACH,yBAAyB,CAAC,SAAS,0BAA0B,IAAI,2BAA2B,CAAC,CAAC,CAAC,CAAC;AAEhG,sCAAsC,CAAC,SAAS,0BAA0B,CAAE,SAAQ,mBAAmB,wBAAwB,CAAC,CAAC,CAAC,CAAC;IACjI;;;;;OAKG;IACH,gBAAgB,CAAC,EAAE,CAAC,CAAC;IACrB;;;OAGG;IACH,cAAc,CAAC,EAAE,KAAK,GAAG,MAAM,GAAG,IAAI,GAAG,WAAW,GAAG,OAAO,GAAG,YAAY,CAAC;IAC9E;;OAEG;IACH,YAAY,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,GAAG,MAAM,GAAG,UAAU,GAAG,QAAQ,GAAG,MAAM,CAAA;CACjF;AAED;;;;GAIG;AACH,wBAAwB,CAAC,SAAS,0BAA0B,IAAI,UAAU,wBAAwB,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;AAE9G,+BAA+B,CAAC,SAAS,0BAA0B,GAAG,kBAAkB,CAAE,SAAQ,gBAAgB;IAChH,mCAAmC;IACnC,UAAU,EAAE,oBAAoB,CAAC,CAAC,CAAC;IACnC,gEAAgE;IAChE,UAAU,EAAE,aAAa,GAAG,oBAAoB,gBAAgB,CAAC,CAAC;IAClE,8DAA8D;IAC9D,gBAAgB,EAAE,aAAa,CAAC;IAChC,gEAAgE;IAChE,iBAAiB,EAAE,aAAa,CAAA;CACjC;AAED;;;;GAIG;AACH,6BAA6B,CAAC,SAAS,0BAA0B,GAAG,kBAAkB,EACpF,KAAK,EAAE,qBAAqB,CAAC,CAAC,EAC9B,GAAG,EAAE,mBAAmB,CAAC,CAAC,GACzB,cAAc,CAAC,CAAC,CAwFlB;AC1LD;IACE,QAAQ,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC;IACnC,aAAa,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAA;CACrC;AASD,sCAAsC,KAAK,EAAE,kBAAkB,EAAE,KAAK,EAAE,uBAAuB,EAAE,QAAQ,EAAE,YAAU,gBAAgB,GAAG,IAAI,CAAC,GAAG,aAAa,CAoI5J;ACnJD,YAAY,EAAC,kBAAkB,EAAC,MAAM,wBAAwB,CAAC","sources":["packages/@react-aria/textfield/src/packages/@react-aria/textfield/src/useTextField.ts","packages/@react-aria/textfield/src/packages/@react-aria/textfield/src/useFormattedTextField.ts","packages/@react-aria/textfield/src/packages/@react-aria/textfield/src/index.ts","packages/@react-aria/textfield/src/index.ts"],"sourcesContent":[null,null,null,"/*\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"],"names":[],"version":3,"file":"types.d.ts.map"}
@@ -1,135 +0,0 @@
1
- var $9076f978e02df845$exports = require("./useTextField.main.js");
2
- var $6PuoT$reactariautils = require("@react-aria/utils");
3
- var $6PuoT$react = require("react");
4
-
5
-
6
- function $parcel$export(e, n, v, s) {
7
- Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
8
- }
9
-
10
- $parcel$export(module.exports, "useFormattedTextField", () => $56b68c3dab9bf16c$export$4f384c9210e583c3);
11
- /*
12
- * Copyright 2021 Adobe. All rights reserved.
13
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
14
- * you may not use this file except in compliance with the License. You may obtain a copy
15
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
16
- *
17
- * Unless required by applicable law or agreed to in writing, software distributed under
18
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
19
- * OF ANY KIND, either express or implied. See the License for the specific language
20
- * governing permissions and limitations under the License.
21
- */
22
-
23
-
24
- function $56b68c3dab9bf16c$var$supportsNativeBeforeInputEvent() {
25
- return typeof window !== 'undefined' && window.InputEvent && typeof InputEvent.prototype.getTargetRanges === 'function';
26
- }
27
- function $56b68c3dab9bf16c$export$4f384c9210e583c3(props, state, inputRef) {
28
- // All browsers implement the 'beforeinput' event natively except Firefox
29
- // (currently behind a flag as of Firefox 84). React's polyfill does not
30
- // run in all cases that the native event fires, e.g. when deleting text.
31
- // Use the native event if available so that we can prevent invalid deletions.
32
- // We do not attempt to polyfill this in Firefox since it would be very complicated,
33
- // the benefit of doing so is fairly minor, and it's going to be natively supported soon.
34
- let onBeforeInputFallback = (0, $6PuoT$reactariautils.useEffectEvent)((e)=>{
35
- let input = inputRef.current;
36
- if (!input) return;
37
- // Compute the next value of the input if the event is allowed to proceed.
38
- // See https://www.w3.org/TR/input-events-2/#interface-InputEvent-Attributes for a full list of input types.
39
- let nextValue = null;
40
- switch(e.inputType){
41
- case 'historyUndo':
42
- case 'historyRedo':
43
- // Explicitly allow undo/redo. e.data is null in this case, but there's no need to validate,
44
- // because presumably the input would have already been validated previously.
45
- return;
46
- case 'insertLineBreak':
47
- // Explicitly allow "insertLineBreak" event, to allow onSubmit for "enter" key. e.data is null in this case.
48
- return;
49
- case 'deleteContent':
50
- case 'deleteByCut':
51
- case 'deleteByDrag':
52
- nextValue = input.value.slice(0, input.selectionStart) + input.value.slice(input.selectionEnd);
53
- break;
54
- case 'deleteContentForward':
55
- // This is potentially incorrect, since the browser may actually delete more than a single UTF-16
56
- // character. In reality, a full Unicode grapheme cluster consisting of multiple UTF-16 characters
57
- // or code points may be deleted. However, in our currently supported locales, there are no such cases.
58
- // If we support additional locales in the future, this may need to change.
59
- 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);
60
- break;
61
- case 'deleteContentBackward':
62
- 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);
63
- break;
64
- case 'deleteSoftLineBackward':
65
- case 'deleteHardLineBackward':
66
- nextValue = input.value.slice(input.selectionStart);
67
- break;
68
- default:
69
- if (e.data != null) nextValue = input.value.slice(0, input.selectionStart) + e.data + input.value.slice(input.selectionEnd);
70
- break;
71
- }
72
- // If we did not compute a value, or the new value is invalid, prevent the event
73
- // so that the browser does not update the input text, move the selection, or add to
74
- // the undo/redo stack.
75
- if (nextValue == null || !state.validate(nextValue)) e.preventDefault();
76
- });
77
- (0, $6PuoT$react.useEffect)(()=>{
78
- if (!$56b68c3dab9bf16c$var$supportsNativeBeforeInputEvent() || !inputRef.current) return;
79
- let input = inputRef.current;
80
- input.addEventListener('beforeinput', onBeforeInputFallback, false);
81
- return ()=>{
82
- input.removeEventListener('beforeinput', onBeforeInputFallback, false);
83
- };
84
- }, [
85
- inputRef
86
- ]);
87
- let onBeforeInput = !$56b68c3dab9bf16c$var$supportsNativeBeforeInputEvent() ? (e)=>{
88
- let nextValue = (0, $6PuoT$reactariautils.getEventTarget)(e).value.slice(0, (0, $6PuoT$reactariautils.getEventTarget)(e).selectionStart) + e.data + (0, $6PuoT$reactariautils.getEventTarget)(e).value.slice((0, $6PuoT$reactariautils.getEventTarget)(e).selectionEnd);
89
- if (!state.validate(nextValue)) e.preventDefault();
90
- } : null;
91
- let { labelProps: labelProps, inputProps: textFieldProps, descriptionProps: descriptionProps, errorMessageProps: errorMessageProps, ...validation } = (0, $9076f978e02df845$exports.useTextField)(props, inputRef);
92
- let compositionStartState = (0, $6PuoT$react.useRef)(null);
93
- return {
94
- inputProps: (0, $6PuoT$reactariautils.mergeProps)(textFieldProps, {
95
- onBeforeInput: onBeforeInput,
96
- onCompositionStart () {
97
- // Chrome does not implement Input Events Level 2, which specifies the insertFromComposition
98
- // and deleteByComposition inputType values for the beforeinput event. These are meant to occur
99
- // at the end of a composition (e.g. Pinyin IME, Android auto correct, etc.), and crucially, are
100
- // cancelable. The insertCompositionText and deleteCompositionText input types are not cancelable,
101
- // nor would we want to cancel them because the input from the user is incomplete at that point.
102
- // In Safari, insertFromComposition/deleteFromComposition will fire, however, allowing us to cancel
103
- // the final composition result if it is invalid. As a fallback for Chrome and Firefox, which either
104
- // don't support Input Events Level 2, or beforeinput at all, we store the state of the input when
105
- // the compositionstart event fires, and undo the changes in compositionend (below) if it is invalid.
106
- // Unfortunately, this messes up the undo/redo stack, but until insertFromComposition/deleteByComposition
107
- // are implemented, there is no other way to prevent composed input.
108
- // See https://bugs.chromium.org/p/chromium/issues/detail?id=1022204
109
- let { value: value, selectionStart: selectionStart, selectionEnd: selectionEnd } = inputRef.current;
110
- compositionStartState.current = {
111
- value: value,
112
- selectionStart: selectionStart,
113
- selectionEnd: selectionEnd
114
- };
115
- },
116
- onCompositionEnd () {
117
- if (inputRef.current && !state.validate(inputRef.current.value)) {
118
- // Restore the input value in the DOM immediately so we can synchronously update the selection position.
119
- // But also update the value in React state as well so it is correct for future updates.
120
- let { value: value, selectionStart: selectionStart, selectionEnd: selectionEnd } = compositionStartState.current;
121
- inputRef.current.value = value;
122
- inputRef.current.setSelectionRange(selectionStart, selectionEnd);
123
- state.setInputValue(value);
124
- }
125
- }
126
- }),
127
- labelProps: labelProps,
128
- descriptionProps: descriptionProps,
129
- errorMessageProps: errorMessageProps,
130
- ...validation
131
- };
132
- }
133
-
134
-
135
- //# sourceMappingURL=useFormattedTextField.main.js.map
@@ -1 +0,0 @@
1
- {"mappings":"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","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 {getEventTarget, mergeProps, useEffectEvent} from '@react-aria/utils';\nimport {InputEventHandler, useEffect, useRef} from 'react';\nimport {RefObject} from '@react-types/shared';\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 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: InputEventHandler<HTMLInputElement> | null = !supportsNativeBeforeInputEvent()\n ? e => {\n let nextValue =\n getEventTarget(e).value.slice(0, getEventTarget(e).selectionStart!) +\n e.data +\n getEventTarget(e).value.slice(getEventTarget(e).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.main.js.map"}
@@ -1,130 +0,0 @@
1
- import {useTextField as $2d73ec29415bd339$export$712718f7aec83d5} from "./useTextField.mjs";
2
- import {useEffectEvent as $jyGKS$useEffectEvent, getEventTarget as $jyGKS$getEventTarget, 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 = (0, $jyGKS$getEventTarget)(e).value.slice(0, (0, $jyGKS$getEventTarget)(e).selectionStart) + e.data + (0, $jyGKS$getEventTarget)(e).value.slice((0, $jyGKS$getEventTarget)(e).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