@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.
Files changed (40) hide show
  1. package/build/cjs/modules/lwr/contextProvider/contextProvider.cjs +24 -22
  2. package/build/cjs/modules/lwr/contextUtils/contextInfo.cjs +62 -8
  3. package/build/cjs/modules/lwr/contextUtils/contextUtils.cjs +55 -22
  4. package/build/cjs/modules/lwr/contextUtils/navigationApiStore.cjs +15 -19
  5. package/build/cjs/modules/lwr/currentPageReference/currentPageReference.cjs +17 -19
  6. package/build/cjs/modules/lwr/currentView/currentView.cjs +15 -19
  7. package/build/cjs/modules/lwr/domRouter/domRouter.cjs +208 -81
  8. package/build/cjs/modules/lwr/domRouterUtils/domRouterUtils.cjs +15 -19
  9. package/build/cjs/modules/lwr/domRouterUtils/historyUtils.cjs +16 -4
  10. package/build/cjs/modules/lwr/domRouterUtils/types.cjs +14 -2
  11. package/build/cjs/modules/lwr/domRouterUtils/uriUtils.cjs +15 -18
  12. package/build/cjs/modules/lwr/historyRouter/historyRouter.cjs +38 -25
  13. package/build/cjs/modules/lwr/navigation/constants.cjs +20 -8
  14. package/build/cjs/modules/lwr/navigation/navigation.cjs +19 -23
  15. package/build/cjs/modules/lwr/navigation/navigationApi.cjs +14 -18
  16. package/build/cjs/modules/lwr/navigation/navigationMixin.cjs +29 -29
  17. package/build/cjs/modules/lwr/navigationContext/navigationContext.cjs +14 -18
  18. package/build/cjs/modules/lwr/navigationMixinHacks/navigationMixinHacks.cjs +14 -18
  19. package/build/cjs/modules/lwr/observable/observable.cjs +16 -4
  20. package/build/cjs/modules/lwr/outlet/outlet.cjs +27 -55
  21. package/build/cjs/modules/lwr/router/router.cjs +130 -40
  22. package/build/cjs/modules/lwr/routerBridge/routerBridge.cjs +37 -29
  23. package/build/cjs/modules/lwr/routerContainer/routerContainer.cjs +47 -40
  24. package/build/cjs/modules/lwr/routerContainer/utils.cjs +40 -20
  25. package/build/cjs/modules/lwr/routerErrors/routerErrors.cjs +16 -4
  26. package/build/cjs/modules/lwr/routerUtils/domUtils.cjs +16 -4
  27. package/build/cjs/modules/lwr/routerUtils/filterUtils.cjs +35 -17
  28. package/build/cjs/modules/lwr/routerUtils/parseUtils.cjs +26 -30
  29. package/build/cjs/modules/lwr/routerUtils/pathToRegexp.cjs +63 -52
  30. package/build/cjs/modules/lwr/routerUtils/routeDefUtils.cjs +25 -28
  31. package/build/cjs/modules/lwr/routerUtils/routeUtils.cjs +30 -34
  32. package/build/cjs/modules/lwr/routerUtils/routerUtils.cjs +21 -25
  33. package/build/cjs/modules/lwr/routerUtils/typeUtils.cjs +21 -7
  34. package/build/cjs/modules/lwr/routerUtils/types.cjs +14 -2
  35. package/build/cjs/modules/lwr/routerUtils/uriUtils.cjs +17 -5
  36. package/build/cjs/modules/lwr/serverRouter/serverRouter.cjs +63 -28
  37. package/build/cjs/services/index.cjs +46 -37
  38. package/build/cjs/services/module-provider/index.cjs +42 -30
  39. package/build/cjs/services/module-provider/utils.cjs +37 -31
  40. package/package.json +6 -6
