BF pin names editable again, A dense Pins list with toggles and panel groups, wire many at once, folding side panels, full zoom-out

- Pins list rows used the class "pin", which the canvas styles as
  unclickable: renaming and focusing pins did nothing. Renamed the class.
- One line per entry; click the value to flip a switch, hold for a button;
  panel rows framed under their panel.
- Drag one wire from a selected part to another part: all selected parts
  connect to its next pins in order; "Wire them all to" in the bulk panel.
- Both side panels fold to an icon strip ([ and ]), remembered per browser.
- Zoom out until the whole circuit fits (further for bigger circuits); grid
  dots hide when they would be too dense.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Fabian @ Blax Software 2026-10-21 10:09:43 +02:00
parent cd718afdda
commit f1b72b3e3c
13 changed files with 546 additions and 94 deletions

View File

@ -19,7 +19,9 @@ Nuxt 4 (client-only editor, `ssr: false`), Tailwind CSS v4, Lucide icons via `@n
- Automatic names: copies continue a series (D0 copied gives D1, D2; A gives B), and so does placing a new input or output after a numbered one. A switch, button, lamp or output pin without a name of its own (or with an automatic one) takes the name of the component pin it gets wired to, made unique (Cin, Cin2); a name typed by hand is kept. On the canvas, a switch, button, clock, lamp or output pin without a name typed by hand shows the name of the component pin it is wired to, dimmed and in italics (or its automatic name, also dimmed); the name follows the wiring as it changes.
- Every circuit is a component. Its input and output nodes become its pins, ordered top to bottom. Double-click a component to open it.
- Lamps and hex displays inside a component show on its box, with their labels, lit by that instance's state. They are laid out in rows the way they sit inside. A checkbox in the inspector turns this off per component.
- The right panel has four tabs. **Selection**: settings of what you clicked (switches to it when you select something on an idle panel). **Circuit**: name, symbol, group, statistics, and where the transistors are (each kind of part with its count; click a line to select those parts). **Pins**: every input and output of the circuit in pin order with its live value; rename in place (Enter goes to the next), "Number all" names a whole side from a pattern (D# → D0, D1, …), duplicate names are flagged, the target icon centres the canvas on a part. **Test**: the challenge or puzzle check and the truth table (opens by itself for a challenge). Display and sound preferences are in Settings (gear in the top bar).
- The right panel has four tabs. **Selection**: settings of what you clicked (switches to it when you select something on an idle panel). **Circuit**: name, symbol, group, statistics, and where the transistors are (each kind of part with its count; click a line to select those parts). **Pins**: every input and output of the circuit in pin order, one line each, with its live value (click it to flip a switch, hold it for a button; panel rows are framed under their panel); rename in place (Enter goes to the next), "Number all" names a whole side from a pattern (D# → D0, D1, …), duplicate names are flagged, the target icon centres the canvas on a part. **Test**: the challenge or puzzle check and the truth table (opens by itself for a challenge). Display and sound preferences are in Settings (gear in the top bar). Both side panels fold away to a strip of icons (the panel icon in their tab row, or [ and ]).
- Wiring many at once: select several parts and drag one wire from one of them to a pin of another part; the others follow onto that part's next pins, in position order (or use "Wire them all to" in the panel).
- Zooming out goes at least far enough to see the whole circuit, further for bigger circuits.
- Several selected parts are edited together: chips to narrow the selection by type, swap them all for another part, rename all top to bottom from a pattern, set every switch to 0 or 1 or flip each, one colour, one clock frequency or note size for all, line them up or spread them evenly, plus make component, connect one by one, unlink, duplicate, delete.
- Transistors: every part shows its count (4 for a NAND, 0 for switches, lamps and cables, the whole inside for a component; the NAND in the palette shows 4T). The count is 4 per CMOS NAND gate the simulator builds, at every depth; a test checks this against the flattened circuit for every example and every wide gate.
- Clicking anything opens its settings on the right. Parts can be swapped in place (wires stay on the pins in the same position): NAND and components with each other, switch/button/clock/constants with each other, output/lamp/display with each other. Clocks have their own frequency or follow the top bar. Switches and buttons can get a keyboard key. Lamps and displays have colours, notes have sizes, components a name on the canvas. Components can be unpacked into their parts or given their own copy of the definition; any part can have all its wires unlinked.

View File

@ -62,11 +62,21 @@ kbd {
}
.workspace {
--left: 236px;
--right: 300px;
display: grid;
grid-template-columns: 236px 1fr 300px;
grid-template-columns: var(--left) 1fr var(--right);
min-height: 0;
}
.workspace.no-left {
--left: 36px !important;
}
.workspace.no-right {
--right: 36px !important;
}
.stage {
position: relative;
min-width: 0;
@ -99,7 +109,8 @@ kbd {
@media (max-width: 1100px) {
.workspace {
grid-template-columns: 210px 1fr 260px;
--left: 210px;
--right: 260px;
}
}
@ -1914,25 +1925,44 @@ kbd {
letter-spacing: 0;
}
.io-list {
display: grid;
gap: 2px;
.io-section {
padding-top: 10px !important;
padding-bottom: 10px !important;
}
.io-list li {
.io-head {
display: flex;
align-items: center;
gap: 8px;
padding: 3px 4px;
border-radius: 6px;
margin-bottom: 6px;
}
.io-head h3 {
flex: 1;
margin: 0 !important;
}
.io-list {
display: grid;
gap: 1px;
}
.io-row {
display: grid;
grid-template-columns: 20px minmax(0, 1fr) auto 22px;
align-items: center;
gap: 6px;
height: 26px;
padding: 0 2px;
border-radius: 5px;
border: 1px solid transparent;
}
.io-list li:hover {
.io-row:hover {
background: var(--panel-2);
}
.io-list li.selected {
.io-row.selected {
border-color: rgb(76 194 255 / 0.5);
background: rgb(76 194 255 / 0.07);
}
@ -1941,14 +1971,23 @@ kbd {
display: grid;
place-items: center;
width: 20px;
height: 20px;
flex-shrink: 0;
border-radius: 5px;
height: 18px;
border-radius: 4px;
background: var(--panel-2);
color: var(--muted);
font-family: var(--font-mono);
font-size: 11px;
font-weight: 700;
cursor: default;
}
.io-value.live {
cursor: pointer;
outline: 1px solid var(--border);
}
.io-value.live:hover {
outline-color: var(--accent);
}
.io-value.on {
@ -1956,22 +1995,17 @@ kbd {
color: var(--on);
}
.io-main {
display: grid;
min-width: 0;
flex: 1;
}
.io-name {
width: 100%;
min-width: 0;
padding: 3px 6px;
height: 22px;
padding: 0 5px;
border: 1px solid transparent;
border-radius: 5px;
border-radius: 4px;
background: transparent;
color: var(--text);
font-family: var(--font-mono);
font-size: 13px;
font-size: 12.5px;
font-weight: 600;
outline: none;
}
@ -1994,16 +2028,51 @@ kbd {
.io-kind {
display: flex;
align-items: center;
gap: 4px;
padding-left: 7px;
gap: 3px;
font-size: 10.5px;
color: var(--muted);
white-space: nowrap;
}
.io-list li.dup .io-kind {
.io-row.dup .io-kind {
color: var(--lamp);
}
.io-locate {
width: 22px !important;
height: 22px !important;
opacity: 0;
}
.io-row:hover .io-locate,
.io-group-head:hover .io-locate,
.io-locate:focus-visible {
opacity: 1;
}
.io-group {
margin: 3px 0;
padding: 0 3px 3px;
border: 1px solid var(--border);
border-radius: 7px;
}
.io-group.selected {
border-color: rgb(76 194 255 / 0.6);
background: rgb(76 194 255 / 0.05);
}
.io-group-head {
display: flex;
align-items: center;
gap: 6px;
height: 24px;
padding: 0 2px 0 5px;
font-size: 11px;
font-weight: 600;
color: var(--muted);
}
.numbering {
margin: 4px 0 12px;
padding: 10px;
@ -2087,3 +2156,59 @@ kbd {
margin-top: -4px;
margin-bottom: 12px;
}
/* ── Collapsible side panels ────────────────────────────────────── */
.collapse-btn {
display: grid;
place-items: center;
color: var(--muted);
flex: 0 0 30px;
}
.collapse-btn:hover {
color: var(--text);
}
.itabs {
grid-template-columns: 30px repeat(4, 1fr);
}
.rail {
display: flex;
flex-direction: column;
align-items: center;
gap: 2px;
padding-top: 6px;
background: var(--panel);
min-height: 0;
}
.rail.left {
border-right: 1px solid var(--border);
}
.rail.right {
border-left: 1px solid var(--border);
}
.rail-btn {
display: grid;
place-items: center;
width: 28px;
height: 28px;
border-radius: 6px;
color: var(--muted);
}
.rail-btn:hover {
background: var(--panel-2);
color: var(--text);
}
.tabs .collapse-btn,
.itabs .collapse-btn {
flex: 0 0 30px;
flex-direction: row;
padding: 0;
border-bottom: 2px solid transparent;
}

View File

@ -20,12 +20,14 @@ onMounted(() => {
<template>
<div class="app">
<EditorToolbar />
<div class="workspace">
<EditorPalette />
<div class="workspace" :class="{ 'no-left': !ed.sidebars.left, 'no-right': !ed.sidebars.right }">
<EditorPalette v-if="ed.sidebars.left" />
<EditorRail v-else side="left" />
<main class="stage">
<EditorCanvas />
</main>
<EditorInspector />
<EditorInspector v-if="ed.sidebars.right" />
<EditorRail v-else side="right" />
</div>
<Transition name="fade">
<div v-if="ed.notice.value" class="toast" :class="ed.notice.value.kind">{{ ed.notice.value.text }}</div>

View File

@ -2,7 +2,7 @@
// Settings for several selected parts at once: one change, all of them.
import { byPosition, numberedNames, sharedFamily, typeKey, type Arrange } from '~/lib/logic/bulk'
import { chipPins } from '~/lib/logic/geometry'
import { SINK_KINDS, SOURCE_KINDS } from '~/lib/logic/ops'
import { pinKeys, SINK_KINDS, SOURCE_KINDS } from '~/lib/logic/ops'
import { KIND_NAMES } from '~/lib/logic/progress'
import { LAMP_COLORS, type LampColor, type NodeKind } from '~/lib/logic/types'
@ -100,6 +100,26 @@ const ARRANGE: { how: Arrange; icon: string; title: string }[] = [
{ how: 'spread-x', icon: 'lucide:align-horizontal-space-around', title: 'Spread evenly left to right' },
]
// ── Wire them all to one part ───────────────────────────────────────
const others = computed(() => {
const sel = new Set(ids.value)
return ed.def.value.nodes
.filter(n => !sel.has(n.id) && n.kind !== 'note')
.map(n => ({ n, pins: pinKeys(n, ed.getDef.value) }))
.filter(o => o.pins.ins.length + o.pins.outs.length > 0)
.sort((a, b) => Number(b.n.kind === 'chip') - Number(a.n.kind === 'chip') || byPosition(a.n, b.n))
.map(o => ({
id: o.n.id,
pins: o.pins,
name: o.n.label?.trim() || (o.n.chip && ed.getDef.value(o.n.chip)?.name) || KIND_NAMES[o.n.kind] || o.n.kind,
}))
})
const target = ref('')
const chosen = computed(() => others.value.find(o => o.id === target.value) ?? others.value[0])
const targetId = computed({ get: () => chosen.value?.id ?? '', set: v => (target.value = v) })
const mineIn = computed(() => nodes.value.some(n => pinKeys(n, ed.getDef.value).ins.length))
const mineOut = computed(() => nodes.value.some(n => pinKeys(n, ed.getDef.value).outs.length))
// ── Make component ──────────────────────────────────────────────────
const packName = ref('')
function pack() {
@ -204,6 +224,22 @@ function pack() {
</div>
</section>
<section v-if="others.length && chosen">
<h3>Wire them all to</h3>
<select v-model="targetId" class="text-input">
<option v-for="o in others" :key="o.id" :value="o.id">{{ o.name }} ({{ o.pins.ins.length }} in, {{ o.pins.outs.length }} out)</option>
</select>
<div class="mt-2 grid gap-2">
<button v-if="mineIn && chosen.pins.outs.length" class="btn w-full" title="Its outputs, in order, into the selected parts, top to bottom" @click="ed.connectSelectionTo(chosen.id, 'in')">
<Icon name="lucide:arrow-right-to-line" class="size-4" /> From {{ chosen.name }}'s outputs
</button>
<button v-if="mineOut && chosen.pins.ins.length" class="btn w-full" title="The selected parts, top to bottom, into its inputs in order" @click="ed.connectSelectionTo(chosen.id, 'out')">
<Icon name="lucide:arrow-left-from-line" class="size-4" /> Into {{ chosen.name }}'s inputs
</button>
</div>
<p class="hint mt-2">Or drag one wire from a selected part to a pin: the others follow onto the next pins.</p>
</section>
<section>
<h3>Make a component</h3>
<p class="hint">Wires that cross the selection border become its pins.</p>

View File

@ -4,6 +4,7 @@ import { cableBits, GRID as G, pinPos, routeWire, type Pt, type Shape } from '~/
import type { CircuitNode, PanelRow, PinRef, Wire } from '~/lib/logic/types'
import { branchCorners, branchTo, moveCorner, moveSegment, segmentDrag, splitDrag } from '~/lib/logic/wires'
import { circuitRoutes, findCrossings } from '~/lib/logic/routing'
import { seriesLinks } from '~/lib/logic/bulk'
import { wirePath } from '~/lib/draw'
import { pinName } from '~/lib/logic/labels'
@ -138,8 +139,7 @@ function fit() {
return
}
const { x0, y0, x1, y1 } = bounds(nodes)
const pad = 2
const zoom = Math.min(2.2, Math.max(0.25, Math.min(size.w / ((x1 - x0 + 2 * pad) * G), size.h / ((y1 - y0 + 2 * pad) * G))))
const zoom = Math.min(2.2, fitZoom())
ed.views[def.value.id] = {
zoom,
x: size.w / 2 - ((x0 + x1) / 2) * G * zoom,
@ -147,9 +147,21 @@ function fit() {
}
}
/** Zoom at which the whole circuit just fits on screen. */
function fitZoom(): number {
const nodes = def.value.nodes
if (!nodes.length) return 1
const { x0, y0, x1, y1 } = bounds(nodes)
const pad = 2
return Math.min(size.w / ((x1 - x0 + 2 * pad) * G), size.h / ((y1 - y0 + 2 * pad) * G))
}
/** Zooming out goes at least far enough to see the whole circuit with room around it. */
const minZoom = () => Math.max(0.005, Math.min(0.15, fitZoom() * 0.5))
function zoomAt(factor: number, sx = size.w / 2, sy = size.h / 2) {
const v = view.value
const zoom = Math.min(4, Math.max(0.15, v.zoom * factor))
const zoom = Math.min(4, Math.max(minZoom(), v.zoom * factor))
const k = zoom / v.zoom
ed.views[def.value.id] = { zoom, x: sx - (sx - v.x) * k, y: sy - (sy - v.y) * k }
}
@ -581,6 +593,11 @@ function onPointerUp() {
}
const target = targetAt(d.cur, d.dir === 'out' ? 'in' : 'out', ed.isBus(d.node, d.pin, d.dir))
if (!target) break
// Dragged from one of several selected parts to another part: wire them all, in order.
if (!d.branch && ed.selection.value.length > 1 && ed.selection.value.includes(d.node) && !ed.selection.value.includes(target.node)) {
ed.connectMany(seriesLinks(def.value, ed.getDef.value, ed.selection.value, { node: d.node, pin: d.pin, dir: d.dir }, target))
break
}
if (d.dir === 'in') {
ed.connect(target, here)
break
@ -698,6 +715,8 @@ function onKey(e: KeyboardEvent) {
if (n?.kind === 'chip' && n.chip) ed.open(n.chip)
} else if (!mod && !e.altKey && key === 'w' && ed.selection.value.length) ed.startLinking(ed.selection.value, e.shiftKey ? 'in' : undefined)
else if (!mod && !e.altKey && key === 'f') fit()
else if (!mod && !e.altKey && e.key === '[') ed.toggleSidebar('left')
else if (!mod && !e.altKey && e.key === ']') ed.toggleSidebar('right')
else if (!mod && !e.altKey && e.key === '?') ed.showHelp.value = !ed.showHelp.value
else if (!mod && !e.altKey && QUICK[key] && ed.canPlaceKind(QUICK[key]!)) ed.placing.value = { kind: QUICK[key]! }
}
@ -826,8 +845,8 @@ defineExpose({ fit, zoomAt })
<circle :cx="0.75" :cy="0.75" r="1.4" class="grid-major" />
</pattern>
</defs>
<rect width="100%" height="100%" fill="url(#grid-dots)" />
<rect width="100%" height="100%" fill="url(#grid-major)" />
<rect v-if="gridSize >= 5" width="100%" height="100%" fill="url(#grid-dots)" />
<rect v-if="gridSize * 8 >= 6" width="100%" height="100%" fill="url(#grid-major)" />
<g :transform="`translate(${view.x} ${view.y}) scale(${view.zoom})`">
<g class="wires">

View File

@ -52,6 +52,9 @@ watch(
<template>
<aside class="inspector">
<nav class="itabs" role="tablist">
<button class="collapse-btn" title="Hide this panel (])" @click="ed.toggleSidebar('right', false)">
<Icon name="lucide:panel-right-close" class="size-4" />
</button>
<button
v-for="t in tabs"
:key="t.id"

View File

@ -99,6 +99,9 @@ const started = computed(() => new Map(ed.project.value.components.filter(d => d
Challenges
<span class="count">{{ solvedCount }}/{{ CHALLENGES.length }}</span>
</button>
<button class="collapse-btn" title="Hide this panel ([)" @click="ed.toggleSidebar('left', false)">
<Icon name="lucide:panel-left-close" class="size-4" />
</button>
</div>
<div v-if="tab === 'parts'" class="scroll">

View File

@ -0,0 +1,65 @@
<script setup lang="ts">
// One line of the Pins list: live value (click to flip a switch, hold for a
// button), the name to edit, what it is, and a button to find it.
import { entryLabel, type IoEntry } from '~/lib/logic/bulk'
const props = defineProps<{ e: IoEntry; group: 'in' | 'out'; index: number; kind: string; placeholder: string; dup: boolean; selected: boolean }>()
const emit = defineEmits<{ next: [e: KeyboardEvent] }>()
const ed = useEditor()
const n = computed(() => props.e.node)
const type = computed(() => (props.e.row ? props.e.row.type : n.value.kind))
const switchable = computed(() => type.value === 'input' || type.value === 'switch')
const holdable = computed(() => type.value === 'button')
const value = computed(() => {
const id = n.value.id
if (props.e.row) return String(ed.val(id, props.e.row.id))
if (n.value.kind === 'hex') return [0, 1, 2, 3].reduce((v, i) => v + (ed.val(id, `b${i}`) << i), 0).toString(16).toUpperCase()
return String(ed.val(id, ['output', 'lamp'].includes(n.value.kind) ? 'a' : 'q'))
})
function flip() {
if (!switchable.value) return
if (props.e.row) ed.toggleRow(n.value, props.e.row)
else ed.toggleInput(n.value)
}
function hold(down: boolean) {
if (!holdable.value) return
if (props.e.row) ed.pressRow(n.value, props.e.row, down)
else ed.press(n.value, down)
}
</script>
<template>
<div class="io-row" :class="{ selected, dup }">
<button
class="io-value"
:class="{ on: value !== '0', live: switchable || holdable }"
:title="switchable ? 'Click to flip' : holdable ? 'Hold to press' : `Now ${value}`"
:tabindex="switchable || holdable ? 0 : -1"
@click="flip"
@pointerdown="hold(true)"
@pointerup="hold(false)"
@pointerleave="hold(false)"
>
{{ value }}
</button>
<input
class="io-name"
:value="entryLabel(e)"
:placeholder="placeholder"
:data-group="group"
:data-i="index"
spellcheck="false"
@focus="ed.selectOnly([n.id])"
@change="ed.setLabel(n, ($event.target as HTMLInputElement).value, e.row)"
@keydown.enter.prevent="emit('next', $event)"
/>
<span class="io-kind" :title="dup ? 'Another one has the same name' : ''">
<Icon v-if="dup" name="lucide:triangle-alert" class="size-3" />{{ kind }}
</span>
<button class="icon-btn io-locate" title="Show on the canvas" @click="ed.focusNode(n.id)"><Icon name="lucide:locate-fixed" class="size-3.5" /></button>
</div>
</template>

View File

@ -1,8 +1,8 @@
<script setup lang="ts">
// Every input and output of the open circuit in one list, to rename them
// quickly: type a name, Enter jumps to the next one.
// quickly (type a name, Enter goes to the next) and to try them out.
import { duplicateNames, entryLabel, ioList, numberedNames, type IoEntry } from '~/lib/logic/bulk'
import { KIND_NAMES } from '~/lib/logic/progress'
import type { CircuitNode } from '~/lib/logic/types'
const ed = useEditor()
const io = computed(() => ioList(ed.def.value))
@ -12,41 +12,48 @@ const groups = computed(() => [
])
const selected = computed(() => new Set(ed.selection.value))
type Block = { panel: CircuitNode; items: { e: IoEntry; i: number }[] } | { e: IoEntry; i: number }
/** Rows of one panel are framed together under the panel's name. */
function blocks(entries: IoEntry[]): Block[] {
const out: Block[] = []
entries.forEach((e, i) => {
const last = out[out.length - 1]
if (e.row && last && 'panel' in last && last.panel.id === e.node.id) last.items.push({ e, i })
else if (e.row) out.push({ panel: e.node, items: [{ e, i }] })
else out.push({ e, i })
})
return out
}
const keyOf = (e: IoEntry) => (e.row ? `${e.node.id}/${e.row.id}` : e.node.id)
function pinNumber(e: IoEntry, entries: IoEntry[]) {
return entries.filter(x => x.pin).indexOf(e) + 1
}
function kindText(e: IoEntry, entries: IoEntry[]): string {
if (e.row) return `${e.node.label?.trim() || 'Panel'} · ${e.row.type}`
const kind = KIND_NAMES[e.node.kind] ?? e.node.kind
if (!e.pin) return kind
return `${kind} · pin ${entries.filter(x => x.pin).indexOf(e) + 1}`
if (e.row) return e.row.type === 'clock' && e.row.hz ? `clock ${e.row.hz} Hz` : e.row.type
if (e.pin) return `pin ${pinNumber(e, entries)}`
if (e.node.kind === 'clock') return e.node.hz ? `clock ${e.node.hz} Hz` : 'clock'
return { button: 'button', lamp: 'lamp', hex: 'display' }[e.node.kind as string] ?? e.node.kind
}
function placeholder(e: IoEntry, entries: IoEntry[]): string {
if (e.row) return e.row.name?.trim() || 'no name'
if (e.pin) {
const i = entries.filter(x => x.pin).indexOf(e) + 1
return e.node.kind === 'input' ? `in${i}` : `out${i}`
}
if (e.pin) return `${e.node.kind === 'input' ? 'in' : 'out'}${pinNumber(e, entries)}`
return 'no name'
}
/** Live value: 0/1, or the digit a display shows. */
function value(e: IoEntry): string {
const id = e.node.id
if (e.row) return String(ed.val(id, e.row.id))
if (e.node.kind === 'hex') return [0, 1, 2, 3].reduce((n, i) => n + (ed.val(id, `b${i}`) << i), 0).toString(16).toUpperCase()
return String(ed.val(id, ['output', 'lamp'].includes(e.node.kind) ? 'a' : 'q'))
}
const list = ref<HTMLElement>()
function next(e: KeyboardEvent, group: string, i: number) {
;(e.target as HTMLInputElement).blur()
function next(ev: KeyboardEvent, group: string, i: number) {
;(ev.target as HTMLInputElement).blur()
const el = list.value?.querySelector<HTMLInputElement>(`input[data-group="${group}"][data-i="${i + 1}"]`)
el?.focus()
el?.select()
}
// Numbering a whole group.
// Numbering a whole side.
const numbering = ref<null | 'in' | 'out'>(null)
const pattern = ref('D#')
const start = ref(0)
@ -79,9 +86,9 @@ function applyNumbering() {
<template>
<div ref="list">
<section v-for="g in groups" :key="g.id">
<div class="flex items-center gap-2">
<h3 class="grow">
<section v-for="g in groups" :key="g.id" class="io-section">
<div class="io-head">
<h3>
{{ g.title }} <span class="count-pill">{{ g.entries.length }}</span>
</h3>
<button v-if="g.entries.length > 1" class="btn-sm" title="Name them all with a numbered pattern" @click="openNumbering(g.id)">
@ -113,38 +120,45 @@ function applyNumbering() {
<p v-if="!g.entries.length" class="hint">
{{ g.id === 'in' ? 'No inputs yet. Place an input switch (I) to give this circuit an input pin.' : 'No outputs yet. Place an output pin (O) or a lamp (L).' }}
</p>
<ul v-else class="io-list">
<li
v-for="(e, i) in g.entries"
:key="keyOf(e)"
:class="{ selected: selected.has(e.node.id), dup: g.dup.has(entryLabel(e).toLowerCase()), pin: e.pin }"
>
<span class="io-value" :class="{ on: value(e) !== '0' }" :title="`Now ${value(e)}`">{{ value(e) }}</span>
<div class="io-main">
<input
class="io-name"
:value="entryLabel(e)"
:placeholder="placeholder(e, g.entries)"
:data-group="g.id"
:data-i="i"
spellcheck="false"
@focus="ed.selectOnly([e.node.id])"
@change="ed.setLabel(e.node, ($event.target as HTMLInputElement).value, e.row)"
@keydown.enter.prevent="next($event, g.id, i)"
<div v-else class="io-list">
<template v-for="b in blocks(g.entries)" :key="'panel' in b ? `p-${b.panel.id}` : keyOf(b.e)">
<div v-if="'panel' in b" class="io-group" :class="{ selected: selected.has(b.panel.id) }">
<div class="io-group-head">
<Icon name="lucide:sliders-vertical" class="size-3.5 shrink-0" />
<span class="grow truncate">{{ b.panel.label?.trim() || 'Input panel' }}</span>
<button class="icon-btn io-locate" title="Show on the canvas" @click="ed.focusNode(b.panel.id)"><Icon name="lucide:locate-fixed" class="size-3.5" /></button>
</div>
<EditorPinRow
v-for="it in b.items"
:key="keyOf(it.e)"
:e="it.e"
:group="g.id"
:index="it.i"
:kind="kindText(it.e, g.entries)"
:placeholder="placeholder(it.e, g.entries)"
:dup="g.dup.has(entryLabel(it.e).toLowerCase())"
:selected="false"
@next="next($event, g.id, it.i)"
/>
<span class="io-kind">
<Icon v-if="g.dup.has(entryLabel(e).toLowerCase())" name="lucide:triangle-alert" class="size-3" title="Another one has the same name" />
{{ kindText(e, g.entries) }}
</span>
</div>
<button class="icon-btn" title="Show on the canvas" @click="ed.focusNode(e.node.id)"><Icon name="lucide:locate-fixed" class="size-3.5" /></button>
</li>
</ul>
<EditorPinRow
v-else
:e="b.e"
:group="g.id"
:index="b.i"
:kind="kindText(b.e, g.entries)"
:placeholder="placeholder(b.e, g.entries)"
:dup="g.dup.has(entryLabel(b.e).toLowerCase())"
:selected="selected.has(b.e.node.id)"
@next="next($event, g.id, b.i)"
/>
</template>
</div>
</section>
<section>
<p class="hint">
Pins are what the circuit shows when you use it as a component, ordered top to bottom. Type a name and press Enter to go to the
next one. Clicking a name selects the part; the target icon centres the canvas on it.
Pins are what the circuit shows when you use it as a component, top to bottom. Click a value to flip a switch (hold a button).
Type a name and press Enter for the next one.
</p>
</section>
</div>

View File

@ -0,0 +1,34 @@
<script setup lang="ts">
// A hidden side panel shrinks to this strip; its buttons bring it back.
const props = defineProps<{ side: 'left' | 'right' }>()
const ed = useEditor()
const TABS = [
{ id: 'selection', label: 'Selection', icon: 'lucide:mouse-pointer-2' },
{ id: 'circuit', label: 'Circuit', icon: 'lucide:cpu' },
{ id: 'pins', label: 'Pins', icon: 'lucide:list' },
{ id: 'test', label: 'Test', icon: 'lucide:table' },
] as const
function openTab(id: (typeof TABS)[number]['id']) {
ed.rightTab.value = id
ed.toggleSidebar('right', true)
}
</script>
<template>
<aside class="rail" :class="props.side">
<button
class="rail-btn"
:title="props.side === 'left' ? 'Show parts and challenges ([)' : 'Show the side panel (])'"
@click="ed.toggleSidebar(props.side, true)"
>
<Icon :name="props.side === 'left' ? 'lucide:panel-left-open' : 'lucide:panel-right-open'" class="size-4" />
</button>
<template v-if="props.side === 'right'">
<button v-for="t in TABS" :key="t.id" class="rail-btn" :title="t.label" @click="openTab(t.id)">
<Icon :name="t.icon" class="size-4" />
</button>
</template>
</aside>
</template>

View File

@ -22,6 +22,7 @@ import {
duplicateComponent,
lookup,
makeUnique,
pinKeys,
mergeComponents,
newComponent,
packageSelection,
@ -36,7 +37,7 @@ import {
type Clip,
type SwapTarget,
} from '~/lib/logic/ops'
import { arrangeNodes, byPosition, numberedNames, type Arrange } from '~/lib/logic/bulk'
import { arrangeNodes, byPosition, numberedNames, seriesLinks, type Arrange, type Link } from '~/lib/logic/bulk'
import { parseProject, toProject } from '~/lib/logic/project'
import { Simulator } from '~/lib/logic/sim'
import {
@ -145,6 +146,17 @@ function create() {
const dialog = ref<null | 'projects' | 'share' | 'account' | 'versions' | 'table' | 'publish' | 'settings'>(null)
/** Tab shown in the right panel. */
const rightTab = ref<'selection' | 'circuit' | 'pins' | 'test'>('circuit')
/** Which side panels are open; remembered in this browser. */
const sidebars = reactive<{ left: boolean; right: boolean }>({ left: true, right: true })
try {
Object.assign(sidebars, JSON.parse(localStorage.getItem('logigate:sidebars') ?? '{}'))
} catch {}
function toggleSidebar(side: 'left' | 'right', open = !sidebars[side]) {
sidebars[side] = open
try {
localStorage.setItem('logigate:sidebars', JSON.stringify(sidebars))
} catch {}
}
/** Asks the canvas to centre on a part. */
const focusRequest = ref<{ id: string; n: number } | null>(null)
/** Pins being wired one after another; `at` is the one the next click connects. */
@ -449,12 +461,10 @@ function create() {
return !!(dir === 'in' ? s.inputs : s.outputs).find(p => p.key === pin)?.bus
}
function connect(from: PinRef, to: PinRef, pts?: Pt[]) {
/** Adds one wire (replacing whatever fed that input) without recording an undo step. False for a cable/wire mismatch. */
function addWire(from: PinRef, to: PinRef, pts?: Pt[]): boolean {
const d = def.value
if (isBus(from.node, from.pin, 'out') !== isBus(to.node, to.pin, 'in')) {
play('error')
return notify('A cable runs from a bundle to a split; single wires go to the bundle’s and split’s side pins', 'error')
}
if (isBus(from.node, from.pin, 'out') !== isBus(to.node, to.pin, 'in')) return false
const old = d.wires.find(w => w.to.node === to.node && w.to.pin === to.pin)
d.wires = d.wires.filter(w => w !== old)
const wire: (typeof d.wires)[number] = { id: uid('w'), from, to }
@ -469,11 +479,43 @@ function create() {
adoptName(d, fn, from.pin, tn, to.pin, getDef.value)
adoptName(d, tn, to.pin, fn, from.pin, getDef.value)
}
return true
}
function connect(from: PinRef, to: PinRef, pts?: Pt[]) {
if (!addWire(from, to, pts)) {
play('error')
return notify('A cable runs from a bundle to a split; single wires go to the bundle’s and split’s side pins', 'error')
}
wireSel.value = []
commit()
play('connect')
}
/** Several wires as one undo step. */
function connectMany(links: Link[]) {
const made = links.filter(l => addWire(l.from, l.to)).length
if (!made) return
wireSel.value = []
commit()
play('connect')
if (made > 1) notify(`Connected ${made} wires`)
}
/**
* The selected parts to another part's pins, in order: their outputs to
* its inputs (dir 'out'), or its outputs to their inputs (dir 'in').
*/
function connectSelectionTo(targetId: string, dir: 'in' | 'out') {
const target = def.value.nodes.find(n => n.id === targetId)
const first = def.value.nodes.filter(n => selection.value.includes(n.id) && n.id !== targetId).sort(byPosition)[0]
if (!target || !first) return
const mine = dir === 'out' ? pinKeys(first, getDef.value).outs[0] : pinKeys(first, getDef.value).ins[0]
const theirs = dir === 'out' ? pinKeys(target, getDef.value).ins[0] : pinKeys(target, getDef.value).outs[0]
if (!mine || !theirs) return notify('No matching pins to connect', 'error')
connectMany(seriesLinks(def.value, getDef.value, selection.value, { node: first.id, pin: mine, dir }, { node: target.id, pin: theirs }))
}
/** Parts plus the panels docked to them: they move, copy and delete together. */
function withDocked(ids: Iterable<string>): Set<string> {
const set = new Set(ids)
@ -1620,8 +1662,12 @@ function create() {
transistorsOfNode,
nands,
rightTab,
sidebars,
toggleSidebar,
focusRequest,
swapMany,
connectMany,
connectSelectionTo,
renameMany,
setLabel,
setSwitches,

View File

@ -4,7 +4,7 @@
import { TRANSISTORS_PER_NAND } from './analyze'
import type { DefLookup } from './geometry'
import { SINK_KINDS, SOURCE_KINDS } from './ops'
import { pinKeys, SINK_KINDS, SOURCE_KINDS } from './ops'
import type { CircuitNode, ComponentDef, PanelRow } from './types'
/** Top to bottom, then left to right: the order pins and names follow. */
@ -132,3 +132,48 @@ export function arrangeNodes(nodes: CircuitNode[], how: Arrange): void {
sorted.forEach((n, i) => (n[axis] = Math.round(lo + i * step)))
}
}
export interface Link {
from: { node: string; pin: string }
to: { node: string; pin: string }
}
/**
* Wiring several parts to one other part in one go. One wire was dragged
* from pin `from` of a selected part to pin `to` of `target`; the other
* selected parts follow in position order, each from its pin in the same
* place, to the target's next pins. Parts beyond the target's last pin are
* left out. Returns every link to make, the dragged one included.
*/
export function seriesLinks(
def: ComponentDef,
get: DefLookup,
selected: string[],
from: { node: string; pin: string; dir: 'in' | 'out' },
to: { node: string; pin: string },
): Link[] {
const side = (n: CircuitNode, dir: 'in' | 'out') => (dir === 'out' ? pinKeys(n, get).outs : pinKeys(n, get).ins)
const single = from.dir === 'out' ? [{ from: { node: from.node, pin: from.pin }, to }] : [{ from: to, to: { node: from.node, pin: from.pin } }]
const source = def.nodes.find(n => n.id === from.node)
const target = def.nodes.find(n => n.id === to.node)
if (!source || !target || !selected.includes(from.node)) return single
const k = side(source, from.dir).indexOf(from.pin)
// Only parts with a pin in the same place take part (a note or a lamp among outputs is skipped).
const ids = new Set(selected)
ids.delete(to.node)
const nodes = def.nodes.filter(n => ids.has(n.id) && side(n, from.dir)[k] !== undefined).sort(byPosition)
const dragged = nodes.findIndex(n => n.id === from.node)
const targetPins = side(target, from.dir === 'out' ? 'in' : 'out')
const t = targetPins.indexOf(to.pin)
if (k < 0 || t < 0) return single
const links: Link[] = []
nodes.forEach((n, i) => {
const mine = side(n, from.dir)[k]
const theirs = targetPins[t + i - dragged]
if (!mine || !theirs) return
const a = { node: n.id, pin: mine }
const b = { node: target.id, pin: theirs }
links.push(from.dir === 'out' ? { from: a, to: b } : { from: b, to: a })
})
return links
}

View File

@ -1,6 +1,6 @@
import { describe, expect, it } from 'vitest'
import { nandCounts, TRANSISTORS_PER_NAND } from '../app/lib/logic/analyze'
import { arrangeNodes, duplicateNames, entryLabel, ioList, numberedNames, sharedFamily, transistorBreakdown } from '../app/lib/logic/bulk'
import { arrangeNodes, duplicateNames, entryLabel, ioList, numberedNames, seriesLinks, sharedFamily, transistorBreakdown } from '../app/lib/logic/bulk'
import { compile } from '../app/lib/logic/compile'
import { createProject, lookup } from '../app/lib/logic/ops'
import type { CircuitNode, ComponentDef } from '../app/lib/logic/types'
@ -94,3 +94,61 @@ describe('transistors', () => {
expect(lines.reduce((s, l) => s + l.total, 0)).toBe((counts.get('ex-fa') ?? 0) * TRANSISTORS_PER_NAND)
})
})
describe('wiring several parts at once', () => {
const p = createProject({ examples: true })
const get = lookup(p)
const add4 = get('ex-add4')!
const outsOfAdder = (n: CircuitNode) => {
const d = get(n.chip!)!
return d.nodes.filter(x => x.kind === 'output').sort((a, b) => a.y - b.y).map(x => x.id)
}
const def: ComponentDef = {
id: 't',
name: 'T',
symbol: 'box',
nodes: [
node('add', 'chip', 0, 0, { chip: add4.id }),
...['Y0', 'Y1', 'Y2', 'Y3', 'Carry'].map((l, i) => node(`y${i}`, 'output', 20, i * 2, { label: l })),
],
wires: [],
}
const sel = ['y0', 'y1', 'y2', 'y3', 'y4']
const S = outsOfAdder(def.nodes[0]!)
it('drags one wire and connects every selected output to the next pin in turn', () => {
const links = seriesLinks(def, get, sel, { node: 'y0', pin: 'a', dir: 'in' }, { node: 'add', pin: S[0]! })
expect(links.map(l => `${l.from.pin}>${l.to.node}`)).toEqual(S.map((s, i) => `${s}>y${i}`))
})
it('counts from the dragged part, both ways, and stops at the last pin', () => {
const links = seriesLinks(def, get, sel, { node: 'y2', pin: 'a', dir: 'in' }, { node: 'add', pin: S[0]! })
expect(links.map(l => `${l.from.pin}>${l.to.node}`)).toEqual([`${S[0]}>y2`, `${S[1]}>y3`, `${S[2]}>y4`])
})
it('falls back to a single wire when the dragged part is not selected', () => {
expect(seriesLinks(def, get, ['y1'], { node: 'y0', pin: 'a', dir: 'in' }, { node: 'add', pin: S[0]! })).toHaveLength(1)
})
})
describe('wiring several parts at once, mixed selection', () => {
it('skips selected parts without a matching pin instead of using up a target pin', () => {
const p = createProject({ examples: true })
const get = lookup(p)
const def: ComponentDef = {
id: 't',
name: 'T',
symbol: 'box',
nodes: [
node('add', 'chip', 0, 0, { chip: 'ex-add4' }),
node('y0', 'output', 20, 0),
node('note', 'note', 0, 1, { label: 'hi' }),
node('y1', 'output', 20, 2),
],
wires: [],
}
const S = get('ex-add4')!.nodes.filter(x => x.kind === 'output').sort((a, b) => a.y - b.y).map(x => x.id)
const links = seriesLinks(def, get, ['y0', 'note', 'y1'], { node: 'y0', pin: 'a', dir: 'in' }, { node: 'add', pin: S[0]! })
expect(links.map(l => `${l.from.pin}>${l.to.node}`)).toEqual([`${S[0]}>y0`, `${S[1]}>y1`])
})
})