{"version":3,"sources":["../source/InputBasic.js"],"names":["React","useCallback","PropTypes","parseIncompletePhoneNumber","formatIncompletePhoneNumber","getInputValuePrefix","removeInputValuePrefix","createInput","defaultMetadata","InputBasic","ref","value","onChange","country","international","metadata","Input","inputComponent","rest","prefix","_onChange","event","newValue","target","newValueFormatted","format","indexOf","slice","forwardRef","propTypes","string","isRequired","func","bool","object","elementType","defaultProps"],"mappings":";;;;;;AAAA,OAAOA,KAAP,IAAgBC,WAAhB,QAAmC,OAAnC;AACA,OAAOC,SAAP,MAAsB,YAAtB;AACA,SAASC,0BAAT,EAAqCC,2BAArC,QAAwE,wBAAxE;AAEA,SAASC,mBAAT,EAA8BC,sBAA9B,QAA4D,oBAA5D;AAEA,OAAO,SAASC,WAAT,CAAqBC,eAArB,EAAsC;AAC5C;;;;;;AAMA,WAASC,UAAT,OAQGC,GARH,EAQQ;AAAA,QAPPC,KAOO,QAPPA,KAOO;AAAA,QANPC,QAMO,QANPA,QAMO;AAAA,QALPC,OAKO,QALPA,OAKO;AAAA,QAJPC,aAIO,QAJPA,aAIO;AAAA,QAHPC,QAGO,QAHPA,QAGO;AAAA,QAFSC,KAET,QAFPC,cAEO;AAAA,QADJC,IACI;;AACP,QAAMC,MAAM,GAAGd,mBAAmB,CAACQ,OAAD,EAAUC,aAAV,EAAyBC,QAAzB,CAAlC;;AAEA,QAAMK,SAAS,GAAGnB,WAAW,CAAC,UAACoB,KAAD,EAAW;AACxC,UAAIC,QAAQ,GAAGnB,0BAA0B,CAACkB,KAAK,CAACE,MAAN,CAAaZ,KAAd,CAAzC,CADwC,CAExC;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,UAAIW,QAAQ,KAAKX,KAAjB,EAAwB;AACvB,YAAMa,iBAAiB,GAAGC,MAAM,CAACN,MAAD,EAASG,QAAT,EAAmBT,OAAnB,EAA4BE,QAA5B,CAAhC;;AACA,YAAIS,iBAAiB,CAACE,OAAlB,CAA0BL,KAAK,CAACE,MAAN,CAAaZ,KAAvC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gBN,MAAhB,EAAwBR,KAAxB,EAA+BE,OAA/B,EAAwCE,QAAxC,EAAkD;AACjD,SAAOT,sBAAsB,CAC5BF,2BAA2B,CAC1Be,MAAM,GAAGR,KADiB,EAE1BE,OAF0B,EAG1BE,QAH0B,CADC,EAM5BI,MAN4B,CAA7B;AAQA","sourcesContent":["import React, { useCallback } from 'react'\r\nimport PropTypes from 'prop-types'\r\nimport { parseIncompletePhoneNumber, formatIncompletePhoneNumber } from 'libphonenumber-js/core'\r\n\r\nimport { getInputValuePrefix, removeInputValuePrefix } from './inputValuePrefix'\r\n\r\nexport function createInput(defaultMetadata) {\r\n\t/**\r\n\t * `InputBasic`'s caret is not as \"smart\" as the default `inputComponent`'s\r\n\t * but still works good enough. When erasing or inserting digits in the middle\r\n\t * of a phone number the caret usually jumps to the end: this is the expected\r\n\t * behaviour and it's the workaround for the [Samsung Galaxy smart caret positioning bug](https://github.com/catamphetamine/react-phone-number-input/issues/75).\r\n\t */\r\n\tfunction InputBasic({\r\n\t\tvalue,\r\n\t\tonChange,\r\n\t\tcountry,\r\n\t\tinternational,\r\n\t\tmetadata,\r\n\t\tinputComponent: Input,\r\n\t\t...rest\r\n\t}, ref) {\r\n\t\tconst prefix = getInputValuePrefix(country, international, metadata)\r\n\r\n\t\tconst _onChange = useCallback((event) => {\r\n\t\t\tlet newValue = parseIncompletePhoneNumber(event.target.value)\r\n\t\t\t// By default, if a value is something like `\"(123)\"`\r\n\t\t\t// then Backspace would only erase the rightmost brace\r\n\t\t\t// becoming something like `\"(123\"`\r\n\t\t\t// which would give the same `\"123\"` value\r\n\t\t\t// which would then be formatted back to `\"(123)\"`\r\n\t\t\t// and so a user wouldn't be able to erase the phone number.\r\n\t\t\t// Working around this issue with this simple hack.\r\n\t\t\tif (newValue === value) {\r\n\t\t\t\tconst newValueFormatted = format(prefix, newValue, country, metadata)\r\n\t\t\t\tif (newValueFormatted.indexOf(event.target.value) === 0) {\r\n\t\t\t\t\t// Trim the last digit (or plus sign).\r\n\t\t\t\t\tnewValue = newValue.slice(0, -1)\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tonChange(newValue)\r\n\t\t}, [prefix, value, onChange, country, metadata])\r\n\r\n\t\treturn (\r\n\t\t\t\r\n\t\t)\r\n\t}\r\n\r\n\tInputBasic = React.forwardRef(InputBasic)\r\n\r\n\tInputBasic.propTypes = {\r\n\t\t/**\r\n\t\t * The parsed phone number.\r\n\t\t * \"Parsed\" not in a sense of \"E.164\"\r\n\t\t * but rather in a sense of \"having only\r\n\t\t * digits and possibly a leading plus character\".\r\n\t\t * Examples: `\"\"`, `\"+\"`, `\"+123\"`, `\"123\"`.\r\n\t\t */\r\n\t\tvalue: PropTypes.string.isRequired,\r\n\r\n\t\t/**\r\n\t\t * Updates the `value`.\r\n\t\t */\r\n\t\tonChange: PropTypes.func.isRequired,\r\n\r\n\t\t/**\r\n\t\t * A two-letter country code for formatting `value`\r\n\t\t * as a national phone number (e.g. `(800) 555 35 35`).\r\n\t\t * E.g. \"US\", \"RU\", etc.\r\n\t\t * If no `country` is passed then `value`\r\n\t\t * is formatted as an international phone number.\r\n\t\t * (e.g. `+7 800 555 35 35`)\r\n\t\t * Perhaps the `country` property should have been called `defaultCountry`\r\n\t\t * because if `value` is an international number then `country` is ignored.\r\n\t\t */\r\n\t\tcountry : PropTypes.string,\r\n\r\n\t\t/**\r\n\t\t * If `country` property is passed along with `international={true}` property\r\n\t\t * then the phone number will be input in \"international\" format for that `country`\r\n\t\t * (without \"country calling code\").\r\n\t\t * For example, if `country=\"US\"` property is passed to \"without country select\" input\r\n\t\t * then the phone number will be input in the \"national\" format for `US` (`(213) 373-4253`).\r\n\t\t * But if both `country=\"US\"` and `international={true}` properties are passed then\r\n\t\t * the phone number will be input in the \"international\" format for `US` (`213 373 4253`)\r\n\t\t * (without \"country calling code\" `+1`).\r\n\t\t */\r\n\t\tinternational: PropTypes.bool,\r\n\r\n\t\t/**\r\n\t\t * `libphonenumber-js` metadata.\r\n\t\t */\r\n\t\tmetadata: PropTypes.object.isRequired,\r\n\r\n\t\t/**\r\n\t\t * The `` component.\r\n\t\t */\r\n\t\tinputComponent: PropTypes.elementType.isRequired\r\n\t}\r\n\r\n\tInputBasic.defaultProps = {\r\n\t\tmetadata: defaultMetadata,\r\n\t\tinputComponent: 'input'\r\n\t}\r\n\r\n\treturn InputBasic\r\n}\r\n\r\nexport default createInput()\r\n\r\nfunction format(prefix, value, country, metadata) {\r\n\treturn removeInputValuePrefix(\r\n\t\tformatIncompletePhoneNumber(\r\n\t\t\tprefix + value,\r\n\t\t\tcountry,\r\n\t\t\tmetadata\r\n\t\t),\r\n\t\tprefix\r\n\t)\r\n}"],"file":"InputBasic.js"}