11<script lang="ts" setup>
2- import { ref , computed } from ' vue'
2+ import { ref , computed , watch } from ' vue'
33import Badge from ' ./components/Badge.ce.vue'
44import List from ' ./components/List.ce.vue'
55import { useChecker } from ' ./useChecker'
@@ -21,11 +21,32 @@ const shouldRender = computed(() => {
2121 return checkerResults .value .some ((p ) => p .diagnostics .length > 0 )
2222})
2323
24- const collapsed = ref <boolean >(! (props ?.overlayConfig ?.initialIsOpen ?? true ))
24+ // collapsed state if requested (otherwise initially open)
25+ const initialCollapsed = ref <boolean >(
26+ props ?.overlayConfig ?.initialIsOpen === false || props ?.overlayConfig ?.initialIsOpen === ' error'
27+ )
28+
29+ // if initialIsOpen is 'error': watch for results and open if there are errors
30+ if (props ?.overlayConfig ?.initialIsOpen === ' error' ) {
31+ // checker result is always initially empty, so need to watch for changes
32+ const unwatch = watch (checkerResults , () => {
33+ if (! checkerResults .value .length ) return
34+ // non-zero results length means the badge will appear. decide whether to open the overlay.
35+ if (checkerResults .value .some ((p ) => p .diagnostics .some ((d : any ) => d .level === 1 ))) {
36+ initialCollapsed .value = false
37+ }
38+ // stop watching and let the user control the overlay state
39+ unwatch ()
40+ })
41+ }
42+
43+ const userCollapsed = ref <boolean | undefined >(undefined )
2544
2645const toggle = () => {
27- collapsed .value = ! collapsed .value
46+ userCollapsed .value = ! ( userCollapsed .value ?? initialCollapsed . value )
2847}
48+
49+ const collapsed = computed <boolean >(() => userCollapsed .value ?? initialCollapsed .value )
2950 </script >
3051
3152<template >
0 commit comments