86 lines
3.2 KiB
Vue
86 lines
3.2 KiB
Vue
<script setup lang="ts">
|
|
// The right panel: tabs for the selection, the circuit, its pins, and testing.
|
|
import { ioList } from '~/lib/logic/bulk'
|
|
|
|
const ed = useEditor()
|
|
type Tab = 'selection' | 'circuit' | 'pins' | 'test'
|
|
|
|
const single = computed(() =>
|
|
ed.selection.value.length === 1 && !ed.wireSel.value.length ? ed.def.value.nodes.find(n => n.id === ed.selection.value[0]) : undefined,
|
|
)
|
|
const selected = computed(() => ed.selection.value.length + ed.wireSel.value.length)
|
|
const pinCount = computed(() => {
|
|
const io = ioList(ed.def.value)
|
|
return io.inputs.length + io.outputs.length
|
|
})
|
|
const hasTask = computed(() => !!ed.task.value)
|
|
|
|
const tabs = computed(() => [
|
|
{ id: 'selection' as Tab, label: 'Selection', icon: 'lucide:mouse-pointer-2', badge: selected.value || '' },
|
|
{ id: 'circuit' as Tab, label: 'Circuit', icon: 'lucide:cpu', badge: '' },
|
|
{ id: 'pins' as Tab, label: 'Pins', icon: 'lucide:list', badge: pinCount.value || '' },
|
|
{ id: 'test' as Tab, label: 'Test', icon: hasTask.value ? 'lucide:flag' : 'lucide:table', badge: '' },
|
|
])
|
|
|
|
// Selecting something shows its settings, unless you are working in Pins or
|
|
// Test (where clicking a switch to try the circuit also selects it).
|
|
let before: Tab = 'circuit'
|
|
watch(selected, (now, was) => {
|
|
const tab = ed.rightTab.value
|
|
if (now && !was && tab === 'circuit') {
|
|
before = tab
|
|
ed.rightTab.value = 'selection'
|
|
} else if (!now && tab === 'selection') ed.rightTab.value = before
|
|
})
|
|
watch(
|
|
() => ed.labelFocus.value,
|
|
() => {
|
|
if (selected.value) ed.rightTab.value = 'selection'
|
|
},
|
|
)
|
|
// Opening a challenge or puzzle shows what to build.
|
|
watch(
|
|
() => ed.def.value.id,
|
|
() => {
|
|
if (ed.task.value) ed.rightTab.value = 'test'
|
|
else if (ed.rightTab.value === 'test') ed.rightTab.value = 'circuit'
|
|
},
|
|
{ immediate: true },
|
|
)
|
|
</script>
|
|
|
|
<template>
|
|
<aside class="inspector">
|
|
<nav class="itabs" role="tablist">
|
|
<button
|
|
v-for="t in tabs"
|
|
:key="t.id"
|
|
role="tab"
|
|
:aria-selected="ed.rightTab.value === t.id"
|
|
:class="{ active: ed.rightTab.value === t.id, task: t.id === 'test' && hasTask }"
|
|
:title="t.label"
|
|
@click="ed.rightTab.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">{{ t.badge }}</span>
|
|
</button>
|
|
</nav>
|
|
<div class="scroll">
|
|
<template v-if="ed.rightTab.value === 'selection'">
|
|
<EditorNodeSettings v-if="single" :key="single.id" :node="single" />
|
|
<EditorBulkSettings v-else-if="ed.selection.value.length" />
|
|
<EditorWireSettings v-else-if="ed.wireSel.value.length" />
|
|
<section v-else class="empty-pane">
|
|
<Icon name="lucide:mouse-pointer-click" class="size-6" />
|
|
<p>Click a part or wire to change it.</p>
|
|
<p class="hint">Shift + click or drag a box to select several; you can then rename, swap or switch them all at once.</p>
|
|
</section>
|
|
</template>
|
|
<EditorCircuitPane v-else-if="ed.rightTab.value === 'circuit'" />
|
|
<EditorPinsPane v-else-if="ed.rightTab.value === 'pins'" />
|
|
<EditorTestPane v-else />
|
|
</div>
|
|
</aside>
|
|
</template>
|