@lwrjs/view-registry 0.11.0-alpha.1 → 0.11.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.
- package/build/cjs/index.cjs +16 -12
- package/build/cjs/linkers/legacy_view_bootstrap.cjs +5 -4
- package/build/cjs/linkers/preload-utils.cjs +2 -1
- package/build/cjs/linkers/utils.cjs +9 -3
- package/build/cjs/linkers/view_bootstrap.cjs +5 -4
- package/build/cjs/utils.cjs +7 -4
- package/build/cjs/view-handler.cjs +15 -10
- package/build/es/index.js +15 -11
- package/build/es/linkers/legacy_view_bootstrap.js +5 -4
- package/build/es/linkers/preload-utils.js +2 -1
- package/build/es/linkers/utils.d.ts +1 -1
- package/build/es/linkers/utils.js +12 -5
- package/build/es/linkers/view_bootstrap.js +5 -4
- package/build/es/utils.d.ts +1 -1
- package/build/es/utils.js +6 -3
- package/build/es/view-handler.d.ts +1 -1
- package/build/es/view-handler.js +17 -10
- package/package.json +7 -7
package/build/cjs/index.cjs
CHANGED
|
@@ -150,6 +150,7 @@ var LwrViewRegistry = class {
|
|
|
150
150
|
layoutTemplate,
|
|
151
151
|
freezeAssets,
|
|
152
152
|
locale: runtimeParams?.locale,
|
|
153
|
+
basePath: runtimeParams?.basePath,
|
|
153
154
|
debug: runtimeEnvironment.debug
|
|
154
155
|
});
|
|
155
156
|
const viewParamKey = viewParamCacheKey ? (0, import_shared_utils.getCacheKeyFromJson)(viewParamCacheKey) : (0, import_shared_utils.getCacheKeyFromJson)(viewParams);
|
|
@@ -167,6 +168,7 @@ var LwrViewRegistry = class {
|
|
|
167
168
|
...view,
|
|
168
169
|
freezeAssets,
|
|
169
170
|
locale: runtimeParams?.locale,
|
|
171
|
+
basePath: runtimeParams?.basePath,
|
|
170
172
|
debug: runtimeEnvironment.debug
|
|
171
173
|
});
|
|
172
174
|
const viewParamKey = viewParamCacheKey ? (0, import_shared_utils.getCacheKeyFromJson)(viewParamCacheKey) : (0, import_shared_utils.getCacheKeyFromJson)(viewParams);
|
|
@@ -199,9 +201,9 @@ var LwrViewRegistry = class {
|
|
|
199
201
|
return viewDefinition;
|
|
200
202
|
}
|
|
201
203
|
async renderView(view, viewParams, runtimeEnvironment, runtimeParams = {}, renderOptions) {
|
|
202
|
-
const {contentTemplate, rootComponent, layoutTemplate} = view;
|
|
204
|
+
const {id, contentTemplate, rootComponent, layoutTemplate} = view;
|
|
203
205
|
const lwrResourcesId = `__LWR_RESOURCES__${Date.now()}`;
|
|
204
|
-
const renderedContent = await this.render({contentTemplate, rootComponent}, {...viewParams, lwr_resources: lwrResourcesId}, renderOptions);
|
|
206
|
+
const renderedContent = await this.render({id, contentTemplate, rootComponent}, {...viewParams, lwr_resources: lwrResourcesId}, runtimeParams, renderOptions);
|
|
205
207
|
let normalizedRenderOptions = (0, import_utils.normalizeRenderOptions)(this.runtimeEnvironment, renderedContent.options, renderOptions);
|
|
206
208
|
const layout = layoutTemplate || renderedContent.compiledView.layoutTemplate;
|
|
207
209
|
if (!layout) {
|
|
@@ -216,12 +218,12 @@ var LwrViewRegistry = class {
|
|
|
216
218
|
return renderedViewDef2;
|
|
217
219
|
}
|
|
218
220
|
const layoutTemplatePath = (0, import_shared_utils.normalizeResourcePath)(layout, this.globalConfig);
|
|
219
|
-
const renderedLayout = await this.render({contentTemplate: layoutTemplatePath}, {
|
|
221
|
+
const renderedLayout = await this.render({id, contentTemplate: layoutTemplatePath}, {
|
|
220
222
|
...renderedContent.compiledView.properties,
|
|
221
223
|
...viewParams,
|
|
222
224
|
body: renderedContent.renderedView,
|
|
223
225
|
lwr_resources: lwrResourcesId
|
|
224
|
-
});
|
|
226
|
+
}, runtimeParams);
|
|
225
227
|
normalizedRenderOptions = (0, import_utils.normalizeRenderOptions)(this.runtimeEnvironment, renderedLayout.options, normalizedRenderOptions);
|
|
226
228
|
const renderedViewDef = await this.link({
|
|
227
229
|
...renderedLayout,
|
|
@@ -237,7 +239,11 @@ var LwrViewRegistry = class {
|
|
|
237
239
|
assetReferences: [
|
|
238
240
|
...renderedContent.metadata.assetReferences,
|
|
239
241
|
...renderedLayout.metadata.assetReferences
|
|
240
|
-
]
|
|
242
|
+
],
|
|
243
|
+
serverData: {
|
|
244
|
+
...renderedContent.metadata.serverData,
|
|
245
|
+
...renderedLayout.metadata.serverData
|
|
246
|
+
}
|
|
241
247
|
}
|
|
242
248
|
}, {
|
|
243
249
|
view: {...view, layoutTemplate: layoutTemplatePath},
|
|
@@ -250,14 +256,12 @@ var LwrViewRegistry = class {
|
|
|
250
256
|
});
|
|
251
257
|
return renderedViewDef;
|
|
252
258
|
}
|
|
253
|
-
async render(viewId, viewParams, renderOptions) {
|
|
259
|
+
async render(viewId, viewParams, runtimeParams, renderOptions) {
|
|
254
260
|
const globalContext = this.globalData;
|
|
255
|
-
const {rootComponent, contentTemplate} = viewId;
|
|
256
|
-
const compiledView = await this.getView({
|
|
257
|
-
contentTemplate,
|
|
258
|
-
rootComponent
|
|
259
|
-
}, renderOptions?.skipCaching);
|
|
261
|
+
const {id, rootComponent, contentTemplate} = viewId;
|
|
262
|
+
const compiledView = await this.getView({id, contentTemplate, rootComponent}, renderOptions?.skipCaching);
|
|
260
263
|
const result = await compiledView.render({
|
|
264
|
+
...runtimeParams,
|
|
261
265
|
...globalContext,
|
|
262
266
|
...compiledView.properties,
|
|
263
267
|
...viewParams
|
|
@@ -287,7 +291,7 @@ var LwrViewRegistry = class {
|
|
|
287
291
|
metadata: renderedViewMetadata,
|
|
288
292
|
compiledView: {immutable = true}
|
|
289
293
|
} = renderedView;
|
|
290
|
-
const linkedMetadata = skipMetadataCollection ? renderedViewMetadata : await (0, import_shared_utils.extractMetadataFromHtml)(renderedViewContent);
|
|
294
|
+
const linkedMetadata = skipMetadataCollection ? renderedViewMetadata : await (0, import_shared_utils.extractMetadataFromHtml)(renderedViewContent, renderedViewMetadata);
|
|
291
295
|
const mergedViewContext = {
|
|
292
296
|
...viewContext,
|
|
293
297
|
runtimeEnvironment,
|
|
@@ -26,6 +26,7 @@ __markAsModule(exports);
|
|
|
26
26
|
__export(exports, {
|
|
27
27
|
getHtmlResources: () => getHtmlResources
|
|
28
28
|
});
|
|
29
|
+
var import_diagnostics = __toModule(require("@lwrjs/diagnostics"));
|
|
29
30
|
var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
|
|
30
31
|
var import_identity = __toModule(require("@lwrjs/app-service/identity"));
|
|
31
32
|
var import_utils = __toModule(require("../utils.cjs"));
|
|
@@ -41,7 +42,7 @@ async function getHtmlResources(view, viewParams, resourceContext) {
|
|
|
41
42
|
viewMetadata
|
|
42
43
|
} = resourceContext;
|
|
43
44
|
const {lwrVersion, format, hmrEnabled, bundle, debug, minify} = runtimeEnvironment;
|
|
44
|
-
const {customElements,
|
|
45
|
+
const {customElements, serverData, serverDebug} = viewMetadata;
|
|
45
46
|
const version = lwrVersion;
|
|
46
47
|
const isAMD = format === "amd";
|
|
47
48
|
const {bundleConfig} = resourceContext;
|
|
@@ -142,7 +143,7 @@ async function getHtmlResources(view, viewParams, resourceContext) {
|
|
|
142
143
|
if (uri2) {
|
|
143
144
|
imports[dynamicDep] = uri2;
|
|
144
145
|
} else {
|
|
145
|
-
|
|
146
|
+
import_diagnostics.logger.warn("Skipping unknown dynamic import " + dynamicDep);
|
|
146
147
|
}
|
|
147
148
|
}
|
|
148
149
|
}
|
|
@@ -191,10 +192,10 @@ async function getHtmlResources(view, viewParams, resourceContext) {
|
|
|
191
192
|
default: (0, import_shared_utils.getModuleUriPrefix)(runtimeEnvironment, runtimeParams)
|
|
192
193
|
},
|
|
193
194
|
rootComponents,
|
|
194
|
-
|
|
195
|
+
serverData,
|
|
195
196
|
...isAMD && {requiredModules: requiredAmdModules},
|
|
196
197
|
...isAMD && {preloadModules: viewPreloads.specifiers}
|
|
197
|
-
}, runtimeEnvironment, runtimeParams));
|
|
198
|
+
}, runtimeEnvironment, runtimeParams, serverDebug?.message));
|
|
198
199
|
}
|
|
199
200
|
if (!isAMD && hmrEnabled) {
|
|
200
201
|
configResources.unshift((0, import_utils2.getViewHmrConfigurationResource)(view, viewMetadata));
|
|
@@ -27,6 +27,7 @@ __export(exports, {
|
|
|
27
27
|
getPreloadModulesMeta: () => getPreloadModulesMeta,
|
|
28
28
|
setPreloadModulesMeta: () => setPreloadModulesMeta
|
|
29
29
|
});
|
|
30
|
+
var import_diagnostics = __toModule(require("@lwrjs/diagnostics"));
|
|
30
31
|
var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
|
|
31
32
|
function setPreloadModulesMeta(specifier, uri, groups, preloads) {
|
|
32
33
|
const [removedVersion, version] = specifier.split("/v/");
|
|
@@ -54,7 +55,7 @@ async function getPreloadModulesMeta(specifier, viewPreloads, bundleConfig, modu
|
|
|
54
55
|
return exclude.includes(specifier2);
|
|
55
56
|
};
|
|
56
57
|
if (isExternal(specifier)) {
|
|
57
|
-
|
|
58
|
+
import_diagnostics.logger.warn(`"${specifier}" is configured in both bundleConfig.externals and bootstrap.preloadModules. We are treating it as external.`);
|
|
58
59
|
} else {
|
|
59
60
|
const versionedModuleId = await (0, import_shared_utils.getVersionedModuleId)(specifier, moduleRegistry, runtimeParams);
|
|
60
61
|
const versionedModuleSpecifier = (0, import_shared_utils.getSpecifier)({
|
|
@@ -30,7 +30,7 @@ __export(exports, {
|
|
|
30
30
|
});
|
|
31
31
|
var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
|
|
32
32
|
var CONTENT_TYPE = "application/javascript";
|
|
33
|
-
function getViewBootstrapConfigurationResource(viewInfo, config, runtimeEnvironment, runtimeParams) {
|
|
33
|
+
function getViewBootstrapConfigurationResource(viewInfo, config, runtimeEnvironment, runtimeParams, debugMessage) {
|
|
34
34
|
const {compat, debug, hmrEnabled, apiVersion, format} = runtimeEnvironment;
|
|
35
35
|
const isESM = format === "esm";
|
|
36
36
|
const defaultUrl = (0, import_shared_utils.getModuleUriPrefix)(runtimeEnvironment, runtimeParams);
|
|
@@ -45,6 +45,11 @@ function getViewBootstrapConfigurationResource(viewInfo, config, runtimeEnvironm
|
|
|
45
45
|
},
|
|
46
46
|
...debug && {modifiers: {debug: "true"}}
|
|
47
47
|
};
|
|
48
|
+
const environment = {
|
|
49
|
+
NODE_ENV: runtimeEnvironment.serverMode,
|
|
50
|
+
SSR: false,
|
|
51
|
+
...(0, import_shared_utils.buildEnvironmentContext)(runtimeParams)
|
|
52
|
+
};
|
|
48
53
|
const configString = [
|
|
49
54
|
"/* This script is generated */",
|
|
50
55
|
"/* Client Bootstrap configuration */",
|
|
@@ -53,8 +58,9 @@ function getViewBootstrapConfigurationResource(viewInfo, config, runtimeEnvironm
|
|
|
53
58
|
...config,
|
|
54
59
|
endpoints
|
|
55
60
|
})});`,
|
|
56
|
-
`globalThis.process = { env:
|
|
57
|
-
`globalThis.lwcRuntimeFlags = { ENABLE_MIXED_SHADOW_MODE: ${viewInfo.mixedMode} }
|
|
61
|
+
`globalThis.process = { env: ${JSON.stringify(environment)} };`,
|
|
62
|
+
`globalThis.lwcRuntimeFlags = { ENABLE_MIXED_SHADOW_MODE: ${viewInfo.mixedMode} };`,
|
|
63
|
+
debug && debugMessage && `console.warn(${JSON.stringify(debugMessage)});`
|
|
58
64
|
].filter(Boolean).join("\n");
|
|
59
65
|
if (viewInfo.configAsSrc) {
|
|
60
66
|
const viewUrl = viewInfo.url || "/";
|
|
@@ -26,6 +26,7 @@ __markAsModule(exports);
|
|
|
26
26
|
__export(exports, {
|
|
27
27
|
getHtmlResources: () => getHtmlResources
|
|
28
28
|
});
|
|
29
|
+
var import_diagnostics = __toModule(require("@lwrjs/diagnostics"));
|
|
29
30
|
var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
|
|
30
31
|
var import_identity = __toModule(require("@lwrjs/app-service/identity"));
|
|
31
32
|
var import_utils = __toModule(require("../utils.cjs"));
|
|
@@ -41,7 +42,7 @@ async function getHtmlResources(view, viewParams, resourceContext) {
|
|
|
41
42
|
viewMetadata
|
|
42
43
|
} = resourceContext;
|
|
43
44
|
const {lwrVersion, format, hmrEnabled, bundle, debug, minify} = runtimeEnvironment;
|
|
44
|
-
const {customElements,
|
|
45
|
+
const {customElements, serverData, serverDebug} = viewMetadata;
|
|
45
46
|
const defRegistry = bundle ? moduleBundler : moduleRegistry;
|
|
46
47
|
const version = lwrVersion;
|
|
47
48
|
const isAMD = format === "amd";
|
|
@@ -133,7 +134,7 @@ async function getHtmlResources(view, viewParams, resourceContext) {
|
|
|
133
134
|
if (uri2) {
|
|
134
135
|
imports[dynamicDep] = uri2;
|
|
135
136
|
} else {
|
|
136
|
-
|
|
137
|
+
import_diagnostics.logger.warn("Skipping unknown dynamic import " + dynamicDep);
|
|
137
138
|
}
|
|
138
139
|
}
|
|
139
140
|
}
|
|
@@ -182,10 +183,10 @@ async function getHtmlResources(view, viewParams, resourceContext) {
|
|
|
182
183
|
imports: importMetadata?.imports,
|
|
183
184
|
index: importMetadata?.index,
|
|
184
185
|
rootComponents,
|
|
185
|
-
|
|
186
|
+
serverData,
|
|
186
187
|
...isAMD && {requiredModules: requiredAmdModules},
|
|
187
188
|
...isAMD && {preloadModules: viewPreloads.specifiers}
|
|
188
|
-
}, runtimeEnvironment, runtimeParams));
|
|
189
|
+
}, runtimeEnvironment, runtimeParams, serverDebug?.message));
|
|
189
190
|
}
|
|
190
191
|
if (!isAMD && hmrEnabled) {
|
|
191
192
|
configResources.unshift((0, import_utils2.getViewHmrConfigurationResource)(view, viewMetadata));
|
package/build/cjs/utils.cjs
CHANGED
|
@@ -93,7 +93,8 @@ function normalizeRenderedResult({
|
|
|
93
93
|
renderedView,
|
|
94
94
|
metadata: {
|
|
95
95
|
customElements: metadata ? metadata.customElements : [],
|
|
96
|
-
assetReferences: metadata ? metadata.assetReferences : []
|
|
96
|
+
assetReferences: metadata ? metadata.assetReferences : [],
|
|
97
|
+
serverData: metadata ? metadata.serverData : {}
|
|
97
98
|
},
|
|
98
99
|
options: {
|
|
99
100
|
skipMetadataCollection: options ? options.skipMetadataCollection : false
|
|
@@ -120,11 +121,13 @@ function normalizeRenderOptions(runtimeEnvironment, overrideRenderOptions, baseR
|
|
|
120
121
|
};
|
|
121
122
|
}
|
|
122
123
|
function getTitleFromFilePath(filePath) {
|
|
123
|
-
return filePath ? (0, import_path.basename)(filePath, (0, import_path.extname)(filePath)) : import_shared_utils.DEFAULT_TITLE;
|
|
124
|
+
return filePath && typeof filePath === "string" ? (0, import_path.basename)(filePath, (0, import_path.extname)(filePath)) : import_shared_utils.DEFAULT_TITLE;
|
|
124
125
|
}
|
|
125
|
-
function generatePageContext({requestPath: url}, {id, contentTemplate, properties}) {
|
|
126
|
+
function generatePageContext({requestPath: url}, {id, contentTemplate, properties}, runtimeParams) {
|
|
126
127
|
const title = properties?.title || getTitleFromFilePath(contentTemplate);
|
|
127
|
-
|
|
128
|
+
const locale = runtimeParams.locale;
|
|
129
|
+
const basePath = runtimeParams.basePath;
|
|
130
|
+
return {basePath, id, locale, title, url};
|
|
128
131
|
}
|
|
129
132
|
function isViewResponse(response) {
|
|
130
133
|
return response.body !== void 0;
|
|
@@ -37,15 +37,16 @@ var LwrViewHandler = class {
|
|
|
37
37
|
this.viewRegistry = context.viewRegistry;
|
|
38
38
|
this.moduleRegistry = context.moduleRegistry;
|
|
39
39
|
}
|
|
40
|
-
async getViewContent(viewRequest, route, runtimeEnvironment, runtimeParams
|
|
40
|
+
async getViewContent(viewRequest, route, runtimeEnvironment, runtimeParams) {
|
|
41
41
|
if (route.routeHandler) {
|
|
42
42
|
const response = await this.getRouteHandlerResponse(viewRequest, route, runtimeEnvironment, runtimeParams);
|
|
43
43
|
if ((0, import_utils.isViewResponse)(response)) {
|
|
44
44
|
return response;
|
|
45
45
|
}
|
|
46
|
-
const {view, viewParams, renderOptions} = normalizeViewProperties(viewRequest, response, route, this.globalConfig);
|
|
46
|
+
const {view, viewParams, renderOptions} = normalizeViewProperties(viewRequest, response, route, this.globalConfig, runtimeParams);
|
|
47
47
|
const viewDefinition2 = await this.viewRegistry.getViewDefinition(view, viewParams, runtimeEnvironment, {
|
|
48
48
|
...runtimeParams,
|
|
49
|
+
url: viewRequest.url,
|
|
49
50
|
params: viewRequest.params,
|
|
50
51
|
query: viewRequest.query
|
|
51
52
|
}, renderOptions);
|
|
@@ -73,7 +74,7 @@ var LwrViewHandler = class {
|
|
|
73
74
|
if ((0, import_utils.isViewResponse)(response)) {
|
|
74
75
|
return response;
|
|
75
76
|
}
|
|
76
|
-
const {view, viewParams, renderOptions} = normalizeViewProperties(viewRequest, response, route, this.globalConfig);
|
|
77
|
+
const {view, viewParams, renderOptions} = normalizeViewProperties(viewRequest, response, route, this.globalConfig, runtimeParams);
|
|
77
78
|
const viewDefinition2 = await this.viewRegistry.getViewDefinition(view, viewParams, runtimeEnvironment, runtimeParams, renderOptions);
|
|
78
79
|
return {
|
|
79
80
|
...response,
|
|
@@ -90,7 +91,7 @@ var LwrViewHandler = class {
|
|
|
90
91
|
if ((0, import_utils.isViewResponse)(response)) {
|
|
91
92
|
return response;
|
|
92
93
|
}
|
|
93
|
-
const {view, viewParams, renderOptions} = normalizeViewProperties(viewRequest, response, route, this.globalConfig);
|
|
94
|
+
const {view, viewParams, renderOptions} = normalizeViewProperties(viewRequest, response, route, this.globalConfig, runtimeParams);
|
|
94
95
|
viewDefinition = await this.viewRegistry.getViewDefinition(view, viewParams, runtimeEnvironment, runtimeParams, renderOptions);
|
|
95
96
|
} else {
|
|
96
97
|
viewDefinition = await this.getDefaultRouteViewDefinition(viewRequest, route, runtimeEnvironment, runtimeParams);
|
|
@@ -110,7 +111,7 @@ var LwrViewHandler = class {
|
|
|
110
111
|
}
|
|
111
112
|
async getDefaultRouteViewDefinition(viewRequest, route, runtimeEnvironment, runtimeParams = {}) {
|
|
112
113
|
const {id, bootstrap, rootComponent, contentTemplate, layoutTemplate, properties} = route;
|
|
113
|
-
const page = (0, import_utils.generatePageContext)(viewRequest, route);
|
|
114
|
+
const page = (0, import_utils.generatePageContext)(viewRequest, route, runtimeParams);
|
|
114
115
|
const viewDefinition = await this.viewRegistry.getViewDefinition({
|
|
115
116
|
id,
|
|
116
117
|
bootstrap,
|
|
@@ -119,6 +120,7 @@ var LwrViewHandler = class {
|
|
|
119
120
|
layoutTemplate
|
|
120
121
|
}, {page, ...properties}, runtimeEnvironment, {
|
|
121
122
|
...runtimeParams,
|
|
123
|
+
url: viewRequest.url,
|
|
122
124
|
params: viewRequest.params,
|
|
123
125
|
query: viewRequest.query
|
|
124
126
|
});
|
|
@@ -128,7 +130,8 @@ var LwrViewHandler = class {
|
|
|
128
130
|
if (!route.routeHandler) {
|
|
129
131
|
throw new Error("Route handler is required for a CustomView");
|
|
130
132
|
}
|
|
131
|
-
const
|
|
133
|
+
const routeHandlerOptions = route.routeHandler[1];
|
|
134
|
+
const routeHandlerFn = this.routeHandlers[route.routeHandler[0]];
|
|
132
135
|
if (!routeHandlerFn) {
|
|
133
136
|
throw new Error(`Route handler does not exist for id: ${route.routeHandler}`);
|
|
134
137
|
}
|
|
@@ -168,7 +171,7 @@ var LwrViewHandler = class {
|
|
|
168
171
|
view: normalizedView,
|
|
169
172
|
viewParams: normalizedViewParams,
|
|
170
173
|
renderOptions: normalizedRenderOptions
|
|
171
|
-
} = normalizeViewProperties(viewRequest, viewResponse, route, this.globalConfig);
|
|
174
|
+
} = normalizeViewProperties(viewRequest, viewResponse, route, this.globalConfig, runtimeParams);
|
|
172
175
|
const viewDefinition = await this.viewRegistry.getViewDefinition(normalizedView, normalizedViewParams, runtimeEnvironment, runtimeParams, normalizedRenderOptions);
|
|
173
176
|
return {
|
|
174
177
|
body: viewDefinition.renderedView,
|
|
@@ -179,7 +182,7 @@ var LwrViewHandler = class {
|
|
|
179
182
|
};
|
|
180
183
|
}
|
|
181
184
|
};
|
|
182
|
-
function normalizeViewProperties(viewRequest, response, route, config) {
|
|
185
|
+
function normalizeViewProperties(viewRequest, response, route, config, runtimeParams) {
|
|
183
186
|
const {
|
|
184
187
|
view: {rootComponent, contentTemplate: cTemplate, layoutTemplate: lTemplate},
|
|
185
188
|
viewParams,
|
|
@@ -191,14 +194,16 @@ function normalizeViewProperties(viewRequest, response, route, config) {
|
|
|
191
194
|
...route,
|
|
192
195
|
contentTemplate: cTemplate,
|
|
193
196
|
properties: viewParams
|
|
194
|
-
});
|
|
197
|
+
}, runtimeParams);
|
|
195
198
|
const {id, bootstrap} = route;
|
|
196
199
|
return {
|
|
197
200
|
view: {
|
|
198
201
|
id,
|
|
199
202
|
bootstrap,
|
|
200
203
|
...rootComponent && {rootComponent},
|
|
201
|
-
...cTemplate && {
|
|
204
|
+
...cTemplate && {
|
|
205
|
+
contentTemplate: typeof cTemplate === "string" ? (0, import_path.resolve)((0, import_shared_utils.normalizeResourcePath)(cTemplate, paths)) : cTemplate
|
|
206
|
+
},
|
|
202
207
|
...lTemplate && {layoutTemplate: (0, import_path.resolve)((0, import_shared_utils.normalizeResourcePath)(lTemplate, paths))}
|
|
203
208
|
},
|
|
204
209
|
viewParams: {page, ...viewParams},
|
package/build/es/index.js
CHANGED
|
@@ -136,6 +136,7 @@ export class LwrViewRegistry {
|
|
|
136
136
|
layoutTemplate,
|
|
137
137
|
freezeAssets,
|
|
138
138
|
locale: runtimeParams?.locale,
|
|
139
|
+
basePath: runtimeParams?.basePath,
|
|
139
140
|
debug: runtimeEnvironment.debug,
|
|
140
141
|
});
|
|
141
142
|
// viewParams is an unbounded object and can be very large (17MB/view for developer.salesforce.com). Allowing conusmers
|
|
@@ -159,6 +160,7 @@ export class LwrViewRegistry {
|
|
|
159
160
|
...view,
|
|
160
161
|
freezeAssets,
|
|
161
162
|
locale: runtimeParams?.locale,
|
|
163
|
+
basePath: runtimeParams?.basePath,
|
|
162
164
|
debug: runtimeEnvironment.debug,
|
|
163
165
|
});
|
|
164
166
|
// viewParams is an unbounded object and can be very large (17MB/view for developer.salesforce.com). Allowing consumers
|
|
@@ -202,9 +204,9 @@ export class LwrViewRegistry {
|
|
|
202
204
|
return viewDefinition;
|
|
203
205
|
}
|
|
204
206
|
async renderView(view, viewParams, runtimeEnvironment, runtimeParams = {}, renderOptions) {
|
|
205
|
-
const { contentTemplate, rootComponent, layoutTemplate } = view;
|
|
207
|
+
const { id, contentTemplate, rootComponent, layoutTemplate } = view;
|
|
206
208
|
const lwrResourcesId = `__LWR_RESOURCES__${Date.now()}`;
|
|
207
|
-
const renderedContent = await this.render({ contentTemplate, rootComponent }, { ...viewParams, lwr_resources: lwrResourcesId }, renderOptions);
|
|
209
|
+
const renderedContent = await this.render({ id, contentTemplate, rootComponent }, { ...viewParams, lwr_resources: lwrResourcesId }, runtimeParams, renderOptions);
|
|
208
210
|
// normalize the renderOptions provided by the CompiledView content with the request options.
|
|
209
211
|
let normalizedRenderOptions = normalizeRenderOptions(this.runtimeEnvironment, renderedContent.options, renderOptions);
|
|
210
212
|
const layout = layoutTemplate || renderedContent.compiledView.layoutTemplate;
|
|
@@ -223,12 +225,12 @@ export class LwrViewRegistry {
|
|
|
223
225
|
}
|
|
224
226
|
// Layout wrapped content: pass in the view provider properties and body from the rendered content
|
|
225
227
|
const layoutTemplatePath = normalizeResourcePath(layout, this.globalConfig);
|
|
226
|
-
const renderedLayout = await this.render({ contentTemplate: layoutTemplatePath }, {
|
|
228
|
+
const renderedLayout = await this.render({ id, contentTemplate: layoutTemplatePath }, {
|
|
227
229
|
...renderedContent.compiledView.properties,
|
|
228
230
|
...viewParams,
|
|
229
231
|
body: renderedContent.renderedView,
|
|
230
232
|
lwr_resources: lwrResourcesId,
|
|
231
|
-
});
|
|
233
|
+
}, runtimeParams);
|
|
232
234
|
normalizedRenderOptions = normalizeRenderOptions(this.runtimeEnvironment, renderedLayout.options, normalizedRenderOptions);
|
|
233
235
|
const renderedViewDef = await this.link({
|
|
234
236
|
...renderedLayout,
|
|
@@ -247,6 +249,10 @@ export class LwrViewRegistry {
|
|
|
247
249
|
...renderedContent.metadata.assetReferences,
|
|
248
250
|
...renderedLayout.metadata.assetReferences,
|
|
249
251
|
],
|
|
252
|
+
serverData: {
|
|
253
|
+
...renderedContent.metadata.serverData,
|
|
254
|
+
...renderedLayout.metadata.serverData,
|
|
255
|
+
},
|
|
250
256
|
},
|
|
251
257
|
},
|
|
252
258
|
// Render Content now contains a layout
|
|
@@ -263,13 +269,10 @@ export class LwrViewRegistry {
|
|
|
263
269
|
});
|
|
264
270
|
return renderedViewDef;
|
|
265
271
|
}
|
|
266
|
-
async render(viewId, viewParams, renderOptions) {
|
|
272
|
+
async render(viewId, viewParams, runtimeParams, renderOptions) {
|
|
267
273
|
const globalContext = this.globalData;
|
|
268
|
-
const { rootComponent, contentTemplate } = viewId;
|
|
269
|
-
const compiledView = await this.getView({
|
|
270
|
-
contentTemplate,
|
|
271
|
-
rootComponent,
|
|
272
|
-
}, renderOptions?.skipCaching);
|
|
274
|
+
const { id, rootComponent, contentTemplate } = viewId;
|
|
275
|
+
const compiledView = await this.getView({ id, contentTemplate, rootComponent }, renderOptions?.skipCaching);
|
|
273
276
|
// Get content/body of the view
|
|
274
277
|
/*
|
|
275
278
|
When rendering the compiled view, a collection variable properties can be passed to the render() to be rendered in
|
|
@@ -281,6 +284,7 @@ export class LwrViewRegistry {
|
|
|
281
284
|
These are merged together in to a combined context used by render()
|
|
282
285
|
*/
|
|
283
286
|
const result = await compiledView.render({
|
|
287
|
+
...runtimeParams,
|
|
284
288
|
...globalContext,
|
|
285
289
|
...compiledView.properties,
|
|
286
290
|
...viewParams,
|
|
@@ -301,7 +305,7 @@ export class LwrViewRegistry {
|
|
|
301
305
|
const { renderedView: renderedViewContent, metadata: renderedViewMetadata, compiledView: { immutable = true }, } = renderedView;
|
|
302
306
|
const linkedMetadata = skipMetadataCollection
|
|
303
307
|
? renderedViewMetadata
|
|
304
|
-
: await extractMetadataFromHtml(renderedViewContent);
|
|
308
|
+
: await extractMetadataFromHtml(renderedViewContent, renderedViewMetadata);
|
|
305
309
|
const mergedViewContext = {
|
|
306
310
|
...viewContext,
|
|
307
311
|
runtimeEnvironment,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { logger } from '@lwrjs/diagnostics';
|
|
2
|
+
import { kebabCaseToModuleSpecifier, getModuleGraphs, GraphDepth, getModuleUriPrefix, explodeSpecifier, isBundler, getHydrateDirective, } from '@lwrjs/shared-utils';
|
|
2
3
|
import { AppResourceEnum, getAppSpecifier } from '@lwrjs/app-service/identity';
|
|
3
4
|
import { generateHtmlTag, getModuleResourceByUri } from '../utils.js';
|
|
4
5
|
import { flattenCustomElements, getViewBootstrapConfigurationResource, getViewHmrConfigurationResource, } from './utils.js';
|
|
@@ -6,7 +7,7 @@ import { setPreloadModulesMeta, getPreloadModulesMeta } from './preload-utils.js
|
|
|
6
7
|
export async function getHtmlResources(view, viewParams, resourceContext) {
|
|
7
8
|
const { runtimeEnvironment, runtimeParams, moduleRegistry, moduleBundler, resourceRegistry, viewMetadata, } = resourceContext;
|
|
8
9
|
const { lwrVersion, format, hmrEnabled, bundle, debug, minify } = runtimeEnvironment;
|
|
9
|
-
const { customElements,
|
|
10
|
+
const { customElements, serverData, serverDebug } = viewMetadata;
|
|
10
11
|
const version = lwrVersion;
|
|
11
12
|
const isAMD = format === 'amd';
|
|
12
13
|
const { bundleConfig } = resourceContext;
|
|
@@ -209,11 +210,11 @@ export async function getHtmlResources(view, viewParams, resourceContext) {
|
|
|
209
210
|
default: getModuleUriPrefix(runtimeEnvironment, runtimeParams),
|
|
210
211
|
},
|
|
211
212
|
rootComponents,
|
|
212
|
-
|
|
213
|
+
serverData,
|
|
213
214
|
...(isAMD && { requiredModules: requiredAmdModules }),
|
|
214
215
|
// in AMD we need to tell the loader what modules we are preloading
|
|
215
216
|
...(isAMD && { preloadModules: viewPreloads.specifiers }),
|
|
216
|
-
}, runtimeEnvironment, runtimeParams));
|
|
217
|
+
}, runtimeEnvironment, runtimeParams, serverDebug?.message));
|
|
217
218
|
}
|
|
218
219
|
if (!isAMD && hmrEnabled) {
|
|
219
220
|
configResources.unshift(getViewHmrConfigurationResource(view, viewMetadata));
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { logger } from '@lwrjs/diagnostics';
|
|
2
|
+
import { explodeSpecifier, getGroupName, getVersionedModuleId, normalizeVersionToUri, VERSION_NOT_PROVIDED, getSpecifier, isGroupie, } from '@lwrjs/shared-utils';
|
|
2
3
|
/**
|
|
3
4
|
* keeps track of preloadModules metadata
|
|
4
5
|
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ClientBootstrapConfig, RuntimeEnvironment, RuntimeParams, ResourceDefinition, RenderedViewMetadata, CustomElementReference, View, ViewInfo } from '@lwrjs/types';
|
|
2
|
-
export declare function getViewBootstrapConfigurationResource(viewInfo: ViewInfo, config: ClientBootstrapConfig, runtimeEnvironment: RuntimeEnvironment, runtimeParams?:
|
|
2
|
+
export declare function getViewBootstrapConfigurationResource(viewInfo: ViewInfo, config: ClientBootstrapConfig, runtimeEnvironment: RuntimeEnvironment, runtimeParams: RuntimeParams, debugMessage?: string): ResourceDefinition;
|
|
3
3
|
export declare function getViewHmrConfigurationResource(view: View, viewMetadata: RenderedViewMetadata): ResourceDefinition;
|
|
4
4
|
export declare function flattenCustomElements(arr: CustomElementReference[], isSSR?: boolean): CustomElementReference[];
|
|
5
5
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { getMappingUriPrefix, getModuleUriPrefix, getClientBootstrapConfigurationUri, hashContent, } from '@lwrjs/shared-utils';
|
|
1
|
+
import { buildEnvironmentContext, getMappingUriPrefix, getModuleUriPrefix, getClientBootstrapConfigurationUri, hashContent, } from '@lwrjs/shared-utils';
|
|
2
2
|
const CONTENT_TYPE = 'application/javascript';
|
|
3
|
-
export function getViewBootstrapConfigurationResource(viewInfo, config, runtimeEnvironment, runtimeParams) {
|
|
3
|
+
export function getViewBootstrapConfigurationResource(viewInfo, config, runtimeEnvironment, runtimeParams, debugMessage) {
|
|
4
4
|
const { compat, debug, hmrEnabled, apiVersion, format } = runtimeEnvironment;
|
|
5
5
|
const isESM = format === 'esm';
|
|
6
6
|
const defaultUrl = getModuleUriPrefix(runtimeEnvironment, runtimeParams);
|
|
@@ -17,6 +17,14 @@ export function getViewBootstrapConfigurationResource(viewInfo, config, runtimeE
|
|
|
17
17
|
},
|
|
18
18
|
...(debug && { modifiers: { debug: 'true' } }),
|
|
19
19
|
};
|
|
20
|
+
const environment = {
|
|
21
|
+
// TODO: W-12639529 change NODE_ENV after addressing downstream customers
|
|
22
|
+
NODE_ENV: runtimeEnvironment.serverMode,
|
|
23
|
+
// Note: SSR is always false because this script is executed on the client
|
|
24
|
+
SSR: false,
|
|
25
|
+
// Used by `lwr/environment`
|
|
26
|
+
...buildEnvironmentContext(runtimeParams),
|
|
27
|
+
};
|
|
20
28
|
const configString = [
|
|
21
29
|
'/* This script is generated */',
|
|
22
30
|
'/* Client Bootstrap configuration */',
|
|
@@ -25,10 +33,9 @@ export function getViewBootstrapConfigurationResource(viewInfo, config, runtimeE
|
|
|
25
33
|
...config,
|
|
26
34
|
endpoints,
|
|
27
35
|
})});`,
|
|
28
|
-
|
|
29
|
-
// Note: SSR is always false because this script is executed on the client
|
|
30
|
-
`globalThis.process = { env: { NODE_ENV: "${runtimeEnvironment.serverMode}", SSR: false } };`,
|
|
36
|
+
`globalThis.process = { env: ${JSON.stringify(environment)} };`,
|
|
31
37
|
`globalThis.lwcRuntimeFlags = { ENABLE_MIXED_SHADOW_MODE: ${viewInfo.mixedMode} };`,
|
|
38
|
+
debug && debugMessage && `console.warn(${JSON.stringify(debugMessage)});`,
|
|
32
39
|
]
|
|
33
40
|
.filter(Boolean)
|
|
34
41
|
.join('\n');
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { logger } from '@lwrjs/diagnostics';
|
|
2
|
+
import { kebabCaseToModuleSpecifier, toImportMetadata, getModuleGraphs, getMappingUriPrefix, GraphDepth, explodeSpecifier, isBundler, getHydrateDirective, } from '@lwrjs/shared-utils';
|
|
2
3
|
import { AppResourceEnum, getAppSpecifier } from '@lwrjs/app-service/identity';
|
|
3
4
|
import { generateHtmlTag, getModuleResourceByUri } from '../utils.js';
|
|
4
5
|
import { flattenCustomElements, getViewBootstrapConfigurationResource, getViewHmrConfigurationResource, } from './utils.js';
|
|
@@ -6,7 +7,7 @@ import { setPreloadModulesMeta, getPreloadModulesMeta } from './preload-utils.js
|
|
|
6
7
|
export async function getHtmlResources(view, viewParams, resourceContext) {
|
|
7
8
|
const { runtimeEnvironment, runtimeParams, moduleRegistry, moduleBundler, resourceRegistry, viewMetadata, } = resourceContext;
|
|
8
9
|
const { lwrVersion, format, hmrEnabled, bundle, debug, minify } = runtimeEnvironment;
|
|
9
|
-
const { customElements,
|
|
10
|
+
const { customElements, serverData, serverDebug } = viewMetadata;
|
|
10
11
|
const defRegistry = bundle ? moduleBundler : moduleRegistry;
|
|
11
12
|
const version = lwrVersion;
|
|
12
13
|
const isAMD = format === 'amd';
|
|
@@ -195,11 +196,11 @@ export async function getHtmlResources(view, viewParams, resourceContext) {
|
|
|
195
196
|
imports: importMetadata?.imports,
|
|
196
197
|
index: importMetadata?.index,
|
|
197
198
|
rootComponents,
|
|
198
|
-
|
|
199
|
+
serverData,
|
|
199
200
|
...(isAMD && { requiredModules: requiredAmdModules }),
|
|
200
201
|
// in AMD we need to tell the loader what modules we are preloading
|
|
201
202
|
...(isAMD && { preloadModules: viewPreloads.specifiers }),
|
|
202
|
-
}, runtimeEnvironment, runtimeParams));
|
|
203
|
+
}, runtimeEnvironment, runtimeParams, serverDebug?.message));
|
|
203
204
|
}
|
|
204
205
|
if (!isAMD && hmrEnabled) {
|
|
205
206
|
configResources.unshift(getViewHmrConfigurationResource(view, viewMetadata));
|
package/build/es/utils.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export declare function generateHtmlTag(definition: HTMLResource): Promise<strin
|
|
|
4
4
|
export declare function normalizeRenderedResult({ renderedView, metadata, options, }: RenderingResult): NormalizedRenderingResult;
|
|
5
5
|
export declare function reduceSourceAssetReferences(assets: AssetReference[]): RenderedAssetReference[];
|
|
6
6
|
export declare function normalizeRenderOptions(runtimeEnvironment: RuntimeEnvironment, overrideRenderOptions?: RenderOptions, baseRenderOptions?: RenderOptions): Required<RenderOptions>;
|
|
7
|
-
export declare function generatePageContext({ requestPath: url }: ViewRequest, { id, contentTemplate, properties }: LwrRoute | LwrErrorRoute): JsonCompatible<ViewPageContext>;
|
|
7
|
+
export declare function generatePageContext({ requestPath: url }: ViewRequest, { id, contentTemplate, properties }: LwrRoute | LwrErrorRoute, runtimeParams: RuntimeParams): JsonCompatible<ViewPageContext>;
|
|
8
8
|
export declare function isViewResponse(response: RouteHandlerViewResponse): response is ViewResponse;
|
|
9
9
|
export declare function toJsonFormat(viewRequest: ViewRequest, viewDefinition: LinkedViewDefinition, route: LwrRoute | LwrErrorRoute, runtimeEnvironment: RuntimeEnvironment, runtimeParams: RuntimeParams, moduleRegistry: ModuleRegistry): Promise<ViewResponse>;
|
|
10
10
|
export declare function getModuleResource(moduleId: Pick<ModuleId, 'specifier' | 'version'>, runtimeEnvironment: RuntimeEnvironment, moduleResourceMeta: ViewModuleResourceContext, defRegistry: ModuleRegistry | ModuleBundler, runtimeParams: RuntimeParams): Promise<ResourceDefinition>;
|
package/build/es/utils.js
CHANGED
|
@@ -58,6 +58,7 @@ export function normalizeRenderedResult({ renderedView, metadata, options, }) {
|
|
|
58
58
|
metadata: {
|
|
59
59
|
customElements: metadata ? metadata.customElements : [],
|
|
60
60
|
assetReferences: metadata ? metadata.assetReferences : [],
|
|
61
|
+
serverData: metadata ? metadata.serverData : {},
|
|
61
62
|
},
|
|
62
63
|
options: {
|
|
63
64
|
skipMetadataCollection: options ? options.skipMetadataCollection : false,
|
|
@@ -85,15 +86,17 @@ export function normalizeRenderOptions(runtimeEnvironment, overrideRenderOptions
|
|
|
85
86
|
};
|
|
86
87
|
}
|
|
87
88
|
function getTitleFromFilePath(filePath) {
|
|
88
|
-
return filePath ? basename(filePath, extname(filePath)) : DEFAULT_TITLE;
|
|
89
|
+
return filePath && typeof filePath === 'string' ? basename(filePath, extname(filePath)) : DEFAULT_TITLE;
|
|
89
90
|
}
|
|
90
|
-
export function generatePageContext({ requestPath: url }, { id, contentTemplate, properties }) {
|
|
91
|
+
export function generatePageContext({ requestPath: url }, { id, contentTemplate, properties }, runtimeParams) {
|
|
91
92
|
// title is set to the first defined value of the following:
|
|
92
93
|
// - properties.title from the route (or viewParams.title from the route handler)
|
|
93
94
|
// - filename from route.contentTemplate
|
|
94
95
|
// - DEFAULT_TITLE
|
|
95
96
|
const title = properties?.title || getTitleFromFilePath(contentTemplate);
|
|
96
|
-
|
|
97
|
+
const locale = runtimeParams.locale;
|
|
98
|
+
const basePath = runtimeParams.basePath;
|
|
99
|
+
return { basePath, id, locale, title, url };
|
|
97
100
|
}
|
|
98
101
|
// type guard for ViewDef responses
|
|
99
102
|
export function isViewResponse(response) {
|
|
@@ -10,7 +10,7 @@ export declare class LwrViewHandler implements ViewHandler {
|
|
|
10
10
|
viewRegistry: ViewRegistry;
|
|
11
11
|
moduleRegistry: ModuleRegistry;
|
|
12
12
|
constructor(context: ViewHandlerContext, globalConfig: NormalizedLwrGlobalConfig);
|
|
13
|
-
getViewContent(viewRequest: ViewRequest, route: LwrRoute | LwrErrorRoute, runtimeEnvironment: RuntimeEnvironment, runtimeParams
|
|
13
|
+
getViewContent(viewRequest: ViewRequest, route: LwrRoute | LwrErrorRoute, runtimeEnvironment: RuntimeEnvironment, runtimeParams: RuntimeParams): Promise<ViewResponse>;
|
|
14
14
|
getViewJson(viewRequest: ViewRequest, route: LwrRoute | LwrErrorRoute, runtimeEnvironment: RuntimeEnvironment, runtimeParams?: RuntimeParams): Promise<ViewResponse>;
|
|
15
15
|
getViewConfiguration(viewRequest: ViewRequest, route: LwrRoute | LwrErrorRoute, runtimeEnvironment: RuntimeEnvironment, runtimeParams?: RuntimeParams): Promise<ViewResponse | undefined>;
|
|
16
16
|
private getDefaultRouteViewDefinition;
|
package/build/es/view-handler.js
CHANGED
|
@@ -16,7 +16,7 @@ export class LwrViewHandler {
|
|
|
16
16
|
// config
|
|
17
17
|
route,
|
|
18
18
|
// context
|
|
19
|
-
runtimeEnvironment, runtimeParams
|
|
19
|
+
runtimeEnvironment, runtimeParams) {
|
|
20
20
|
if (route.routeHandler) {
|
|
21
21
|
const response = await this.getRouteHandlerResponse(viewRequest, route, runtimeEnvironment, runtimeParams);
|
|
22
22
|
if (isViewResponse(response)) {
|
|
@@ -24,9 +24,10 @@ export class LwrViewHandler {
|
|
|
24
24
|
return response;
|
|
25
25
|
}
|
|
26
26
|
// Process ViewDefinitionResponse
|
|
27
|
-
const { view, viewParams, renderOptions } = normalizeViewProperties(viewRequest, response, route, this.globalConfig);
|
|
27
|
+
const { view, viewParams, renderOptions } = normalizeViewProperties(viewRequest, response, route, this.globalConfig, runtimeParams);
|
|
28
28
|
const viewDefinition = await this.viewRegistry.getViewDefinition(view, viewParams, runtimeEnvironment, {
|
|
29
29
|
...runtimeParams,
|
|
30
|
+
url: viewRequest.url,
|
|
30
31
|
params: viewRequest.params,
|
|
31
32
|
query: viewRequest.query,
|
|
32
33
|
}, renderOptions);
|
|
@@ -63,7 +64,7 @@ export class LwrViewHandler {
|
|
|
63
64
|
// Return custom view response payload as-is
|
|
64
65
|
return response;
|
|
65
66
|
}
|
|
66
|
-
const { view, viewParams, renderOptions } = normalizeViewProperties(viewRequest, response, route, this.globalConfig);
|
|
67
|
+
const { view, viewParams, renderOptions } = normalizeViewProperties(viewRequest, response, route, this.globalConfig, runtimeParams);
|
|
67
68
|
const viewDefinition = await this.viewRegistry.getViewDefinition(view, viewParams, runtimeEnvironment, runtimeParams, renderOptions);
|
|
68
69
|
return {
|
|
69
70
|
...response,
|
|
@@ -92,7 +93,7 @@ export class LwrViewHandler {
|
|
|
92
93
|
// Return custom view response payload as-is
|
|
93
94
|
return response;
|
|
94
95
|
}
|
|
95
|
-
const { view, viewParams, renderOptions } = normalizeViewProperties(viewRequest, response, route, this.globalConfig);
|
|
96
|
+
const { view, viewParams, renderOptions } = normalizeViewProperties(viewRequest, response, route, this.globalConfig, runtimeParams);
|
|
96
97
|
viewDefinition = await this.viewRegistry.getViewDefinition(view, viewParams, runtimeEnvironment, runtimeParams, renderOptions);
|
|
97
98
|
}
|
|
98
99
|
else {
|
|
@@ -122,7 +123,7 @@ export class LwrViewHandler {
|
|
|
122
123
|
// context
|
|
123
124
|
runtimeEnvironment, runtimeParams = {}) {
|
|
124
125
|
const { id, bootstrap, rootComponent, contentTemplate, layoutTemplate, properties } = route;
|
|
125
|
-
const page = generatePageContext(viewRequest, route);
|
|
126
|
+
const page = generatePageContext(viewRequest, route, runtimeParams);
|
|
126
127
|
const viewDefinition = await this.viewRegistry.getViewDefinition({
|
|
127
128
|
id,
|
|
128
129
|
bootstrap,
|
|
@@ -131,6 +132,7 @@ export class LwrViewHandler {
|
|
|
131
132
|
layoutTemplate,
|
|
132
133
|
}, { page, ...properties }, runtimeEnvironment, {
|
|
133
134
|
...runtimeParams,
|
|
135
|
+
url: viewRequest.url,
|
|
134
136
|
params: viewRequest.params,
|
|
135
137
|
query: viewRequest.query,
|
|
136
138
|
});
|
|
@@ -144,7 +146,8 @@ export class LwrViewHandler {
|
|
|
144
146
|
if (!route.routeHandler) {
|
|
145
147
|
throw new Error('Route handler is required for a CustomView');
|
|
146
148
|
}
|
|
147
|
-
const
|
|
149
|
+
const routeHandlerOptions = route.routeHandler[1];
|
|
150
|
+
const routeHandlerFn = this.routeHandlers[route.routeHandler[0]];
|
|
148
151
|
if (!routeHandlerFn) {
|
|
149
152
|
throw new Error(`Route handler does not exist for id: ${route.routeHandler}`);
|
|
150
153
|
}
|
|
@@ -191,7 +194,7 @@ export class LwrViewHandler {
|
|
|
191
194
|
viewParams,
|
|
192
195
|
renderOptions,
|
|
193
196
|
};
|
|
194
|
-
const { view: normalizedView, viewParams: normalizedViewParams, renderOptions: normalizedRenderOptions, } = normalizeViewProperties(viewRequest, viewResponse, route, this.globalConfig);
|
|
197
|
+
const { view: normalizedView, viewParams: normalizedViewParams, renderOptions: normalizedRenderOptions, } = normalizeViewProperties(viewRequest, viewResponse, route, this.globalConfig, runtimeParams);
|
|
195
198
|
const viewDefinition = await this.viewRegistry.getViewDefinition(normalizedView, normalizedViewParams, runtimeEnvironment, runtimeParams, normalizedRenderOptions);
|
|
196
199
|
return {
|
|
197
200
|
body: viewDefinition.renderedView,
|
|
@@ -202,7 +205,7 @@ export class LwrViewHandler {
|
|
|
202
205
|
};
|
|
203
206
|
}
|
|
204
207
|
}
|
|
205
|
-
function normalizeViewProperties(viewRequest, response, route, config) {
|
|
208
|
+
function normalizeViewProperties(viewRequest, response, route, config, runtimeParams) {
|
|
206
209
|
const { view: { rootComponent, contentTemplate: cTemplate, layoutTemplate: lTemplate }, viewParams, renderOptions, } = response;
|
|
207
210
|
const { rootDir, assets, contentDir, layoutsDir } = config;
|
|
208
211
|
const paths = { rootDir, assets, contentDir, layoutsDir };
|
|
@@ -211,14 +214,18 @@ function normalizeViewProperties(viewRequest, response, route, config) {
|
|
|
211
214
|
...route,
|
|
212
215
|
contentTemplate: cTemplate,
|
|
213
216
|
properties: viewParams,
|
|
214
|
-
});
|
|
217
|
+
}, runtimeParams);
|
|
215
218
|
const { id, bootstrap } = route;
|
|
216
219
|
return {
|
|
217
220
|
view: {
|
|
218
221
|
id,
|
|
219
222
|
bootstrap,
|
|
220
223
|
...(rootComponent && { rootComponent }),
|
|
221
|
-
...(cTemplate && {
|
|
224
|
+
...(cTemplate && {
|
|
225
|
+
contentTemplate: typeof cTemplate === 'string'
|
|
226
|
+
? resolve(normalizeResourcePath(cTemplate, paths))
|
|
227
|
+
: cTemplate,
|
|
228
|
+
}),
|
|
222
229
|
...(lTemplate && { layoutTemplate: resolve(normalizeResourcePath(lTemplate, paths)) }),
|
|
223
230
|
},
|
|
224
231
|
viewParams: { page, ...viewParams },
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.11.0-alpha.
|
|
7
|
+
"version": "0.11.0-alpha.10",
|
|
8
8
|
"homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
@@ -30,17 +30,17 @@
|
|
|
30
30
|
"build/**/*.d.ts"
|
|
31
31
|
],
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@lwrjs/app-service": "0.11.0-alpha.
|
|
34
|
-
"@lwrjs/diagnostics": "0.11.0-alpha.
|
|
35
|
-
"@lwrjs/instrumentation": "0.11.0-alpha.
|
|
36
|
-
"@lwrjs/shared-utils": "0.11.0-alpha.
|
|
33
|
+
"@lwrjs/app-service": "0.11.0-alpha.10",
|
|
34
|
+
"@lwrjs/diagnostics": "0.11.0-alpha.10",
|
|
35
|
+
"@lwrjs/instrumentation": "0.11.0-alpha.10",
|
|
36
|
+
"@lwrjs/shared-utils": "0.11.0-alpha.10",
|
|
37
37
|
"lru-cache": "^10.0.0"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@lwrjs/types": "0.11.0-alpha.
|
|
40
|
+
"@lwrjs/types": "0.11.0-alpha.10"
|
|
41
41
|
},
|
|
42
42
|
"engines": {
|
|
43
43
|
"node": ">=16.0.0"
|
|
44
44
|
},
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "34b1e289e8de12531f5624b64512e870157195d4"
|
|
46
46
|
}
|