|
|
@@ -3,6 +3,8 @@
|
|
3
|
3
|
</template>
|
|
4
|
4
|
|
|
5
|
5
|
<script>
|
|
|
6
|
+let treeToAppend = null
|
|
|
7
|
+
|
|
6
|
8
|
export default {
|
|
7
|
9
|
name: 'rblock',
|
|
8
|
10
|
props: {
|
|
|
@@ -10,6 +12,7 @@ export default {
|
|
10
|
12
|
},
|
|
11
|
13
|
data() {
|
|
12
|
14
|
return {
|
|
|
15
|
+ isLoading: true,
|
|
13
|
16
|
id: null,
|
|
14
|
17
|
root: null,
|
|
15
|
18
|
treeDepth: 0,
|
|
|
@@ -62,25 +65,39 @@ export default {
|
|
62
|
65
|
|
|
63
|
66
|
this.treeDepth--
|
|
64
|
67
|
},
|
|
65
|
|
- },
|
|
66
|
|
- mounted() {
|
|
67
|
|
- if(typeof this.block !== 'object' || this.block.hasOwnProperty('gallery')) return
|
|
|
68
|
+ buildBlocks() {
|
|
|
69
|
+ if(typeof this.block !== 'object' || this.block.hasOwnProperty('gallery')) return
|
|
68
|
70
|
|
|
69
|
|
- // Add the top-level blocks to the document tree
|
|
70
|
|
- const tree = new DocumentFragment()
|
|
71
|
|
- this.root = document.createElement('div')
|
|
72
|
|
- // console.log(this.block)
|
|
73
|
|
- this.root.classList.add('wp-block-columns')
|
|
74
|
|
- tree.appendChild(this.root)
|
|
75
|
|
-
|
|
76
|
|
- // Loop over all the nodes and append children
|
|
77
|
|
- for(const block of this.block) {
|
|
78
|
|
- this.processBlock(block, this.root)
|
|
79
|
|
- }
|
|
|
71
|
+ // Add the top-level blocks to the document tree
|
|
|
72
|
+ treeToAppend = new DocumentFragment()
|
|
|
73
|
+ this.root = document.createElement('div')
|
|
|
74
|
+ // console.log(this.block)
|
|
|
75
|
+ this.root.classList.add('wp-block-columns')
|
|
|
76
|
+ treeToAppend.appendChild(this.root)
|
|
80
|
77
|
|
|
|
78
|
+ // Loop over all the nodes and append children
|
|
|
79
|
+ if(this.block.length == 1) {
|
|
|
80
|
+ for(const block of this.block) {
|
|
|
81
|
+ this.processBlock(block, this.root)
|
|
|
82
|
+ }
|
|
|
83
|
+ }
|
|
|
84
|
+ else {
|
|
|
85
|
+ console.warn('more than one block in here')
|
|
|
86
|
+ }
|
|
|
87
|
+ },
|
|
|
88
|
+ },
|
|
|
89
|
+ mounted() {
|
|
81
|
90
|
// Append the final product to DOM
|
|
82
|
|
- document.getElementById(`block-${this.$.uid}`).appendChild(tree)
|
|
83
|
|
-
|
|
|
91
|
+ this.buildBlocks()
|
|
|
92
|
+ document.getElementById(`block-${this.$.uid}`).innerHTML = ''
|
|
|
93
|
+ document.getElementById(`block-${this.$.uid}`).appendChild(treeToAppend)
|
|
|
94
|
+ },
|
|
|
95
|
+ watch: {
|
|
|
96
|
+ block(newVal, oldVal) {
|
|
|
97
|
+ this.buildBlocks()
|
|
|
98
|
+ document.getElementById(`block-${this.$.uid}`).innerHTML = ''
|
|
|
99
|
+ document.getElementById(`block-${this.$.uid}`).appendChild(treeToAppend)
|
|
|
100
|
+ }
|
|
84
|
101
|
}
|
|
85
|
102
|
}
|
|
86
|
103
|
</script>
|