enigmatic 0.29.0 → 0.29.1
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 +1 -1
- package/public/client.js +45 -16
package/package.json
CHANGED
package/public/client.js
CHANGED
|
@@ -2,6 +2,48 @@ window.api_url = "https://localhost:3000"
|
|
|
2
2
|
window.$ = document.querySelector.bind(document)
|
|
3
3
|
window.$$ = document.querySelectorAll.bind(document)
|
|
4
4
|
window.$c = (selector) => $0.closest(selector);
|
|
5
|
+
|
|
6
|
+
// Initialize custom elements
|
|
7
|
+
window.initCustomElements = function() {
|
|
8
|
+
Object.keys(window.custom || {}).forEach(tagName => {
|
|
9
|
+
$$(tagName).forEach(async el => {
|
|
10
|
+
const f = window.custom[tagName];
|
|
11
|
+
if (typeof f === 'function') {
|
|
12
|
+
el.innerHTML = await f();
|
|
13
|
+
} else if (f && typeof f.render === 'function') {
|
|
14
|
+
el.innerHTML = f.render();
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// Make window.custom a Proxy that auto-initializes when properties are added
|
|
21
|
+
if (!window.custom) window.custom = {};
|
|
22
|
+
const customProxy = new Proxy(window.custom, {
|
|
23
|
+
set(target, prop, value) {
|
|
24
|
+
target[prop] = value;
|
|
25
|
+
if (typeof value === 'function' || (value && typeof value.render === 'function')) {
|
|
26
|
+
setTimeout(() => {
|
|
27
|
+
$$(prop).forEach(async el => {
|
|
28
|
+
if (typeof value === 'function') {
|
|
29
|
+
el.innerHTML = await value();
|
|
30
|
+
} else {
|
|
31
|
+
el.innerHTML = value.render();
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}, 0);
|
|
35
|
+
}
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
Object.defineProperty(window, 'custom', {
|
|
40
|
+
get: () => customProxy,
|
|
41
|
+
set: (val) => {
|
|
42
|
+
Object.assign(customProxy, val || {});
|
|
43
|
+
},
|
|
44
|
+
configurable: true
|
|
45
|
+
});
|
|
46
|
+
|
|
5
47
|
window.state = new Proxy({}, {
|
|
6
48
|
set(obj, prop, value) {
|
|
7
49
|
obj[prop] = value
|
|
@@ -77,22 +119,9 @@ window.logout = function() {
|
|
|
77
119
|
window.location.href = `${window.api_url}/logout`
|
|
78
120
|
}
|
|
79
121
|
|
|
80
|
-
//
|
|
81
|
-
function initCustomElements() {
|
|
82
|
-
Object.keys(window.custom).forEach(tagName => {
|
|
83
|
-
$$(tagName).forEach(async el => {
|
|
84
|
-
const f = window.custom[tagName];
|
|
85
|
-
if (typeof f === 'function') {
|
|
86
|
-
el.innerHTML = await f();
|
|
87
|
-
} else if (f && typeof f.render === 'function') {
|
|
88
|
-
el.innerHTML = f.render();
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
|
|
122
|
+
// Auto-initialize on load
|
|
94
123
|
if (document.readyState === 'loading') {
|
|
95
|
-
document.addEventListener('DOMContentLoaded', initCustomElements);
|
|
124
|
+
document.addEventListener('DOMContentLoaded', window.initCustomElements);
|
|
96
125
|
} else {
|
|
97
|
-
initCustomElements();
|
|
126
|
+
window.initCustomElements();
|
|
98
127
|
}
|