logigate/app/components/editor/Inspector.vue

66 lines
2.2 KiB
Vue

<script setup lang="ts">
// The panel on the left, about the circuit you are in: "This" (its name,
// check, challenge, truth table, statistics and tools) and its Pins.
import { ioList } from '~/lib/logic/bulk'
const ed = useEditor()
type Tab = 'circuit' | 'pins'
const pinCount = computed(() => {
const io = ioList(ed.def.value)
return io.inputs.length + io.outputs.length
})
const hasTask = computed(() => !!ed.task.value)
/** Errors and warnings in the open circuit, on the This tab. */
const problems = computed(() => ed.issues.value.filter(i => i.level !== 'info').length)
const tabs = computed(() => [
{ id: 'circuit' as Tab, label: 'This', icon: hasTask.value ? 'lucide:flag' : 'lucide:cpu', badge: problems.value || '', warn: problems.value > 0 },
{ id: 'pins' as Tab, label: 'Pins', icon: 'lucide:list', badge: pinCount.value || '', warn: false },
])
// Renaming with nothing selected renames the circuit; opening a challenge shows what to build.
watch(
() => ed.labelFocus.value,
() => {
if (!ed.selection.value.length) ed.panelTab.value = 'circuit'
},
)
watch(
() => ed.def.value.id,
() => {
if (ed.task.value) ed.panelTab.value = 'circuit'
},
)
</script>
<template>
<aside class="inspector">
<nav class="itabs" role="tablist">
<button class="collapse-btn" title="Hide this panel ([)" @click="ed.togglePanel(false)">
<Icon name="lucide:panel-left-close" class="size-4" />
</button>
<button
v-for="t in tabs"
:key="t.id"
role="tab"
:aria-selected="ed.panelTab.value === t.id"
:class="{ active: ed.panelTab.value === t.id, task: t.id === 'circuit' && hasTask }"
:title="t.id === 'circuit' ? 'The circuit you are in' : 'Its inputs and outputs'"
@click="ed.panelTab.value = t.id"
>
<Icon :name="t.icon" class="size-4 shrink-0" />
<span class="label">{{ t.label }}</span>
<span v-if="t.badge" class="badge" :class="{ warn: t.warn }">{{ t.badge }}</span>
</button>
</nav>
<div class="scroll">
<template v-if="ed.panelTab.value === 'circuit'">
<EditorTestPane part="task" />
<EditorCircuitPane />
</template>
<EditorPinsPane v-else />
</div>
</aside>
</template>