@lwrjs/view-registry 0.7.0-alpha.3 → 0.7.0-alpha.7

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.
@@ -56,6 +56,7 @@ async function getHtmlResources(view, viewParams, resourceContext) {
56
56
  const visitedCache = new Map();
57
57
  const imports = {};
58
58
  const rootComponents = [];
59
+ const rootProperties = {};
59
60
  const requiredAmdModules = [];
60
61
  const preloadAmdModules = [];
61
62
  if (isAMD) {
@@ -102,16 +103,20 @@ async function getHtmlResources(view, viewParams, resourceContext) {
102
103
  }
103
104
  }
104
105
  }
106
+ const isSSR = view.bootstrap?.experimentalSSR;
105
107
  const customElementsRecords = [];
106
- const flattenedElements = (0, import_utils2.flattenCustomElements)(customElements);
107
- await Promise.all(flattenedElements.map(async ({tagName: element}) => {
108
- const graph = await (0, import_shared_utils.getModuleGraphs)((0, import_shared_utils.kebabcaseToCamelcase)(element), {includeUris: true, includeLinkedDefinitions: true, depth}, moduleRegistry, bundle ? moduleBundler : moduleRegistry, runtimeEnvironment, runtimeParams ? runtimeParams : {}, visitedCache);
108
+ const flattenedElements = (0, import_utils2.flattenCustomElements)(customElements, isSSR);
109
+ await Promise.all(flattenedElements.map(async ({tagName: element, props}) => {
110
+ const graph = await (0, import_shared_utils.getModuleGraphs)((0, import_shared_utils.kebabCaseToModuleSpecifer)(element), {includeUris: true, includeLinkedDefinitions: true, depth}, moduleRegistry, bundle ? moduleBundler : moduleRegistry, runtimeEnvironment, runtimeParams ? runtimeParams : {}, visitedCache);
109
111
  customElementsRecords.push({elementName: element, flatGraph: graph});
110
112
  const specifier = graph.graphs[0].specifier;
111
113
  const uri2 = graph.uriMap[specifier];
112
114
  moduleResources.push((0, import_utils.getModuleResourceByUri)(uri2, runtimeEnvironment, true));
113
115
  rootComponents.push(specifier);
114
116
  imports[specifier] = uri2;
117
+ if (isSSR && props) {
118
+ rootProperties[specifier] = props;
119
+ }
115
120
  if (isAMD) {
116
121
  preloadAmdModules.push(specifier);
117
122
  for (const staticDep of graph.graphs[0].static) {
@@ -137,6 +142,7 @@ async function getHtmlResources(view, viewParams, resourceContext) {
137
142
  default: (0, import_shared_utils.getModuleUriPrefix)(runtimeEnvironment, runtimeParams)
138
143
  },
139
144
  rootComponents,
145
+ rootProperties: isSSR ? rootProperties : void 0,
140
146
  ...isAMD && {requiredModules: requiredAmdModules},
141
147
  ...isAMD && {preloadModules: preloadAmdModules}
142
148
  }, runtimeEnvironment, runtimeParams));
@@ -98,16 +98,18 @@ function getViewHmrConfigurationResource(view, viewMetadata) {
98
98
  content: configString
99
99
  };
100
100
  }
101
- function flattenCustomElements(arr) {
101
+ function flattenCustomElements(arr, isSSR = false) {
102
102
  const ret = [];
103
103
  const visitedTags = new Set();
104
104
  function flatten(arr2) {
105
105
  for (const val of arr2) {
106
- const {tagName, children} = val;
106
+ const {tagName, children, props} = val;
107
107
  if (!visitedTags.has(tagName)) {
108
- ret.push({
109
- tagName
110
- });
108
+ if (isSSR) {
109
+ ret.push({tagName, props});
110
+ } else {
111
+ ret.push({tagName});
112
+ }
111
113
  visitedTags.add(tagName);
112
114
  }
113
115
  if (children) {
@@ -56,6 +56,7 @@ async function getHtmlResources(view, viewParams, resourceContext) {
56
56
  const visitedCache = new Map();
57
57
  const imports = {};
58
58
  const rootComponents = [];
59
+ const rootProperties = {};
59
60
  const requiredAmdModules = [];
60
61
  const preloadAmdModules = [];
61
62
  if (isAMD) {
@@ -103,16 +104,20 @@ async function getHtmlResources(view, viewParams, resourceContext) {
103
104
  }
104
105
  }
105
106
  let importMetadata = await (0, import_shared_utils.toImportMetadata)(bootstrapModuleGraph, {imports: {}, index: {}}, moduleRegistry, runtimeEnvironment, runtimeParams);
107
+ const isSSR = view.bootstrap?.experimentalSSR;
106
108
  const customElementsRecords = [];
107
- const flattenedElements = (0, import_utils2.flattenCustomElements)(customElements);
108
- await Promise.all(flattenedElements.map(async ({tagName: element}) => {
109
- const graph = await (0, import_shared_utils.getModuleGraphs)((0, import_shared_utils.kebabcaseToCamelcase)(element), {includeUris: true, includeLinkedDefinitions: true, depth}, moduleRegistry, bundle ? moduleBundler : moduleRegistry, runtimeEnvironment, runtimeParams ? runtimeParams : {}, visitedCache);
109
+ const flattenedElements = (0, import_utils2.flattenCustomElements)(customElements, isSSR);
110
+ await Promise.all(flattenedElements.map(async ({tagName: element, props}) => {
111
+ const graph = await (0, import_shared_utils.getModuleGraphs)((0, import_shared_utils.kebabCaseToModuleSpecifer)(element), {includeUris: true, includeLinkedDefinitions: true, depth}, moduleRegistry, bundle ? moduleBundler : moduleRegistry, runtimeEnvironment, runtimeParams ? runtimeParams : {}, visitedCache);
110
112
  customElementsRecords.push({elementName: element, flatGraph: graph});
111
113
  const specifier = graph.graphs[0].specifier;
112
114
  const uri2 = graph.uriMap[specifier];
113
115
  moduleResources.push((0, import_utils.getModuleResourceByUri)(uri2, runtimeEnvironment, true));
114
116
  rootComponents.push(specifier);
115
117
  imports[specifier] = uri2;
118
+ if (isSSR && props) {
119
+ rootProperties[specifier] = props;
120
+ }
116
121
  if (isAMD) {
117
122
  preloadAmdModules.push(specifier);
118
123
  for (const staticDep of graph.graphs[0].static) {
@@ -137,6 +142,7 @@ async function getHtmlResources(view, viewParams, resourceContext) {
137
142
  imports: importMetadata?.imports,
138
143
  index: importMetadata?.index,
139
144
  rootComponents,
145
+ rootProperties: isSSR ? rootProperties : void 0,
140
146
  ...isAMD && {requiredModules: requiredAmdModules},
141
147
  ...isAMD && {preloadModules: preloadAmdModules}
142
148
  }, runtimeEnvironment, runtimeParams));
@@ -1,4 +1,4 @@
1
- import { kebabcaseToCamelcase, getModuleGraphs, GraphDepth, getModuleUriPrefix } from '@lwrjs/shared-utils';
1
+ import { kebabCaseToModuleSpecifer, getModuleGraphs, GraphDepth, getModuleUriPrefix, } from '@lwrjs/shared-utils';
2
2
  import { AppResourceEnum, getAppSpecifier } from '@lwrjs/app-service/identity';
3
3
  import { generateHtmlTag, getModuleResource, getModuleResourceByUri } from '../utils.js';
4
4
  import { flattenCustomElements, getViewBootstrapConfigurationResource, getViewHmrConfigurationResource, } from './utils.js';
@@ -35,6 +35,8 @@ export async function getHtmlResources(view, viewParams, resourceContext) {
35
35
  const imports = {};
36
36
  // Collection of root view component specifiers
37
37
  const rootComponents = [];
38
+ // Collection of root view component properties, used for SSR hydration
39
+ const rootProperties = {};
38
40
  // Collection of modules specifiers that MUST be loaded in the view
39
41
  const requiredAmdModules = [];
40
42
  // Collection of modules that will be loaded in the view
@@ -108,10 +110,11 @@ export async function getHtmlResources(view, viewParams, resourceContext) {
108
110
  }
109
111
  }
110
112
  // ------- View related custom element moduleResources
113
+ const isSSR = view.bootstrap?.experimentalSSR;
111
114
  const customElementsRecords = [];
112
- const flattenedElements = flattenCustomElements(customElements);
113
- await Promise.all(flattenedElements.map(async ({ tagName: element }) => {
114
- const graph = await getModuleGraphs(kebabcaseToCamelcase(element), { includeUris: true, includeLinkedDefinitions: true, depth }, moduleRegistry, bundle ? moduleBundler : moduleRegistry, runtimeEnvironment, runtimeParams ? runtimeParams : {}, visitedCache);
115
+ const flattenedElements = flattenCustomElements(customElements, isSSR);
116
+ await Promise.all(flattenedElements.map(async ({ tagName: element, props }) => {
117
+ const graph = await getModuleGraphs(kebabCaseToModuleSpecifer(element), { includeUris: true, includeLinkedDefinitions: true, depth }, moduleRegistry, bundle ? moduleBundler : moduleRegistry, runtimeEnvironment, runtimeParams ? runtimeParams : {}, visitedCache);
115
118
  // add to the viewRecord
116
119
  customElementsRecords.push({ elementName: element, flatGraph: graph });
117
120
  // PRELOAD custom element static deps as link resource
@@ -121,6 +124,10 @@ export async function getHtmlResources(view, viewParams, resourceContext) {
121
124
  // ADD register custom elements as a uri addressable rootComponents
122
125
  rootComponents.push(specifier);
123
126
  imports[specifier] = uri;
127
+ // ADD properties for each rootComponent if SSR is on
128
+ if (isSSR && props) {
129
+ rootProperties[specifier] = props;
130
+ }
124
131
  if (isAMD) {
125
132
  preloadAmdModules.push(specifier);
126
133
  for (const staticDep of graph.graphs[0].static) {
@@ -149,6 +156,7 @@ export async function getHtmlResources(view, viewParams, resourceContext) {
149
156
  default: getModuleUriPrefix(runtimeEnvironment, runtimeParams),
150
157
  },
151
158
  rootComponents,
159
+ rootProperties: isSSR ? rootProperties : undefined,
152
160
  ...(isAMD && { requiredModules: requiredAmdModules }),
153
161
  ...(isAMD && { preloadModules: preloadAmdModules }),
154
162
  }, runtimeEnvironment, runtimeParams));
@@ -2,5 +2,5 @@ import { ClientBootstrapConfig, RuntimeEnvironment, RuntimeParams, ResourceDefin
2
2
  import { View, ViewInfo } from '@lwrjs/types';
3
3
  export declare function getViewBootstrapConfigurationResource(viewInfo: ViewInfo, config: ClientBootstrapConfig, runtimeEnvironment: RuntimeEnvironment, runtimeParams?: RuntimeParams): ResourceDefinition;
4
4
  export declare function getViewHmrConfigurationResource(view: View, viewMetadata: RenderedViewMetadata): ResourceDefinition;
5
- export declare function flattenCustomElements(arr: CustomElementReference[]): CustomElementReference[];
5
+ export declare function flattenCustomElements(arr: CustomElementReference[], isSSR?: boolean): CustomElementReference[];
6
6
  //# sourceMappingURL=utils.d.ts.map
@@ -76,16 +76,19 @@ export function getViewHmrConfigurationResource(view, viewMetadata) {
76
76
  content: configString,
77
77
  };
78
78
  }
79
- export function flattenCustomElements(arr) {
79
+ export function flattenCustomElements(arr, isSSR = false) {
80
80
  const ret = [];
81
81
  const visitedTags = new Set();
82
82
  function flatten(arr) {
83
83
  for (const val of arr) {
84
- const { tagName, children } = val;
84
+ const { tagName, children, props } = val;
85
85
  if (!visitedTags.has(tagName)) {
86
- ret.push({
87
- tagName,
88
- });
86
+ if (isSSR) {
87
+ ret.push({ tagName, props });
88
+ }
89
+ else {
90
+ ret.push({ tagName });
91
+ }
89
92
  visitedTags.add(tagName);
90
93
  }
91
94
  if (children) {
@@ -1,4 +1,4 @@
1
- import { kebabcaseToCamelcase, toImportMetadata, getModuleGraphs, getMappingUriPrefix, GraphDepth, } from '@lwrjs/shared-utils';
1
+ import { kebabCaseToModuleSpecifer, toImportMetadata, getModuleGraphs, getMappingUriPrefix, GraphDepth, } from '@lwrjs/shared-utils';
2
2
  import { AppResourceEnum, getAppSpecifier } from '@lwrjs/app-service/identity';
3
3
  import { generateHtmlTag, getModuleResource, getModuleResourceByUri } from '../utils.js';
4
4
  import { flattenCustomElements, getViewBootstrapConfigurationResource, getViewHmrConfigurationResource, } from './utils.js';
@@ -35,6 +35,8 @@ export async function getHtmlResources(view, viewParams, resourceContext) {
35
35
  const imports = {};
36
36
  // Collection of root view component specifiers
37
37
  const rootComponents = [];
38
+ // Collection of root view component properties, used for SSR hydration
39
+ const rootProperties = {};
38
40
  // Collection of modules specifiers that MUST be loaded in the view
39
41
  const requiredAmdModules = [];
40
42
  // Collection of modules that will be loaded in the view
@@ -108,10 +110,11 @@ export async function getHtmlResources(view, viewParams, resourceContext) {
108
110
  }
109
111
  let importMetadata = await toImportMetadata(bootstrapModuleGraph, { imports: {}, index: {} }, moduleRegistry, runtimeEnvironment, runtimeParams);
110
112
  // ------- View related custom element moduleResources
113
+ const isSSR = view.bootstrap?.experimentalSSR;
111
114
  const customElementsRecords = [];
112
- const flattenedElements = flattenCustomElements(customElements);
113
- await Promise.all(flattenedElements.map(async ({ tagName: element }) => {
114
- const graph = await getModuleGraphs(kebabcaseToCamelcase(element), { includeUris: true, includeLinkedDefinitions: true, depth }, moduleRegistry, bundle ? moduleBundler : moduleRegistry, runtimeEnvironment, runtimeParams ? runtimeParams : {}, visitedCache);
115
+ const flattenedElements = flattenCustomElements(customElements, isSSR);
116
+ await Promise.all(flattenedElements.map(async ({ tagName: element, props }) => {
117
+ const graph = await getModuleGraphs(kebabCaseToModuleSpecifer(element), { includeUris: true, includeLinkedDefinitions: true, depth }, moduleRegistry, bundle ? moduleBundler : moduleRegistry, runtimeEnvironment, runtimeParams ? runtimeParams : {}, visitedCache);
115
118
  // add to the viewRecord
116
119
  customElementsRecords.push({ elementName: element, flatGraph: graph });
117
120
  // PRELOAD custom element static deps as link resource
@@ -121,6 +124,10 @@ export async function getHtmlResources(view, viewParams, resourceContext) {
121
124
  // ADD register custom elements as a uri addressable rootComponents
122
125
  rootComponents.push(specifier);
123
126
  imports[specifier] = uri;
127
+ // ADD properties for each rootComponent if SSR is on
128
+ if (isSSR && props) {
129
+ rootProperties[specifier] = props;
130
+ }
124
131
  if (isAMD) {
125
132
  preloadAmdModules.push(specifier);
126
133
  for (const staticDep of graph.graphs[0].static) {
@@ -148,6 +155,7 @@ export async function getHtmlResources(view, viewParams, resourceContext) {
148
155
  imports: importMetadata?.imports,
149
156
  index: importMetadata?.index,
150
157
  rootComponents,
158
+ rootProperties: isSSR ? rootProperties : undefined,
151
159
  ...(isAMD && { requiredModules: requiredAmdModules }),
152
160
  ...(isAMD && { preloadModules: preloadAmdModules }),
153
161
  }, runtimeEnvironment, runtimeParams));
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.7.0-alpha.3",
7
+ "version": "0.7.0-alpha.7",
8
8
  "homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
9
9
  "repository": {
10
10
  "type": "git",
@@ -30,15 +30,15 @@
30
30
  "build/**/*.d.ts"
31
31
  ],
32
32
  "dependencies": {
33
- "@lwrjs/app-service": "0.7.0-alpha.3",
34
- "@lwrjs/diagnostics": "0.7.0-alpha.3",
35
- "@lwrjs/shared-utils": "0.7.0-alpha.3"
33
+ "@lwrjs/app-service": "0.7.0-alpha.7",
34
+ "@lwrjs/diagnostics": "0.7.0-alpha.7",
35
+ "@lwrjs/shared-utils": "0.7.0-alpha.7"
36
36
  },
37
37
  "devDependencies": {
38
- "@lwrjs/types": "0.7.0-alpha.3"
38
+ "@lwrjs/types": "0.7.0-alpha.7"
39
39
  },
40
40
  "engines": {
41
41
  "node": ">=14.15.4 <17"
42
42
  },
43
- "gitHead": "5331416846f2de30b42a6c17f9ef723de2f30271"
43
+ "gitHead": "37d42307c304716834ce39944d5677e95d04a63a"
44
44
  }