@lwrjs/router 0.24.1 → 0.24.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,68 +1,90 @@
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/domRouter/domRouter.ts
25
- __markAsModule(exports);
26
- __export(exports, {
21
+ var domRouter_exports = {};
22
+ __export(domRouter_exports, {
27
23
  DomRouterImpl: () => DomRouterImpl,
28
24
  NAV_EVENT: () => NAV_EVENT,
29
25
  PARENT_EVENT: () => PARENT_EVENT,
30
26
  createDomRouter: () => createDomRouter
31
27
  });
32
- var import_navigation = __toModule(require("lwr/navigation"));
33
- var import_contextProvider = __toModule(require("lwr/contextProvider"));
34
- var import_routerErrors = __toModule(require("lwr/routerErrors"));
35
- var import_routerUtils = __toModule(require("lwr/routerUtils"));
36
- var import_observable = __toModule(require("lwr/observable"));
37
- var import_metrics = __toModule(require("lwr/metrics"));
38
- var import_profiler = __toModule(require("lwr/profiler"));
39
- var import_navigationMixinHacks = __toModule(require("lwr/navigationMixinHacks"));
28
+ module.exports = __toCommonJS(domRouter_exports);
29
+ var import_navigation = require("lwr/navigation");
30
+ var import_contextProvider = require("lwr/contextProvider");
31
+ var import_routerErrors = require("lwr/routerErrors");
32
+ var import_routerUtils = require("lwr/routerUtils");
33
+ var import_observable = require("lwr/observable");
34
+ var import_metrics = require("lwr/metrics");
35
+ var import_profiler = require("lwr/profiler");
36
+ var import_navigationMixinHacks = require("lwr/navigationMixinHacks");
40
37
  var NAV_EVENT = `universalcontainernavigationevent${(0, import_routerUtils.guid)()}`;
41
38
  var PARENT_EVENT = `universalcontainerparentevent${(0, import_routerUtils.guid)()}`;
42
39
  var DomRouterImpl = class {
40
+ /**
41
+ * Create and configure the Router.
42
+ *
43
+ * @param {object} config - The domRouter config object, all properties are optional
44
+ * @param {object} router - an optional Router
45
+ * @param {HTMLElement} target - DOM node to attach to
46
+ */
43
47
  constructor(config, router, target) {
44
48
  this.pendingRoute = null;
45
49
  this.committedRoute = null;
50
+ // used for instrumentation
46
51
  this.contextId = Object.freeze(() => void 0);
47
52
  this.connected = false;
48
53
  this.preNavFilters = (0, import_routerUtils.createFilterChain)();
49
54
  this.errorNavFilters = (0, import_routerUtils.createFilterChain)();
55
+ /**
56
+ * Inspect a navigation event bubbling up from a descendent component.
57
+ * This node can choose to stop the event by returning false.
58
+ * If propagation is not stopped, and this node is the root (no parent),
59
+ * then begin the root -> leaf processing of this new route.
60
+ * This will update the navigation event subscribers in each DomRouter, top down.
61
+ *
62
+ * @param {Event} event - With detail: { url, options }
63
+ */
50
64
  this._handleNavigationEvent = (event) => {
51
65
  const navigationEvent = event;
52
66
  if (navigationEvent.detail && typeof navigationEvent.detail === "object") {
53
- const {url, replace, address} = navigationEvent.detail;
67
+ const { url, replace, address } = navigationEvent.detail;
54
68
  const continueNavigation = this.config.handleNavigation(address, replace);
55
69
  if (!continueNavigation) {
56
70
  navigationEvent.stopPropagation();
57
71
  } else {
58
72
  if (this.root && !url) {
59
- this.root.processError((0, import_routerErrors.generateMessageObject)(import_routerErrors.messages.MISSING_URL, [JSON.stringify(address)]));
73
+ this.root.processError(
74
+ (0, import_routerErrors.generateMessageObject)(import_routerErrors.messages.MISSING_URL, [JSON.stringify(address)])
75
+ );
60
76
  } else if (!this.parent) {
61
77
  this.process(url, replace);
62
78
  }
63
79
  }
64
80
  }
65
81
  };
82
+ /**
83
+ * Be discovered as a parent for descendent components.
84
+ * Stop immediate propagation because we only want 1 parent to be found.
85
+ *
86
+ * @param {Event} event - With detail: callback
87
+ */
66
88
  this._handleParentEvent = (event) => {
67
89
  event.stopImmediatePropagation();
68
90
  const parentRouterEvent = event;
@@ -78,6 +100,9 @@ var DomRouterImpl = class {
78
100
  this.router.contextId = this.contextId;
79
101
  this.routeObservable = (0, import_observable.createObservable)();
80
102
  }
103
+ /**
104
+ * Search up the node chain until the root node is hit
105
+ */
81
106
  get root() {
82
107
  if (!this.parent) {
83
108
  return this;
@@ -91,6 +116,13 @@ var DomRouterImpl = class {
91
116
  }
92
117
  throw new Error("No root router could be found");
93
118
  }
119
+ /**
120
+ * Informs an wire listeners of routing changes/errors
121
+ *
122
+ * @param {RoutingResult} result - result object from navigation event
123
+ * @param {string} url - url from the page reference that triggered the navigation event
124
+ * @param {MessageObject} error - if an error occurred during the navigation
125
+ */
94
126
  updateWires(result, url, error) {
95
127
  if (error) {
96
128
  this.processError(error);
@@ -98,17 +130,20 @@ var DomRouterImpl = class {
98
130
  if (this.committedRoute && result.route === this.committedRoute.route) {
99
131
  return;
100
132
  }
101
- (0, import_profiler.logOperationEnd)({id: import_metrics.ROUTER_VIEW, specifier: this.eventId});
102
- this.pendingRoute = this.pendingRoute || {...result, url};
103
- this.committedRoute = {...this.pendingRoute, ...result};
133
+ (0, import_profiler.logOperationEnd)({ id: import_metrics.ROUTER_VIEW, specifier: this.eventId });
134
+ this.pendingRoute = this.pendingRoute || { ...result, url };
135
+ this.committedRoute = { ...this.pendingRoute, ...result };
104
136
  import_navigation.CurrentPageReference.setContext(this.target, result.route.pageReference);
105
- this.routeObservable.next({...this.committedRoute, viewset: result.viewset});
106
- (0, import_profiler.logOperationEnd)({id: import_metrics.ROUTER_NAV, specifier: this.eventId});
137
+ this.routeObservable.next({ ...this.committedRoute, viewset: result.viewset });
138
+ (0, import_profiler.logOperationEnd)({ id: import_metrics.ROUTER_NAV, specifier: this.eventId });
107
139
  if (this.child) {
108
140
  this.child.process(this._stripUrlForChild(this.committedRoute.url));
109
141
  }
110
142
  }
111
143
  }
144
+ /**
145
+ * Override to provide this router as a navigation context
146
+ */
112
147
  connect() {
113
148
  this._sendEvent(PARENT_EVENT, (router) => {
114
149
  this.parent = router;
@@ -131,16 +166,18 @@ var DomRouterImpl = class {
131
166
  }
132
167
  if (result.status && result.status >= 400) {
133
168
  const error = result.error || new Error();
134
- this.processError((0, import_routerErrors.generateMessageObject)(import_routerErrors.messages.DESTINATION_ERROR, [
135
- result.status.toString(),
136
- error.message,
137
- error.stack || ""
138
- ]));
169
+ this.processError(
170
+ (0, import_routerErrors.generateMessageObject)(import_routerErrors.messages.DESTINATION_ERROR, [
171
+ result.status.toString(),
172
+ error.message,
173
+ error.stack || ""
174
+ ])
175
+ );
139
176
  return;
140
177
  }
141
178
  const pageReference = result.route.pageReference || {};
142
179
  const url = this.router.generateUrl(pageReference) || "";
143
- (0, import_profiler.logOperationStart)({id: import_metrics.ROUTER_VIEW, specifier: this.eventId});
180
+ (0, import_profiler.logOperationStart)({ id: import_metrics.ROUTER_VIEW, specifier: this.eventId });
144
181
  if (result.viewset) {
145
182
  const currentViewContext = {
146
183
  viewset: result.viewset,
@@ -176,12 +213,28 @@ var DomRouterImpl = class {
176
213
  this.child = void 0;
177
214
  this.connected = false;
178
215
  }
216
+ /**
217
+ * Add listeners to this router hook which run BEFORE a new URL is processed (root -> leaf).
218
+ *
219
+ * @param {object | object[]} filters
220
+ */
179
221
  addPreNavigate(filters) {
180
222
  this.preNavFilters.add(filters);
181
223
  }
224
+ /**
225
+ * Add listeners to this router hook which run when there is an error navigating.
226
+ *
227
+ * @param {object | object[]} filters
228
+ */
182
229
  addErrorNavigate(filters) {
183
230
  this.errorNavFilters.add(filters);
184
231
  }
232
+ /**
233
+ * Override parent implementation.
234
+ * Pass the current state down to a new child.
235
+ *
236
+ * @param {child} child - Child router
237
+ */
185
238
  async addChild(child) {
186
239
  await new Promise((resolve) => {
187
240
  setTimeout(() => {
@@ -198,9 +251,23 @@ var DomRouterImpl = class {
198
251
  }
199
252
  }
200
253
  }
254
+ /**
255
+ * Process the current URL passed down by the parent router.
256
+ * Stop propagation of the navigation event if a preNavigate filter returns false.
257
+ *
258
+ * Update the current path and route matches.
259
+ * Update the observable to hold the new route.
260
+ *
261
+ * After processing, delegate to a child router, if it exists.
262
+ *
263
+ * @param {string} url - Relative URL string to process
264
+ * @param {NavigateOptions} options - Additional navigation options (i.e. switch root locale)
265
+ * @returns {boolean} - True if the processing was NOT blocked by a preNavigate listener
266
+ */
267
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
201
268
  async process(url, _shouldReplace, options, _updateHistory) {
202
- this.eventId = new Date().getTime().toString();
203
- (0, import_profiler.logOperationStart)({id: import_metrics.ROUTER_NAV, specifier: this.eventId});
269
+ this.eventId = (/* @__PURE__ */ new Date()).getTime().toString();
270
+ (0, import_profiler.logOperationStart)({ id: import_metrics.ROUTER_NAV, specifier: this.eventId });
204
271
  try {
205
272
  if (!this.parent) {
206
273
  await this.preProcess(url, options);
@@ -218,13 +285,22 @@ var DomRouterImpl = class {
218
285
  }
219
286
  return true;
220
287
  }
288
+ /**
289
+ * Run the preNavigate filters for this router.
290
+ * After processing, delegate to a child router, if it exists.
291
+ *
292
+ * @param {string} url - Relative URL string to process,
293
+ * cannot use a route since the processing is done in context
294
+ *
295
+ * @returns {Promise<boolean>} - Resolves to true if successful
296
+ */
221
297
  preProcess(url, options) {
222
298
  const address = this.router.parseUrl(url);
223
299
  const routingMatch = address && this.router.matchRoute(address, options);
224
300
  if (!routingMatch) {
225
301
  return Promise.reject((0, import_routerErrors.generateMessageObject)(import_routerErrors.messages.MISSING_ROUTE, [url]));
226
302
  }
227
- this.pendingRoute = {url, ...routingMatch};
303
+ this.pendingRoute = { url, ...routingMatch };
228
304
  const canGo = this.preNavFilters.empty() ? Promise.resolve(true) : this.preNavFilters.compile({
229
305
  current: this.committedRoute || void 0,
230
306
  next: this.pendingRoute
@@ -235,13 +311,28 @@ var DomRouterImpl = class {
235
311
  return canContinue || Promise.reject((0, import_routerErrors.generateMessageObject)(import_routerErrors.messages.PRENAV_FAILED, [url]));
236
312
  });
237
313
  }
314
+ /**
315
+ * Run the errorNavigate filters for this router.
316
+ * After processing, delegate to a child router, if it exists.
317
+ *
318
+ * @param {object} e - An error object to pass into the error hook listeners.
319
+ */
238
320
  processError(messageObject) {
239
- (0, import_profiler.logOperationStart)({id: import_metrics.ROUTER_ERROR});
321
+ (0, import_profiler.logOperationStart)({ id: import_metrics.ROUTER_ERROR });
240
322
  this.errorNavFilters.compile(messageObject);
241
323
  if (this.child) {
242
324
  this.child.processError(messageObject);
243
325
  }
244
326
  }
327
+ /**
328
+ * lightning/navigation
329
+ * Fire an event to send the navigation event up the DOM.
330
+ * The root router will be the last to catch the event if it is not stopped.
331
+ *
332
+ * @param {object} address - Address to navigate to
333
+ * @param {*} options - Usually a boolean; when true the previous browser history
334
+ * entry should be replaced by this one
335
+ */
245
336
  navigate(address, replace, options) {
246
337
  const routerOptions = this.filterNavigateOptions(options);
247
338
  let url = this.router.generateUrl(address, routerOptions);
@@ -249,8 +340,17 @@ var DomRouterImpl = class {
249
340
  const parentPath = this.parent && this.parent.committedRoute && this.parent.committedRoute.pathMatch || "";
250
341
  url = parentPath.concat(url);
251
342
  }
252
- this._sendEvent(NAV_EVENT, {url, replace, address});
343
+ this._sendEvent(NAV_EVENT, { url, replace, address });
253
344
  }
345
+ /**
346
+ * lightning/navigation
347
+ * Generate a URL based on the given route.
348
+ * Return the URL string.
349
+ *
350
+ * @param {object} route - Route to generate a url for
351
+ *
352
+ * @returns {string}
353
+ */
254
354
  generateUrl(address, options) {
255
355
  const routerOptions = this.filterNavigateOptions(options);
256
356
  const url = this.router.generateUrl(address, routerOptions);
@@ -260,6 +360,10 @@ var DomRouterImpl = class {
260
360
  const parentPath = this.parent && this.parent.committedRoute && this.parent.committedRoute.pathMatch || "";
261
361
  return `${parentPath}${url}`;
262
362
  }
363
+ /**
364
+ * Async version of generateUrl, used by the NavigationMixin and goes through the generateUrlFilter.
365
+ * @returns {Promise<string>}
366
+ */
263
367
  async generateUrlAsync(address, options) {
264
368
  const routerOptions = this.filterNavigateOptions(options);
265
369
  const url = await this.router.generateUrlAsync(address, routerOptions);
@@ -269,21 +373,34 @@ var DomRouterImpl = class {
269
373
  const parentPath = this.parent && this.parent.committedRoute && this.parent.committedRoute.pathMatch || "";
270
374
  return `${parentPath}${url}`;
271
375
  }
376
+ /**
377
+ * lightning/navigation
378
+ * Subscribe a callback to the Observable on the current route of this router.
379
+ *
380
+ * @param {function} callback - A callback function invoked when the navigation state changes
381
+ * callback(route, routeDef)
382
+ * @param {boolean} replay - Flag to determine if callback should be called with current route and data immediately
383
+ */
272
384
  subscribe(callback, replay) {
273
- return this.routeObservable.subscribe({
274
- next: callback,
275
- error: () => {
385
+ return this.routeObservable.subscribe(
386
+ {
387
+ next: callback,
388
+ error: () => {
389
+ },
390
+ complete: () => {
391
+ }
276
392
  },
277
- complete: () => {
278
- }
279
- }, Boolean(replay));
393
+ Boolean(replay)
394
+ );
280
395
  }
281
396
  _sendEvent(name, payload) {
282
- import_routerUtils.hasDocument && this.target.dispatchEvent(new CustomEvent(name, {
283
- bubbles: true,
284
- composed: true,
285
- detail: payload
286
- }));
397
+ import_routerUtils.hasDocument && this.target.dispatchEvent(
398
+ new CustomEvent(name, {
399
+ bubbles: true,
400
+ composed: true,
401
+ detail: payload
402
+ })
403
+ );
287
404
  }
288
405
  _stripUrlForChild(url) {
289
406
  if (this.pendingRoute && url.indexOf(this.pendingRoute.pathMatch) === 0) {
@@ -291,10 +408,14 @@ var DomRouterImpl = class {
291
408
  }
292
409
  return url;
293
410
  }
411
+ /**
412
+ * Filter the navigate options based on if this is a root router or not.
413
+ */
294
414
  filterNavigateOptions(options) {
295
415
  const isRoot = !this.parent;
296
416
  const routerOptions = {
297
417
  ...options,
418
+ // Only allow switch locales if this is a root router
298
419
  locale: isRoot ? options?.locale : void 0
299
420
  };
300
421
  return routerOptions;
@@ -1,33 +1,30 @@
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/domRouterUtils/domRouterUtils.ts
25
- __markAsModule(exports);
26
- __export(exports, {
21
+ var domRouterUtils_exports = {};
22
+ __export(domRouterUtils_exports, {
27
23
  getRelativeUrl: () => import_uriUtils.getRelativeUrl,
28
24
  removeFragment: () => import_uriUtils.removeFragment,
29
25
  replace: () => import_historyUtils.replace,
30
26
  set: () => import_historyUtils.set
31
27
  });
32
- var import_uriUtils = __toModule(require("./uriUtils.cjs"));
33
- var import_historyUtils = __toModule(require("./historyUtils.cjs"));
28
+ module.exports = __toCommonJS(domRouterUtils_exports);
29
+ var import_uriUtils = require("./uriUtils.cjs");
30
+ var import_historyUtils = require("./historyUtils.cjs");
@@ -1,16 +1,29 @@
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/domRouterUtils/historyUtils.ts
9
- __markAsModule(exports);
10
- __export(exports, {
21
+ var historyUtils_exports = {};
22
+ __export(historyUtils_exports, {
11
23
  replace: () => replace,
12
24
  set: () => set
13
25
  });
26
+ module.exports = __toCommonJS(historyUtils_exports);
14
27
  function set(path, route) {
15
28
  const data = route || {};
16
29
  window.history.pushState(data, "", path);
@@ -1,5 +1,18 @@
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;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
3
15
 
4
16
  // packages/@lwrjs/router/src/modules/lwr/domRouterUtils/types.ts
5
- __markAsModule(exports);
17
+ var types_exports = {};
18
+ module.exports = __toCommonJS(types_exports);
@@ -1,34 +1,31 @@
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/domRouterUtils/uriUtils.ts
25
- __markAsModule(exports);
26
- __export(exports, {
21
+ var uriUtils_exports = {};
22
+ __export(uriUtils_exports, {
27
23
  getRelativeUrl: () => getRelativeUrl,
28
24
  getUrlObject: () => getUrlObject,
29
25
  removeFragment: () => removeFragment
30
26
  });
31
- var import_routerUtils = __toModule(require("lwr/routerUtils"));
27
+ module.exports = __toCommonJS(uriUtils_exports);
28
+ var import_routerUtils = require("lwr/routerUtils");
32
29
  function getUrlObject(url = "") {
33
30
  url = url || "";
34
31
  if (url.indexOf("://") < 0) {
@@ -51,6 +48,7 @@ function getUrlObject(url = "") {
51
48
  href: link.href,
52
49
  origin: `${link.protocol}//${link.hostname}${link.port ? `:${link.port}` : ""}`,
53
50
  pathname: link.pathname.replace(/(\/)?/, "/"),
51
+ // ensure there is a leading slash (IE11)
54
52
  searchParams
55
53
  };
56
54
  }
@@ -1,41 +1,42 @@
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/historyRouter/historyRouter.ts
25
- __markAsModule(exports);
26
- __export(exports, {
21
+ var historyRouter_exports = {};
22
+ __export(historyRouter_exports, {
27
23
  HistoryRouter: () => HistoryRouter,
28
24
  createHistoryRouter: () => createHistoryRouter
29
25
  });
30
- var import_domRouter = __toModule(require("lwr/domRouter"));
31
- var import_domRouterUtils = __toModule(require("lwr/domRouterUtils"));
32
- var import_routerUtils = __toModule(require("lwr/routerUtils"));
26
+ module.exports = __toCommonJS(historyRouter_exports);
27
+ var import_domRouter = require("lwr/domRouter");
28
+ var import_domRouterUtils = require("lwr/domRouterUtils");
29
+ var import_routerUtils = require("lwr/routerUtils");
33
30
  var HistoryRouter = class extends import_domRouter.DomRouterImpl {
34
31
  constructor() {
35
32
  super(...arguments);
36
33
  this.historyDisabled = false;
37
34
  this.currentUrl = "";
38
35
  }
36
+ /**
37
+ * Override.
38
+ * Initialize with the current route and listen to the popstate event for future changes.
39
+ */
39
40
  connect() {
40
41
  super.connect();
41
42
  if (!this.historyDisabled) {
@@ -56,6 +57,16 @@ var HistoryRouter = class extends import_domRouter.DomRouterImpl {
56
57
  super.disconnect();
57
58
  import_routerUtils.hasDocument && window.removeEventListener("popstate", this.onpopstate);
58
59
  }
60
+ /**
61
+ * Override.
62
+ * Update the browser history if the preNavigate hooks.
63
+ *
64
+ * @param {string} url - The URL to go to
65
+ * @param {boolean} shouldReplace - True if the current history state should be replaced
66
+ * @param {boolean} updateHistory - True if the browser history should be updated with the new URL
67
+ *
68
+ * @returns {boolean} - True if the processing was NOT blocked by a preNavigate listener
69
+ */
59
70
  async process(url, shouldReplace, options, updateHistory = true) {
60
71
  const canContinue = await super.process(url, shouldReplace, options, updateHistory);
61
72
  if (canContinue && this.connected && !this.parent) {
@@ -70,6 +81,12 @@ var HistoryRouter = class extends import_domRouter.DomRouterImpl {
70
81
  }
71
82
  return canContinue;
72
83
  }
84
+ /**
85
+ * Update the root route, and trickle down the router tree.
86
+ * Redirect to use the base path, if it is missing.
87
+ *
88
+ * @param {string} url - The URL to go to
89
+ */
73
90
  catchBrowserUpdate(url) {
74
91
  this.process(url, false, {}, false);
75
92
  }