@lwrjs/router 0.10.0-alpha.1 → 0.10.0-alpha.10

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 (97) hide show
  1. package/build/bundle/prod/lwr/navigation/es/modules/lwr/currentView/currentView.d.ts +28 -0
  2. package/build/bundle/prod/lwr/navigation/navigation.js +1 -1
  3. package/build/bundle/prod/lwr/router/es/modules/lwr/currentView/currentView.d.ts +28 -0
  4. package/build/bundle/prod/lwr/router/router.js +1 -1
  5. package/build/bundle/prod/lwr/routerContainer/es/modules/lwr/currentView/currentView.d.ts +28 -0
  6. package/build/bundle/prod/lwr/routerContainer/routerContainer.js +1 -1
  7. package/build/cjs/modules/lwr/outlet/outlet.cjs +4 -1
  8. package/build/es/modules/lwr/contextProvider/contextProvider.js +30 -0
  9. package/build/es/modules/lwr/contextUtils/contextInfo.js +93 -0
  10. package/build/es/modules/lwr/contextUtils/contextUtils.js +77 -0
  11. package/build/es/modules/lwr/contextUtils/navigationApiStore.js +46 -0
  12. package/build/{modules → es/modules}/lwr/currentPageReference/currentPageReference.d.ts +1 -1
  13. package/build/es/modules/lwr/currentPageReference/currentPageReference.js +14 -0
  14. package/build/{modules → es/modules}/lwr/currentView/currentView.d.ts +2 -2
  15. package/build/es/modules/lwr/currentView/currentView.js +62 -0
  16. package/build/{modules → es/modules}/lwr/domRouter/domRouter.d.ts +2 -2
  17. package/build/es/modules/lwr/domRouter/domRouter.js +441 -0
  18. package/build/es/modules/lwr/domRouterUtils/domRouterUtils.js +3 -0
  19. package/build/es/modules/lwr/domRouterUtils/historyUtils.js +30 -0
  20. package/build/{modules → es/modules}/lwr/domRouterUtils/types.d.ts +1 -1
  21. package/build/es/modules/lwr/domRouterUtils/types.js +2 -0
  22. package/build/es/modules/lwr/domRouterUtils/uriUtils.js +69 -0
  23. package/build/es/modules/lwr/historyRouter/historyRouter.js +88 -0
  24. package/build/es/modules/lwr/navigation/navigation.js +20 -0
  25. package/build/es/modules/lwr/navigation/navigationApi.js +27 -0
  26. package/build/es/modules/lwr/navigation/navigationMixin.js +76 -0
  27. package/build/{modules → es/modules}/lwr/navigationContext/navigationContext.d.ts +2 -2
  28. package/build/es/modules/lwr/navigationContext/navigationContext.js +10 -0
  29. package/build/es/modules/lwr/navigationMixinHacks/navigationMixinHacks.d.ts +7 -0
  30. package/build/es/modules/lwr/navigationMixinHacks/navigationMixinHacks.js +5 -0
  31. package/build/es/modules/lwr/observable/observable.js +71 -0
  32. package/build/{modules → es/modules}/lwr/outlet/outlet.d.ts +1 -0
  33. package/build/es/modules/lwr/outlet/outlet.js +69 -0
  34. package/build/es/modules/lwr/router/router.js +201 -0
  35. package/build/es/modules/lwr/routerBridge/routerBridge.js +85 -0
  36. package/build/es/modules/lwr/routerContainer/routerContainer.js +116 -0
  37. package/build/es/modules/lwr/routerContainer/utils.js +83 -0
  38. package/build/es/modules/lwr/routerErrors/routerErrors.js +154 -0
  39. package/build/es/modules/lwr/routerUtils/domUtils.js +3 -0
  40. package/build/{modules → es/modules}/lwr/routerUtils/filterUtils.d.ts +1 -1
  41. package/build/es/modules/lwr/routerUtils/filterUtils.js +74 -0
  42. package/build/es/modules/lwr/routerUtils/parseUtils.js +182 -0
  43. package/build/{modules → es/modules}/lwr/routerUtils/pathToRegexp.d.ts +5 -5
  44. package/build/es/modules/lwr/routerUtils/pathToRegexp.js +415 -0
  45. package/build/es/modules/lwr/routerUtils/routeDefUtils.js +204 -0
  46. package/build/es/modules/lwr/routerUtils/routeUtils.js +239 -0
  47. package/build/es/modules/lwr/routerUtils/routerUtils.js +19 -0
  48. package/build/es/modules/lwr/routerUtils/typeUtils.js +112 -0
  49. package/build/{modules → es/modules}/lwr/routerUtils/types.d.ts +23 -23
  50. package/build/es/modules/lwr/routerUtils/types.js +2 -0
  51. package/build/es/modules/lwr/routerUtils/uriUtils.js +134 -0
  52. package/build/modules/lwr/contextUtils/contextUtils.js +5 -0
  53. package/build/modules/lwr/contextUtils/navigationApiStore.js +7 -0
  54. package/build/modules/lwr/domRouter/domRouter.js +6 -0
  55. package/build/modules/lwr/domRouterUtils/historyUtils.js +0 -1
  56. package/build/modules/lwr/outlet/outlet.css +1 -1
  57. package/build/modules/lwr/outlet/outlet.html +2 -2
  58. package/build/modules/lwr/outlet/outlet.js +3 -4
  59. package/build/modules/lwr/router/router.js +3 -0
  60. package/build/modules/lwr/routerContainer/utils.js +1 -3
  61. package/build/modules/lwr/routerUtils/pathToRegexp.js +17 -0
  62. package/build/modules/lwr/routerUtils/typeUtils.js +0 -1
  63. package/package.json +17 -9
  64. package/pageObjects/outlet.cjs +21 -4
  65. package/pageObjects/outlet.d.ts +10 -2
  66. package/pageObjects/outlet.js +22 -5
  67. package/build/modules/lwr/navigationMixinHacks/navigationMixinHacks.d.ts +0 -7
  68. /package/build/{modules → es/modules}/lwr/contextProvider/contextProvider.d.ts +0 -0
  69. /package/build/{modules → es/modules}/lwr/contextUtils/contextInfo.d.ts +0 -0
  70. /package/build/{modules → es/modules}/lwr/contextUtils/contextUtils.d.ts +0 -0
  71. /package/build/{modules → es/modules}/lwr/contextUtils/navigationApiStore.d.ts +0 -0
  72. /package/build/{modules → es/modules}/lwr/domRouterUtils/domRouterUtils.d.ts +0 -0
  73. /package/build/{modules → es/modules}/lwr/domRouterUtils/historyUtils.d.ts +0 -0
  74. /package/build/{modules → es/modules}/lwr/domRouterUtils/uriUtils.d.ts +0 -0
  75. /package/build/{modules → es/modules}/lwr/historyRouter/historyRouter.d.ts +0 -0
  76. /package/build/{modules → es/modules}/lwr/navigation/navigation.d.ts +0 -0
  77. /package/build/{modules → es/modules}/lwr/navigation/navigationApi.d.ts +0 -0
  78. /package/build/{modules → es/modules}/lwr/navigation/navigationMixin.d.ts +0 -0
  79. /package/build/{modules → es/modules}/lwr/observable/observable.d.ts +0 -0
  80. /package/build/{modules → es/modules}/lwr/router/router.d.ts +0 -0
  81. /package/build/{modules → es/modules}/lwr/routerBridge/routerBridge.d.ts +0 -0
  82. /package/build/{modules → es/modules}/lwr/routerContainer/routerContainer.d.ts +0 -0
  83. /package/build/{modules → es/modules}/lwr/routerContainer/utils.d.ts +0 -0
  84. /package/build/{modules → es/modules}/lwr/routerErrors/routerErrors.d.ts +0 -0
  85. /package/build/{modules → es/modules}/lwr/routerUtils/domUtils.d.ts +0 -0
  86. /package/build/{modules → es/modules}/lwr/routerUtils/parseUtils.d.ts +0 -0
  87. /package/build/{modules → es/modules}/lwr/routerUtils/routeDefUtils.d.ts +0 -0
  88. /package/build/{modules → es/modules}/lwr/routerUtils/routeUtils.d.ts +0 -0
  89. /package/build/{modules → es/modules}/lwr/routerUtils/routerUtils.d.ts +0 -0
  90. /package/build/{modules → es/modules}/lwr/routerUtils/typeUtils.d.ts +0 -0
  91. /package/build/{modules → es/modules}/lwr/routerUtils/uriUtils.d.ts +0 -0
  92. /package/build/{services → es/services}/index.d.ts +0 -0
  93. /package/build/{services → es/services}/index.js +0 -0
  94. /package/build/{services → es/services}/module-provider/index.d.ts +0 -0
  95. /package/build/{services → es/services}/module-provider/index.js +0 -0
  96. /package/build/{services → es/services}/module-provider/utils.d.ts +0 -0
  97. /package/build/{services → es/services}/module-provider/utils.js +0 -0
