{"version":3,"sources":["../source/InputBasic.js"],"names":["createInput","defaultMetadata","InputBasic","ref","value","onChange","country","international","metadata","Input","inputComponent","rest","prefix","_onChange","event","newValue","target","newValueFormatted","format","indexOf","slice","React","forwardRef","propTypes","PropTypes","string","isRequired","func","bool","object","elementType","defaultProps"],"mappings":";;;;;;;;;;AAAA;;AACA;;AACA;;AAEA;;;;;;;;;;;;;;AAEO,SAASA,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,GAAG,2CAAoBN,OAApB,EAA6BC,aAA7B,EAA4CC,QAA5C,CAAf;;AAEA,QAAMK,SAAS,GAAG,wBAAY,UAACC,KAAD,EAAW;AACxC,UAAIC,QAAQ,GAAG,sCAA2BD,KAAK,CAACE,MAAN,CAAaZ,KAAxC,CAAf,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,MAAkD,CAAtD,EAAyD;AACxD;AACAW,UAAAA,QAAQ,GAAGA,QAAQ,CAACK,KAAT,CAAe,CAAf,EAAkB,CAAC,CAAnB,CAAX;AACA;AACD;;AACDf,MAAAA,QAAQ,CAACU,QAAD,CAAR;AACA,KAjBiB,EAiBf,CAACH,MAAD,EAASR,KAAT,EAAgBC,QAAhB,EAA0BC,OAA1B,EAAmCE,QAAnC,CAjBe,CAAlB;;AAmBA,WACC,gCAAC,KAAD,eACKG,IADL;AAEC,MAAA,GAAG,EAAER,GAFN;AAGC,MAAA,KAAK,EAAEe,MAAM,CAACN,MAAD,EAASR,KAAT,EAAgBE,OAAhB,EAAyBE,QAAzB,CAHd;AAIC,MAAA,QAAQ,EAAEK;AAJX,OADD;AAOA;;AAEDX,EAAAA,UAAU,GAAGmB,kBAAMC,UAAN,CAAiBpB,UAAjB,CAAb;AAEAA,EAAAA,UAAU,CAACqB,SAAX,GAAuB;AACtB;;;;;;;AAOAnB,IAAAA,KAAK,EAAEoB,sBAAUC,MAAV,CAAiBC,UARF;;AAUtB;;;AAGArB,IAAAA,QAAQ,EAAEmB,sBAAUG,IAAV,CAAeD,UAbH;;AAetB;;;;;;;;;;AAUApB,IAAAA,OAAO,EAAGkB,sBAAUC,MAzBE;;AA2BtB;;;;;;;;;;AAUAlB,IAAAA,aAAa,EAAEiB,sBAAUI,IArCH;;AAuCtB;;;AAGApB,IAAAA,QAAQ,EAAEgB,sBAAUK,MAAV,CAAiBH,UA1CL;;AA4CtB;;;AAGAhB,IAAAA,cAAc,EAAEc,sBAAUM,WAAV,CAAsBJ;AA/ChB,GAAvB;AAkDAxB,EAAAA,UAAU,CAAC6B,YAAX,GAA0B;AACzBvB,IAAAA,QAAQ,EAAEP,eADe;AAEzBS,IAAAA,cAAc,EAAE;AAFS,GAA1B;AAKA,SAAOR,UAAP;AACA;;eAEcF,WAAW,E;;;;AAE1B,SAASkB,MAAT,CAAgBN,MAAhB,EAAwBR,KAAxB,EAA+BE,OAA/B,EAAwCE,QAAxC,EAAkD;AACjD,SAAO,8CACN,uCACCI,MAAM,GAAGR,KADV,EAECE,OAFD,EAGCE,QAHD,CADM,EAMNI,MANM,CAAP;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"}