enigmatic 0.10.2 → 0.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/{components.mjs → components.js} +3 -2
- package/enigmatic.js +14 -7
- package/index.html +8 -1
- package/package.json +1 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
window.components = {
|
|
2
2
|
'hello-world': {
|
|
3
3
|
style: 'color: red',
|
|
4
|
+
onMount: async x => console.log('mounted h-w'),
|
|
4
5
|
template: 'Hello World'
|
|
5
6
|
},
|
|
6
7
|
'random-users': {
|
|
@@ -9,8 +10,8 @@ window.components = {
|
|
|
9
10
|
beforeData: x => x.results[0].name.first = 'John'
|
|
10
11
|
},
|
|
11
12
|
'tailwind-example': {
|
|
12
|
-
template: '<div class="bg-blue-
|
|
13
|
-
onMount: e => loadCSS('https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css')
|
|
13
|
+
template: '<div class="bg-blue-300 text-white font-bold py-2 px-4 rounded">I am Tailwind</div>',
|
|
14
|
+
onMount: async e => await loadCSS('https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css')
|
|
14
15
|
}
|
|
15
16
|
}
|
|
16
17
|
|
package/enigmatic.js
CHANGED
|
@@ -40,16 +40,18 @@ w.child = (type = 'div', html = '') => {
|
|
|
40
40
|
|
|
41
41
|
// Custom element
|
|
42
42
|
|
|
43
|
-
if(window.components) {
|
|
44
|
-
for(let name in window.components)
|
|
45
|
-
w.element(name, window.components[name])
|
|
46
|
-
}
|
|
47
43
|
w.element = (name, {onMount = x=>x, beforeData = x=>x, style, template = ''}) => {
|
|
48
44
|
customElements.define(name, class extends HTMLElement {
|
|
49
|
-
connectedCallback(props) {
|
|
50
|
-
onMount()
|
|
51
|
-
if (style)
|
|
45
|
+
async connectedCallback(props) {
|
|
46
|
+
await onMount()
|
|
47
|
+
if (style) {
|
|
48
|
+
const s = document.createElement('style')
|
|
49
|
+
s.innerHTML = `${name} {${style}}`
|
|
50
|
+
d.body.appendChild(s);
|
|
51
|
+
}
|
|
52
52
|
this.template = template;
|
|
53
|
+
if(!this.template.match('{'))
|
|
54
|
+
this.innerHTML = this.template
|
|
53
55
|
}
|
|
54
56
|
set(o) {
|
|
55
57
|
this.innerHTML = ''
|
|
@@ -61,6 +63,11 @@ w.element = (name, {onMount = x=>x, beforeData = x=>x, style, template = ''}) =>
|
|
|
61
63
|
})
|
|
62
64
|
}
|
|
63
65
|
|
|
66
|
+
if (window.components) {
|
|
67
|
+
for (let name in window.components)
|
|
68
|
+
w.element(name, window.components[name])
|
|
69
|
+
}
|
|
70
|
+
|
|
64
71
|
// Data
|
|
65
72
|
|
|
66
73
|
w.state = new Proxy(
|
package/index.html
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
<script src='components.js'></script>
|
|
1
2
|
<script src='enigmatic.js'></script>
|
|
2
3
|
|
|
3
|
-
<div data='key'>This is data: {o.a}</div>
|
|
4
|
+
<div data='key'>This is data: {o.a}</div>
|
|
5
|
+
<hello-world></hello-world>
|
|
6
|
+
<tailwind-example></tailwind-example>
|
|
7
|
+
|
|
8
|
+
<script>
|
|
9
|
+
main = x => state.key = [{a: 'one'}, { a: 'two' }]
|
|
10
|
+
</script>
|
package/package.json
CHANGED