@@ -0,0 +1,85 @@
1
+ import { PARENT_EVENT } from 'lwr/domRouter';
2
+ // Bridge navigation events, without access to a <lwr-router-container> or NavigationContext
3
+ // Used to allow a bridge between a LWR Router and vanilla HTML/JS (eg: in LWR Everywhere)
4
+ class DomRouterBridge {
5
+ constructor(config = {}, target = window) {
6
+ // Routers send out the PARENT_EVENT to build a router hierarchy
7
+ // Listen for this event to find the topmost router located beneath the bridge in the DOM
8
+ // NOTE: because of the restrictions on "lwr/router" hierachy, this is only called 0 or 1 time(s)
9
+ // - only ONE root router is allowed in a document
10
+ // - sibling routers are NOT allowed
11
+ this.handleParentEvent = (event) => {
12
+ const parentEvent = event;
13
+ if (parentEvent && parentEvent.detail && typeof parentEvent.detail === 'function') {
14
+ // event.detail() will call this.addChild()
15
+ parentEvent.detail(this);
16
+ if (this.bridgedRouter) {
17
+ // Ensure the bridge does not become part of the router hierarchy
18
+ this.bridgedRouter.parent = undefined;
19
+ this.target.removeEventListener(PARENT_EVENT, this.handleParentEvent);
20
+ }
21
+ }
22
+ };
23
+ // Provide fallbacks for missing config values
24
+ this.config = {
25
+ historyDisabled: !!config.historyDisabled,
26
+ onReady: config.onReady ||
27
+ (() => {
28
+ /* noop */
29
+ }),
30
+ onPostNavigate: config.onPostNavigate ||
31
+ (() => {
32
+ /* noop */
33
+ }),
34
+ onError: config.onError ||
35
+ (() => {
36
+ return true;
37
+ }),
38
+ };
39
+ // Add a listener for the parent router event
40
+ this.target = target;
41
+ this.target.addEventListener(PARENT_EVENT, this.handleParentEvent);
42
+ }
43
+ // Save an observed router and subscribe to its navigation and error updates
44
+ async addChild(child) {
45
+ this.bridgedRouter = child;
46
+ this.bridgedRouter.subscribe(({ route: { pageReference } }) => {
47
+ this.config.onPostNavigate(pageReference); // ONLY return the page reference
48
+ });
49
+ this.bridgedRouter.addErrorNavigate(this.config.onError);
50
+ // Prevent the observed router from altering the browser URL or history
51
+ // This is good practice for routers embedded in an outside host document
52
+ if (this.config.historyDisabled) {
53
+ this.bridgedRouter.historyDisabled = true;
54
+ }
55
+ // The router PARENT_EVENT is sent before the NAV_EVENT is subscribed,
56
+ // so mark this bridge as ready in the next event loop.
57
+ // The events are both set up during router.connect(),
58
+ // so they'll be finished before the timeout triggers.
59
+ await new Promise((resolve) => {
60
+ /* eslint-disable-next-line */
61
+ setTimeout(() => {
62
+ this.config.onReady();
63
+ resolve();
64
+ }, 0);
65
+ });
66
+ }
67
+ // Use the observed router to navigate to the given page reference
68
+ // Return true if the router is connected and the navigation event was sent
69
+ // False is returned if there are no mounted routers to observe (yet)
70
+ navigate(pageRef) {
71
+ if (this.bridgedRouter && this.bridgedRouter.connected) {
72
+ this.bridgedRouter.navigate(pageRef);
73
+ return true;
74
+ }
75
+ return false;
76
+ }
77
+ }
78
+ // Return a subset of the bridge class instance, as an API
79
+ export function createBridge(config, target) {
80
+ const bridge = new DomRouterBridge(config, target);
81
+ return {
82
+ navigate: bridge.navigate.bind(bridge),
83
+ };
84
+ }
85
+ //# sourceMappingURL=routerBridge.js.map
@@ -0,0 +1,116 @@
1
+ /**
2
+ * Copyright (c) 2019, salesforce.com, inc.
3
+ * All rights reserved.
4
+ * SPDX-License-Identifier: MIT
5
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
6
+ */
7
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
8
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
9
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
10
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
11
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
12
+ };
13
+ import { LightningElement, api } from 'lwc';
14
+ import { createNavigationContext } from './utils';
15
+ import { hasDocument } from 'lwr/routerUtils';
16
+ /*
17
+ * Provides a LWC router component. These can be nested and all report to the root router.
18
+ */
19
+ export default class RouterContainer extends LightningElement {
20
+ constructor() {
21
+ super();
22
+ this.historyDisabled = false;
23
+ this.currentTitle = hasDocument ? document.title : '';
24
+ }
25
+ /**
26
+ * Create a router attached to this component.
27
+ */
28
+ connectedCallback() {
29
+ const config = {
30
+ historyDisabled: this.historyDisabled,
31
+ handleNavigation: this.handleNavigation.bind(this),
32
+ };
33
+ if (this.router) {
34
+ // Create the router.
35
+ this.routerApi = createNavigationContext(this, config, this.router);
36
+ // Convert hook APIs into DOM events.
37
+ // The events do not bubble and are not composed (they cannot exit this shadow DOM)
38
+ // They are meant to be exposed only to the owner (direct parent) of the router
39
+ this.routerApi
40
+ .addPreNavigate(this.preNavigate.bind(this))
41
+ .addPostNavigate(this.postNavigate.bind(this))
42
+ .addErrorNavigate(this.errorNavigate.bind(this))
43
+ // Connect the router.
44
+ .connect();
45
+ }
46
+ }
47
+ /**
48
+ * The preNavigate hook surfaced as a cancelable CustomEvent.
49
+ * @param {RouteChange} - the current and proposed route information
50
+ */
51
+ preNavigate(routeChange) {
52
+ const event = this._createEvent('prenavigate', routeChange, true);
53
+ this.dispatchEvent(event);
54
+ return !event.defaultPrevented;
55
+ }
56
+ /**
57
+ * The postNavigate hook surfaced as a CustomEvent.
58
+ * @param {RoutingResult} - the resulting navigation information
59
+ */
60
+ postNavigate(routingResult) {
61
+ this.dispatchEvent(this._createEvent('postnavigate', routingResult));
62
+ // If the current route definition metadata contains a title, set it as the document title
63
+ const title = routingResult.routeDefinition.metadata && routingResult.routeDefinition.metadata.title;
64
+ if (title) {
65
+ this.currentTitle = title;
66
+ document.title = title;
67
+ }
68
+ // Update the inner HTML of the aria-live region for screen readers
69
+ // This DOM node must be touched for every route change
70
+ const a11yTitle = this.querySelector('span.router-title');
71
+ if (a11yTitle)
72
+ a11yTitle.innerHTML = this.currentTitle;
73
+ }
74
+ /**
75
+ * The errorNavigate hook surfaced as a CustomEvent.
76
+ * @param {MessageObject} - error, the error encountered while navigating (if applicable)
77
+ */
78
+ errorNavigate(error) {
79
+ this.dispatchEvent(this._createEvent('errornavigate', error));
80
+ return true;
81
+ }
82
+ /**
83
+ * The preNavigate hook surfaced as a cancelable CustomEvent.
84
+ * @param {object} - address: The address being navigated to
85
+ * @param {boolean} - shouldReplace
86
+ */
87
+ handleNavigation(address, replace) {
88
+ const event = this._createEvent('handlenavigation', { address, replace }, true);
89
+ this.dispatchEvent(event);
90
+ return !event.defaultPrevented;
91
+ }
92
+ /**
93
+ * Disconnect the router after DOM removal.
94
+ */
95
+ disconnectedCallback() {
96
+ if (this.routerApi) {
97
+ this.routerApi.disconnect();
98
+ }
99
+ }
100
+ _createEvent(name, payload, cancelable) {
101
+ return new CustomEvent(name, {
102
+ detail: payload,
103
+ bubbles: false,
104
+ composed: false,
105
+ cancelable,
106
+ });
107
+ }
108
+ }
109
+ RouterContainer.renderMode = 'light';
110
+ __decorate([
111
+ api
112
+ ], RouterContainer.prototype, "router", void 0);
113
+ __decorate([
114
+ api
115
+ ], RouterContainer.prototype, "historyDisabled", void 0);
116
+ //# sourceMappingURL=routerContainer.js.map
@@ -0,0 +1,83 @@
1
+ /**
2
+ * Copyright (c) 2019, salesforce.com, inc.
3
+ * All rights reserved.
4
+ * SPDX-License-Identifier: MIT
5
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
6
+ */
7
+ import { HistoryRouter } from 'lwr/historyRouter';
8
+ import { invariant, messages } from 'lwr/routerErrors';
9
+ import { DomRouterImpl } from 'lwr/domRouter';
10
+ /*
11
+ * Provides programmatic routing capabilities.
12
+ */
13
+ // The application may create 1 root router at a time.
14
+ let hasRoot = false;
15
+ /**
16
+ * Create a new navigation context, attach to the given node.
17
+ * An application can only have ONE root router.
18
+ *
19
+ * @param {HTMLElement} - The DOM node where the navigation context should be established
20
+ * @param {object} config - The router config object, all properties are optional
21
+ *
22
+ * @returns {object} - { addPreNavigate, addPostNavigate, addErrorNavigate, connect, disconnect }
23
+ */
24
+ export function createNavigationContext(node, config = {}, portableRouter) {
25
+ // Create a DOM or History Router
26
+ const newRouter = config.historyDisabled
27
+ ? new DomRouterImpl(config, portableRouter, node)
28
+ : new HistoryRouter(config, portableRouter, node);
29
+ // Return a subset of the new router's capabilities.
30
+ const routerAPI = {
31
+ /**
32
+ * Surface the preNavigate hook register function.
33
+ *
34
+ * @param {function} listener - The preNavigate hook listener function
35
+ * @returns {object} - This bag of Router functions, for chaining
36
+ */
37
+ addPreNavigate: (listener) => {
38
+ newRouter.addPreNavigate(listener);
39
+ return routerAPI;
40
+ },
41
+ /**
42
+ * Surface the postNavigate hook register function.
43
+ *
44
+ * @param {function} listener - The postNavigate hook listener function
45
+ * @returns {object} - This bag of Router functions, for chaining
46
+ */
47
+ addPostNavigate: (listener) => {
48
+ newRouter.subscribe(listener);
49
+ return routerAPI;
50
+ },
51
+ /**
52
+ * Surface the errorNavigate hook register function.
53
+ *
54
+ * @param {function} listener - The errorNavigate hook listener function
55
+ * @returns {object} - This bag of Router functions, for chaining
56
+ */
57
+ addErrorNavigate: (listener) => {
58
+ newRouter.addErrorNavigate(listener);
59
+ return routerAPI;
60
+ },
61
+ /**
62
+ * Connect the root router if there isn't already one connected.
63
+ */
64
+ connect: () => {
65
+ // Connect and expose this router's navigation context.
66
+ newRouter.connect();
67
+ // If there is already a root router, the new router must be a child (have a parent).
68
+ invariant(!hasRoot || !!newRouter.parent, messages.MULTIPLE_ROOTS);
69
+ hasRoot = hasRoot || !newRouter.parent;
70
+ routerAPI.id = newRouter.contextId;
71
+ },
72
+ /**
73
+ * Disconnect the router, and reset the root tracking variable.
74
+ */
75
+ disconnect: () => {
76
+ hasRoot = hasRoot && !!newRouter.parent;
77
+ newRouter.disconnect();
78
+ },
79
+ };
80
+ // Return the public Router functions.
81
+ return routerAPI;
82
+ }
83
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1,154 @@
1
+ const ERROR_CODE_PREFIX = 'LWR';
2
+ const DiagnosticLevel = {
3
+ Fatal: 0,
4
+ Error: 1,
5
+ Warning: 2,
6
+ Log: 3,
7
+ };
8
+ function replaceArgs(message, args) {
9
+ return Array.isArray(args)
10
+ ? message.replace(/\{([0-9]+)\}/g, (_, index) => {
11
+ return args[index];
12
+ })
13
+ : message;
14
+ }
15
+ export function generateMessage(info, args) {
16
+ return `${info.code}: ${replaceArgs(info.message, args)}`;
17
+ }
18
+ export function generateMessageObject(info, args) {
19
+ const messageObject = {
20
+ ...info,
21
+ message: replaceArgs(info.message, args),
22
+ };
23
+ if (info.address) {
24
+ messageObject.address = replaceArgs(info.address, args);
25
+ }
26
+ if (info.stack) {
27
+ messageObject.stack = replaceArgs(info.stack, args);
28
+ }
29
+ return messageObject;
30
+ }
31
+ export function invariant(condition, errorInfo, args) {
32
+ if (!condition) {
33
+ throw new Error(generateMessage(errorInfo, args));
34
+ }
35
+ }
36
+ export const messages = {
37
+ INVALID_MIXIN_CMP: {
38
+ code: `${ERROR_CODE_PREFIX}4001`,
39
+ message: '{0} must be an Element type',
40
+ level: DiagnosticLevel.Error,
41
+ },
42
+ MISSING_CONTEXT: {
43
+ code: `${ERROR_CODE_PREFIX}4002`,
44
+ message: 'Could not find context to perform navigation action.',
45
+ level: DiagnosticLevel.Error,
46
+ },
47
+ INVALID_CONTEXT: {
48
+ code: `${ERROR_CODE_PREFIX}4003`,
49
+ message: 'Cannot register navigation context; it must have this shape: { navigate, generateUrl, subscribe }',
50
+ level: DiagnosticLevel.Error,
51
+ },
52
+ MULTIPLE_ROOTS: {
53
+ code: `${ERROR_CODE_PREFIX}4004`,
54
+ message: 'Router connection failed. There can only be one root router.',
55
+ level: DiagnosticLevel.Error,
56
+ },
57
+ MULTIPLE_CHILDREN: {
58
+ code: `${ERROR_CODE_PREFIX}4005`,
59
+ message: 'Could not add to the navigation hierarchy. There can only be one child per navigation node.',
60
+ level: DiagnosticLevel.Error,
61
+ },
62
+ MISSING_ROUTE: {
63
+ code: `${ERROR_CODE_PREFIX}4006`,
64
+ message: 'A route cannot be created to navigate to URL "{0}"',
65
+ level: DiagnosticLevel.Error,
66
+ address: '{0}',
67
+ },
68
+ MISSING_URL: {
69
+ code: `${ERROR_CODE_PREFIX}4007`,
70
+ message: 'A URL cannot be created to navigate to route "{0}"',
71
+ level: DiagnosticLevel.Error,
72
+ address: '{0}',
73
+ },
74
+ PRENAV_FAILED: {
75
+ code: `${ERROR_CODE_PREFIX}4008`,
76
+ message: 'A preNavigate hook listener blocked routing to "{0}"',
77
+ level: DiagnosticLevel.Warning,
78
+ address: '{0}',
79
+ },
80
+ MISSING_ROUTE_TEMPLATE: {
81
+ code: `${ERROR_CODE_PREFIX}4009`,
82
+ message: 'A route definition must contain a "uri" property.',
83
+ level: DiagnosticLevel.Error,
84
+ },
85
+ MISSING_ROUTE_CMP: {
86
+ code: `${ERROR_CODE_PREFIX}4016`,
87
+ message: 'Expected a route view component with a default export.',
88
+ level: DiagnosticLevel.Error,
89
+ },
90
+ MISSING_DATA_CONTEXT: {
91
+ code: `${ERROR_CODE_PREFIX}4018`,
92
+ message: 'Could not find context to retrieve navigation data.',
93
+ level: DiagnosticLevel.Error,
94
+ },
95
+ INVALID_ROUTE_QUERY: {
96
+ code: `${ERROR_CODE_PREFIX}4019`,
97
+ message: 'Invalid query param in route definition.',
98
+ level: DiagnosticLevel.Error,
99
+ },
100
+ MISSING_PAGE_BINDING: {
101
+ code: `${ERROR_CODE_PREFIX}4020`,
102
+ message: 'Route definition must provide page binding',
103
+ level: DiagnosticLevel.Error,
104
+ },
105
+ INVALID_PAGE_BINDING: {
106
+ code: `${ERROR_CODE_PREFIX}4021`,
107
+ message: 'Invalid page binding in route definition',
108
+ level: DiagnosticLevel.Error,
109
+ },
110
+ INVALID_URI_SYNTAX: {
111
+ code: `${ERROR_CODE_PREFIX}4022`,
112
+ message: 'Invalid uri syntax. URI cannot contain *, +, (, ), ',
113
+ level: DiagnosticLevel.Error,
114
+ },
115
+ VIEW_IMPORT_FAILED: {
116
+ code: `${ERROR_CODE_PREFIX}4023`,
117
+ message: 'Error importing view with name "{0}", failure was: {1}',
118
+ level: DiagnosticLevel.Error,
119
+ stack: '{2}',
120
+ },
121
+ VIEW_MISSING: {
122
+ code: `${ERROR_CODE_PREFIX}4024`,
123
+ message: 'Expected a view with name "{0}" in the viewset',
124
+ level: DiagnosticLevel.Error,
125
+ },
126
+ VIEW_IMPORT_FAILED_WITH_SPECIFIER: {
127
+ code: `${ERROR_CODE_PREFIX}4025`,
128
+ message: 'Error importing module "{0}" from view with name "{1}", failure was: {2}',
129
+ level: DiagnosticLevel.Error,
130
+ stack: '{3}',
131
+ },
132
+ NO_ROUTE_MATCH: {
133
+ code: `${ERROR_CODE_PREFIX}4026`,
134
+ message: 'A routing match cannot be found for: {0}',
135
+ level: DiagnosticLevel.Error,
136
+ },
137
+ INVALID_ROUTE_HANDLER: {
138
+ code: `${ERROR_CODE_PREFIX}4027`,
139
+ message: 'Route definition "{0}" does not have a valid route handler module',
140
+ level: DiagnosticLevel.Error,
141
+ },
142
+ DESTINATION_NOT_FOUND: {
143
+ code: `${ERROR_CODE_PREFIX}4028`,
144
+ message: 'Route handler returned 404: Not Found',
145
+ level: DiagnosticLevel.Error,
146
+ },
147
+ DESTINATION_ERROR: {
148
+ code: `${ERROR_CODE_PREFIX}4029`,
149
+ message: 'Route handler returned error status {0}: {1}',
150
+ level: DiagnosticLevel.Error,
151
+ stack: '{2}',
152
+ },
153
+ };
154
+ //# sourceMappingURL=routerErrors.js.map
@@ -0,0 +1,3 @@
1
+ /* eslint-disable lwr/no-unguarded-apis */
2
+ export const hasDocument = typeof document !== 'undefined';
3
+ //# sourceMappingURL=domUtils.js.map
@@ -4,7 +4,7 @@
4
4
  * SPDX-License-Identifier: MIT
