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