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