pawajs 1.3.9 → 1.4.0
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/CHANGELOG.md +3 -0
- package/merger/for.js +4 -4
- package/package.json +1 -1
- package/utils.js +3 -19
package/CHANGELOG.md
ADDED
package/merger/for.js
CHANGED
|
@@ -48,9 +48,9 @@ export const merger_for = (el, stateContext, attr, arrayName, arrayItem, indexes
|
|
|
48
48
|
const removeElement = []
|
|
49
49
|
|
|
50
50
|
const newElementsMap = new Map()
|
|
51
|
-
Array.from(div.children).forEach(child => {
|
|
52
|
-
const key = child.getAttribute('for-key')
|
|
53
|
-
if (key) newElementsMap.set(key, child)
|
|
51
|
+
Array.from(div.children).forEach((child,i) => {
|
|
52
|
+
const key = child.getAttribute('for-key') || i
|
|
53
|
+
if (key || key === 0) newElementsMap.set(key, child)
|
|
54
54
|
})
|
|
55
55
|
|
|
56
56
|
elementArray.forEach((keyComment) => {
|
|
@@ -103,7 +103,7 @@ export const merger_for = (el, stateContext, attr, arrayName, arrayItem, indexes
|
|
|
103
103
|
keyMap.set(child._forKey, child)
|
|
104
104
|
})
|
|
105
105
|
Array.from(div.children).forEach((child, index) => {
|
|
106
|
-
const key = child.getAttribute('for-key')
|
|
106
|
+
const key = child.getAttribute('for-key') || index
|
|
107
107
|
const context = el._context
|
|
108
108
|
const itemContext = {
|
|
109
109
|
[arrayItem]: array[index],
|
package/package.json
CHANGED
package/utils.js
CHANGED
|
@@ -33,23 +33,9 @@ export const processNode = (node, itemContext) => {
|
|
|
33
33
|
return
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
if (node.
|
|
37
|
-
const text = node.textContent
|
|
38
|
-
const newText = text.replace(/{{(.+?)}}/g, (match, exp) => {
|
|
39
|
-
try {
|
|
40
|
-
const keys = Object.keys(itemContext)
|
|
41
|
-
|
|
42
|
-
const values = keys.map(key => itemContext[key])
|
|
43
|
-
|
|
44
|
-
return new Function(...keys, `return ${exp}`)(...values)
|
|
45
|
-
} catch {
|
|
46
|
-
return match
|
|
47
|
-
}
|
|
48
|
-
})
|
|
49
|
-
//console.log(newText)
|
|
50
|
-
node.textContent = newText
|
|
51
|
-
} else if (node.attributes) {
|
|
36
|
+
if (node.attributes) {
|
|
52
37
|
Array.from(node.attributes).forEach(attr => {
|
|
38
|
+
if(attr.name !== 'for-key') return
|
|
53
39
|
const newValue = attr.value.replace(/{{(.+?)}}/g, (match, exp) => {
|
|
54
40
|
try {
|
|
55
41
|
const keys = Object.keys(itemContext)
|
|
@@ -62,9 +48,7 @@ export const processNode = (node, itemContext) => {
|
|
|
62
48
|
attr.value = newValue
|
|
63
49
|
})
|
|
64
50
|
}
|
|
65
|
-
|
|
66
|
-
processNode(n, itemContext)
|
|
67
|
-
})
|
|
51
|
+
|
|
68
52
|
}
|
|
69
53
|
|
|
70
54
|
export const extractContextValues = (context) => {
|