@@ -1,38 +1,46 @@
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 __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
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 __exportStar = (target, module2, desc) => {
13
- if (module2 && typeof module2 === "object" || typeof module2 === "function") {
14
- for (let key of __getOwnPropNames(module2))
15
- if (!__hasOwnProp.call(target, key) && key !== "default")
16
- __defProp(target, key, {get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable});
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 target;
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/router/router.ts
25
- __markAsModule(exports);
26
- __export(exports, {
20
+ var router_exports = {};
21
+ __export(router_exports, {
27
22
  createRouter: () => createRouter
28
23
  });
29
- var import_routerUtils = __toModule(require("lwr/routerUtils"));
30
- var import_routerErrors = __toModule(require("lwr/routerErrors"));
31
- var import_observable = __toModule(require("lwr/observable"));
24
+ module.exports = __toCommonJS(router_exports);
25
+ var import_routerUtils = require("lwr/routerUtils");
26
+ var import_routerErrors = require("lwr/routerErrors");
27
+ var import_observable = require("lwr/observable");
32
28
  var RouterImpl = class {
29
+ config;
30
+ basePath;
31
+ deprecatedConfig = {};
32
+ compiledRoutes;
33
+ // The in-flight route state to be committed once the view mapping is handled
34
+ pendingRoute;
35
+ routeObservable;
36
+ routeHandler;
37
+ routeHandlerId = 0;
38
+ /**
39
+ * Create and configure the Router.
40
+ *
41
+ * @param {object} config - The router config object, all properties are optional
42
+ */
33
43
  constructor(config) {
34
- this.deprecatedConfig = {};
35
- this.routeHandlerId = 0;
36
44
  this.compiledRoutes = [];
37
45
  this.routeObservable = (0, import_observable.createObservable)();
38
46
  this.basePath = config.basePath || "";
@@ -41,10 +49,21 @@ var RouterImpl = class {
41
49
  i18n: config.i18n || import_routerUtils.DEFAULT_I18N_ROUTER_CONFIG,
42
50
  caseSensitive: Boolean(config.caseSensitive),
43
51
  routes: config.routes || [],
44
- generateUrl: (address, options) => (0, import_routerUtils.getUrlFromPageReference)(address, this.compiledRoutes, this.config.basePath, this.config.i18n, options),
45
- parseUrl: (url) => (0, import_routerUtils.getPageReferenceFromUrl)(url, this.compiledRoutes, this.config.basePath, this.config.i18n)
52
+ generateUrl: (address, options) => (0, import_routerUtils.getUrlFromPageReference)(
53
+ address,
54
+ this.compiledRoutes,
55
+ this.config.basePath,
56
+ this.config.i18n,
57
+ options
58
+ ),
59
+ parseUrl: (url) => (0, import_routerUtils.getPageReferenceFromUrl)(
60
+ url,
61
+ this.compiledRoutes,
62
+ this.config.basePath,
63
+ this.config.i18n
64
+ )
46
65
  };
47
- const {generateUrlFilter, DEPRECATED_getRouteFromUrl, DEPRECATED_getUrlFromRoute} = config;
66
+ const { generateUrlFilter, DEPRECATED_getRouteFromUrl, DEPRECATED_getUrlFromRoute } = config;
48
67
  if (generateUrlFilter) {
49
68
  this.config.generateUrlFilter = generateUrlFilter;
50
69
  }
@@ -56,37 +75,69 @@ var RouterImpl = class {
56
75
  }
57
76
  this.compiledRoutes = (0, import_routerUtils.parseRoutes)(this.config);
58
77
  }
78
+ /**
79
+ * Convert address to url string.
80
+ *
81
+ * @param address
82
+ */
59
83
  generateUrl(address, options) {
60
- const {DEPRECATED_getUrlFromRoute: getUrlFromRoute} = this.deprecatedConfig;
84
+ const { DEPRECATED_getUrlFromRoute: getUrlFromRoute } = this.deprecatedConfig;
61
85
  if (getUrlFromRoute) {
62
86
  return getUrlFromRoute(address, this.config.generateUrl, options);
63
87
  } else {
64
88
  return this.config.generateUrl(address, options);
65
89
  }
66
90
  }
91
+ /**
92
+ * Async version of generateUrl.
93
+ * @returns {Promise<string | null>}
94
+ */
67
95
  generateUrlAsync(address, options) {
68
- const {generateUrlFilter} = this.config;
96
+ const { generateUrlFilter } = this.config;
69
97
  if (generateUrlFilter) {
70
98
  return generateUrlFilter(address, this.config.generateUrl, options);
71
99
  } else {
72
100
  return Promise.resolve(this.generateUrl(address, options));
73
101
  }
74
102
  }
103
+ /**
104
+ * Convert url string to address.
105
+ *
106
+ * @param url
107
+ */
75
108
  parseUrl(url) {
76
- const {DEPRECATED_getRouteFromUrl: getRouteFromUrl} = this.deprecatedConfig;
109
+ const { DEPRECATED_getRouteFromUrl: getRouteFromUrl } = this.deprecatedConfig;
77
110
  if (getRouteFromUrl) {
78
111
  return getRouteFromUrl(url, this.config.parseUrl);
79
112
  } else {
80
113
  return this.config.parseUrl(url);
81
114
  }
82
115
  }
116
+ /**
117
+ * Match the given url against the internal route definitions and return info
118
+ * on the match.
119
+ *
120
+ * @param address - The address to match
121
+ */
83
122
  matchRoute(address, options) {
84
123
  const url = typeof address === "string" ? address : this.generateUrl(address, options);
85
124
  if (url === null) {
86
125
  return null;
87
126
  }
88
- const match = (0, import_routerUtils.matchRouteByUrl)(url, this.compiledRoutes, this.config.basePath, this.config.i18n, options);
89
- const pathMatch = match && (0, import_routerUtils.getUrlFromPageReferenceAndRouteDef)(match.route.pageReference, match.routeDefinition, this.config.basePath, this.config.i18n, options);
127
+ const match = (0, import_routerUtils.matchRouteByUrl)(
128
+ url,
129
+ this.compiledRoutes,
130
+ this.config.basePath,
131
+ this.config.i18n,
132
+ options
133
+ );
134
+ const pathMatch = match && (0, import_routerUtils.getUrlFromPageReferenceAndRouteDef)(
135
+ match.route.pageReference,
136
+ match.routeDefinition,
137
+ this.config.basePath,
138
+ this.config.i18n,
139
+ options
140
+ );
90
141
  if (!match || !pathMatch) {
91
142
  return null;
92
143
  }
@@ -96,6 +147,11 @@ var RouterImpl = class {
96
147
  routeDefinition: match.routeDefinition.original
97
148
  };
98
149
  }
150
+ /**
151
+ * Given an address, return the associated viewset by calling the route handler.
152
+ *
153
+ * @param address - The address to match to a viewset
154
+ */
99
155
  async resolveView(address, options) {
100
156
  return new Promise((resolve, reject) => {
101
157
  const routingMatch = this.matchRoute(address, options);
@@ -105,7 +161,9 @@ var RouterImpl = class {
105
161
  return routingMatch.routeDefinition.handler?.().then((handlerModule) => {
106
162
  const routeHandlerClass = handlerModule.default;
107
163
  if (!routeHandlerClass) {
108
- return reject((0, import_routerErrors.generateMessage)(import_routerErrors.messages.INVALID_ROUTE_HANDLER, [routingMatch.routeDefinition.id]));
164
+ return reject(
165
+ (0, import_routerErrors.generateMessage)(import_routerErrors.messages.INVALID_ROUTE_HANDLER, [routingMatch.routeDefinition.id])
166
+ );
109
167
  }
110
168
  const routeHandler = new routeHandlerClass(resolve);
111
169
  if (routeHandler) {
@@ -114,30 +172,57 @@ var RouterImpl = class {
114
172
  });
115
173
  });
116
174
  }
175
+ /**
176
+ * Process the given URL by matching it to an existing route and looking up
177
+ * the associated view
178
+ *
179
+ * @param {object} address
180
+ */
117
181
  navigate(address, options) {
118
182
  const routingMatch = this.matchRoute(address, options);
119
183
  if (!routingMatch) {
120
184
  throw new Error((0, import_routerErrors.generateMessage)(import_routerErrors.messages.MISSING_ROUTE, [JSON.stringify(address)]));
121
185
  }
122
- this.pendingRoute = {...routingMatch};
186
+ this.pendingRoute = { ...routingMatch };
123
187
  this._mapView(this.pendingRoute);
124
188
  }
189
+ /**
190
+ * lightning/navigation
191
+ * Subscribe a callback to the Observable on the current route of this router.
192
+ *
193
+ * @param {function} callback - A callback function invoked when the navigation state changes
194
+ * callback(route, routeDef)
195
+ * @param {boolean} replay - Flag to determine if callback should be called with current route and data immediately
196
+ */
125
197
  subscribe(callback, replay) {
126
- return this.routeObservable.subscribe({
127
- next: callback,
128
- error: () => {
198
+ return this.routeObservable.subscribe(
199
+ {
200
+ next: callback,
201
+ error: () => {
202
+ },
203
+ complete: () => {
204
+ }
129
205
  },
130
- complete: () => {
131
- }
132
- }, Boolean(replay));
206
+ Boolean(replay)
207
+ );
133
208
  }
209
+ /**
210
+ * Map the given route to a view set that can be emitted to subscribers. After the correct handler
211
+ * is determined (picked from the routers routes in the config), view mapping is delegated to the
212
+ * handler with a callback to finish processing and emit the final result.
213
+ *
214
+ * @param {*} route
215
+ * @param {*} routeInfo
216
+ */
134
217
  async _mapView(routingMatch) {
135
218
  const routeHandlerId = Math.random();
136
219
  this.routeHandlerId = routeHandlerId;
137
220
  const handlerModule = await routingMatch.routeDefinition.handler?.();
138
221
  const routeHandlerClass = handlerModule?.default;
139
222
  if (!routeHandlerClass) {
140
- throw new Error((0, import_routerErrors.generateMessage)(import_routerErrors.messages.INVALID_ROUTE_HANDLER, [routingMatch.routeDefinition.id]));
223
+ throw new Error(
224
+ (0, import_routerErrors.generateMessage)(import_routerErrors.messages.INVALID_ROUTE_HANDLER, [routingMatch.routeDefinition.id])
225
+ );
141
226
  }
142
227
  this.routeHandler = new routeHandlerClass((routeDestination) => {
143
228
  this._updateView(routeHandlerId, routeDestination);
@@ -147,6 +232,11 @@ var RouterImpl = class {
147
232
  }
148
233
  return true;
149
234
  }
235
+ /**
236
+ * Set internal state, notify observable with frozen data, and propagate to child router
237
+ *
238
+ * @param {*} viewDestination
239
+ */
150
240
  _updateView(viewHandlerId, routeDestination) {
151
241
  if (!routeDestination || viewHandlerId !== this.routeHandlerId) {
152
242
  return;
@@ -155,7 +245,7 @@ var RouterImpl = class {
155
245
  throw new Error("Trying to commit route state without a route");
156
246
  }
157
247
  const viewset = (0, import_routerUtils.freeze)(routeDestination.viewset);
158
- this.routeObservable.next({...this.pendingRoute, ...routeDestination, viewset});
248
+ this.routeObservable.next({ ...this.pendingRoute, ...routeDestination, viewset });
159
249
  }
160
250
  };
161
251
  function createRouter(config = {}) {
@@ -1,44 +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 __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
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 __exportStar = (target, module2, desc) => {
13
- if (module2 && typeof module2 === "object" || typeof module2 === "function") {
14
- for (let key of __getOwnPropNames(module2))
15
- if (!__hasOwnProp.call(target, key) && key !== "default")
16
- __defProp(target, key, {get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable});
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 target;
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/routerBridge/routerBridge.ts
25
- __markAsModule(exports);
26
- __export(exports, {
20
+ var routerBridge_exports = {};
21
+ __export(routerBridge_exports, {
27
22
  createBridge: () => createBridge
28
23
  });
29
- var import_domRouter = __toModule(require("lwr/domRouter"));
24
+ module.exports = __toCommonJS(routerBridge_exports);
25
+ var import_domRouter = require("lwr/domRouter");
30
26
  var DomRouterBridge = class {
27
+ config;
28
+ target;
29
+ bridgedRouter;
31
30
  constructor(config = {}, target = window) {
32
- this.handleParentEvent = (event) => {
33
- const parentEvent = event;
34
- if (parentEvent && parentEvent.detail && typeof parentEvent.detail === "function") {
35
- parentEvent.detail(this);
36
- if (this.bridgedRouter) {
37
- this.bridgedRouter.parent = void 0;
38
- this.target.removeEventListener(import_domRouter.PARENT_EVENT, this.handleParentEvent);
39
- }
40
- }
41
- };
42
31
  this.config = {
43
32
  historyDisabled: !!config.historyDisabled,
44
33
  onReady: config.onReady || (() => {
@@ -52,9 +41,25 @@ var DomRouterBridge = class {
52
41
  this.target = target;
53
42
  this.target.addEventListener(import_domRouter.PARENT_EVENT, this.handleParentEvent);
54
43
  }
44
+ // Routers send out the PARENT_EVENT to build a router hierarchy
45
+ // Listen for this event to find the topmost router located beneath the bridge in the DOM
46
+ // NOTE: because of the restrictions on "lwr/router" hierachy, this is only called 0 or 1 time(s)
47
+ // - only ONE root router is allowed in a document
48
+ // - sibling routers are NOT allowed
49
+ handleParentEvent = (event) => {
50
+ const parentEvent = event;
51
+ if (parentEvent && parentEvent.detail && typeof parentEvent.detail === "function") {
52
+ parentEvent.detail(this);
53
+ if (this.bridgedRouter) {
54
+ this.bridgedRouter.parent = void 0;
55
+ this.target.removeEventListener(import_domRouter.PARENT_EVENT, this.handleParentEvent);
56
+ }
57
+ }
58
+ };
59
+ // Save an observed router and subscribe to its navigation and error updates
55
60
  async addChild(child) {
56
61
  this.bridgedRouter = child;
57
- this.bridgedRouter.subscribe(({route: {pageReference}}) => {
62
+ this.bridgedRouter.subscribe(({ route: { pageReference } }) => {
58
63
  this.config.onPostNavigate(pageReference);
59
64
  });
60
65
  this.bridgedRouter.addErrorNavigate(this.config.onError);
@@ -68,6 +73,9 @@ var DomRouterBridge = class {
68
73
  }, 0);
69
74
  });
70
75
  }
76
+ // Use the observed router to navigate to the given page reference
77
+ // Return true if the router is connected and the navigation event was sent
78
+ // False is returned if there are no mounted routers to observe (yet)
71
79
  navigate(pageRef) {
72
80
  if (this.bridgedRouter && this.bridgedRouter.connected) {
73
81
  this.bridgedRouter.navigate(pageRef);
@@ -1,49 +1,44 @@
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 __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
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 __exportStar = (target, module2, desc) => {
13
- if (module2 && typeof module2 === "object" || typeof module2 === "function") {
14
- for (let key of __getOwnPropNames(module2))
15
- if (!__hasOwnProp.call(target, key) && key !== "default")
16
- __defProp(target, key, {get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable});
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 target;
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);
22
- };
23
- var __decorate = (decorators, target, key, kind) => {
24
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
25
- for (var i = decorators.length - 1, decorator; i >= 0; i--)
26
- if (decorator = decorators[i])
27
- result = (kind ? decorator(target, key, result) : decorator(result)) || result;
28
- if (kind && result)
29
- __defProp(target, key, result);
30
- return result;
15
+ return to;
31
16
  };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
32
18
 
33
19
  // packages/@lwrjs/router/src/modules/lwr/routerContainer/routerContainer.ts
34
- __markAsModule(exports);
35
- __export(exports, {
36
- default: () => routerContainer_default
20
+ var routerContainer_exports = {};
21
+ __export(routerContainer_exports, {
22
+ default: () => RouterContainer
37
23
  });
38
- var import_lwc = __toModule(require("lwc"));
39
- var import_utils = __toModule(require("./utils.cjs"));
40
- var import_routerUtils = __toModule(require("lwr/routerUtils"));
24
+ module.exports = __toCommonJS(routerContainer_exports);
25
+ var import_lwc = require("lwc");
26
+ var import_utils = require("./utils.cjs");
27
+ var import_routerUtils = require("lwr/routerUtils");
41
28
  var RouterContainer = class extends import_lwc.LightningElement {
29
+ static renderMode = "light";
30
+ // Instance of the Router class for this LWC.
31
+ routerApi;
32
+ @import_lwc.api router;
33
+ @import_lwc.api historyDisabled = false;
34
+ currentTitle;
42
35
  constructor() {
43
36
  super();
44
- this.historyDisabled = false;
45
37
  this.currentTitle = import_routerUtils.hasDocument ? document.title : "";
46
38
  }
39
+ /**
40
+ * Create a router attached to this component.
41
+ */
47
42
  connectedCallback() {
48
43
  const config = {
49
44
  historyDisabled: this.historyDisabled,
@@ -54,11 +49,19 @@ var RouterContainer = class extends import_lwc.LightningElement {
54
49
  this.routerApi.addPreNavigate(this.preNavigate.bind(this)).addPostNavigate(this.postNavigate.bind(this)).addErrorNavigate(this.errorNavigate.bind(this)).connect();
55
50
  }
56
51
  }
52
+ /**
53
+ * The preNavigate hook surfaced as a cancelable CustomEvent.
54
+ * @param {RouteChange} - the current and proposed route information
55
+ */
57
56
  preNavigate(routeChange) {
58
57
  const event = this._createEvent("prenavigate", routeChange, true);
59
58
  this.dispatchEvent(event);
60
59
  return !event.defaultPrevented;
61
60
  }
61
+ /**
62
+ * The postNavigate hook surfaced as a CustomEvent.
63
+ * @param {RoutingResult} - the resulting navigation information
64
+ */
62
65
  postNavigate(routingResult) {
63
66
  this.dispatchEvent(this._createEvent("postnavigate", routingResult));
64
67
  const title = routingResult.routeDefinition.metadata && routingResult.routeDefinition.metadata.title;
@@ -89,15 +92,27 @@ var RouterContainer = class extends import_lwc.LightningElement {
89
92
  }, 500);
90
93
  }
91
94
  }
95
+ /**
96
+ * The errorNavigate hook surfaced as a CustomEvent.
97
+ * @param {MessageObject} - error, the error encountered while navigating (if applicable)
98
+ */
92
99
  errorNavigate(error) {
93
100
  this.dispatchEvent(this._createEvent("errornavigate", error));
94
101
  return true;
95
102
  }
103
+ /**
104
+ * The preNavigate hook surfaced as a cancelable CustomEvent.
105
+ * @param {object} - address: The address being navigated to
106
+ * @param {boolean} - shouldReplace
107
+ */
96
108
  handleNavigation(address, replace) {
97
- const event = this._createEvent("handlenavigation", {address, replace}, true);
109
+ const event = this._createEvent("handlenavigation", { address, replace }, true);
98
110
  this.dispatchEvent(event);
99
111
  return !event.defaultPrevented;
100
112
  }
113
+ /**
114
+ * Disconnect the router after DOM removal.
115
+ */
101
116
  disconnectedCallback() {
102
117
  if (this.routerApi) {
103
118
  this.routerApi.disconnect();
@@ -112,11 +127,3 @@ var RouterContainer = class extends import_lwc.LightningElement {
112
127
  });
113
128
  }
114
129
  };
115
- RouterContainer.renderMode = "light";
116
- __decorate([
117
- import_lwc.api
118
- ], RouterContainer.prototype, "router", 2);
119
- __decorate([
120
- import_lwc.api
121
- ], RouterContainer.prototype, "historyDisabled", 2);
122
- var routerContainer_default = RouterContainer;
@@ -1,56 +1,76 @@
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 __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
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 __exportStar = (target, module2, desc) => {
13
- if (module2 && typeof module2 === "object" || typeof module2 === "function") {
14
- for (let key of __getOwnPropNames(module2))
15
- if (!__hasOwnProp.call(target, key) && key !== "default")
16
- __defProp(target, key, {get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable});
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 target;
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/routerContainer/utils.ts
25
- __markAsModule(exports);
26
- __export(exports, {
20
+ var utils_exports = {};
21
+ __export(utils_exports, {
27
22
  createNavigationContext: () => createNavigationContext
28
23
  });
29
- var import_historyRouter = __toModule(require("lwr/historyRouter"));
30
- var import_routerErrors = __toModule(require("lwr/routerErrors"));
31
- var import_domRouter = __toModule(require("lwr/domRouter"));
24
+ module.exports = __toCommonJS(utils_exports);
25
+ var import_historyRouter = require("lwr/historyRouter");
26
+ var import_routerErrors = require("lwr/routerErrors");
27
+ var import_domRouter = require("lwr/domRouter");
32
28
  var hasRoot = false;
33
29
  function createNavigationContext(node, config = {}, portableRouter) {
34
30
  const newRouter = config.historyDisabled ? new import_domRouter.DomRouterImpl(config, portableRouter, node) : new import_historyRouter.HistoryRouter(config, portableRouter, node);
35
31
  const routerAPI = {
32
+ /**
33
+ * Surface the preNavigate hook register function.
34
+ *
35
+ * @param {function} listener - The preNavigate hook listener function
36
+ * @returns {object} - This bag of Router functions, for chaining
37
+ */
36
38
  addPreNavigate: (listener) => {
37
39
  newRouter.addPreNavigate(listener);
38
40
  return routerAPI;
39
41
  },
42
+ /**
43
+ * Surface the postNavigate hook register function.
44
+ *
45
+ * @param {function} listener - The postNavigate hook listener function
46
+ * @returns {object} - This bag of Router functions, for chaining
47
+ */
40
48
  addPostNavigate: (listener) => {
41
49
  newRouter.subscribe(listener);
42
50
  return routerAPI;
43
51
  },
52
+ /**
53
+ * Surface the errorNavigate hook register function.
54
+ *
55
+ * @param {function} listener - The errorNavigate hook listener function
56
+ * @returns {object} - This bag of Router functions, for chaining
57
+ */
44
58
  addErrorNavigate: (listener) => {
45
59
  newRouter.addErrorNavigate(listener);
46
60
  return routerAPI;
47
61
  },
62
+ /**
63
+ * Connect the root router if there isn't already one connected.
64
+ */
48
65
  connect: () => {
49
66
  newRouter.connect();
50
67
  (0, import_routerErrors.invariant)(!hasRoot || !!newRouter.parent, import_routerErrors.messages.MULTIPLE_ROOTS);
51
68
  hasRoot = hasRoot || !newRouter.parent;
52
69
  routerAPI.id = newRouter.contextId;
53
70
  },
71
+ /**
72
+ * Disconnect the router, and reset the root tracking variable.
73
+ */
54
74
  disconnect: () => {
55
75
  hasRoot = hasRoot && !!newRouter.parent;
56
76
  newRouter.disconnect();
@@ -1,18 +1,30 @@
1
1
  var __defProp = Object.defineProperty;
2
- var __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
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/routerErrors/routerErrors.ts
9
- __markAsModule(exports);
10
- __export(exports, {
20
+ var routerErrors_exports = {};
21
+ __export(routerErrors_exports, {
11
22
  generateMessage: () => generateMessage,
12
23
  generateMessageObject: () => generateMessageObject,
13
24
  invariant: () => invariant,
14
25
  messages: () => messages
15
26
  });
27
+ module.exports = __toCommonJS(routerErrors_exports);
16
28
  var ERROR_CODE_PREFIX = "LWR";
17
29
  var DiagnosticLevel = {
18
30
  Fatal: 0,