UNPKG

@wordpress/components

Version:
8 lines (7 loc) 1.94 kB
{ "version": 3, "sources": ["../../../src/navigator/utils/router.ts"], "sourcesContent": ["/**\n * External dependencies\n */\nimport { match } from 'path-to-regexp';\n\n/**\n * Internal dependencies\n */\n\nfunction matchPath(path, pattern) {\n const matchingFunction = match(pattern, {\n decode: decodeURIComponent\n });\n return matchingFunction(path);\n}\nexport function patternMatch(path, screens) {\n for (const screen of screens) {\n const matched = matchPath(path, screen.path);\n if (matched) {\n return {\n params: matched.params,\n id: screen.id\n };\n }\n }\n return undefined;\n}\nexport function findParent(path, screens) {\n if (!path.startsWith('/')) {\n return undefined;\n }\n const pathParts = path.split('/');\n let parentPath;\n while (pathParts.length > 1 && parentPath === undefined) {\n pathParts.pop();\n const potentialParentPath = pathParts.join('/') === '' ? '/' : pathParts.join('/');\n if (screens.find(screen => {\n return matchPath(potentialParentPath, screen.path) !== false;\n })) {\n parentPath = potentialParentPath;\n }\n }\n return parentPath;\n}"], "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,4BAAsB;AAMtB,SAAS,UAAU,MAAM,SAAS;AAChC,QAAM,uBAAmB,6BAAM,SAAS;AAAA,IACtC,QAAQ;AAAA,EACV,CAAC;AACD,SAAO,iBAAiB,IAAI;AAC9B;AACO,SAAS,aAAa,MAAM,SAAS;AAC1C,aAAW,UAAU,SAAS;AAC5B,UAAM,UAAU,UAAU,MAAM,OAAO,IAAI;AAC3C,QAAI,SAAS;AACX,aAAO;AAAA,QACL,QAAQ,QAAQ;AAAA,QAChB,IAAI,OAAO;AAAA,MACb;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;AACO,SAAS,WAAW,MAAM,SAAS;AACxC,MAAI,CAAC,KAAK,WAAW,GAAG,GAAG;AACzB,WAAO;AAAA,EACT;AACA,QAAM,YAAY,KAAK,MAAM,GAAG;AAChC,MAAI;AACJ,SAAO,UAAU,SAAS,KAAK,eAAe,QAAW;AACvD,cAAU,IAAI;AACd,UAAM,sBAAsB,UAAU,KAAK,GAAG,MAAM,KAAK,MAAM,UAAU,KAAK,GAAG;AACjF,QAAI,QAAQ,KAAK,YAAU;AACzB,aAAO,UAAU,qBAAqB,OAAO,IAAI,MAAM;AAAA,IACzD,CAAC,GAAG;AACF,mBAAa;AAAA,IACf;AAAA,EACF;AACA,SAAO;AACT;", "names": [] }