enigmatic 0.29.1 → 0.31.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "enigmatic",
3
- "version": "0.29.1",
3
+ "version": "0.31.0",
4
4
  "unpkg": "./public/client.js",
5
5
  "scripts": {
6
6
  "start": "bun --hot ./bun-server.js",
package/public/client.js CHANGED
@@ -25,10 +25,14 @@ const customProxy = new Proxy(window.custom, {
25
25
  if (typeof value === 'function' || (value && typeof value.render === 'function')) {
26
26
  setTimeout(() => {
27
27
  $$(prop).forEach(async el => {
28
- if (typeof value === 'function') {
29
- el.innerHTML = await value();
30
- } else {
31
- el.innerHTML = value.render();
28
+ try {
29
+ if (typeof value === 'function') {
30
+ el.innerHTML = await value();
31
+ } else if (value && typeof value.render === 'function') {
32
+ el.innerHTML = value.render();
33
+ }
34
+ } catch (e) {
35
+ console.error('Custom element error:', e);
32
36
  }
33
37
  });
34
38
  }, 0);
@@ -39,7 +43,8 @@ const customProxy = new Proxy(window.custom, {
39
43
  Object.defineProperty(window, 'custom', {
40
44
  get: () => customProxy,
41
45
  set: (val) => {
42
- Object.assign(customProxy, val || {});
46
+ Object.keys(val || {}).forEach(key => customProxy[key] = val[key]);
47
+ window.initCustomElements();
43
48
  },
44
49
  configurable: true
45
50
  });
@@ -119,9 +124,14 @@ window.logout = function() {
119
124
  window.location.href = `${window.api_url}/logout`
120
125
  }
121
126
 
122
- // Auto-initialize on load
127
+ // Auto-initialize on load and watch for new elements
123
128
  if (document.readyState === 'loading') {
124
- document.addEventListener('DOMContentLoaded', window.initCustomElements);
129
+ document.addEventListener('DOMContentLoaded', () => {
130
+ window.initCustomElements();
131
+ // Watch for new custom elements added to DOM
132
+ new MutationObserver(() => window.initCustomElements()).observe(document.body, { childList: true, subtree: true });
133
+ });
125
134
  } else {
126
135
  window.initCustomElements();
136
+ new MutationObserver(() => window.initCustomElements()).observe(document.body, { childList: true, subtree: true });
127
137
  }
@@ -0,0 +1,3 @@
1
+ <script src='https://unpkg.com/enigmatic@0.30.0/public/client.js'></script>
2
+
3
+ <hello-world></hello-world>