leanweb 3.10.2 → 3.10.3
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/commands/build.js +1 -1
- package/package.json +1 -1
- package/templates/lib/lw-element.js +59 -62
package/commands/build.js
CHANGED
|
@@ -54,7 +54,7 @@ const buildModule = (projectPath) => {
|
|
|
54
54
|
imports.push(url);
|
|
55
55
|
return '';
|
|
56
56
|
});
|
|
57
|
-
const jsModule = `globalThis.leanweb
|
|
57
|
+
const jsModule = `globalThis.leanweb ??= {};\nconst sheet = new CSSStyleSheet();\nsheet.replaceSync(${JSON.stringify(inlineCss)});\nglobalThis.leanweb.__lw_globalStyleSheet = sheet;\nglobalThis.leanweb.__lw_globalStyleImports = ${JSON.stringify(imports)};\n`;
|
|
58
58
|
utils.writeIfChanged(`${utils.dirs.build}/global-styles.js`, jsModule);
|
|
59
59
|
};
|
|
60
60
|
|
package/package.json
CHANGED
|
@@ -1,77 +1,74 @@
|
|
|
1
1
|
import * as parser from './lw-expr-parser.js';
|
|
2
2
|
import LWEventBus from './lw-event-bus.js';
|
|
3
3
|
|
|
4
|
-
globalThis.leanweb
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
set urlHash(hash) {
|
|
18
|
-
location.hash = hash;
|
|
19
|
-
},
|
|
20
|
-
|
|
21
|
-
get urlHash() {
|
|
22
|
-
return location.hash;
|
|
23
|
-
},
|
|
24
|
-
|
|
25
|
-
set urlHashPath(hashPath) {
|
|
26
|
-
const s = this.urlHash.split('?');
|
|
27
|
-
if (s.length === 1) {
|
|
28
|
-
this.urlHash = hashPath;
|
|
29
|
-
} else if (s.length > 1) {
|
|
30
|
-
this.urlHash = hashPath + '?' + s[1];
|
|
31
|
-
}
|
|
32
|
-
},
|
|
4
|
+
globalThis.leanweb ??= {};
|
|
5
|
+
|
|
6
|
+
leanweb.componentsListeningOnUrlChanges = [];
|
|
7
|
+
leanweb.eventBus = new LWEventBus();
|
|
8
|
+
leanweb.updateComponents = function (...tagNames) {
|
|
9
|
+
if (tagNames?.length) {
|
|
10
|
+
tagNames.forEach(tagName => {
|
|
11
|
+
leanweb.eventBus.dispatchEvent(tagName);
|
|
12
|
+
});
|
|
13
|
+
} else {
|
|
14
|
+
leanweb.eventBus.dispatchEvent('update');
|
|
15
|
+
}
|
|
16
|
+
};
|
|
33
17
|
|
|
34
|
-
|
|
35
|
-
|
|
18
|
+
Object.defineProperties(leanweb, {
|
|
19
|
+
urlHash: {
|
|
20
|
+
set(hash) { location.hash = hash; },
|
|
21
|
+
get() { return location.hash; }
|
|
36
22
|
},
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
Object.keys(hashParams).forEach(key => {
|
|
45
|
-
const value = hashParams[key];
|
|
46
|
-
if (Array.isArray(value)) {
|
|
47
|
-
value.forEach(v => {
|
|
48
|
-
paramArray.push(key + '=' + encodeURIComponent(v));
|
|
49
|
-
});
|
|
50
|
-
} else {
|
|
51
|
-
paramArray.push(key + '=' + encodeURIComponent(value));
|
|
23
|
+
urlHashPath: {
|
|
24
|
+
set(hashPath) {
|
|
25
|
+
const s = this.urlHash.split('?');
|
|
26
|
+
if (s.length === 1) {
|
|
27
|
+
this.urlHash = hashPath;
|
|
28
|
+
} else if (s.length > 1) {
|
|
29
|
+
this.urlHash = hashPath + '?' + s[1];
|
|
52
30
|
}
|
|
53
|
-
}
|
|
54
|
-
|
|
31
|
+
},
|
|
32
|
+
get() { return this.urlHash.split('?')[0]; }
|
|
55
33
|
},
|
|
34
|
+
urlHashParams: {
|
|
35
|
+
set(hashParams) {
|
|
36
|
+
if (!hashParams) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
56
39
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
ret[k] = v;
|
|
65
|
-
} else if (Array.isArray(ret[k])) {
|
|
66
|
-
ret[k].push(v);
|
|
40
|
+
const paramArray = [];
|
|
41
|
+
Object.keys(hashParams).forEach(key => {
|
|
42
|
+
const value = hashParams[key];
|
|
43
|
+
if (Array.isArray(value)) {
|
|
44
|
+
value.forEach(v => {
|
|
45
|
+
paramArray.push(key + '=' + encodeURIComponent(v));
|
|
46
|
+
});
|
|
67
47
|
} else {
|
|
68
|
-
|
|
48
|
+
paramArray.push(key + '=' + encodeURIComponent(value));
|
|
69
49
|
}
|
|
70
50
|
});
|
|
51
|
+
this.urlHash = this.urlHashPath + '?' + paramArray.join('&');
|
|
52
|
+
},
|
|
53
|
+
get() {
|
|
54
|
+
const ret = {};
|
|
55
|
+
const s = this.urlHash.split('?');
|
|
56
|
+
if (s.length > 1) {
|
|
57
|
+
const p = new URLSearchParams(s[1]);
|
|
58
|
+
p.forEach((v, k) => {
|
|
59
|
+
if (ret[k] === undefined) {
|
|
60
|
+
ret[k] = v;
|
|
61
|
+
} else if (Array.isArray(ret[k])) {
|
|
62
|
+
ret[k].push(v);
|
|
63
|
+
} else {
|
|
64
|
+
ret[k] = [ret[k], v];
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
return ret;
|
|
71
69
|
}
|
|
72
|
-
return ret;
|
|
73
70
|
}
|
|
74
|
-
};
|
|
71
|
+
});
|
|
75
72
|
|
|
76
73
|
globalThis.addEventListener('hashchange', () => {
|
|
77
74
|
leanweb.componentsListeningOnUrlChanges.forEach(component => {
|
|
@@ -110,7 +107,7 @@ export default class LWElement extends HTMLElement {
|
|
|
110
107
|
componentSheet.replaceSync(ast.css);
|
|
111
108
|
node.innerHTML = ast.html;
|
|
112
109
|
this.attachShadow({ mode: 'open' }).appendChild(node.content);
|
|
113
|
-
this.shadowRoot.adoptedStyleSheets = [globalThis.leanweb.__lw_globalStyleSheet, componentSheet];
|
|
110
|
+
this.shadowRoot.adoptedStyleSheets = [globalThis.leanweb.__lw_globalStyleSheet, componentSheet].filter(Boolean);
|
|
114
111
|
globalThis.leanweb.__lw_globalStyleImports?.forEach(url => {
|
|
115
112
|
const link = document.createElement('link');
|
|
116
113
|
link.rel = 'stylesheet';
|