diff --git a/components/CodeEditor.vue b/components/CodeEditor.vue index 0911b7b..51ea0dd 100644 --- a/components/CodeEditor.vue +++ b/components/CodeEditor.vue @@ -55,7 +55,7 @@ if (props.input) { range: monaco.Range.fromPositions(start, end), options: { isWholeLine: false, - className: 'input-editor-highlight', + className: 'ast-highlight', }, }, ]) @@ -79,9 +79,3 @@ if (props.input) { - - diff --git a/components/OutputContainer.vue b/components/OutputContainer.vue index da2c737..90774c3 100644 --- a/components/OutputContainer.vue +++ b/components/OutputContainer.vue @@ -89,8 +89,7 @@ watch(outputView, (view) => { JSON - - + 0, ) -const isHover = computed(() => { +const isHovering = computed(() => { if (Array.isArray(props.value)) { return props.value.some((v) => checkRange(getRange(v))) } @@ -41,15 +41,20 @@ const isHover = computed(() => { }) const openManual = ref() const open = computed( - () => openable.value && (openManual.value ?? (props.open || isHover.value)), + () => + openable.value && + (openManual.value ?? (props.open || (autoFocus.value && isHovering.value))), ) +const valueCreated = ref(false) +watch(open, () => (valueCreated.value ||= open.value), { immediate: true }) + function toggleOpen() { if (!openable.value) return if ( openManual.value !== undefined && - openManual.value !== (props.open || isHover.value) + openManual.value !== (props.open || isHovering.value) ) { openManual.value = undefined } else { @@ -81,12 +86,33 @@ function handleMouseLeave() { outputHoverRange.value = undefined } } + +const container = ref() +const exactHover = ref(false) + +function handleSubHoverChange(subHovering: boolean) { + exactHover.value = isHovering.value && !subHovering +} + +watch( + [autoFocus, exactHover, isHovering, container], + ([autoFocus, exactHover, isHovering, container]) => { + if (autoFocus && exactHover && isHovering && container) { + requestAnimationFrame(() => container.scrollIntoView({ block: 'center' })) + } + }, + { immediate: true }, +) + +defineExpose({ isHovering }) @@ -117,7 +143,13 @@ function handleMouseLeave() { v-text="title" /> - - + + + + diff --git a/components/ast/Value.vue b/components/ast/Value.vue index 21cd1a1..e39934c 100644 --- a/components/ast/Value.vue +++ b/components/ast/Value.vue @@ -1,5 +1,9 @@ @@ -21,7 +31,7 @@ const valueColor = useHighlightColor(value) - + diff --git a/styles/global.css b/styles/global.css index 1708d3a..bb85282 100644 --- a/styles/global.css +++ b/styles/global.css @@ -21,6 +21,10 @@ option { background-color: transparent !important; } +.ast-highlight { + --at-apply: 'bg-yellow-400/30 dark:bg-yellow-400/20'; +} + /* Color Mode transition */ ::view-transition-old(root), ::view-transition-new(root) {