4848 <tr >
4949 <th class =" w-60" >Field</th >
5050 <th class =" mobile-hidden" >Value</th >
51- <th class =" w-20" ><input type =" checkbox" class =" toggle toggle-primary" @change =" toggleAll($event)" /></th >
51+ <th class =" w-20" >
52+ <input type =" checkbox" class =" toggle toggle-primary" v-model =" toggleAllFields" title =" Toggle all" />
53+ </th >
5254 </tr >
5355 </thead >
5456 <tbody ref =" list" >
@@ -85,19 +87,9 @@ function toggleField(key: string[]) {
8587 visibleKeys .value = new Map <string [], boolean >(fields .value .map (({ key }) => [key , true ]));
8688 }
8789
88- const enabled = visibleKeys .value .get (key );
89- visibleKeys .value .set (key , ! enabled );
90- }
91-
92- function toggleAll(e : Event ) {
93- if (visibleKeys .value .size === 0 ) {
94- visibleKeys .value = new Map <string [], boolean >(fields .value .map (({ key }) => [key , true ]));
95- }
90+ const enabled = visibleKeys .value .get (key ) ?? true ;
9691
97- const enabled = e .target instanceof HTMLInputElement && e .target .checked ;
98- for (const key of visibleKeys .value .keys ()) {
99- visibleKeys .value .set (key , enabled );
100- }
92+ visibleKeys .value .set (key , ! enabled );
10193}
10294
10395const fields = computed ({
@@ -116,7 +108,7 @@ const fields = computed({
116108
117109 for (const [key, value] of allFields ) {
118110 if ([... visibleKeys .value .keys ()].findIndex ((k ) => arrayEquals (k , key )) === - 1 ) {
119- fieldsWithValue .push ({ key , value , enabled: false });
111+ fieldsWithValue .push ({ key , value , enabled: true });
120112 }
121113 }
122114 }
@@ -132,6 +124,18 @@ const fields = computed({
132124 },
133125});
134126
127+ const toggleAllFields = computed ({
128+ get : () => fields .value .every (({ enabled }) => enabled ),
129+ set(value ) {
130+ if (visibleKeys .value .size === 0 ) {
131+ visibleKeys .value = new Map <string [], boolean >(fields .value .map (({ key }) => [key , true ]));
132+ }
133+ for (const key of visibleKeys .value .keys ()) {
134+ visibleKeys .value .set (key , value );
135+ }
136+ },
137+ });
138+
135139function syntaxHighlight(json : any ) {
136140 json = JSON .stringify (json , null , 2 );
137141 return json .replace (
@@ -149,7 +153,7 @@ function syntaxHighlight(json: any) {
149153 } else if (/ null/ .test (match )) {
150154 cls = " json-null" ;
151155 }
152- return ' <span class="' + cls + ' "> ' + match + " </span>" ;
156+ return ` <span class="${ cls }">${ match } </span> ` ;
153157 },
154158 );
155159}
0 commit comments