@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,43 +1,40 @@
|
|
|
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/routeUtils.ts
|
|
25
|
-
|
|
26
|
-
__export(
|
|
21
|
+
var routeUtils_exports = {};
|
|
22
|
+
__export(routeUtils_exports, {
|
|
27
23
|
DEFAULT_I18N_ROUTER_CONFIG: () => DEFAULT_I18N_ROUTER_CONFIG,
|
|
28
24
|
getPageReferenceFromUrl: () => getPageReferenceFromUrl,
|
|
29
25
|
getUrlFromPageReference: () => getUrlFromPageReference,
|
|
30
26
|
getUrlFromPageReferenceAndRouteDef: () => getUrlFromPageReferenceAndRouteDef,
|
|
31
27
|
matchRouteByUrl: () => matchRouteByUrl
|
|
32
28
|
});
|
|
33
|
-
|
|
34
|
-
var
|
|
29
|
+
module.exports = __toCommonJS(routeUtils_exports);
|
|
30
|
+
var import_uriUtils = require("./uriUtils.cjs");
|
|
31
|
+
var import_routeDefUtils = require("./routeDefUtils.cjs");
|
|
35
32
|
var DEFAULT_I18N_ROUTER_CONFIG = {
|
|
36
33
|
locale: "en-US",
|
|
37
34
|
defaultLocale: "en-US"
|
|
38
35
|
};
|
|
39
36
|
function isRoutePatternsMatched(path, queryObj, routeDef) {
|
|
40
|
-
const {original: {patterns = null} = {}} = routeDef || {};
|
|
37
|
+
const { original: { patterns = null } = {} } = routeDef || {};
|
|
41
38
|
if (patterns) {
|
|
42
39
|
const pathParams = (0, import_routeDefUtils.getPathParams)(path, routeDef);
|
|
43
40
|
const queryParams = (0, import_routeDefUtils.getQueryParams)(queryObj, routeDef);
|
|
@@ -59,7 +56,7 @@ function getRouteDefinitionForUri(uri, routeDefs) {
|
|
|
59
56
|
const queryObj = (0, import_uriUtils.getQueryFromUrl)(uri);
|
|
60
57
|
const matchedPaths = routeDefs ? routeDefs.filter((def) => def.regex.test(path)) : [];
|
|
61
58
|
const [matched] = matchedPaths.filter((def) => {
|
|
62
|
-
const {queryMatcher} = def;
|
|
59
|
+
const { queryMatcher } = def;
|
|
63
60
|
return queryMatcher(queryObj) && isRoutePatternsMatched(path, queryObj, def);
|
|
64
61
|
});
|
|
65
62
|
return matched || null;
|
|
@@ -85,12 +82,12 @@ function matchRouteByUrl(url, routeDefs, basePath = "", i18n = DEFAULT_I18N_ROUT
|
|
|
85
82
|
matchInfo = {
|
|
86
83
|
route: {
|
|
87
84
|
id: originalRouteDef.id,
|
|
88
|
-
attributes: {...pageReference.attributes},
|
|
89
|
-
state: {...pageReference.state},
|
|
85
|
+
attributes: { ...pageReference.attributes },
|
|
86
|
+
state: { ...pageReference.state },
|
|
90
87
|
pageReference: {
|
|
91
88
|
type: pageReference.type,
|
|
92
|
-
attributes: {...pageReference.attributes},
|
|
93
|
-
state: {...pageReference.state}
|
|
89
|
+
attributes: { ...pageReference.attributes },
|
|
90
|
+
state: { ...pageReference.state }
|
|
94
91
|
}
|
|
95
92
|
},
|
|
96
93
|
routeDefinition: routeDef
|
|
@@ -108,8 +105,8 @@ function getUrlFromPageReference(pageReference, routeDefs, basePath = "", i18n =
|
|
|
108
105
|
return null;
|
|
109
106
|
}
|
|
110
107
|
function extractBindingValues(parameters, pageReference, pageBindings) {
|
|
111
|
-
const {attributeBindings, stateBindings} = pageBindings;
|
|
112
|
-
const {attributes: refAttributes, state: refState} = pageReference;
|
|
108
|
+
const { attributeBindings, stateBindings } = pageBindings;
|
|
109
|
+
const { attributes: refAttributes, state: refState } = pageReference;
|
|
113
110
|
const parameterValueMapping = {};
|
|
114
111
|
parameters.forEach((paramName) => {
|
|
115
112
|
const [attributeBindingKey] = Object.keys(attributeBindings).filter((attributeBindingKey2) => {
|
|
@@ -129,11 +126,11 @@ function extractBindingValues(parameters, pageReference, pageBindings) {
|
|
|
129
126
|
return parameterValueMapping;
|
|
130
127
|
}
|
|
131
128
|
function getUrlFromPageReferenceAndRouteDef(pageReference, routeDef, basePath = "", i18n = DEFAULT_I18N_ROUTER_CONFIG, options) {
|
|
132
|
-
const {params, original: {page = {}} = {}, toPath, compiledQuery} = routeDef;
|
|
133
|
-
const {attributes: attributeBindings = {}, state: stateBindings = {}} = page;
|
|
134
|
-
const pathParamNames = params.filter(({name}) => {
|
|
129
|
+
const { params, original: { page = {} } = {}, toPath, compiledQuery } = routeDef;
|
|
130
|
+
const { attributes: attributeBindings = {}, state: stateBindings = {} } = page;
|
|
131
|
+
const pathParamNames = params.filter(({ name }) => {
|
|
135
132
|
return typeof name === "string";
|
|
136
|
-
}).map(({name}) => {
|
|
133
|
+
}).map(({ name }) => {
|
|
137
134
|
return name;
|
|
138
135
|
});
|
|
139
136
|
const pathParameters = extractBindingValues(pathParamNames, pageReference, {
|
|
@@ -156,10 +153,10 @@ function getQueryObjectForParametersAndPageReference(pageReference, queryParamet
|
|
|
156
153
|
const {
|
|
157
154
|
compiledQuery,
|
|
158
155
|
original: {
|
|
159
|
-
page: {state: stateBindings = {}}
|
|
156
|
+
page: { state: stateBindings = {} }
|
|
160
157
|
}
|
|
161
158
|
} = routeDef;
|
|
162
|
-
const {state: refState = {}} = pageReference || {};
|
|
159
|
+
const { state: refState = {} } = pageReference || {};
|
|
163
160
|
const nonParamState = {};
|
|
164
161
|
Object.keys(refState).filter((stateKey) => {
|
|
165
162
|
const bindingValue = stateBindings[stateKey];
|
|
@@ -170,7 +167,7 @@ function getQueryObjectForParametersAndPageReference(pageReference, queryParamet
|
|
|
170
167
|
const paramValue = queryParameters[paramName];
|
|
171
168
|
const [compiledQueryMatch] = Object.keys(compiledQuery).filter((key) => {
|
|
172
169
|
const compiledValue = compiledQuery[key];
|
|
173
|
-
const {routeParamName} = compiledValue;
|
|
170
|
+
const { routeParamName } = compiledValue;
|
|
174
171
|
return (0, import_uriUtils.getParamName)(routeParamName) === paramName;
|
|
175
172
|
});
|
|
176
173
|
if (compiledQueryMatch) {
|
|
@@ -1,29 +1,25 @@
|
|
|
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/routerUtils.ts
|
|
25
|
-
|
|
26
|
-
__export(
|
|
21
|
+
var routerUtils_exports = {};
|
|
22
|
+
__export(routerUtils_exports, {
|
|
27
23
|
DEFAULT_I18N_ROUTER_CONFIG: () => import_routeUtils.DEFAULT_I18N_ROUTER_CONFIG,
|
|
28
24
|
createFilterChain: () => import_filterUtils.createFilterChain,
|
|
29
25
|
decode: () => import_uriUtils.decode,
|
|
@@ -44,14 +40,15 @@ __export(exports, {
|
|
|
44
40
|
parseRoutes: () => import_parseUtils.parseRoutes,
|
|
45
41
|
pathToRegexp: () => pathToRegexp
|
|
46
42
|
});
|
|
47
|
-
|
|
48
|
-
var
|
|
49
|
-
var
|
|
50
|
-
var
|
|
51
|
-
var
|
|
52
|
-
var
|
|
53
|
-
var
|
|
54
|
-
var
|
|
43
|
+
module.exports = __toCommonJS(routerUtils_exports);
|
|
44
|
+
var import_filterUtils = require("./filterUtils.cjs");
|
|
45
|
+
var import_routeDefUtils = require("./routeDefUtils.cjs");
|
|
46
|
+
var import_routeUtils = require("./routeUtils.cjs");
|
|
47
|
+
var import_typeUtils = require("./typeUtils.cjs");
|
|
48
|
+
var import_parseUtils = require("./parseUtils.cjs");
|
|
49
|
+
var import_pathToRegexp = require("./pathToRegexp.cjs");
|
|
50
|
+
var import_uriUtils = require("./uriUtils.cjs");
|
|
51
|
+
var import_domUtils = require("./domUtils.cjs");
|
|
55
52
|
var pathToRegexp = {
|
|
56
53
|
pathToRegexp: import_pathToRegexp.pathToRegexp,
|
|
57
54
|
compile: import_pathToRegexp.compile
|
|
@@ -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/typeUtils.ts
|
|
9
|
-
|
|
10
|
-
__export(
|
|
21
|
+
var typeUtils_exports = {};
|
|
22
|
+
__export(typeUtils_exports, {
|
|
11
23
|
freeze: () => freeze,
|
|
12
24
|
guid: () => guid,
|
|
13
25
|
isObject: () => isObject,
|
|
@@ -15,6 +27,7 @@ __export(exports, {
|
|
|
15
27
|
isValidPageReference: () => isValidPageReference,
|
|
16
28
|
isValidRoute: () => isValidRoute
|
|
17
29
|
});
|
|
30
|
+
module.exports = __toCommonJS(typeUtils_exports);
|
|
18
31
|
function isObject(o) {
|
|
19
32
|
return typeof o === "object" && o !== null && !Array.isArray(o);
|
|
20
33
|
}
|
|
@@ -48,12 +61,12 @@ function guid() {
|
|
|
48
61
|
}
|
|
49
62
|
function isValidRoute(object) {
|
|
50
63
|
const expected = ["id", "attributes", "state", "pageReference"];
|
|
51
|
-
const {pageReference = null} = object || {};
|
|
64
|
+
const { pageReference = null } = object || {};
|
|
52
65
|
return isObject(object) && hasExactProperties(object, expected) && isValidPageReference(pageReference);
|
|
53
66
|
}
|
|
54
67
|
function isValidPageReference(object) {
|
|
55
68
|
const expected = ["type", "state", "attributes"];
|
|
56
|
-
const {type, state, attributes} = object || {};
|
|
69
|
+
const { type, state, attributes } = object || {};
|
|
57
70
|
const validTypes = isObject(object) && isString(type) && isObject(state) && validNullableString(state) && isObject(attributes) && validNullableString(attributes);
|
|
58
71
|
return hasExactProperties(object, expected) && validTypes;
|
|
59
72
|
}
|
|
@@ -65,7 +78,9 @@ function validNullableString(object) {
|
|
|
65
78
|
}
|
|
66
79
|
function hasExactProperties(object, expectedKeys) {
|
|
67
80
|
if (isObject(object)) {
|
|
68
|
-
const hasAllExpected = expectedKeys.every(
|
|
81
|
+
const hasAllExpected = expectedKeys.every(
|
|
82
|
+
(expectedKey) => objectHasKey(object, expectedKey)
|
|
83
|
+
);
|
|
69
84
|
const actual = Object.keys(expectedKeys);
|
|
70
85
|
const actualHasNoExtraProperties = actual.length === expectedKeys.length;
|
|
71
86
|
return hasAllExpected && actualHasNoExtraProperties;
|
|
@@ -1,5 +1,18 @@
|
|
|
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;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
3
15
|
|
|
4
16
|
// packages/@lwrjs/router/src/modules/lwr/routerUtils/types.ts
|
|
5
|
-
|
|
17
|
+
var types_exports = {};
|
|
18
|
+
module.exports = __toCommonJS(types_exports);
|
|
@@ -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/uriUtils.ts
|
|
9
|
-
|
|
10
|
-
__export(
|
|
21
|
+
var uriUtils_exports = {};
|
|
22
|
+
__export(uriUtils_exports, {
|
|
11
23
|
decode: () => decode,
|
|
12
24
|
encode: () => encode,
|
|
13
25
|
getParamName: () => getParamName,
|
|
@@ -17,6 +29,7 @@ __export(exports, {
|
|
|
17
29
|
getQueryString: () => getQueryString,
|
|
18
30
|
isParam: () => isParam
|
|
19
31
|
});
|
|
32
|
+
module.exports = __toCommonJS(uriUtils_exports);
|
|
20
33
|
function encode(str = "") {
|
|
21
34
|
str = str || "";
|
|
22
35
|
return encodeURIComponent(str);
|
|
@@ -75,7 +88,7 @@ function getParamName(routeParamName) {
|
|
|
75
88
|
return routeParamName ? isParam(routeParamName) ? routeParamName.substr(1) : false : false;
|
|
76
89
|
}
|
|
77
90
|
function getQueryNames(compiledQuery) {
|
|
78
|
-
return Object.values(compiledQuery).reduce((paramNames, {routeParamName}) => {
|
|
91
|
+
return Object.values(compiledQuery).reduce((paramNames, { routeParamName }) => {
|
|
79
92
|
const paramName = getParamName(routeParamName);
|
|
80
93
|
if (paramName) {
|
|
81
94
|
paramNames.push(paramName);
|
|
@@ -1,40 +1,37 @@
|
|
|
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/serverRouter/serverRouter.ts
|
|
25
|
-
|
|
26
|
-
__export(
|
|
21
|
+
var serverRouter_exports = {};
|
|
22
|
+
__export(serverRouter_exports, {
|
|
27
23
|
ServerRouter: () => ServerRouter,
|
|
28
24
|
createServerRouter: () => createServerRouter
|
|
29
25
|
});
|
|
30
|
-
|
|
31
|
-
var
|
|
32
|
-
var
|
|
33
|
-
var
|
|
34
|
-
var
|
|
35
|
-
var
|
|
36
|
-
var
|
|
37
|
-
var
|
|
26
|
+
module.exports = __toCommonJS(serverRouter_exports);
|
|
27
|
+
var import_contextProvider = require("lwr/contextProvider");
|
|
28
|
+
var import_metrics = require("lwr/metrics");
|
|
29
|
+
var import_navigation = require("lwr/navigation");
|
|
30
|
+
var import_navigationMixinHacks = require("lwr/navigationMixinHacks");
|
|
31
|
+
var import_profiler = require("lwr/profiler");
|
|
32
|
+
var import_router = require("lwr/router");
|
|
33
|
+
var import_routerErrors = require("lwr/routerErrors");
|
|
34
|
+
var import_routerUtils = require("lwr/routerUtils");
|
|
38
35
|
var ServerRouter = class {
|
|
39
36
|
constructor(config, router, target) {
|
|
40
37
|
this.contextId = Object.freeze(() => void 0);
|
|
@@ -45,6 +42,11 @@ var ServerRouter = class {
|
|
|
45
42
|
this.errorNavHook = config.errorNavigate;
|
|
46
43
|
this.initWires(config.url);
|
|
47
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* lightning/navigation
|
|
47
|
+
* Perform a hard navigation to the given page reference
|
|
48
|
+
* Client only!
|
|
49
|
+
*/
|
|
48
50
|
async navigate(address, _replace, options) {
|
|
49
51
|
if (import_routerUtils.hasDocument) {
|
|
50
52
|
if (this.handleNavHook && !this.handleNavHook(address)) {
|
|
@@ -56,12 +58,24 @@ var ServerRouter = class {
|
|
|
56
58
|
}
|
|
57
59
|
}
|
|
58
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* lightning/navigation
|
|
63
|
+
* Generate a URL based on the given page reference
|
|
64
|
+
*/
|
|
59
65
|
generateUrl(address, options) {
|
|
60
66
|
return this.router.generateUrl(address, options);
|
|
61
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* Async version of generateUrl
|
|
70
|
+
*/
|
|
62
71
|
generateUrlAsync(address, options) {
|
|
63
72
|
return this.router.generateUrlAsync(address, options);
|
|
64
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
* Initialize the CurrentPageReference & NavigationContext wires plus the client-only NavigationMixin
|
|
76
|
+
* On the server, use the URL from the config
|
|
77
|
+
* On the client, pull the URL from the current location
|
|
78
|
+
*/
|
|
65
79
|
initWires(url) {
|
|
66
80
|
if (!url && import_routerUtils.hasDocument) {
|
|
67
81
|
url = document.location.href;
|
|
@@ -76,12 +90,18 @@ var ServerRouter = class {
|
|
|
76
90
|
navigate: (address, replace, options) => this.navigate(address, replace, options),
|
|
77
91
|
generateUrl: (address, options) => this.generateUrl(address, options),
|
|
78
92
|
generateUrlAsync: (address, options) => this.generateUrlAsync(address, options),
|
|
93
|
+
// the JS context is lost during hard navigation, so subscribing to route changes will not work
|
|
79
94
|
subscribe: () => {
|
|
80
95
|
throw new Error("The server router does not support the subscribe API");
|
|
81
96
|
}
|
|
82
97
|
});
|
|
83
98
|
(0, import_contextProvider.provideContext)(this.contextId, this.target, import_contextProvider.navigationContextContextualizer, import_navigation.NavigationContext);
|
|
84
|
-
(0, import_contextProvider.provideContext)(
|
|
99
|
+
(0, import_contextProvider.provideContext)(
|
|
100
|
+
this.currentRoute?.route.pageReference,
|
|
101
|
+
this.target,
|
|
102
|
+
import_contextProvider.currentPageReferenceContextualizer,
|
|
103
|
+
import_navigation.CurrentPageReference
|
|
104
|
+
);
|
|
85
105
|
if (import_routerUtils.hasDocument) {
|
|
86
106
|
this.target.addEventListener(import_navigationMixinHacks.CONTEXT_ID_BACKDOOR, (event) => {
|
|
87
107
|
const navCtxEvent = event;
|
|
@@ -91,6 +111,10 @@ var ServerRouter = class {
|
|
|
91
111
|
});
|
|
92
112
|
}
|
|
93
113
|
}
|
|
114
|
+
/**
|
|
115
|
+
* Get a relative URL from a fully qualified one
|
|
116
|
+
* eg: "http://www.site.com/items/123abc?mode=dark" -> "/items/123abc?mode=dark"
|
|
117
|
+
*/
|
|
94
118
|
getRelativeUrl(url) {
|
|
95
119
|
if (url.startsWith("http")) {
|
|
96
120
|
const parsed = new URL(url);
|
|
@@ -98,6 +122,9 @@ var ServerRouter = class {
|
|
|
98
122
|
}
|
|
99
123
|
return url;
|
|
100
124
|
}
|
|
125
|
+
/**
|
|
126
|
+
* Validate the page reference passed to the navigate API
|
|
127
|
+
*/
|
|
101
128
|
async getValidatedUrl(address, options) {
|
|
102
129
|
const routingMatch = this.router.matchRoute(address, {});
|
|
103
130
|
if (!routingMatch) {
|
|
@@ -114,8 +141,11 @@ var ServerRouter = class {
|
|
|
114
141
|
}
|
|
115
142
|
return this.router.generateUrl(address, options);
|
|
116
143
|
}
|
|
144
|
+
/**
|
|
145
|
+
* Run the errorNavigate filters
|
|
146
|
+
*/
|
|
117
147
|
processError(messageObject) {
|
|
118
|
-
(0, import_profiler.logOperationStart)({id: import_metrics.ROUTER_ERROR});
|
|
148
|
+
(0, import_profiler.logOperationStart)({ id: import_metrics.ROUTER_ERROR });
|
|
119
149
|
this.errorNavHook && this.errorNavHook(messageObject);
|
|
120
150
|
}
|
|
121
151
|
};
|
|
@@ -1,51 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
3
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
4
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
-
var __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
|
|
8
8
|
var __export = (target, all) => {
|
|
9
9
|
for (var name in all)
|
|
10
|
-
__defProp(target, name, {get: all[name], enumerable: true});
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
11
|
};
|
|
12
|
-
var
|
|
13
|
-
if (
|
|
14
|
-
for (let key of __getOwnPropNames(
|
|
15
|
-
if (!__hasOwnProp.call(
|
|
16
|
-
__defProp(
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
17
|
}
|
|
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);
|
|
18
|
+
return to;
|
|
22
19
|
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
23
29
|
|
|
24
30
|
// packages/@lwrjs/router/src/services/index.ts
|
|
25
|
-
|
|
26
|
-
__export(
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
27
33
|
DEFAULT_SCHEMA: () => DEFAULT_SCHEMA,
|
|
28
34
|
deleteRouterConfigJsonCacheEntry: () => deleteRouterConfigJsonCacheEntry,
|
|
29
35
|
getClientRoutes: () => getClientRoutes
|
|
30
36
|
});
|
|
31
|
-
|
|
32
|
-
var
|
|
33
|
-
var
|
|
34
|
-
var
|
|
37
|
+
module.exports = __toCommonJS(index_exports);
|
|
38
|
+
var import_ajv = __toESM(require("ajv"), 1);
|
|
39
|
+
var import_fs = require("fs");
|
|
40
|
+
var import_shared_utils = require("@lwrjs/shared-utils");
|
|
41
|
+
var import_diagnostics = require("@lwrjs/diagnostics");
|
|
35
42
|
var DEFAULT_SCHEMA = "pageReference_v1";
|
|
36
43
|
var RouteDefinitionSchema = {
|
|
37
44
|
definitions: {
|
|
38
45
|
map: {
|
|
39
46
|
type: "object",
|
|
40
47
|
patternProperties: {
|
|
41
|
-
"^.+$": {type: "string", minLength: 1}
|
|
48
|
+
"^.+$": { type: "string", minLength: 1 }
|
|
42
49
|
}
|
|
43
50
|
},
|
|
44
51
|
nullableMap: {
|
|
45
52
|
type: "object",
|
|
46
53
|
patternProperties: {
|
|
47
54
|
"^.+$": {
|
|
48
|
-
anyOf: [{type: "string", minLength: 1}, {type: "null"}]
|
|
55
|
+
anyOf: [{ type: "string", minLength: 1 }, { type: "null" }]
|
|
49
56
|
}
|
|
50
57
|
}
|
|
51
58
|
},
|
|
@@ -56,21 +63,21 @@ var RouteDefinitionSchema = {
|
|
|
56
63
|
routeDef: {
|
|
57
64
|
type: "object",
|
|
58
65
|
properties: {
|
|
59
|
-
id: {type: "string", minLength: 1},
|
|
60
|
-
uri: {type: "string", minLength: 1},
|
|
61
|
-
patterns: {$ref: "#/definitions/map"},
|
|
62
|
-
exact: {type: "boolean"},
|
|
66
|
+
id: { type: "string", minLength: 1 },
|
|
67
|
+
uri: { type: "string", minLength: 1 },
|
|
68
|
+
patterns: { $ref: "#/definitions/map" },
|
|
69
|
+
exact: { type: "boolean" },
|
|
63
70
|
page: {
|
|
64
71
|
type: "object",
|
|
65
72
|
properties: {
|
|
66
|
-
type: {type: "string", minLength: 1},
|
|
67
|
-
attributes: {$ref: "#/definitions/nullableMap"},
|
|
68
|
-
state: {$ref: "#/definitions/nullableMap"}
|
|
73
|
+
type: { type: "string", minLength: 1 },
|
|
74
|
+
attributes: { $ref: "#/definitions/nullableMap" },
|
|
75
|
+
state: { $ref: "#/definitions/nullableMap" }
|
|
69
76
|
}
|
|
70
77
|
},
|
|
71
78
|
metadata: {},
|
|
72
|
-
handler: {$ref: "#/definitions/specifier"},
|
|
73
|
-
component: {$ref: "#/definitions/specifier"}
|
|
79
|
+
handler: { $ref: "#/definitions/specifier" },
|
|
80
|
+
component: { $ref: "#/definitions/specifier" }
|
|
74
81
|
},
|
|
75
82
|
required: ["id", "uri", "page"],
|
|
76
83
|
additionalProperties: false
|
|
@@ -78,11 +85,11 @@ var RouteDefinitionSchema = {
|
|
|
78
85
|
},
|
|
79
86
|
type: "object",
|
|
80
87
|
properties: {
|
|
81
|
-
schema: {type: "string", pattern: `^${DEFAULT_SCHEMA}$`},
|
|
82
|
-
caseSensitive: {type: "boolean"},
|
|
88
|
+
schema: { type: "string", pattern: `^${DEFAULT_SCHEMA}$` },
|
|
89
|
+
caseSensitive: { type: "boolean" },
|
|
83
90
|
routes: {
|
|
84
91
|
type: "array",
|
|
85
|
-
items: {$ref: "#/definitions/routeDef"}
|
|
92
|
+
items: { $ref: "#/definitions/routeDef" }
|
|
86
93
|
}
|
|
87
94
|
},
|
|
88
95
|
required: ["routes"],
|
|
@@ -90,7 +97,7 @@ var RouteDefinitionSchema = {
|
|
|
90
97
|
};
|
|
91
98
|
var ajv = new import_ajv.default();
|
|
92
99
|
var validate = ajv.compile(RouteDefinitionSchema);
|
|
93
|
-
var routerConfigJsonCache = new Map();
|
|
100
|
+
var routerConfigJsonCache = /* @__PURE__ */ new Map();
|
|
94
101
|
function deleteRouterConfigJsonCacheEntry(path) {
|
|
95
102
|
routerConfigJsonCache.delete(path);
|
|
96
103
|
}
|
|
@@ -105,12 +112,12 @@ function getClientRoutes(path) {
|
|
|
105
112
|
try {
|
|
106
113
|
const json = JSON.parse((0, import_shared_utils.readFile)(path));
|
|
107
114
|
if (!validate(json)) {
|
|
108
|
-
throw new Error(ajv.errorsText(validate.errors, {separator: "\n"}));
|
|
115
|
+
throw new Error(ajv.errorsText(validate.errors, { separator: "\n" }));
|
|
109
116
|
}
|
|
110
117
|
const config = json;
|
|
111
118
|
const routes = config.routes;
|
|
112
119
|
routes.forEach((route, index) => {
|
|
113
|
-
const {id, handler, component} = route;
|
|
120
|
+
const { id, handler, component } = route;
|
|
114
121
|
if (routes.findIndex((r) => r.id === id) !== index) {
|
|
115
122
|
throw new Error(`Duplicate route definition id: ${id}`);
|
|
116
123
|
}
|
|
@@ -124,6 +131,9 @@ function getClientRoutes(path) {
|
|
|
124
131
|
routerConfigJsonCache.set(path, config);
|
|
125
132
|
return config;
|
|
126
133
|
} catch (e) {
|
|
127
|
-
throw new import_diagnostics.LwrUnresolvableError(
|
|
134
|
+
throw new import_diagnostics.LwrUnresolvableError(
|
|
135
|
+
import_diagnostics.descriptions.UNRESOLVABLE.ROUTES_MODULE(path, e.message),
|
|
136
|
+
"module"
|
|
137
|
+
);
|
|
128
138
|
}
|
|
129
139
|
}
|