5
5
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
6
6
  */
7
- export declare type Filter<V> = (v: V) => Promise<boolean> | boolean;
7
+ export type Filter<V> = (v: V) => Promise<boolean> | boolean;
8
8
  export interface FilterChain<V> {
9
9
  add: (f: Filter<V>[] | Filter<V>) => void;
10
10
  compile: (arg: V) => Promise<boolean>;
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Copyright (c) 2019, salesforce.com, inc.
3
+ * All rights reserved.
4
+ * SPDX-License-Identifier: MIT
5
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
6
+ */
7
+ /**
8
+ * Creates a filter chain as an array. Filters can return true, false or a Promise resulting in true or false.
9
+ *
10
+ * @returns {object}
11
+ */
12
+ export function createFilterChain() {
13
+ // The filter array.
14
+ const filters = [];
15
+ // Return true if this chain contains no filters.
16
+ const empty = () => {
17
+ return filters.length === 0;
18
+ };
19
+ const addSingle = (filter) => {
20
+ if (typeof filter === 'function') {
21
+ filters.push(filter);
22
+ }
23
+ };
24
+ // Add a filter or array of filters to the chain.
25
+ const add = (f = []) => {
26
+ if (Array.isArray(f)) {
27
+ f.forEach((l) => addSingle(l));
28
+ }
29
+ else {
30
+ addSingle(f);
31
+ }
32
+ };
33
+ // Get the Promised results for all filters.
34
+ const compile = (arg) => {
35
+ // Call all the functions with the given arguments.
36
+ // Return Promise<true> if there are no filters.
37
+ return filters.length === 0
38
+ ? Promise.resolve(true)
39
+ : // Reduce the listener array down to a single value:
40
+ // a false -> false
41
+ // all truthy -> true
42
+ // Previous is a Promise and current is a function.
43
+ filters
44
+ .reduce((previous, current) => {
45
+ // Chain the current to the previous listener function; reject false values.
46
+ // Remember that previous is a Promise and current is a functions.
47
+ return previous.then((val) => {
48
+ return val === false ? Promise.reject() : Promise.resolve(current(arg));
49
+ });
50
+ // Start optimistically with TRUE.
51
+ }, Promise.resolve(true))
52
+ // Handle trailing false values
53
+ // This happens when the last listener returns a Promise that resolves to false
54
+ .then((val) => {
55
+ return val === false ? false : true;
56
+ })
57
+ // If caught promise rejection contains an Error, throw instead of resolving to false
58
+ .catch((error) => {
59
+ if (error instanceof Error) {
60
+ throw error;
61
+ }
62
+ else {
63
+ return false;
64
+ }
65
+ });
66
+ };
67
+ // Return the API methods.
68
+ return {
69
+ add,
70
+ compile,
71
+ empty,
72
+ };
73
+ }
74
+ //# sourceMappingURL=filterUtils.js.map