enigmatic 0.11.2 → 0.11.4
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.js +31 -31
- package/package.json +1 -1
- package/test-flatten.html +8 -0
package/enigmatic.js
CHANGED
|
@@ -41,8 +41,9 @@ w.flatten = (obj, text) => {
|
|
|
41
41
|
for (let k in obj) {
|
|
42
42
|
let html = text.replaceAll('{$key}', k)
|
|
43
43
|
for (let j in obj[k]) {
|
|
44
|
-
|
|
45
|
-
html = html.replaceAll(
|
|
44
|
+
const val = typeof obj[k] === 'object' ? obj[k][j] : obj[k]
|
|
45
|
+
html = html.replaceAll('{_key_}', j).replaceAll('{_val_}', val)
|
|
46
|
+
html = html.replaceAll(`{${j}}`, val)
|
|
46
47
|
}
|
|
47
48
|
htmls += html
|
|
48
49
|
}
|
|
@@ -68,12 +69,9 @@ w.element = (
|
|
|
68
69
|
if (!this.template.match('{')) this.innerHTML = this.template
|
|
69
70
|
}
|
|
70
71
|
set(o) {
|
|
71
|
-
this.innerHTML = ''
|
|
72
72
|
o = beforeData(o)
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
o.map((i) => (this.innerHTML += m(i)))
|
|
76
|
-
return true
|
|
73
|
+
w.flatten(o, this.template)
|
|
74
|
+
return o
|
|
77
75
|
}
|
|
78
76
|
}
|
|
79
77
|
)
|
|
@@ -85,22 +83,22 @@ if (window.components) {
|
|
|
85
83
|
|
|
86
84
|
/////// State, data, and reactivity
|
|
87
85
|
w.state = new Proxy({}, {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
}
|
|
96
|
-
obj[prop] = value
|
|
97
|
-
return value
|
|
98
|
-
},
|
|
99
|
-
get: (obj, prop, receiver) => {
|
|
100
|
-
if (prop == '_all') return obj
|
|
101
|
-
return obj[prop]
|
|
86
|
+
set: (obj, prop, value) => {
|
|
87
|
+
console.log(prop, value)
|
|
88
|
+
if (this[prop] === value) {
|
|
89
|
+
return true
|
|
90
|
+
}
|
|
91
|
+
for (const e of $$(`[data=${prop}]`)) {
|
|
92
|
+
if (e.set) e.set(value)
|
|
102
93
|
}
|
|
94
|
+
obj[prop] = value
|
|
95
|
+
return value
|
|
96
|
+
},
|
|
97
|
+
get: (obj, prop, receiver) => {
|
|
98
|
+
if (prop == '_all') return obj
|
|
99
|
+
return obj[prop]
|
|
103
100
|
}
|
|
101
|
+
}
|
|
104
102
|
)
|
|
105
103
|
|
|
106
104
|
w.save = (obj, name) => {
|
|
@@ -147,19 +145,21 @@ w.start = async () => {
|
|
|
147
145
|
let dta = e.attr?.data
|
|
148
146
|
if (dta) {
|
|
149
147
|
console.log(`processing ${e}`)
|
|
150
|
-
if (e.
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
e.innerHTML
|
|
148
|
+
if (!e.set) {
|
|
149
|
+
if (e.innerHTML) {
|
|
150
|
+
e.template = e.innerHTML
|
|
151
|
+
if (e.innerHTML.match('{')) {
|
|
152
|
+
e.innerHTML = ''
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
e.set = (o) => {
|
|
156
|
+
e.innerHTML = w.flatten(o, e.template)
|
|
154
157
|
}
|
|
155
|
-
}
|
|
156
|
-
e.set = (o) => {
|
|
157
|
-
e.innerHTML = w.flatten(o, e.template)
|
|
158
158
|
}
|
|
159
159
|
if (e.attr?.value) {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
160
|
+
let o = e.attr.value
|
|
161
|
+
try { o = JSON.parse(o) } catch (e) { }
|
|
162
|
+
w.state[dta] = o
|
|
163
163
|
}
|
|
164
164
|
}
|
|
165
165
|
})
|
package/package.json
CHANGED
package/test-flatten.html
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
<button onclick='window.testone()'>Test one</button>
|
|
8
8
|
<button onclick='window.testtwo()'>Test two</button>
|
|
9
|
+
<button onclick='window.testthree()'>Test three</button>
|
|
9
10
|
|
|
10
11
|
<script type="module">
|
|
11
12
|
window.testone = () => {
|
|
@@ -22,4 +23,11 @@
|
|
|
22
23
|
}
|
|
23
24
|
state.akey = testt
|
|
24
25
|
}
|
|
26
|
+
window.testthree = () => {
|
|
27
|
+
const testt = {
|
|
28
|
+
"k1": 'val1',
|
|
29
|
+
"k2": 'val2',
|
|
30
|
+
}
|
|
31
|
+
state.akey = testt
|
|
32
|
+
}
|
|
25
33
|
</script>
|