@lwrjs/router 0.24.2 → 0.24.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cjs/modules/lwr/contextProvider/contextProvider.cjs +24 -22
- package/build/cjs/modules/lwr/contextUtils/contextInfo.cjs +62 -8
- package/build/cjs/modules/lwr/contextUtils/contextUtils.cjs +55 -22
- package/build/cjs/modules/lwr/contextUtils/navigationApiStore.cjs +15 -19
- package/build/cjs/modules/lwr/currentPageReference/currentPageReference.cjs +17 -19
- package/build/cjs/modules/lwr/currentView/currentView.cjs +15 -19
- package/build/cjs/modules/lwr/domRouter/domRouter.cjs +208 -81
- package/build/cjs/modules/lwr/domRouterUtils/domRouterUtils.cjs +15 -19
- package/build/cjs/modules/lwr/domRouterUtils/historyUtils.cjs +16 -4
- package/build/cjs/modules/lwr/domRouterUtils/types.cjs +14 -2
- package/build/cjs/modules/lwr/domRouterUtils/uriUtils.cjs +15 -18
- package/build/cjs/modules/lwr/historyRouter/historyRouter.cjs +38 -25
- package/build/cjs/modules/lwr/navigation/constants.cjs +20 -8
- package/build/cjs/modules/lwr/navigation/navigation.cjs +19 -23
- package/build/cjs/modules/lwr/navigation/navigationApi.cjs +14 -18
- package/build/cjs/modules/lwr/navigation/navigationMixin.cjs +29 -29
- package/build/cjs/modules/lwr/navigationContext/navigationContext.cjs +14 -18
- package/build/cjs/modules/lwr/navigationMixinHacks/navigationMixinHacks.cjs +14 -18
- package/build/cjs/modules/lwr/observable/observable.cjs +16 -4
- package/build/cjs/modules/lwr/outlet/outlet.cjs +27 -55
- package/build/cjs/modules/lwr/router/router.cjs +130 -40
- package/build/cjs/modules/lwr/routerBridge/routerBridge.cjs +37 -29
- package/build/cjs/modules/lwr/routerContainer/routerContainer.cjs +47 -40
- package/build/cjs/modules/lwr/routerContainer/utils.cjs +40 -20
- package/build/cjs/modules/lwr/routerErrors/routerErrors.cjs +16 -4
- package/build/cjs/modules/lwr/routerUtils/domUtils.cjs +16 -4
- package/build/cjs/modules/lwr/routerUtils/filterUtils.cjs +35 -17
- package/build/cjs/modules/lwr/routerUtils/parseUtils.cjs +26 -30
- package/build/cjs/modules/lwr/routerUtils/pathToRegexp.cjs +63 -52
- package/build/cjs/modules/lwr/routerUtils/routeDefUtils.cjs +25 -28
- package/build/cjs/modules/lwr/routerUtils/routeUtils.cjs +30 -34
- package/build/cjs/modules/lwr/routerUtils/routerUtils.cjs +21 -25
- package/build/cjs/modules/lwr/routerUtils/typeUtils.cjs +21 -7
- package/build/cjs/modules/lwr/routerUtils/types.cjs +14 -2
- package/build/cjs/modules/lwr/routerUtils/uriUtils.cjs +17 -5
- package/build/cjs/modules/lwr/serverRouter/serverRouter.cjs +63 -28
- package/build/cjs/services/index.cjs +46 -37
- package/build/cjs/services/module-provider/index.cjs +42 -30
- package/build/cjs/services/module-provider/utils.cjs +37 -31
- package/package.json +6 -6
|
@@ -1,13 +1,25 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
|
-
var
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
3
5
|
var __export = (target, all) => {
|
|
4
6
|
for (var name in all)
|
|
5
|
-
__defProp(target, name, {get: all[name], enumerable: true});
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
6
8
|
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
7
18
|
|
|
8
19
|
// packages/@lwrjs/router/src/modules/lwr/routerUtils/domUtils.ts
|
|
9
|
-
|
|
10
|
-
__export(
|
|
20
|
+
var domUtils_exports = {};
|
|
21
|
+
__export(domUtils_exports, {
|
|
11
22
|
hasDocument: () => hasDocument
|
|
12
23
|
});
|
|
24
|
+
module.exports = __toCommonJS(domUtils_exports);
|
|
13
25
|
var hasDocument = typeof document !== "undefined";
|
|
@@ -1,15 +1,27 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
|
-
var
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
3
5
|
var __export = (target, all) => {
|
|
4
6
|
for (var name in all)
|
|
5
|
-
__defProp(target, name, {get: all[name], enumerable: true});
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
6
8
|
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
7
18
|
|
|
8
19
|
// packages/@lwrjs/router/src/modules/lwr/routerUtils/filterUtils.ts
|
|
9
|
-
|
|
10
|
-
__export(
|
|
20
|
+
var filterUtils_exports = {};
|
|
21
|
+
__export(filterUtils_exports, {
|
|
11
22
|
createFilterChain: () => createFilterChain
|
|
12
23
|
});
|
|
24
|
+
module.exports = __toCommonJS(filterUtils_exports);
|
|
13
25
|
function createFilterChain() {
|
|
14
26
|
const filters = [];
|
|
15
27
|
const empty = () => {
|
|
@@ -28,19 +40,25 @@ function createFilterChain() {
|
|
|
28
40
|
}
|
|
29
41
|
};
|
|
30
42
|
const compile = (arg) => {
|
|
31
|
-
return filters.length === 0 ? Promise.resolve(true) :
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
return false;
|
|
42
|
-
}
|
|
43
|
-
|
|
43
|
+
return filters.length === 0 ? Promise.resolve(true) : (
|
|
44
|
+
// Reduce the listener array down to a single value:
|
|
45
|
+
// a false -> false
|
|
46
|
+
// all truthy -> true
|
|
47
|
+
// Previous is a Promise and current is a function.
|
|
48
|
+
filters.reduce((previous, current) => {
|
|
49
|
+
return previous.then((val) => {
|
|
50
|
+
return val === false ? Promise.reject() : Promise.resolve(current(arg));
|
|
51
|
+
});
|
|
52
|
+
}, Promise.resolve(true)).then((val) => {
|
|
53
|
+
return val === false ? false : true;
|
|
54
|
+
}).catch((error) => {
|
|
55
|
+
if (error instanceof Error) {
|
|
56
|
+
throw error;
|
|
57
|
+
} else {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
})
|
|
61
|
+
);
|
|
44
62
|
};
|
|
45
63
|
return {
|
|
46
64
|
add,
|
|
@@ -1,36 +1,32 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
1
|
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
2
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
-
var
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
5
|
var __export = (target, all) => {
|
|
9
6
|
for (var name in all)
|
|
10
|
-
__defProp(target, name, {get: all[name], enumerable: true});
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
8
|
};
|
|
12
|
-
var
|
|
13
|
-
if (
|
|
14
|
-
for (let key of __getOwnPropNames(
|
|
15
|
-
if (!__hasOwnProp.call(
|
|
16
|
-
__defProp(
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
14
|
}
|
|
18
|
-
return
|
|
19
|
-
};
|
|
20
|
-
var __toModule = (module2) => {
|
|
21
|
-
return __exportStar(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? {get: () => module2.default, enumerable: true} : {value: module2, enumerable: true})), module2);
|
|
15
|
+
return to;
|
|
22
16
|
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
23
18
|
|
|
24
19
|
// packages/@lwrjs/router/src/modules/lwr/routerUtils/parseUtils.ts
|
|
25
|
-
|
|
26
|
-
__export(
|
|
20
|
+
var parseUtils_exports = {};
|
|
21
|
+
__export(parseUtils_exports, {
|
|
27
22
|
compileQueryObject: () => compileQueryObject,
|
|
28
23
|
getQueryMatcher: () => getQueryMatcher,
|
|
29
24
|
parseRoutes: () => parseRoutes
|
|
30
25
|
});
|
|
31
|
-
|
|
32
|
-
var
|
|
33
|
-
var
|
|
26
|
+
module.exports = __toCommonJS(parseUtils_exports);
|
|
27
|
+
var import_routerErrors = require("lwr/routerErrors");
|
|
28
|
+
var import_pathToRegexp = require("./pathToRegexp.cjs");
|
|
29
|
+
var import_uriUtils = require("./uriUtils.cjs");
|
|
34
30
|
var {
|
|
35
31
|
INVALID_ROUTE_QUERY,
|
|
36
32
|
MISSING_ROUTE_TEMPLATE,
|
|
@@ -39,14 +35,14 @@ var {
|
|
|
39
35
|
INVALID_URI_SYNTAX
|
|
40
36
|
} = import_routerErrors.messages;
|
|
41
37
|
function parseRoutes(config) {
|
|
42
|
-
const {routes, caseSensitive} = config;
|
|
38
|
+
const { routes, caseSensitive } = config;
|
|
43
39
|
return routes.map((def) => {
|
|
44
40
|
return parseUriRoute(def, caseSensitive);
|
|
45
41
|
});
|
|
46
42
|
}
|
|
47
43
|
function parseUriRoute(def, caseSensitive = false) {
|
|
48
44
|
const params = [];
|
|
49
|
-
const {id, uri, page} = def;
|
|
45
|
+
const { id, uri, page } = def;
|
|
50
46
|
(0, import_routerErrors.invariant)(!!uri, (0, import_routerErrors.generateMessageObject)(MISSING_ROUTE_TEMPLATE, [id]));
|
|
51
47
|
(0, import_routerErrors.invariant)(isValidUri(uri), (0, import_routerErrors.generateMessageObject)(INVALID_URI_SYNTAX, [id]));
|
|
52
48
|
(0, import_routerErrors.invariant)(!!page, (0, import_routerErrors.generateMessageObject)(MISSING_PAGE_BINDING, [id]));
|
|
@@ -54,12 +50,13 @@ function parseUriRoute(def, caseSensitive = false) {
|
|
|
54
50
|
const query = (0, import_uriUtils.getQueryFromUrl)(uri);
|
|
55
51
|
const regex = (0, import_pathToRegexp.pathToRegexp)(path, params, {
|
|
56
52
|
sensitive: caseSensitive,
|
|
53
|
+
// True if this is a leaf route, and must match URLs exactly with no trailing segments.
|
|
57
54
|
end: def.exact === false ? false : true
|
|
58
55
|
});
|
|
59
|
-
const toPath = (0, import_pathToRegexp.compile)(path, {encode: encodeURIComponent});
|
|
56
|
+
const toPath = (0, import_pathToRegexp.compile)(path, { encode: encodeURIComponent });
|
|
60
57
|
const compiledQuery = compileQueryObject(query);
|
|
61
58
|
const queryMatcher = getQueryMatcher(compiledQuery, caseSensitive);
|
|
62
|
-
const compiledRoute = {original: def, regex, params, toPath, compiledQuery, queryMatcher};
|
|
59
|
+
const compiledRoute = { original: def, regex, params, toPath, compiledQuery, queryMatcher };
|
|
63
60
|
(0, import_routerErrors.invariant)(isValidPageBinding(compiledRoute), (0, import_routerErrors.generateMessageObject)(INVALID_PAGE_BINDING, [id]));
|
|
64
61
|
return compiledRoute;
|
|
65
62
|
}
|
|
@@ -69,14 +66,14 @@ function isValidUri(uri = "") {
|
|
|
69
66
|
return !containsInvalidCharacter;
|
|
70
67
|
}
|
|
71
68
|
function isValidPageBinding(compiledDef) {
|
|
72
|
-
const {original: {page} = {}, params, compiledQuery} = compiledDef;
|
|
69
|
+
const { original: { page } = {}, params, compiledQuery } = compiledDef;
|
|
73
70
|
const pageType = page ? page.type : page;
|
|
74
71
|
const pageAttributes = (page ? page.attributes : page) || {};
|
|
75
72
|
const pageState = (page ? page.state : page) || {};
|
|
76
73
|
if (typeof pageType !== "string" || typeof pageAttributes !== "object" || typeof pageState !== "object") {
|
|
77
74
|
return false;
|
|
78
75
|
}
|
|
79
|
-
const pathParams = Object.values(params).map(({name}) => name);
|
|
76
|
+
const pathParams = Object.values(params).map(({ name }) => name);
|
|
80
77
|
const queryParams = (0, import_uriUtils.getQueryNames)(compiledQuery);
|
|
81
78
|
const allParams = [...pathParams, ...queryParams];
|
|
82
79
|
const attributeBindings = Object.values(pageAttributes).filter(import_uriUtils.isParam).map(import_uriUtils.getParamName);
|
|
@@ -118,9 +115,8 @@ function getQueryMatcher(compiledQuery, caseSensitive = false) {
|
|
|
118
115
|
const hasAllDefKeys = defKeys.every((defKey) => inputKeys.indexOf(defKey) >= 0);
|
|
119
116
|
if (hasAllDefKeys) {
|
|
120
117
|
return defKeys.reduce((matched, defKey) => {
|
|
121
|
-
if (matched === null)
|
|
122
|
-
|
|
123
|
-
const {literalValue, routeParamName} = compiledQuery[defKey];
|
|
118
|
+
if (matched === null) return null;
|
|
119
|
+
const { literalValue, routeParamName } = compiledQuery[defKey];
|
|
124
120
|
const inputValue = queryObject[defKey];
|
|
125
121
|
let literalValueMatches = true;
|
|
126
122
|
if (typeof literalValue === "string") {
|
|
@@ -129,7 +125,7 @@ function getQueryMatcher(compiledQuery, caseSensitive = false) {
|
|
|
129
125
|
literalValueMatches = inputValue === literalValue;
|
|
130
126
|
}
|
|
131
127
|
if (literalValueMatches) {
|
|
132
|
-
matched = {...matched, [defKey]: {value: inputValue, routeParamName}};
|
|
128
|
+
matched = { ...matched, [defKey]: { value: inputValue, routeParamName } };
|
|
133
129
|
} else {
|
|
134
130
|
matched = null;
|
|
135
131
|
}
|
|
@@ -1,13 +1,24 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
|
-
var
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
3
5
|
var __export = (target, all) => {
|
|
4
6
|
for (var name in all)
|
|
5
|
-
__defProp(target, name, {get: all[name], enumerable: true});
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
6
8
|
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
7
18
|
|
|
8
19
|
// packages/@lwrjs/router/src/modules/lwr/routerUtils/pathToRegexp.ts
|
|
9
|
-
|
|
10
|
-
__export(
|
|
20
|
+
var pathToRegexp_exports = {};
|
|
21
|
+
__export(pathToRegexp_exports, {
|
|
11
22
|
compile: () => compile,
|
|
12
23
|
match: () => match,
|
|
13
24
|
parse: () => parse,
|
|
@@ -16,25 +27,26 @@ __export(exports, {
|
|
|
16
27
|
tokensToFunction: () => tokensToFunction,
|
|
17
28
|
tokensToRegexp: () => tokensToRegexp
|
|
18
29
|
});
|
|
30
|
+
module.exports = __toCommonJS(pathToRegexp_exports);
|
|
19
31
|
function lexer(str) {
|
|
20
32
|
const tokens = [];
|
|
21
33
|
let i = 0;
|
|
22
34
|
while (i < str.length) {
|
|
23
35
|
const char = str[i];
|
|
24
36
|
if (char === "*" || char === "+" || char === "?") {
|
|
25
|
-
tokens.push({type: "MODIFIER", index: i, value: str[i++]});
|
|
37
|
+
tokens.push({ type: "MODIFIER", index: i, value: str[i++] });
|
|
26
38
|
continue;
|
|
27
39
|
}
|
|
28
40
|
if (char === "\\") {
|
|
29
|
-
tokens.push({type: "ESCAPED_CHAR", index: i++, value: str[i++]});
|
|
41
|
+
tokens.push({ type: "ESCAPED_CHAR", index: i++, value: str[i++] });
|
|
30
42
|
continue;
|
|
31
43
|
}
|
|
32
44
|
if (char === "{") {
|
|
33
|
-
tokens.push({type: "OPEN", index: i, value: str[i++]});
|
|
45
|
+
tokens.push({ type: "OPEN", index: i, value: str[i++] });
|
|
34
46
|
continue;
|
|
35
47
|
}
|
|
36
48
|
if (char === "}") {
|
|
37
|
-
tokens.push({type: "CLOSE", index: i, value: str[i++]});
|
|
49
|
+
tokens.push({ type: "CLOSE", index: i, value: str[i++] });
|
|
38
50
|
continue;
|
|
39
51
|
}
|
|
40
52
|
if (char === ":") {
|
|
@@ -42,15 +54,20 @@ function lexer(str) {
|
|
|
42
54
|
let j = i + 1;
|
|
43
55
|
while (j < str.length) {
|
|
44
56
|
const code = str.charCodeAt(j);
|
|
45
|
-
if (
|
|
57
|
+
if (
|
|
58
|
+
// `0-9`
|
|
59
|
+
code >= 48 && code <= 57 || // `A-Z`
|
|
60
|
+
code >= 65 && code <= 90 || // `a-z`
|
|
61
|
+
code >= 97 && code <= 122 || // `_`
|
|
62
|
+
code === 95
|
|
63
|
+
) {
|
|
46
64
|
name += str[j++];
|
|
47
65
|
continue;
|
|
48
66
|
}
|
|
49
67
|
break;
|
|
50
68
|
}
|
|
51
|
-
if (!name)
|
|
52
|
-
|
|
53
|
-
tokens.push({type: "NAME", index: i, value: name});
|
|
69
|
+
if (!name) throw new TypeError(`Missing parameter name at ${i}`);
|
|
70
|
+
tokens.push({ type: "NAME", index: i, value: name });
|
|
54
71
|
i = j;
|
|
55
72
|
continue;
|
|
56
73
|
}
|
|
@@ -80,17 +97,15 @@ function lexer(str) {
|
|
|
80
97
|
}
|
|
81
98
|
pattern += str[j++];
|
|
82
99
|
}
|
|
83
|
-
if (count)
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
throw new TypeError(`Missing pattern at ${i}`);
|
|
87
|
-
tokens.push({type: "PATTERN", index: i, value: pattern});
|
|
100
|
+
if (count) throw new TypeError(`Unbalanced pattern at ${i}`);
|
|
101
|
+
if (!pattern) throw new TypeError(`Missing pattern at ${i}`);
|
|
102
|
+
tokens.push({ type: "PATTERN", index: i, value: pattern });
|
|
88
103
|
i = j;
|
|
89
104
|
continue;
|
|
90
105
|
}
|
|
91
|
-
tokens.push({type: "CHAR", index: i, value: str[i++]});
|
|
106
|
+
tokens.push({ type: "CHAR", index: i, value: str[i++] });
|
|
92
107
|
}
|
|
93
|
-
tokens.push({type: "END", index: i, value: ""});
|
|
108
|
+
tokens.push({ type: "END", index: i, value: "" });
|
|
94
109
|
return tokens;
|
|
95
110
|
}
|
|
96
111
|
function escapeString(str) {
|
|
@@ -101,21 +116,19 @@ function flags(options) {
|
|
|
101
116
|
}
|
|
102
117
|
function parse(str, options = {}) {
|
|
103
118
|
const tokens = lexer(str);
|
|
104
|
-
const {prefixes = "./"} = options;
|
|
119
|
+
const { prefixes = "./" } = options;
|
|
105
120
|
const defaultPattern = `[^${escapeString(options.delimiter || "/#?")}]+?`;
|
|
106
121
|
const result = [];
|
|
107
122
|
let key = 0;
|
|
108
123
|
let i = 0;
|
|
109
124
|
let path = "";
|
|
110
125
|
const tryConsume = (type) => {
|
|
111
|
-
if (i < tokens.length && tokens[i].type === type)
|
|
112
|
-
return tokens[i++].value;
|
|
126
|
+
if (i < tokens.length && tokens[i].type === type) return tokens[i++].value;
|
|
113
127
|
};
|
|
114
128
|
const mustConsume = (type) => {
|
|
115
129
|
const value = tryConsume(type);
|
|
116
|
-
if (value !== void 0)
|
|
117
|
-
|
|
118
|
-
const {type: nextType, index} = tokens[i];
|
|
130
|
+
if (value !== void 0) return value;
|
|
131
|
+
const { type: nextType, index } = tokens[i];
|
|
119
132
|
throw new TypeError(`Unexpected ${nextType} at ${index}, expected ${type}`);
|
|
120
133
|
};
|
|
121
134
|
const consumeText = () => {
|
|
@@ -180,7 +193,7 @@ function parse(str, options = {}) {
|
|
|
180
193
|
}
|
|
181
194
|
function tokensToFunction(tokens, options = {}) {
|
|
182
195
|
const reFlags = flags(options);
|
|
183
|
-
const {encode = (x) => x, validate = true} = options;
|
|
196
|
+
const { encode = (x) => x, validate = true } = options;
|
|
184
197
|
const matches = tokens.map((token) => {
|
|
185
198
|
if (typeof token === "object") {
|
|
186
199
|
return new RegExp(`^(?:${token.pattern})$`, reFlags);
|
|
@@ -202,14 +215,15 @@ function tokensToFunction(tokens, options = {}) {
|
|
|
202
215
|
throw new TypeError(`Expected "${token.name}" to not repeat, but got an array`);
|
|
203
216
|
}
|
|
204
217
|
if (value.length === 0) {
|
|
205
|
-
if (optional)
|
|
206
|
-
continue;
|
|
218
|
+
if (optional) continue;
|
|
207
219
|
throw new TypeError(`Expected "${token.name}" to not be empty`);
|
|
208
220
|
}
|
|
209
221
|
for (let j = 0; j < value.length; j++) {
|
|
210
222
|
const segment = encode(value[j], token);
|
|
211
223
|
if (validate && !matches[i].test(segment)) {
|
|
212
|
-
throw new TypeError(
|
|
224
|
+
throw new TypeError(
|
|
225
|
+
`Expected all "${token.name}" to match "${token.pattern}", but got "${segment}"`
|
|
226
|
+
);
|
|
213
227
|
}
|
|
214
228
|
path += token.prefix + segment + token.suffix;
|
|
215
229
|
}
|
|
@@ -218,13 +232,14 @@ function tokensToFunction(tokens, options = {}) {
|
|
|
218
232
|
if (typeof value === "string" || typeof value === "number") {
|
|
219
233
|
const segment = encode(String(value), token);
|
|
220
234
|
if (validate && !matches[i].test(segment)) {
|
|
221
|
-
throw new TypeError(
|
|
235
|
+
throw new TypeError(
|
|
236
|
+
`Expected "${token.name}" to match "${token.pattern}", but got "${segment}"`
|
|
237
|
+
);
|
|
222
238
|
}
|
|
223
239
|
path += token.prefix + segment + token.suffix;
|
|
224
240
|
continue;
|
|
225
241
|
}
|
|
226
|
-
if (optional)
|
|
227
|
-
continue;
|
|
242
|
+
if (optional) continue;
|
|
228
243
|
const typeOfMessage = repeat ? "an array" : "a string";
|
|
229
244
|
throw new TypeError(`Expected "${token.name}" to be ${typeOfMessage}`);
|
|
230
245
|
}
|
|
@@ -235,16 +250,14 @@ function compile(str, options) {
|
|
|
235
250
|
return tokensToFunction(parse(str, options), options);
|
|
236
251
|
}
|
|
237
252
|
function regexpToFunction(re, keys, options = {}) {
|
|
238
|
-
const {decode = (x) => x} = options;
|
|
253
|
+
const { decode = (x) => x } = options;
|
|
239
254
|
return function(pathname) {
|
|
240
255
|
const m = re.exec(pathname);
|
|
241
|
-
if (!m)
|
|
242
|
-
|
|
243
|
-
const
|
|
244
|
-
const params = Object.create(null);
|
|
256
|
+
if (!m) return false;
|
|
257
|
+
const { 0: path, index } = m;
|
|
258
|
+
const params = /* @__PURE__ */ Object.create(null);
|
|
245
259
|
for (let i = 1; i < m.length; i++) {
|
|
246
|
-
if (m[i] === void 0)
|
|
247
|
-
continue;
|
|
260
|
+
if (m[i] === void 0) continue;
|
|
248
261
|
const key = keys[i - 1];
|
|
249
262
|
if (key.modifier === "*" || key.modifier === "+") {
|
|
250
263
|
params[key.name] = m[i].split(key.prefix + key.suffix).map((value) => {
|
|
@@ -254,12 +267,11 @@ function regexpToFunction(re, keys, options = {}) {
|
|
|
254
267
|
params[key.name] = decode(m[i], key);
|
|
255
268
|
}
|
|
256
269
|
}
|
|
257
|
-
return {path, index, params};
|
|
270
|
+
return { path, index, params };
|
|
258
271
|
};
|
|
259
272
|
}
|
|
260
273
|
function regexpToRegexp(path, keys) {
|
|
261
|
-
if (!keys)
|
|
262
|
-
return path;
|
|
274
|
+
if (!keys) return path;
|
|
263
275
|
const groups = path.source.match(/\((?!\?)/g);
|
|
264
276
|
if (groups) {
|
|
265
277
|
for (let i = 0; i < groups.length; i++) {
|
|
@@ -275,7 +287,7 @@ function regexpToRegexp(path, keys) {
|
|
|
275
287
|
return path;
|
|
276
288
|
}
|
|
277
289
|
function tokensToRegexp(tokens, keys, options = {}) {
|
|
278
|
-
const {strict = false, start = true, end = true, encode = (x) => x} = options;
|
|
290
|
+
const { strict = false, start = true, end = true, encode = (x) => x } = options;
|
|
279
291
|
const endsWith = `[${escapeString(options.endsWith || "")}]|$`;
|
|
280
292
|
const delimiter = `[${escapeString(options.delimiter || "/#?")}]`;
|
|
281
293
|
let route = start ? "^" : "";
|
|
@@ -286,8 +298,7 @@ function tokensToRegexp(tokens, keys, options = {}) {
|
|
|
286
298
|
const prefix = escapeString(encode(token.prefix));
|
|
287
299
|
const suffix = escapeString(encode(token.suffix));
|
|
288
300
|
if (token.pattern) {
|
|
289
|
-
if (keys)
|
|
290
|
-
keys.push(token);
|
|
301
|
+
if (keys) keys.push(token);
|
|
291
302
|
if (prefix || suffix) {
|
|
292
303
|
if (token.modifier === "+" || token.modifier === "*") {
|
|
293
304
|
const mod = token.modifier === "*" ? "?" : "";
|
|
@@ -304,12 +315,14 @@ function tokensToRegexp(tokens, keys, options = {}) {
|
|
|
304
315
|
}
|
|
305
316
|
}
|
|
306
317
|
if (end) {
|
|
307
|
-
if (!strict)
|
|
308
|
-
route += `${delimiter}?`;
|
|
318
|
+
if (!strict) route += `${delimiter}?`;
|
|
309
319
|
route += !options.endsWith ? "$" : `(?=${endsWith})`;
|
|
310
320
|
} else {
|
|
311
321
|
const endToken = tokens[tokens.length - 1];
|
|
312
|
-
const isEndDelimited = typeof endToken === "string" ? delimiter.indexOf(endToken[endToken.length - 1]) > -1 :
|
|
322
|
+
const isEndDelimited = typeof endToken === "string" ? delimiter.indexOf(endToken[endToken.length - 1]) > -1 : (
|
|
323
|
+
// tslint:disable-next-line
|
|
324
|
+
endToken === void 0
|
|
325
|
+
);
|
|
313
326
|
if (!strict) {
|
|
314
327
|
route += `(?:${delimiter}(?=${endsWith}))?`;
|
|
315
328
|
}
|
|
@@ -323,10 +336,8 @@ function stringToRegexp(path, keys, options) {
|
|
|
323
336
|
return tokensToRegexp(parse(path, options), keys, options);
|
|
324
337
|
}
|
|
325
338
|
function pathToRegexp(path, keys, options) {
|
|
326
|
-
if (path instanceof RegExp)
|
|
327
|
-
|
|
328
|
-
if (Array.isArray(path))
|
|
329
|
-
return arrayToRegexp(path, keys, options);
|
|
339
|
+
if (path instanceof RegExp) return regexpToRegexp(path, keys);
|
|
340
|
+
if (Array.isArray(path)) return arrayToRegexp(path, keys, options);
|
|
330
341
|
return stringToRegexp(path, keys, options);
|
|
331
342
|
}
|
|
332
343
|
function match(str, options) {
|
|
@@ -1,44 +1,40 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
1
|
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
2
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
-
var
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
5
|
var __export = (target, all) => {
|
|
9
6
|
for (var name in all)
|
|
10
|
-
__defProp(target, name, {get: all[name], enumerable: true});
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
8
|
};
|
|
12
|
-
var
|
|
13
|
-
if (
|
|
14
|
-
for (let key of __getOwnPropNames(
|
|
15
|
-
if (!__hasOwnProp.call(
|
|
16
|
-
__defProp(
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
14
|
}
|
|
18
|
-
return
|
|
19
|
-
};
|
|
20
|
-
var __toModule = (module2) => {
|
|
21
|
-
return __exportStar(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? {get: () => module2.default, enumerable: true} : {value: module2, enumerable: true})), module2);
|
|
15
|
+
return to;
|
|
22
16
|
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
23
18
|
|
|
24
19
|
// packages/@lwrjs/router/src/modules/lwr/routerUtils/routeDefUtils.ts
|
|
25
|
-
|
|
26
|
-
__export(
|
|
20
|
+
var routeDefUtils_exports = {};
|
|
21
|
+
__export(routeDefUtils_exports, {
|
|
27
22
|
getPageReferenceFromUriAndRouteDef: () => getPageReferenceFromUriAndRouteDef,
|
|
28
23
|
getPathParams: () => getPathParams,
|
|
29
24
|
getQueryParams: () => getQueryParams,
|
|
30
25
|
matchRouteDefinitionByPageReference: () => matchRouteDefinitionByPageReference
|
|
31
26
|
});
|
|
32
|
-
|
|
27
|
+
module.exports = __toCommonJS(routeDefUtils_exports);
|
|
28
|
+
var import_uriUtils = require("./uriUtils.cjs");
|
|
33
29
|
function matchRouteDefinitionByPageReference(pageReference, routeDefs) {
|
|
34
30
|
if (!pageReference) {
|
|
35
31
|
return null;
|
|
36
32
|
}
|
|
37
|
-
const {type: refType, attributes: refAttrs = {}, state: refState = {}} = pageReference;
|
|
33
|
+
const { type: refType, attributes: refAttrs = {}, state: refState = {} } = pageReference;
|
|
38
34
|
if (refType) {
|
|
39
35
|
const [matched] = routeDefs.filter((compiledDef) => {
|
|
40
36
|
const {
|
|
41
|
-
original: {page: {type = null, attributes: pageAttrs = {}, state: pageState = {}} = {}}
|
|
37
|
+
original: { page: { type = null, attributes: pageAttrs = {}, state: pageState = {} } = {} }
|
|
42
38
|
} = compiledDef;
|
|
43
39
|
const matchesType = type === refType;
|
|
44
40
|
const refAttributesHasAllPageKeys = Object.keys(pageAttrs).every((key) => {
|
|
@@ -63,13 +59,13 @@ function matchRouteDefinitionByPageReference(pageReference, routeDefs) {
|
|
|
63
59
|
return null;
|
|
64
60
|
}
|
|
65
61
|
function getPathParams(path, routeDef) {
|
|
66
|
-
const {regex, params: definedParams} = routeDef;
|
|
62
|
+
const { regex, params: definedParams } = routeDef;
|
|
67
63
|
const execArray = regex.exec(path);
|
|
68
64
|
if (execArray) {
|
|
69
65
|
const [, ...pathParamValues] = execArray;
|
|
70
66
|
const pathParams = {};
|
|
71
67
|
definedParams.forEach((param, index) => {
|
|
72
|
-
const {name: paramName} = param;
|
|
68
|
+
const { name: paramName } = param;
|
|
73
69
|
const paramValue = pathParamValues[index];
|
|
74
70
|
pathParams[paramName] = paramValue ? (0, import_uriUtils.decode)(paramValue) : paramValue;
|
|
75
71
|
});
|
|
@@ -79,13 +75,13 @@ function getPathParams(path, routeDef) {
|
|
|
79
75
|
}
|
|
80
76
|
function getQueryParams(queryObj, routeDef) {
|
|
81
77
|
if (queryObj && routeDef) {
|
|
82
|
-
const {queryMatcher} = routeDef;
|
|
78
|
+
const { queryMatcher } = routeDef;
|
|
83
79
|
const matchedQuery = queryMatcher(queryObj);
|
|
84
80
|
if (matchedQuery) {
|
|
85
81
|
const params = {};
|
|
86
82
|
Object.keys(matchedQuery).forEach((queryKeyName) => {
|
|
87
83
|
const paramValue = matchedQuery[queryKeyName];
|
|
88
|
-
const {value, routeParamName} = paramValue;
|
|
84
|
+
const { value, routeParamName } = paramValue;
|
|
89
85
|
const paramName = routeParamName ? routeParamName.substr(1) : queryKeyName;
|
|
90
86
|
params[paramName] = value ? (0, import_uriUtils.decode)(value) : value;
|
|
91
87
|
});
|
|
@@ -95,9 +91,9 @@ function getQueryParams(queryObj, routeDef) {
|
|
|
95
91
|
return null;
|
|
96
92
|
}
|
|
97
93
|
function getUnboundQueries(queryObj, routeDef) {
|
|
98
|
-
const {compiledQuery} = routeDef;
|
|
94
|
+
const { compiledQuery } = routeDef;
|
|
99
95
|
const boundKeys = Object.keys(compiledQuery).filter((qKey) => {
|
|
100
|
-
const {literalValue} = compiledQuery[qKey];
|
|
96
|
+
const { literalValue } = compiledQuery[qKey];
|
|
101
97
|
return !literalValue;
|
|
102
98
|
});
|
|
103
99
|
const unbound = {};
|
|
@@ -113,7 +109,7 @@ function getPageReferenceFromUriAndRouteDef(uri, routeDef) {
|
|
|
113
109
|
if (routeDef) {
|
|
114
110
|
const {
|
|
115
111
|
original: {
|
|
116
|
-
page: {type: pageType = "", attributes: pageAttributes = {}, state: pageState = {}} = {}
|
|
112
|
+
page: { type: pageType = "", attributes: pageAttributes = {}, state: pageState = {} } = {}
|
|
117
113
|
} = {}
|
|
118
114
|
} = routeDef;
|
|
119
115
|
const path = (0, import_uriUtils.getPathFromUrl)(uri);
|
|
@@ -152,10 +148,11 @@ function getPageReferenceFromUriAndRouteDef(uri, routeDef) {
|
|
|
152
148
|
const unboundState = getUnboundQueries(query, routeDef);
|
|
153
149
|
return {
|
|
154
150
|
type: pageType,
|
|
155
|
-
attributes: {...boundAttributeParams},
|
|
151
|
+
attributes: { ...boundAttributeParams },
|
|
156
152
|
state: {
|
|
157
153
|
...unboundState,
|
|
158
154
|
...boundStateParams
|
|
155
|
+
// bound state params override unbound param
|
|
159
156
|
}
|
|
160
157
|
};
|
|
161
158
|
}
|