17
17
18
18
<script >
19
19
import { mapState } from ' vuex'
20
-
20
+ const breadthFirstSearch = (array ,id ) => {
21
+ let queue = [... array .filter (el => typeof el === ' object' )];
22
+ while (queue .length ){
23
+ let evaluated = queue .shift ()
24
+ if (evaluated .id === id){
25
+ return evaluated
26
+ }
27
+ else {
28
+ if (evaluated .children .length ){
29
+ queue .push (... evaluated .children )
30
+ }
31
+ }
32
+ }
33
+ console .log (" We shouldn't be ever getting here, how did you even search an id that didn't exist?" )
34
+ }
21
35
export default {
22
36
data () {
23
37
return {
@@ -58,7 +72,27 @@ export default {
58
72
}
59
73
// console.log('storage is ', this.elementStorage)
60
74
},
75
+ activeLayer: {
76
+ deep: true ,
77
+ handler (){
78
+ if (this .activeComponent )
79
+ {
80
+ this .elementStorage = {};
81
+ if (this .activeLayer .id !== ' ' && this .activeHTML === ' ' ) {
82
+ let activeLayerObj = breadthFirstSearch (this .componentMap [this .activeComponent ].htmlList , this .activeLayer .id )
83
+ activeLayerObj .children .forEach (el => {
84
+ if (! this .elementStorage [el .text ]) {
85
+ this .elementStorage [el .text ] = 1 ;
86
+ } else {
87
+ this .elementStorage [el .text ] += 1 ;
88
+ }
89
+ })
90
+ }
91
+ }
92
+ }
93
+ },
61
94
// if componentMap is updated (i.e. element is added to component's htmlList), elementStorage will update its cache of elements & frequency
95
+
62
96
componentMap: {
63
97
deep: true ,
64
98
handler () {
@@ -67,17 +101,71 @@ export default {
67
101
// console.log('htmlList', this.componentMap[this.activeComponent].htmlList)
68
102
if (this .activeComponent ) {
69
103
this .elementStorage = {};
70
- this .componentMap [this .activeComponent ].htmlList .forEach (el => {
104
+ if (this .activeLayer .id !== ' ' && this .activeHTML === ' ' ) {
105
+ let activeLayerObj = breadthFirstSearch (this .componentMap [this .activeComponent ].htmlList , this .activeLayer .id )
106
+ activeLayerObj .children .forEach (el => {
71
107
if (! this .elementStorage [el .text ]) {
72
108
this .elementStorage [el .text ] = 1 ;
73
109
} else {
74
110
this .elementStorage [el .text ] += 1 ;
75
111
}
76
112
})
113
+ } else if (this .activeHTML !== ' ' ){
114
+ let activeHtmlObj = breadthFirstSearch (this .componentMap [this .activeComponent ].htmlList , this .activeHTML )
115
+ activeHtmlObj .children .forEach (el => {
116
+ if (! this .elementStorage [el .text ]) {
117
+ this .elementStorage [el .text ] = 1 ;
118
+ } else {
119
+ this .elementStorage [el .text ] += 1 ;
120
+ }
121
+ })
122
+ } else {
123
+ this .componentMap [this .activeComponent ].htmlList .forEach (el => {
124
+ if (! this .elementStorage [el .text ]) {
125
+ this .elementStorage [el .text ] = 1 ;
126
+ } else {
127
+ this .elementStorage [el .text ] += 1 ;
128
+ }
129
+ })
130
+ }
77
131
// console.log('elementStorage is ', this.elementStorage);
78
132
}
79
133
},
80
134
},
135
+
136
+ activeHTML : function () {
137
+ this .elementStorage = {};
138
+ if (this .activeHTML !== ' ' ){
139
+ let activeHtmlObj = breadthFirstSearch (this .componentMap [this .activeComponent ].htmlList , this .activeHTML )
140
+ activeHtmlObj .children .forEach (el => {
141
+ if (! this .elementStorage [el .text ]) {
142
+ this .elementStorage [el .text ] = 1 ;
143
+ } else {
144
+ this .elementStorage [el .text ] += 1 ;
145
+ }
146
+ })
147
+ }
148
+ else {
149
+ if (this .activeLayer .id !== ' ' && this .activeHTML === ' ' ) {
150
+ let activeLayerObj = breadthFirstSearch (this .componentMap [this .activeComponent ].htmlList , this .activeLayer .id )
151
+ activeLayerObj .children .forEach (el => {
152
+ if (! this .elementStorage [el .text ]) {
153
+ this .elementStorage [el .text ] = 1 ;
154
+ } else {
155
+ this .elementStorage [el .text ] += 1 ;
156
+ }
157
+ })
158
+ } else {
159
+ this .componentMap [this .activeComponent ].htmlList .forEach (el => {
160
+ if (! this .elementStorage [el .text ]) {
161
+ this .elementStorage [el .text ] = 1 ;
162
+ } else {
163
+ this .elementStorage [el .text ] += 1 ;
164
+ }
165
+ })
166
+ }
167
+ }
168
+ },
81
169
// if activeComponent is updated, elementStorage will update its cache of elements & frequency to reflect new active component
82
170
activeComponent : function () {
83
171
// console.log('watching activeComponent', this.activeComponent);
0 commit comments