{"version":3,"sources":["../source/InputSmart.js"],"names":["createInput","defaultMetadata","InputSmart","ref","country","international","metadata","rest","format","value","formatter","AsYouType","prefix","text","input","template","getTemplate","parsePhoneNumberCharacter","React","forwardRef","propTypes","PropTypes","string","bool","object","isRequired","defaultProps"],"mappings":";;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AAEA;;;;;;;;;;;;;;AAMO,SAASA,WAAT,CAAqBC,eAArB,EACP;AACC,WAASC,UAAT,OAKGC,GALH,EAKQ;AAAA,QAJPC,OAIO,QAJPA,OAIO;AAAA,QAHPC,aAGO,QAHPA,aAGO;AAAA,QAFPC,QAEO,QAFPA,QAEO;AAAA,QADJC,IACI;;AACP,QAAMC,MAAM,GAAG,wBAAY,UAACC,KAAD,EAAW;AACrC;AACA,UAAMC,SAAS,GAAG,IAAIC,eAAJ,CAAcP,OAAd,EAAuBE,QAAvB,CAAlB;AACA,UAAMM,MAAM,GAAG,2CAAoBR,OAApB,EAA6BC,aAA7B,EAA4CC,QAA5C,CAAf,CAHqC,CAIrC;;AACA,UAAIO,IAAI,GAAGH,SAAS,CAACI,KAAV,CAAgBF,MAAM,GAAGH,KAAzB,CAAX;AACA,UAAIM,QAAQ,GAAGL,SAAS,CAACM,WAAV,EAAf;;AACA,UAAIJ,MAAJ,EAAY;AACXC,QAAAA,IAAI,GAAG,8CAAuBA,IAAvB,EAA6BD,MAA7B,CAAP,CADW,CAEX;;AACA,YAAIG,QAAJ,EAAc;AACbA,UAAAA,QAAQ,GAAG,8CAAuBA,QAAvB,EAAiCH,MAAjC,CAAX;AACA;AACD;;AACD,aAAO;AACNC,QAAAA,IAAI,EAAJA,IADM;AAENE,QAAAA,QAAQ,EAARA;AAFM,OAAP;AAIA,KAlBc,EAkBZ,CAACX,OAAD,EAAUE,QAAV,CAlBY,CAAf;AAmBA,WACC,gCAAC,kBAAD,eACKC,IADL;AAEC,MAAA,GAAG,EAAEJ,GAFN;AAGC,MAAA,KAAK,EAAEc,+BAHR;AAIC,MAAA,MAAM,EAAET;AAJT,OADD;AAOA;;AAEDN,EAAAA,UAAU,GAAGgB,kBAAMC,UAAN,CAAiBjB,UAAjB,CAAb;AAEAA,EAAAA,UAAU,CAACkB,SAAX,GAAuB;AACtB;;;;;;;;;;AAUAhB,IAAAA,OAAO,EAAEiB,sBAAUC,MAXG;;AAatB;;;;;;;;;;AAUAjB,IAAAA,aAAa,EAAEgB,sBAAUE,IAvBH;;AAyBtB;;;AAGAjB,IAAAA,QAAQ,EAAEe,sBAAUG,MAAV,CAAiBC;AA5BL,GAAvB;AA+BAvB,EAAAA,UAAU,CAACwB,YAAX,GAA0B;AACzBpB,IAAAA,QAAQ,EAAEL;AADe,GAA1B;AAIA,SAAOC,UAAP;AACA;;eAEcF,WAAW,E","sourcesContent":["import React, { useCallback } from 'react'\r\nimport PropTypes from 'prop-types'\r\nimport Input from 'input-format/react'\r\nimport { AsYouType, parsePhoneNumberCharacter } from 'libphonenumber-js/core'\r\n\r\nimport { getInputValuePrefix, removeInputValuePrefix } from './inputValuePrefix'\r\n\r\n/**\r\n * This input uses `input-format` library\r\n * for \"smart\" caret positioning.\r\n */\r\nexport function createInput(defaultMetadata)\r\n{\r\n\tfunction InputSmart({\r\n\t\tcountry,\r\n\t\tinternational,\r\n\t\tmetadata,\r\n\t\t...rest\r\n\t}, ref) {\r\n\t\tconst format = useCallback((value) => {\r\n\t\t\t// \"As you type\" formatter.\r\n\t\t\tconst formatter = new AsYouType(country, metadata)\r\n\t\t\tconst prefix = getInputValuePrefix(country, international, metadata)\r\n\t\t\t// Format the number.\r\n\t\t\tlet text = formatter.input(prefix + value)\r\n\t\t\tlet template = formatter.getTemplate()\r\n\t\t\tif (prefix) {\r\n\t\t\t\ttext = removeInputValuePrefix(text, prefix)\r\n\t\t\t\t// `AsYouType.getTemplate()` can be `undefined`.\r\n\t\t\t\tif (template) {\r\n\t\t\t\t\ttemplate = removeInputValuePrefix(template, prefix)\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\treturn {\r\n\t\t\t\ttext,\r\n\t\t\t\ttemplate\r\n\t\t\t}\r\n\t\t}, [country, metadata])\r\n\t\treturn (\r\n\t\t\t\r\n\t\t)\r\n\t}\r\n\r\n\tInputSmart = React.forwardRef(InputSmart)\r\n\r\n\tInputSmart.propTypes = {\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\t}\r\n\r\n\tInputSmart.defaultProps = {\r\n\t\tmetadata: defaultMetadata\r\n\t}\r\n\r\n\treturn InputSmart\r\n}\r\n\r\nexport default createInput()"],"file":"InputSmart.js"}