leanweb 3.10.1 → 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 CHANGED
@@ -54,7 +54,7 @@ const buildModule = (projectPath) => {
54
54
  imports.push(url);
55
55
  return '';
56
56
  });
57
- const jsModule = `const sheet = new CSSStyleSheet();\nsheet.replaceSync(${JSON.stringify(inlineCss)});\nglobalThis.__lw_globalStyleSheet = sheet;\nglobalThis.__lw_globalStyleImports = ${JSON.stringify(imports)};\n`;
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,6 +1,6 @@
1
1
  {
2
2
  "name": "leanweb",
3
- "version": "3.10.1",
3
+ "version": "3.10.3",
4
4
  "description": "Builds framework agnostic web components.",
5
5
  "bin": {
6
6
  "leanweb": "leanweb.js",
@@ -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 = globalThis.leanweb ?? {
5
- componentsListeningOnUrlChanges: [],
6
- eventBus: new LWEventBus(),
7
- updateComponents(...tagNames) {
8
- if (tagNames?.length) {
9
- tagNames.forEach(tagName => {
10
- leanweb.eventBus.dispatchEvent(tagName);
11
- });
12
- } else {
13
- leanweb.eventBus.dispatchEvent('update');
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
- get urlHashPath() {
35
- return this.urlHash.split('?')[0];
18
+ Object.defineProperties(leanweb, {
19
+ urlHash: {
20
+ set(hash) { location.hash = hash; },
21
+ get() { return location.hash; }
36
22
  },
37
-
38
- set urlHashParams(hashParams) {
39
- if (!hashParams) {
40
- return;
41
- }
42
-
43
- const paramArray = [];
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
- this.urlHash = this.urlHashPath + '?' + paramArray.join('&');
31
+ },
32
+ get() { return this.urlHash.split('?')[0]; }
55
33
  },
34
+ urlHashParams: {
35
+ set(hashParams) {
36
+ if (!hashParams) {
37
+ return;
38
+ }
56
39
 
57
- get urlHashParams() {
58
- const ret = {};
59
- const s = this.urlHash.split('?');
60
- if (s.length > 1) {
61
- const p = new URLSearchParams(s[1]);
62
- p.forEach((v, k) => {
63
- if (ret[k] === undefined) {
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
- ret[k] = [ret[k], v];
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,8 +107,8 @@ 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.__lw_globalStyleSheet, componentSheet];
114
- globalThis.__lw_globalStyleImports?.forEach(url => {
110
+ this.shadowRoot.adoptedStyleSheets = [globalThis.leanweb.__lw_globalStyleSheet, componentSheet].filter(Boolean);
111
+ globalThis.leanweb.__lw_globalStyleImports?.forEach(url => {
115
112
  const link = document.createElement('link');
116
113
  link.rel = 'stylesheet';
117
114
  link.href = url;