@lwrjs/client-modules 0.10.0-alpha.2 → 0.10.0-alpha.4
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
import{BOOTSTRAP_END as e}from"lwr/metrics";import{logOperationStart as t}from"lwr/profiler";import{createElement as o}from"lwc";function
|
|
1
|
+
import{BOOTSTRAP_END as e}from"lwr/metrics";import{logOperationStart as t}from"lwr/profiler";import{createElement as o,hydrateComponent as r}from"lwc";function n(e,t){return o(e,{is:t})}function c(e){return e.replace(/\/v\/[a-zA-Z0-9-_.]+$/,"").replace("/","-").replace(/([A-Z])/g,(e=>`-${e.toLowerCase()}`))}const l=/-([a-z])/g;function d(e){return e.replace(l,(e=>e[1].toUpperCase()))}function i(o,l={}){if("undefined"!=typeof customElements&&"undefined"!=typeof document){const e=document.querySelector("[lwr-root]");o.forEach((([t,o])=>{const i=c(t);let p=document.body.querySelector(i);if(p){document.querySelectorAll(i).forEach((e=>{const t=e.dataset.lwrPropsId;if(t){const n=l[t]||{};r(e,o,n)}else{const t=n(i,o);for(const{name:o,value:r}of e.attributes){t.setAttribute(o,r);const e=d(o);e in t&&(t[e]=r)}for(;e.childNodes.length>0;)t.appendChild(e.childNodes[0]);e.parentElement.replaceChild(t,e)}}))}else p=n(i,o),e?e.appendChild(p):document.body.appendChild(p)}))}t({id:e})}export{d as getPropFromAttrName,i as init,c as toKebabCase};
|
|
@@ -4,7 +4,7 @@ import { logOperationStart } from 'lwr/profiler';
|
|
|
4
4
|
// TODO: This is a temporal workaround until https://github.com/salesforce/lwc/pull/2083 is sorted
|
|
5
5
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
6
6
|
// @ts-ignore
|
|
7
|
-
import { createElement } from 'lwc';
|
|
7
|
+
import { createElement, hydrateComponent } from 'lwc';
|
|
8
8
|
function initializeWebComponent(elementName, Ctor) {
|
|
9
9
|
return createElement(elementName, {
|
|
10
10
|
is: Ctor
|
|
@@ -41,7 +41,7 @@ export function getPropFromAttrName(propName) {
|
|
|
41
41
|
* bare specifier and corresponding LightningElement constructor
|
|
42
42
|
* @example - [['x/appRoot', appCtor], ['x/nav', navCtor]]
|
|
43
43
|
*/
|
|
44
|
-
export function init(rootModules) {
|
|
44
|
+
export function init(rootModules, ssrProps = {}) {
|
|
45
45
|
if (typeof customElements !== 'undefined' && typeof document !== 'undefined') {
|
|
46
46
|
const container = document.querySelector('[lwr-root]');
|
|
47
47
|
rootModules.forEach(([moduleSpecifier, ctor]) => {
|
|
@@ -66,24 +66,32 @@ export function init(rootModules) {
|
|
|
66
66
|
// we collect the attributes and we replace the element with the new synthetic contructor
|
|
67
67
|
const customElements = document.querySelectorAll(elementName);
|
|
68
68
|
customElements.forEach(customElement => {
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
69
|
+
const propsId = customElement.dataset.lwrPropsId;
|
|
70
|
+
if (propsId) {
|
|
71
|
+
// Hydrate an SSRed component
|
|
72
|
+
const props = ssrProps[propsId] || {};
|
|
73
|
+
hydrateComponent(customElement, ctor, props);
|
|
74
|
+
} else {
|
|
75
|
+
// Create a CSRed component
|
|
76
|
+
const newElement = initializeWebComponent(elementName, ctor);
|
|
77
|
+
for (const {
|
|
78
|
+
name,
|
|
79
|
+
value
|
|
80
|
+
} of customElement.attributes) {
|
|
81
|
+
newElement.setAttribute(name, value);
|
|
82
|
+
const prop = getPropFromAttrName(name);
|
|
83
|
+
if (prop in newElement) {
|
|
84
|
+
// Set attributes as properties too for reactivity
|
|
85
|
+
newElement[prop] = value;
|
|
86
|
+
}
|
|
79
87
|
}
|
|
80
|
-
}
|
|
81
88
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
89
|
+
// Move the children and replace the custom element
|
|
90
|
+
while (customElement.childNodes.length > 0) {
|
|
91
|
+
newElement.appendChild(customElement.childNodes[0]);
|
|
92
|
+
}
|
|
93
|
+
customElement.parentElement.replaceChild(newElement, customElement);
|
|
85
94
|
}
|
|
86
|
-
customElement.parentElement.replaceChild(newElement, customElement);
|
|
87
95
|
});
|
|
88
96
|
}
|
|
89
97
|
});
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.10.0-alpha.
|
|
7
|
+
"version": "0.10.0-alpha.4",
|
|
8
8
|
"homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@locker/sandbox": "0.19.0",
|
|
35
|
-
"@lwrjs/shared-utils": "0.10.0-alpha.
|
|
35
|
+
"@lwrjs/shared-utils": "0.10.0-alpha.4"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"rollup-plugin-terser": "^7.0.2"
|
|
@@ -47,7 +47,6 @@
|
|
|
47
47
|
"lwr/hmr",
|
|
48
48
|
"lwr/preInit",
|
|
49
49
|
"lwr/init",
|
|
50
|
-
"lwr/initSsr",
|
|
51
50
|
"lwr/servicesESM",
|
|
52
51
|
"lwr/lockerDefine",
|
|
53
52
|
"lwr/lockerSandbox",
|
|
@@ -58,5 +57,5 @@
|
|
|
58
57
|
"engines": {
|
|
59
58
|
"node": ">=16.0.0 <20"
|
|
60
59
|
},
|
|
61
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "f39a534d92fd3980b87839820f484729172e1067"
|
|
62
61
|
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
// TODO: This is a temporal workaround until https://github.com/salesforce/lwc/pull/2564 is sorted
|
|
2
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
3
|
-
// @ts-ignore
|
|
4
|
-
import { hydrateComponent } from 'lwc';
|
|
5
|
-
export function toKebabCase(specifier) {
|
|
6
|
-
return specifier.replace(/\/v\/[a-zA-Z0-9-_.]+$/, '').replace('/', '-').replace(/([A-Z])/g, c => `-${c.toLowerCase()}`);
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Hydrate the given component(s) which were server-side rendered (see the lwc-ssr/viewTransformer).
|
|
11
|
-
* @param components - An array of arrays, each one holding:
|
|
12
|
-
* 0. a bare specifier
|
|
13
|
-
* 1. the corresponding LightningElement constructor
|
|
14
|
-
* @param ssrProps - map of properties to set on each component
|
|
15
|
-
* @example - [['x/appRoot', appCtor], ['x/nav', navCtor]]
|
|
16
|
-
*/
|
|
17
|
-
export function init(components, ssrProps = {}) {
|
|
18
|
-
if (typeof document !== 'undefined') {
|
|
19
|
-
components.forEach(([moduleSpecifier, ctor]) => {
|
|
20
|
-
// Kebab-case the specifier
|
|
21
|
-
const elementName = toKebabCase(moduleSpecifier);
|
|
22
|
-
// Find all instances of the component in the document, and hydrate them all
|
|
23
|
-
const customElements = document.querySelectorAll(elementName);
|
|
24
|
-
customElements.forEach(customElement => {
|
|
25
|
-
const propsId = customElement.dataset.lwrPropsId;
|
|
26
|
-
const props = ssrProps[propsId] || {};
|
|
27
|
-
hydrateComponent(customElement, ctor, props);
|
|
28
|
-
});
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
}
|