1ccf42bd69f0c6b61f4395c2574b0d5e.json
23.3 KB
{"ast":null,"code":"var _interopRequireWildcard=require(\"@babel/runtime/helpers/interopRequireWildcard\");var _interopRequireDefault=require(\"@babel/runtime/helpers/interopRequireDefault\");Object.defineProperty(exports,\"__esModule\",{value:true});exports.createPathParser=exports.urlToPathAndParams=exports.getParamsFromPath=void 0;var _slicedToArray2=_interopRequireDefault(require(\"@babel/runtime/helpers/slicedToArray\"));var _objectSpread2=_interopRequireDefault(require(\"@babel/runtime/helpers/objectSpread\"));var _pathToRegexp=_interopRequireWildcard(require(\"path-to-regexp\"));var NavigationActions=_interopRequireWildcard(require(\"../NavigationActions\"));var _invariant=_interopRequireDefault(require(\"../utils/invariant\"));var queryString=require('query-string');var getParamsFromPath=function getParamsFromPath(inputParams,pathMatch,pathMatchKeys){var params=pathMatch.slice(1).reduce(function(paramsOut,matchResult,i){var key=pathMatchKeys[i];if(!key||key.asterisk){return paramsOut;}var paramName=key.name;var decodedMatchResult;if(matchResult){try{decodedMatchResult=decodeURIComponent(matchResult);}catch(e){}}paramsOut[paramName]=decodedMatchResult||matchResult;return paramsOut;},(0,_objectSpread2.default)({},inputParams));return params;};exports.getParamsFromPath=getParamsFromPath;var getRestOfPath=function getRestOfPath(pathMatch,pathMatchKeys){var rest=pathMatch[pathMatchKeys.findIndex(function(k){return k.asterisk;})+1];return rest;};var determineDelimiter=function determineDelimiter(uri,uriPrefix){if(Array.isArray(uriPrefix)){if(uriPrefix.length===1)return uriPrefix[0];for(var _iterator=uriPrefix,_isArray=Array.isArray(_iterator),_i=0,_iterator=_isArray?_iterator:_iterator[typeof Symbol===\"function\"?typeof Symbol===\"function\"?Symbol.iterator:\"@@iterator\":\"@@iterator\"]();;){var _ref;if(_isArray){if(_i>=_iterator.length)break;_ref=_iterator[_i++];}else{_i=_iterator.next();if(_i.done)break;_ref=_i.value;}var _prefix=_ref;if(uri.startsWith(_prefix))return _prefix;}return null;}return uriPrefix;};var urlToPathAndParams=function urlToPathAndParams(url,uriPrefix){var searchMatch=url.match(/^(.*)\\?(.*)$/);var _ref2=searchMatch||[null,url,{}],_ref3=(0,_slicedToArray2.default)(_ref2,3),urlWithoutQuery=_ref3[1],query=_ref3[2];var params=queryString.parse(query);var delimiter=determineDelimiter(urlWithoutQuery,uriPrefix)||'://';var path=urlWithoutQuery.split(delimiter)[1];if(path===undefined){path=urlWithoutQuery;}if(path==='/'){path='';}if(path[path.length-1]==='/'){path=path.slice(0,-1);}return{path:path,params:params};};exports.urlToPathAndParams=urlToPathAndParams;var createPathParser=function createPathParser(childRouters,routeConfigs,_ref4){var _ref4$paths=_ref4.paths,pathConfigs=_ref4$paths===void 0?{}:_ref4$paths,disableRouteNamePaths=_ref4.disableRouteNamePaths;var pathsByRouteNames={};var paths=[];Object.keys(childRouters).forEach(function(routeName){var pathPattern;if(pathConfigs[routeName]!==undefined){pathPattern=pathConfigs[routeName];}else{pathPattern=routeConfigs[routeName].path;}if(pathPattern===undefined){pathPattern=disableRouteNamePaths?null:routeName;}(0,_invariant.default)(pathPattern===null||typeof pathPattern==='string',\"Route path for \"+routeName+\" must be specified as a string, or null.\");var isPathMatchable=pathPattern!==null;var exactReKeys=[];var exactRe=isPathMatchable?(0,_pathToRegexp.default)(pathPattern,exactReKeys):null;var extendedPathReKeys=[];var isWildcard=pathPattern===''||!isPathMatchable;var extendedPathRe=(0,_pathToRegexp.default)(isWildcard?'*':pathPattern+\"/*\",extendedPathReKeys);pathsByRouteNames[routeName]={exactRe:exactRe,exactReKeys:exactReKeys,extendedPathRe:extendedPathRe,extendedPathReKeys:extendedPathReKeys,isWildcard:isWildcard,toPath:pathPattern===null?function(){return'';}:(0,_pathToRegexp.compile)(pathPattern)};});paths=Object.entries(pathsByRouteNames);var getActionForPathAndParams=function getActionForPathAndParams(){var pathToResolve=arguments.length>0&&arguments[0]!==undefined?arguments[0]:'';var inputParams=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};for(var _iterator2=paths,_isArray2=Array.isArray(_iterator2),_i2=0,_iterator2=_isArray2?_iterator2:_iterator2[typeof Symbol===\"function\"?typeof Symbol===\"function\"?Symbol.iterator:\"@@iterator\":\"@@iterator\"]();;){var _ref7;if(_isArray2){if(_i2>=_iterator2.length)break;_ref7=_iterator2[_i2++];}else{_i2=_iterator2.next();if(_i2.done)break;_ref7=_i2.value;}var _ref11=_ref7;var _ref6=(0,_slicedToArray2.default)(_ref11,2);var _routeName2=_ref6[0];var _path2=_ref6[1];var exactRe=_path2.exactRe,exactReKeys=_path2.exactReKeys,extendedPathRe=_path2.extendedPathRe,extendedPathReKeys=_path2.extendedPathReKeys;var childRouter=childRouters[_routeName2];var exactMatch=exactRe&&exactRe.exec(pathToResolve);if(exactMatch&&exactMatch.length){var extendedMatch=extendedPathRe&&extendedPathRe.exec(pathToResolve);var childAction=null;if(extendedMatch&&childRouter){var restOfPath=getRestOfPath(extendedMatch,extendedPathReKeys);childAction=childRouter.getActionForPathAndParams(restOfPath,inputParams);}return NavigationActions.navigate({routeName:_routeName2,params:getParamsFromPath(inputParams,exactMatch,exactReKeys),action:childAction});}}for(var _iterator3=paths,_isArray3=Array.isArray(_iterator3),_i3=0,_iterator3=_isArray3?_iterator3:_iterator3[typeof Symbol===\"function\"?typeof Symbol===\"function\"?Symbol.iterator:\"@@iterator\":\"@@iterator\"]();;){var _ref10;if(_isArray3){if(_i3>=_iterator3.length)break;_ref10=_iterator3[_i3++];}else{_i3=_iterator3.next();if(_i3.done)break;_ref10=_i3.value;}var _ref12=_ref10;var _ref9=(0,_slicedToArray2.default)(_ref12,2);var _routeName3=_ref9[0];var _path3=_ref9[1];var _extendedPathRe=_path3.extendedPathRe,_extendedPathReKeys=_path3.extendedPathReKeys;var _childRouter=childRouters[_routeName3];var _extendedMatch=_extendedPathRe&&_extendedPathRe.exec(pathToResolve);if(_extendedMatch&&_extendedMatch.length){var _restOfPath=getRestOfPath(_extendedMatch,_extendedPathReKeys);var _childAction=null;if(_childRouter){_childAction=_childRouter.getActionForPathAndParams(_restOfPath,inputParams);}if(!_childAction){continue;}return NavigationActions.navigate({routeName:_routeName3,params:getParamsFromPath(inputParams,_extendedMatch,_extendedPathReKeys),action:_childAction});}}return null;};var getPathAndParamsForRoute=function getPathAndParamsForRoute(route){var routeName=route.routeName,params=route.params;var childRouter=childRouters[routeName];var _pathsByRouteNames$ro=pathsByRouteNames[routeName],toPath=_pathsByRouteNames$ro.toPath,exactReKeys=_pathsByRouteNames$ro.exactReKeys;var subPath=toPath(params);var nonPathParams={};if(params){Object.keys(params).filter(function(paramName){return!exactReKeys.find(function(k){return k.name===paramName;});}).forEach(function(paramName){nonPathParams[paramName]=params[paramName];});}if(childRouter){var child=childRouter.getPathAndParamsForState(route);return{path:subPath?subPath+\"/\"+child.path:child.path,params:child.params?(0,_objectSpread2.default)({},nonPathParams,child.params):nonPathParams};}return{path:subPath,params:nonPathParams};};return{getActionForPathAndParams:getActionForPathAndParams,getPathAndParamsForRoute:getPathAndParamsForRoute};};exports.createPathParser=createPathParser;","map":{"version":3,"sources":["pathUtils.js"],"names":["queryString","require","getParamsFromPath","params","pathMatch","key","pathMatchKeys","paramName","decodedMatchResult","decodeURIComponent","paramsOut","getRestOfPath","rest","k","determineDelimiter","Array","uriPrefix","prefix","uri","urlToPathAndParams","searchMatch","url","urlWithoutQuery","query","delimiter","path","createPathParser","paths","pathConfigs","disableRouteNamePaths","pathsByRouteNames","Object","pathPattern","routeConfigs","invariant","isPathMatchable","exactReKeys","exactRe","pathToRegexp","extendedPathReKeys","isWildcard","extendedPathRe","toPath","compile","getActionForPathAndParams","pathToResolve","inputParams","routeName","childRouter","childRouters","exactMatch","extendedMatch","childAction","restOfPath","NavigationActions","action","getPathAndParamsForRoute","route","subPath","nonPathParams","child"],"mappings":"4eAEA,qEACA,+EACA,qEAEA,GAAMA,CAAAA,WAAW,CAAGC,OAAO,CAA3B,cAA2B,CAA3B,CAEO,GAAMC,CAAAA,iBAAiB,CAAjBA,QAAAA,CAAAA,iBAAAA,CAAoB,WAAp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AAAA,OAAO,CAAGhB,MAAM,CAAtB,MAAsB,CAAtB,CACA,GAAMiB,CAAAA,aAAa,CAAnB,EAAA,CACA,GAAA,MAAA,CAAY,CACV5B,MAAM,CAANA,IAAAA,CAAAA,MAAAA,EAAAA,MAAAA,CACU,SAAA,SAAA,CAAS,CAAA,MAAI,CAACK,WAAW,CAAXA,IAAAA,CAAiB,SAAA,CAAA,CAAC,CAAA,MAAIvB,CAAAA,CAAC,CAADA,IAAAA,GAAJ,SAAA,CAAvB,CAAKuB,CAAL,CADnBL,CAAAA,EAAAA,OAAAA,CAEW,SAAA,SAAA,CAAa,CACpB4B,aAAa,CAAbA,SAAa,CAAbA,CAA2BxD,MAAM,CAAjCwD,SAAiC,CAAjCA,CAHJ5B,CAAAA,EAMF,IAAA,WAAA,CAAiB,CAGf,GAAM6B,CAAAA,KAAK,CAAGZ,WAAW,CAAXA,wBAAAA,CAAd,KAAcA,CAAd,CACA,MAAO,CACLvB,IAAI,CAAEiC,OAAO,CAAMA,OAAN,CAAA,GAAMA,CAAWE,KAAK,CAAtB,IAAA,CAAgCA,KAAK,CAD7C,IAAA,CAELzD,MAAM,CAAEyD,KAAK,CAALA,MAAAA,CAAAA,2BAAAA,EAAAA,CAAAA,aAAAA,CACmBA,KAAK,CADxBA,MAAAA,CAAAA,CAFV,aAAO,CAAP,CAOF,OAAO,CACLnC,IAAI,CADC,OAAA,CAELtB,MAAM,CAFR,aAAO,CAAP,CAxBF,CAAA,CA6BA,MAAO,CAAEyC,yBAAyB,CAA3B,yBAAA,CAA6BY,wBAAwB,CAA5D,wBAAO,CAAP,CAlJK,CAAA,C","sourcesContent":["/* eslint-disable import/no-commonjs */\n\nimport pathToRegexp, { compile } from 'path-to-regexp';\nimport * as NavigationActions from '../NavigationActions';\nimport invariant from '../utils/invariant';\n\nconst queryString = require('query-string');\n\nexport const getParamsFromPath = (inputParams, pathMatch, pathMatchKeys) => {\n const params = pathMatch.slice(1).reduce(\n // iterate over matched path params\n (paramsOut, matchResult, i) => {\n const key = pathMatchKeys[i];\n if (!key || key.asterisk) {\n return paramsOut;\n }\n const paramName = key.name;\n\n let decodedMatchResult;\n if (matchResult) {\n try {\n decodedMatchResult = decodeURIComponent(matchResult);\n } catch (e) {\n // ignore `URIError: malformed URI`\n }\n }\n\n paramsOut[paramName] = decodedMatchResult || matchResult;\n return paramsOut;\n },\n {\n // start with the input(query string) params, which will get overridden by path params\n ...inputParams,\n }\n );\n return params;\n};\nconst getRestOfPath = (pathMatch, pathMatchKeys) => {\n const rest = pathMatch[pathMatchKeys.findIndex(k => k.asterisk) + 1];\n return rest;\n};\n\nconst determineDelimiter = (uri, uriPrefix) => {\n if (Array.isArray(uriPrefix)) {\n if (uriPrefix.length === 1) return uriPrefix[0];\n for (let prefix of uriPrefix) {\n if (uri.startsWith(prefix)) return prefix;\n }\n return null;\n }\n return uriPrefix;\n};\n\nexport const urlToPathAndParams = (url, uriPrefix) => {\n const searchMatch = url.match(/^(.*)\\?(.*)$/);\n const [, urlWithoutQuery, query] = searchMatch || [null, url, {}];\n const params = queryString.parse(query);\n const delimiter = determineDelimiter(urlWithoutQuery, uriPrefix) || '://';\n let path = urlWithoutQuery.split(delimiter)[1];\n if (path === undefined) {\n path = urlWithoutQuery;\n }\n if (path === '/') {\n path = '';\n }\n if (path[path.length - 1] === '/') {\n path = path.slice(0, -1);\n }\n return {\n path,\n params,\n };\n};\n\nexport const createPathParser = (\n childRouters,\n routeConfigs,\n { paths: pathConfigs = {}, disableRouteNamePaths }\n) => {\n const pathsByRouteNames = {};\n let paths = [];\n\n // Build pathsByRouteNames, which includes a regex to match paths for each route. Keep in mind, the regex will pass for the route and all child routes. The code that uses pathsByRouteNames will need to also verify that the child router produces an action, in the case of isPathMatchable false (a null path).\n Object.keys(childRouters).forEach(routeName => {\n let pathPattern;\n\n // First check for paths on the router, then check the route config\n if (pathConfigs[routeName] !== undefined) {\n pathPattern = pathConfigs[routeName];\n } else {\n pathPattern = routeConfigs[routeName].path;\n }\n\n if (pathPattern === undefined) {\n // If the user hasn't specified a path at all nor disableRouteNamePaths, then we assume the routeName is an appropriate path\n pathPattern = disableRouteNamePaths ? null : routeName;\n }\n\n invariant(\n pathPattern === null || typeof pathPattern === 'string',\n `Route path for ${routeName} must be specified as a string, or null.`\n );\n\n // the path may be specified as null, which is similar to empty string because it allows child routers to handle the action, but it will not match empty paths\n const isPathMatchable = pathPattern !== null;\n // pathPattern is a string with inline params, such as people/:id/*foo\n const exactReKeys = [];\n const exactRe = isPathMatchable\n ? pathToRegexp(pathPattern, exactReKeys)\n : null;\n const extendedPathReKeys = [];\n const isWildcard = pathPattern === '' || !isPathMatchable;\n const extendedPathRe = pathToRegexp(\n isWildcard ? '*' : `${pathPattern}/*`,\n extendedPathReKeys\n );\n\n pathsByRouteNames[routeName] = {\n exactRe,\n exactReKeys,\n extendedPathRe,\n extendedPathReKeys,\n isWildcard,\n toPath: pathPattern === null ? () => '' : compile(pathPattern),\n };\n });\n\n paths = Object.entries(pathsByRouteNames);\n\n const getActionForPathAndParams = (pathToResolve = '', inputParams = {}) => {\n // Attempt to match `pathToResolve` with a route in this router's routeConfigs, deferring to child routers\n\n for (const [routeName, path] of paths) {\n const { exactRe, exactReKeys, extendedPathRe, extendedPathReKeys } = path;\n const childRouter = childRouters[routeName];\n\n const exactMatch = exactRe && exactRe.exec(pathToResolve);\n\n if (exactMatch && exactMatch.length) {\n const extendedMatch =\n extendedPathRe && extendedPathRe.exec(pathToResolve);\n let childAction = null;\n if (extendedMatch && childRouter) {\n const restOfPath = getRestOfPath(extendedMatch, extendedPathReKeys);\n childAction = childRouter.getActionForPathAndParams(\n restOfPath,\n inputParams\n );\n }\n\n return NavigationActions.navigate({\n routeName,\n params: getParamsFromPath(inputParams, exactMatch, exactReKeys),\n action: childAction,\n });\n }\n }\n\n for (const [routeName, path] of paths) {\n const { extendedPathRe, extendedPathReKeys } = path;\n const childRouter = childRouters[routeName];\n\n const extendedMatch =\n extendedPathRe && extendedPathRe.exec(pathToResolve);\n\n if (extendedMatch && extendedMatch.length) {\n const restOfPath = getRestOfPath(extendedMatch, extendedPathReKeys);\n let childAction = null;\n if (childRouter) {\n childAction = childRouter.getActionForPathAndParams(\n restOfPath,\n inputParams\n );\n }\n if (!childAction) {\n continue;\n }\n return NavigationActions.navigate({\n routeName,\n params: getParamsFromPath(\n inputParams,\n extendedMatch,\n extendedPathReKeys\n ),\n action: childAction,\n });\n }\n }\n\n return null;\n };\n const getPathAndParamsForRoute = route => {\n const { routeName, params } = route;\n const childRouter = childRouters[routeName];\n const { toPath, exactReKeys } = pathsByRouteNames[routeName];\n const subPath = toPath(params);\n const nonPathParams = {};\n if (params) {\n Object.keys(params)\n .filter(paramName => !exactReKeys.find(k => k.name === paramName))\n .forEach(paramName => {\n nonPathParams[paramName] = params[paramName];\n });\n }\n if (childRouter) {\n // If it has a router it's a navigator.\n // If it doesn't have router it's an ordinary React component.\n const child = childRouter.getPathAndParamsForState(route);\n return {\n path: subPath ? `${subPath}/${child.path}` : child.path,\n params: child.params\n ? { ...nonPathParams, ...child.params }\n : nonPathParams,\n };\n }\n return {\n path: subPath,\n params: nonPathParams,\n };\n };\n return { getActionForPathAndParams, getPathAndParamsForRoute };\n};\n"]},"metadata":{},"sourceType":"script"}