enigmatic 0.21.5 → 0.21.7
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/enigmatic.css +0 -1
- package/enigmatic.js +17 -2
- package/package.json +1 -1
- package/tests/test.html +21 -5
package/enigmatic.css
CHANGED
package/enigmatic.js
CHANGED
|
@@ -70,9 +70,22 @@ w.flatten = (obj, text) => {
|
|
|
70
70
|
return htmls
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
+
w.e = (name, fn = {}, style = {}) => {
|
|
74
|
+
customElements.define(name, class extends HTMLElement {
|
|
75
|
+
connectedCallback() {
|
|
76
|
+
Object.assign(this.style, style)
|
|
77
|
+
Object.assign(this, fn)
|
|
78
|
+
Object.keys(fn).filter(k=>k.match(/click/)).forEach(k=>{
|
|
79
|
+
this.addEventListener(k, fn[k], true)
|
|
80
|
+
})
|
|
81
|
+
if(this.init) this.init(this)
|
|
82
|
+
}
|
|
83
|
+
})
|
|
84
|
+
}
|
|
85
|
+
|
|
73
86
|
w.element = (
|
|
74
87
|
name,
|
|
75
|
-
{ onMount = x => x, beforeData = (x) => x, style, template = '' }
|
|
88
|
+
{ onMount = x => x, beforeData = (x) => x, style, template = '', fn = {} }
|
|
76
89
|
) => {
|
|
77
90
|
customElements.define(
|
|
78
91
|
name,
|
|
@@ -86,6 +99,7 @@ w.element = (
|
|
|
86
99
|
}
|
|
87
100
|
this.template = template
|
|
88
101
|
if (!this.template.match('{')) this.innerHTML = this.template
|
|
102
|
+
Object.assign(this, fn)
|
|
89
103
|
}
|
|
90
104
|
set(o) {
|
|
91
105
|
o = beforeData(o)
|
|
@@ -162,7 +176,8 @@ w.start = async () => {
|
|
|
162
176
|
e.innerHTML = w.flatten(obj, template) + ignore
|
|
163
177
|
let pos = 0
|
|
164
178
|
for(c in e.children) {
|
|
165
|
-
|
|
179
|
+
const ele = e.children[c]
|
|
180
|
+
if(typeof ele === 'object' && 'set' in ele)
|
|
166
181
|
e.children[c].set(obj[pos++])
|
|
167
182
|
}
|
|
168
183
|
return obj
|
package/package.json
CHANGED
package/tests/test.html
CHANGED
|
@@ -5,24 +5,40 @@
|
|
|
5
5
|
<body style="--cols:1fr 10fr 1fr; --rows:1fr">
|
|
6
6
|
<div class="bg-black">a</div>
|
|
7
7
|
<section class="bg-white">
|
|
8
|
-
|
|
9
8
|
<div id='par' fetch='[{"id": 1, "control": "input"},{"id": 2, "control": "select"}]'>
|
|
10
9
|
<div>{control}</div>
|
|
11
|
-
<test-element id="{id}"></test-element>
|
|
10
|
+
<test-element id="a{id}"></test-element>
|
|
12
11
|
<br>
|
|
13
12
|
<!--IGNORE-->
|
|
14
|
-
|
|
13
|
+
<test-link></test-link>
|
|
15
14
|
<!--ENDIGNORE-->
|
|
16
15
|
</div>
|
|
17
|
-
|
|
18
16
|
</section>
|
|
19
17
|
<div class="bg-yellow"></div>
|
|
20
18
|
</body>
|
|
21
19
|
|
|
22
20
|
<script>
|
|
21
|
+
e('test-element', {
|
|
22
|
+
set: o=>console.log(o),
|
|
23
|
+
click: ev=>alert()
|
|
24
|
+
}, { border: '4px green solid' })
|
|
25
|
+
|
|
26
|
+
e('test-link', {
|
|
27
|
+
init: e => e.innerHTML = '<a>Click me</a>',
|
|
28
|
+
click: ev => alert()
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
/*
|
|
32
|
+
More verbose:
|
|
23
33
|
customElements.define('test-element', class extends HTMLElement {
|
|
34
|
+
connectedCallback() {
|
|
35
|
+
this.style.border = '3px black solid'
|
|
36
|
+
}
|
|
24
37
|
set(o) {
|
|
25
38
|
this.innerHTML = `<${o.control}></${o.control}>`
|
|
26
39
|
}
|
|
27
|
-
|
|
40
|
+
myfunc() {
|
|
41
|
+
alert('custom func')
|
|
42
|
+
}
|
|
43
|
+
})*/
|
|
28
44
|
</script>
|