forked from quasarframework/quasar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCatchAll.vue
More file actions
112 lines (98 loc) · 2.62 KB
/
CatchAll.vue
File metadata and controls
112 lines (98 loc) · 2.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<template>
<div class="q-pa-md">
<div class="row no-wrap q-gutter-md">
<q-btn label="Add row" color="primary" @click="addRow" :disable="listItems.length >= 7" />
<q-btn label="Remove row" color="accent" @click="removeRow" :disable="listItems.length === 0" />
</div>
<div class="row no-wrap q-col-gutter-md">
<div v-mutation="handler" class="col-4">
<q-list v-if="listItems.length > 0" bordered separator class="q-mt-md rounded-borders">
<q-item v-for="(item, index) in listItems" :key="item" :id="`item-${index}`">
<q-item-section>
{{ item }}
</q-item-section>
</q-item>
</q-list>
</div>
<div class="col-8">
<q-card v-if="mutationInfo.length > 0" bordered flat class="q-mt-md overflow-auto">
<pre class="catch-all-pre q-pa-md">{{ mutationInfo }}</pre>
</q-card>
</div>
</div>
</div>
</template>
<script>
import { ref } from 'vue'
function domToObj (domEl, whitelist) {
const obj = {}
for (let i = 0; i < whitelist.length; i++) {
if (domEl[ whitelist[ i ] ] instanceof NodeList) {
obj[ whitelist[ i ] ] = Array.from(domEl[ whitelist[ i ] ])
}
else {
obj[ whitelist[ i ] ] = domEl[ whitelist[ i ] ]
}
}
return obj
}
const whitelist = [
'id',
'type',
'addedNodes',
'removedNodes',
'attributeName',
'attributeNamespace',
'nextSibling',
'oldValue',
'previousSibling',
'target',
'tagName',
'className',
'childNodes'
]
export default {
setup () {
const listItems = ref([])
const mutationInfo = ref('')
return {
listItems,
mutationInfo,
handler (mutationRecords) {
const info = []
for (const index in mutationRecords) {
const record = mutationRecords[ index ]
info.push(
JSON.stringify(record, (name, value) => {
if (name === '') {
return domToObj(value, whitelist)
}
if (Array.isArray(this)) {
if (typeof value === 'object') {
return domToObj(value, whitelist)
}
return value
}
if (whitelist.find(x => (x === name))) {
return value
}
}, 2)
)
}
mutationInfo.value = info.join('\n')
},
addRow () {
listItems.value.push(`List item #${listItems.value.length + 1}`)
},
removeRow () {
listItems.value.pop()
}
}
}
}
</script>
<style lang="sass">
.catch-all-pre
font-size: 10px
max-height: 350px
</style>