@lwrjs/everywhere 0.8.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.
@@ -0,0 +1,127 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ import { LightningElement, api } from 'lwc';
3
+ // Host component constants
4
+ const SPECIFIER_REGEX = /^@?[\w-]+(\/[\w-]+)*$/; // Navigation events
5
+
6
+ const NAV_EVENT = 'navigate'; // FIRED after a navigation event has been completed
7
+
8
+ const NAV_ERROR_EVENT = 'navigationerror'; // FIRED when a navigation event has failed
9
+
10
+ export default class LwrHost extends LightningElement {
11
+ // The component specifier of the Salesforce UI content to embed
12
+ @api
13
+ componentId = undefined; // Getter and setter for the public (@api) properties on the embedded component
14
+
15
+ _props = {};
16
+
17
+ @api
18
+ get properties() {
19
+ return this._props;
20
+ }
21
+
22
+ set properties(value) {
23
+ this._props = value;
24
+ this.setProperties(value);
25
+ } // Import and embed the Salesforce UI content
26
+
27
+
28
+ ctor = undefined;
29
+
30
+ async connectedCallback() {
31
+ // Setup navigation hooks before the embedded component is mounted
32
+ await this.setUpNavBridge();
33
+
34
+ if (this.componentId) {
35
+ if (typeof this.componentId !== 'string' || !SPECIFIER_REGEX.test(this.componentId)) {
36
+ // Validate component specifier format
37
+ console.error('LWR Everywhere - Salesforce UI content has an invalid component-id:', this.componentId);
38
+ return;
39
+ }
40
+
41
+ try {
42
+ const module = await import(this.componentId);
43
+ this.ctor = module.default;
44
+ } catch (e) {
45
+ // When the embedded Salesforce UI content cannot load, show the error slot
46
+ console.error('LWR Everywhere - Salesforce UI content did not load:', e.message);
47
+ }
48
+ }
49
+ } // Initialize public (@api) properties on the embedded content
50
+
51
+
52
+ renderedCallback() {
53
+ this.setProperties(this.properties);
54
+ } // When the Salesforce UI content has an unhandled error, print an error to the console
55
+
56
+
57
+ errorCallback(e) {
58
+ console.error(`LWR Everywhere - Salesforce UI content for "${this.componentId}" cannot be displayed:`, e.message);
59
+ } // Update public (@api) properties on the embedded content
60
+
61
+
62
+ setProperties(properties) {
63
+ const dynamicContent = this.template.querySelector('lwr-dynamic');
64
+
65
+ if (dynamicContent) {
66
+ Object.entries(properties).forEach(([key, value]) => {
67
+ dynamicContent[key] = value;
68
+ });
69
+ }
70
+ }
71
+ /**
72
+ * NAVIGATION FEATURE PROPERTIES AND METHODS
73
+ * The navigation feature creates a bridge between the root router of embedded
74
+ * Salesforce UI content and the host document with public properties and events
75
+ */
76
+
77
+
78
+ @api
79
+ navigation = false; // Create the router bridge
80
+
81
+ async setUpNavBridge() {
82
+ if (this.navigation && !this.bridge) {
83
+ const routerBridgeModule = await import('lwr/routerBridge');
84
+ this.bridge = routerBridgeModule.createBridge({
85
+ historyDisabled: true,
86
+ // block the HistoryRouter for embedded nav
87
+ onReady: () => {
88
+ if (this.pendingPageRef) {
89
+ // Retry navigating to the pending page reference
90
+ this.navigate(this.pendingPageRef);
91
+ }
92
+ },
93
+ onPostNavigate: pageRef => this.dispatchEvent(new CustomEvent(NAV_EVENT, {
94
+ detail: pageRef
95
+ })),
96
+ onError: error => this.dispatchEvent(new CustomEvent(NAV_ERROR_EVENT, {
97
+ detail: error
98
+ }))
99
+ }, // The bridge is attached to this component, and observes the root router inside its slot
100
+ this);
101
+ }
102
+ } // Navigate via the bridge, which is hooked into its descendent root router
103
+ // The host component cannot call "lwr/navigation" APIs; it has no access to a NavigationContext
104
+
105
+
106
+ navigate(pageRef) {
107
+ if (this.bridge && this.bridge.navigate(pageRef)) {
108
+ // CLEAR the pending page reference if the navigation event was fired
109
+ this.pendingPageRef = undefined;
110
+ } else if (pageRef) {
111
+ // SAVE the pending page reference if the navigation event was NOT fired
112
+ this.pendingPageRef = pageRef;
113
+ }
114
+ } // Navigate to the page reference when set from the host document
115
+
116
+
117
+ @api
118
+ get pageReference() {
119
+ return this._pageRef;
120
+ }
121
+
122
+ set pageReference(pageRef) {
123
+ this._pageRef = pageRef;
124
+ this.navigate(pageRef);
125
+ }
126
+
127
+ }
@@ -0,0 +1,10 @@
1
+ // Credential vault for storing setters and subscribers for OAuth info
2
+ // This module is a SINGLETON and must be excluded from ESM bundling
3
+ let authInfo; // Get and set the OAuth info
4
+
5
+ export function getAuthInfo() {
6
+ return authInfo;
7
+ }
8
+ export function setAuthInfo(ai) {
9
+ authInfo = ai;
10
+ }
package/package.cjs ADDED
@@ -0,0 +1,9 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const rootPath = path.join(__dirname, './');
4
+ const version = JSON.parse(fs.readFileSync(path.join(rootPath, 'package.json'), 'utf-8')).version;
5
+
6
+ module.exports = {
7
+ rootPath,
8
+ version,
9
+ };
package/package.json ADDED
@@ -0,0 +1,67 @@
1
+ {
2
+ "name": "@lwrjs/everywhere",
3
+ "description": "LWR Everywhere",
4
+ "version": "0.8.0-alpha.10",
5
+ "license": "MIT",
6
+ "publishConfig": {
7
+ "access": "public"
8
+ },
9
+ "homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/salesforce/lwr.git",
13
+ "directory": "packages/@lwrjs/everywhere"
14
+ },
15
+ "bugs": {
16
+ "url": "https://github.com/salesforce/lwr/issues"
17
+ },
18
+ "type": "module",
19
+ "types": "build/es/index.d.ts",
20
+ "main": "build/es/index.js",
21
+ "module": "build/es/index.js",
22
+ "exports": {
23
+ ".": {
24
+ "import": "./build/es/index.js"
25
+ },
26
+ "./generate": {
27
+ "import": "./build/es/generate.js"
28
+ },
29
+ "./package": "./package.cjs"
30
+ },
31
+ "files": [
32
+ "build/*.js",
33
+ "build/**/*.js",
34
+ "build/**/*.html",
35
+ "build/**/*.d.ts",
36
+ "package.cjs"
37
+ ],
38
+ "scripts": {
39
+ "build:amd": "node scripts/generate-amd-modules.mjs",
40
+ "build:scripts": "node scripts/generate-client-runtimes.mjs",
41
+ "build": "tsc -b && node ../../../bin/pack-lwc --dir modules build/modules && yarn build:amd && yarn build:scripts"
42
+ },
43
+ "devDependencies": {
44
+ "@lwc/module-resolver": "2.17.0",
45
+ "@lwrjs/loader": "0.8.0-alpha.10",
46
+ "@lwrjs/router": "0.8.0-alpha.10",
47
+ "@lwrjs/types": "0.8.0-alpha.10",
48
+ "@rollup/plugin-replace": "^2.4.2",
49
+ "rollup-plugin-terser": "^7.0.2",
50
+ "rollup-plugin-typescript": "^1.0.1"
51
+ },
52
+ "lwc": {
53
+ "modules": [
54
+ {
55
+ "dir": "build/modules"
56
+ }
57
+ ],
58
+ "expose": [
59
+ "lwr/everywhere",
60
+ "lwr/everywhereAmd",
61
+ "lwr/everywhereEsm",
62
+ "lwr/host",
63
+ "lwr/vault"
64
+ ]
65
+ },
66
+ "gitHead": "55922351f484d77784d86ef7b03ebe788fa3e12c"
67
+ }