@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,42 +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/services/module-provider/index.ts
|
|
25
|
-
|
|
26
|
-
__export(
|
|
27
|
-
default: () =>
|
|
20
|
+
var module_provider_exports = {};
|
|
21
|
+
__export(module_provider_exports, {
|
|
22
|
+
default: () => RouterModuleProvider
|
|
28
23
|
});
|
|
29
|
-
|
|
30
|
-
var
|
|
31
|
-
var
|
|
24
|
+
module.exports = __toCommonJS(module_provider_exports);
|
|
25
|
+
var import_shared_utils = require("@lwrjs/shared-utils");
|
|
26
|
+
var import_utils = require("./utils.cjs");
|
|
27
|
+
var import__ = require("../index.cjs");
|
|
32
28
|
var DEFAULT_DIR = "$rootDir/src/routes";
|
|
33
29
|
var RouterModuleProvider = class {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
30
|
+
name = "router-module-provider";
|
|
31
|
+
version;
|
|
32
|
+
routesDir;
|
|
33
|
+
appBasePath;
|
|
34
|
+
i18n;
|
|
35
|
+
// Watch the Router Config files and recompile the modules on change
|
|
36
|
+
routerWatcher;
|
|
37
|
+
watchedFileSet = /* @__PURE__ */ new Set();
|
|
38
|
+
// <config path, module id>
|
|
39
|
+
constructor({ routesDir = DEFAULT_DIR }, context) {
|
|
37
40
|
const {
|
|
38
|
-
config: {rootDir, contentDir, i18n, layoutsDir},
|
|
39
|
-
runtimeEnvironment: {lwrVersion, watchFiles},
|
|
41
|
+
config: { rootDir, contentDir, i18n, layoutsDir },
|
|
42
|
+
runtimeEnvironment: { lwrVersion, watchFiles },
|
|
40
43
|
watcherFactory
|
|
41
44
|
} = context;
|
|
42
45
|
this.version = lwrVersion;
|
|
@@ -49,9 +52,14 @@ var RouterModuleProvider = class {
|
|
|
49
52
|
}).replace(/\/$/, "");
|
|
50
53
|
this.routerWatcher = watchFiles && watcherFactory ? (0, import_utils.setUpWatcher)(watcherFactory, this.onRouterModuleChange.bind(this)) : void 0;
|
|
51
54
|
}
|
|
55
|
+
// When Router Metadata changes on the file system:
|
|
56
|
+
// 1. delete the config data from the routerConfigJsonCache (in ../index)
|
|
52
57
|
async onRouterModuleChange(configPath) {
|
|
53
58
|
(0, import__.deleteRouterConfigJsonCacheEntry)(configPath);
|
|
54
59
|
}
|
|
60
|
+
// Watch Router Config files:
|
|
61
|
+
// 1. Add files to the watcher
|
|
62
|
+
// 2. Track watched files in the watchedFileSet
|
|
55
63
|
watchConfigs(configPath) {
|
|
56
64
|
if (this.routerWatcher) {
|
|
57
65
|
if (!this.watchedFileSet.has(configPath)) {
|
|
@@ -60,6 +68,9 @@ var RouterModuleProvider = class {
|
|
|
60
68
|
}
|
|
61
69
|
}
|
|
62
70
|
}
|
|
71
|
+
// 1. Check that:
|
|
72
|
+
// a. the specifier is in the correct format: "@lwrjs/router/{routerId}"
|
|
73
|
+
// b. the config JSON addressed by "routerId" is available on the file system
|
|
63
74
|
getRouterConfig(specifier) {
|
|
64
75
|
let config;
|
|
65
76
|
const routerId = (0, import_utils.parseSpecifier)(specifier);
|
|
@@ -70,12 +81,14 @@ var RouterModuleProvider = class {
|
|
|
70
81
|
}
|
|
71
82
|
return config;
|
|
72
83
|
}
|
|
73
|
-
async getModuleEntry({specifier}, runtimeParams) {
|
|
84
|
+
async getModuleEntry({ specifier }, runtimeParams) {
|
|
74
85
|
const config = this.getRouterConfig(specifier);
|
|
75
86
|
if (config) {
|
|
76
87
|
return {
|
|
77
88
|
id: `${specifier}|${this.version}|${runtimeParams.basePath}|${runtimeParams.locale}`,
|
|
89
|
+
// used as part of the cache key for this module by the LWR Module Registry
|
|
78
90
|
virtual: true,
|
|
91
|
+
// ...because this is a server-generated module
|
|
79
92
|
entry: `<virtual>/${specifier}.js`,
|
|
80
93
|
specifier,
|
|
81
94
|
version: this.version
|
|
@@ -83,8 +96,8 @@ var RouterModuleProvider = class {
|
|
|
83
96
|
}
|
|
84
97
|
}
|
|
85
98
|
async getModule(moduleId, runtimeParams) {
|
|
86
|
-
const {specifier, namespace, name = specifier} = moduleId;
|
|
87
|
-
const moduleEntry = await this.getModuleEntry({specifier}, runtimeParams);
|
|
99
|
+
const { specifier, namespace, name = specifier } = moduleId;
|
|
100
|
+
const moduleEntry = await this.getModuleEntry({ specifier }, runtimeParams);
|
|
88
101
|
if (!moduleEntry) {
|
|
89
102
|
return;
|
|
90
103
|
}
|
|
@@ -104,4 +117,3 @@ var RouterModuleProvider = class {
|
|
|
104
117
|
return moduleCompiled;
|
|
105
118
|
}
|
|
106
119
|
};
|
|
107
|
-
var module_provider_default = RouterModuleProvider;
|
|
@@ -1,37 +1,33 @@
|
|
|
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/services/module-provider/utils.ts
|
|
25
|
-
|
|
26
|
-
__export(
|
|
20
|
+
var utils_exports = {};
|
|
21
|
+
__export(utils_exports, {
|
|
27
22
|
SPECIFIER_PREFIX: () => SPECIFIER_PREFIX,
|
|
28
23
|
generateModule: () => generateModule,
|
|
29
24
|
getRouterConfigPath: () => getRouterConfigPath,
|
|
30
25
|
parseSpecifier: () => parseSpecifier,
|
|
31
26
|
setUpWatcher: () => setUpWatcher
|
|
32
27
|
});
|
|
33
|
-
|
|
34
|
-
var
|
|
28
|
+
module.exports = __toCommonJS(utils_exports);
|
|
29
|
+
var import_diagnostics = require("@lwrjs/diagnostics");
|
|
30
|
+
var import_shared_utils = require("@lwrjs/shared-utils");
|
|
35
31
|
var SPECIFIER_PREFIX = "@lwrjs/router/";
|
|
36
32
|
function parseSpecifier(specifier) {
|
|
37
33
|
return specifier.startsWith(SPECIFIER_PREFIX) ? specifier.replace(SPECIFIER_PREFIX, "") : void 0;
|
|
@@ -42,9 +38,18 @@ function getRouterConfigPath(dir, specifier) {
|
|
|
42
38
|
}
|
|
43
39
|
function setUpWatcher(factory, onModuleChange) {
|
|
44
40
|
const watcher = factory.createFileWatcher();
|
|
45
|
-
watcher.on(
|
|
46
|
-
|
|
47
|
-
|
|
41
|
+
watcher.on(
|
|
42
|
+
"change",
|
|
43
|
+
(0, import_shared_utils.debounce)((file) => onModuleChange(file), 500)
|
|
44
|
+
);
|
|
45
|
+
watcher.on(
|
|
46
|
+
"unlink",
|
|
47
|
+
(0, import_shared_utils.debounce)((file) => onModuleChange(file, true), 500)
|
|
48
|
+
);
|
|
49
|
+
watcher.on(
|
|
50
|
+
"add",
|
|
51
|
+
(file) => import_diagnostics.logger.info({ label: `@lwrjs/router`, message: `Watching Router Config file at "${file}"` })
|
|
52
|
+
);
|
|
48
53
|
return watcher;
|
|
49
54
|
}
|
|
50
55
|
function getHandlerClassName(specifier) {
|
|
@@ -52,10 +57,9 @@ function getHandlerClassName(specifier) {
|
|
|
52
57
|
}
|
|
53
58
|
function generateHandlerClasses(routes) {
|
|
54
59
|
let handlerClasses = "";
|
|
55
|
-
const seenComponents = new Set();
|
|
60
|
+
const seenComponents = /* @__PURE__ */ new Set();
|
|
56
61
|
const filteredAndDeDupedArray = routes.filter((item) => {
|
|
57
|
-
if (!item.component)
|
|
58
|
-
return false;
|
|
62
|
+
if (!item.component) return false;
|
|
59
63
|
if (!seenComponents.has(item.component)) {
|
|
60
64
|
seenComponents.add(item.component);
|
|
61
65
|
return true;
|
|
@@ -88,25 +92,27 @@ function generateHandlerClasses(routes) {
|
|
|
88
92
|
function generateRouteDefinitions(routes) {
|
|
89
93
|
let routeDefs = "[\n";
|
|
90
94
|
routes.forEach((r) => {
|
|
91
|
-
const {handler, component, ...routeDef} = r;
|
|
95
|
+
const { handler, component, ...routeDef } = r;
|
|
92
96
|
const portableProps = JSON.stringify(routeDef);
|
|
93
97
|
if (handler) {
|
|
94
|
-
routeDefs +=
|
|
98
|
+
routeDefs += // translate the handler specifier => a handler dynamic import
|
|
99
|
+
portableProps.slice(0, portableProps.length - 1) + `, handler: () => import('${handler}') },
|
|
95
100
|
`;
|
|
96
101
|
} else if (component) {
|
|
97
|
-
routeDefs +=
|
|
102
|
+
routeDefs += // translate the component specifier => a resolved handler class
|
|
103
|
+
portableProps.slice(0, portableProps.length - 1) + `, handler: () => Promise.resolve({ default: ${getHandlerClassName(component)} }) },
|
|
98
104
|
`;
|
|
99
105
|
}
|
|
100
106
|
});
|
|
101
107
|
return `${routeDefs} ]`;
|
|
102
108
|
}
|
|
103
|
-
function generateModule(config = {routes: []}, {defaultLocale, uriPattern}, runtimeParams) {
|
|
104
|
-
const {caseSensitive, routes: jsonRoutes} = config;
|
|
109
|
+
function generateModule(config = { routes: [] }, { defaultLocale, uriPattern }, runtimeParams) {
|
|
110
|
+
const { caseSensitive, routes: jsonRoutes } = config;
|
|
105
111
|
const csString = caseSensitive ? "true" : "false";
|
|
106
112
|
const routes = generateRouteDefinitions(jsonRoutes);
|
|
107
113
|
const handlers = generateHandlerClasses(jsonRoutes);
|
|
108
114
|
const basePath = runtimeParams?.basePath || "";
|
|
109
|
-
const i18nRouterConfig = uriPattern === "path-prefix" ? `${JSON.stringify({locale: runtimeParams?.locale, defaultLocale})}` : void 0;
|
|
115
|
+
const i18nRouterConfig = uriPattern === "path-prefix" ? `${JSON.stringify({ locale: runtimeParams?.locale, defaultLocale })}` : void 0;
|
|
110
116
|
return `import { createRouter as createLwrRouter } from 'lwr/router';
|
|
111
117
|
${handlers}
|
|
112
118
|
export function createRouter({ basePath = '${basePath}', caseSensitive = ${csString}, DEPRECATED_getRouteFromUrl, DEPRECATED_getUrlFromRoute } = {}) {
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
8
|
-
"version": "0.24.
|
|
8
|
+
"version": "0.24.4",
|
|
9
9
|
"homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
@@ -53,14 +53,14 @@
|
|
|
53
53
|
"test:server": "jest --config ./jest.server.config.cjs"
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"@lwrjs/client-modules": "0.24.
|
|
57
|
-
"@lwrjs/diagnostics": "0.24.
|
|
58
|
-
"@lwrjs/shared-utils": "0.24.
|
|
56
|
+
"@lwrjs/client-modules": "0.24.4",
|
|
57
|
+
"@lwrjs/diagnostics": "0.24.4",
|
|
58
|
+
"@lwrjs/shared-utils": "0.24.4",
|
|
59
59
|
"ajv": "8.18.0"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
62
|
"@lwc/jest-preset": "^19.6.1",
|
|
63
|
-
"@lwrjs/fs-watch": "0.24.
|
|
63
|
+
"@lwrjs/fs-watch": "0.24.4",
|
|
64
64
|
"@rollup/plugin-typescript": "^11.1.6",
|
|
65
65
|
"jest": "29.7.0",
|
|
66
66
|
"memfs": "^4.13.0",
|
|
@@ -100,5 +100,5 @@
|
|
|
100
100
|
"volta": {
|
|
101
101
|
"extends": "../../../package.json"
|
|
102
102
|
},
|
|
103
|
-
"gitHead": "
|
|
103
|
+
"gitHead": "63feabb6eea1340e80a82146cc1c24bfc4f2d518"
|
|
104
104
|
}
|