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