enigmatic 0.21.5 → 0.21.6
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 +14 -3
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, mount, style, fn) => {
|
|
74
|
+
customElements.define(name, class extends HTMLElement {
|
|
75
|
+
connectedCallback() {
|
|
76
|
+
Object.assign(this.style, style)
|
|
77
|
+
if (mount) mount()
|
|
78
|
+
Object.assign(this, fn)
|
|
79
|
+
Object.keys(fn).filter(k=>k.match(/click/)).forEach(k=>{
|
|
80
|
+
this.addEventListener(k, fn[k], true)
|
|
81
|
+
})
|
|
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
|
@@ -8,21 +8,32 @@
|
|
|
8
8
|
|
|
9
9
|
<div id='par' fetch='[{"id": 1, "control": "input"},{"id": 2, "control": "select"}]'>
|
|
10
10
|
<div>{control}</div>
|
|
11
|
-
<test-element id="{id}"></test-element>
|
|
11
|
+
<test-element id="a{id}"></test-element>
|
|
12
12
|
<br>
|
|
13
13
|
<!--IGNORE-->
|
|
14
14
|
ignore this
|
|
15
15
|
<!--ENDIGNORE-->
|
|
16
16
|
</div>
|
|
17
|
-
|
|
18
17
|
</section>
|
|
19
18
|
<div class="bg-yellow"></div>
|
|
20
19
|
</body>
|
|
21
20
|
|
|
22
21
|
<script>
|
|
22
|
+
e('test-element', null, {border: '4px green solid'}, {
|
|
23
|
+
set: o=>console.log(o),
|
|
24
|
+
click: x=>alert()
|
|
25
|
+
})
|
|
26
|
+
/*
|
|
27
|
+
More verbose:
|
|
23
28
|
customElements.define('test-element', class extends HTMLElement {
|
|
29
|
+
connectedCallback() {
|
|
30
|
+
this.style.border = '3px black solid'
|
|
31
|
+
}
|
|
24
32
|
set(o) {
|
|
25
33
|
this.innerHTML = `<${o.control}></${o.control}>`
|
|
26
34
|
}
|
|
27
|
-
|
|
35
|
+
myfunc() {
|
|
36
|
+
alert('custom func')
|
|
37
|
+
}
|
|
38
|
+
})*/
|
|
28
39
|
</script>
|