A parts dropped from the list connect where they land, cable buttons beside a selected part's pins, a reload offer for new releases

- Dragging (or placing) a part onto pins: its free pins land on pins they can join, a square away is enough, green rings show where; dropped, it is placed and wired in one step (Alt: just place)
- A selected component, panel or hex display shows a cable button beside its outputs and its inputs: one click for a cable onto those pins (or pick S0–S3, all 5, ...)
- Cable from outputs (or into inputs) whose pins already have one wire each takes those wires into the cable instead of adding a second path
- An open tab notices a new release within a minute and offers a reload (work is saved)

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Fabian @ Blax Software 2026-10-21 14:21:40 +02:00
parent b19057b9d8
commit 7a00546e63
8 changed files with 204 additions and 14 deletions

View File

@ -960,6 +960,32 @@ kbd {
.node .face-text.ink-green { fill: #3ddc84; }
.node .face-text.ink-blue { fill: #4dabff; }
/* Cable buttons beside a selected part's pins. */
.cable-btn {
cursor: pointer;
}
.cable-btn circle {
fill: var(--panel-2);
stroke: var(--accent);
stroke-width: 1.3;
}
.cable-btn path {
fill: none;
stroke: var(--text);
stroke-width: 1.5;
stroke-linecap: round;
}
.cable-btn:hover circle {
fill: var(--accent);
}
.cable-btn:hover path {
stroke: #0e1116;
}
/* + and − under a selected gate. */
.widen-btn {
cursor: pointer;
@ -3173,3 +3199,27 @@ kbd {
flex: 1;
min-width: 120px;
}
/* A new release is out: offer a reload. */
.update-bar {
position: fixed;
top: 56px;
left: 50%;
z-index: 65;
display: flex;
align-items: center;
gap: 10px;
padding: 7px 8px 7px 14px;
transform: translateX(-50%);
border: 1px solid rgb(76 194 255 / 0.5);
border-radius: 10px;
background: #142231;
box-shadow: 0 10px 30px rgb(0 0 0 / 0.4);
color: var(--text);
font-size: 13px;
}
.update-bar .btn-sm {
border-color: var(--accent);
color: var(--accent);
}

View File

@ -1,5 +1,11 @@
<script setup lang="ts">
const ed = useEditor()
const updateReady = useState('update-ready', () => false)
function reload() {
// Unsaved changes are written when the page unloads.
location.reload()
}
const link = computed(() => {
const l = ed.linking.value
@ -32,6 +38,12 @@ onMounted(() => {
<Transition name="fade">
<div v-if="ed.notice.value" class="toast" :class="ed.notice.value.kind">{{ ed.notice.value.text }}</div>
</Transition>
<div v-if="updateReady" class="update-bar" role="status">
<Icon name="lucide:sparkles" class="size-4 shrink-0" />
<span>A new version of Logigate is ready. Your work is saved.</span>
<button class="btn-sm" @click="reload">Reload now</button>
<button class="icon-btn" title="Later" @click="updateReady = false"><Icon name="lucide:x" class="size-3.5" /></button>
</div>
<div v-if="ed.cabling.value" class="placing-hint">
<strong>Cable with {{ ed.cabling.value.wires.length }} wires:</strong>
{{ ed.cabling.value.start ? 'click where it ends (its split).' : 'click where it starts (its bundle).' }} <kbd>Esc</kbd> cancels.

View File

@ -262,21 +262,90 @@ function originFor(p: { kind: CircuitNode['kind']; chip?: string }, at: Pt): Pt
return [Math.round(at[0] - (b.x + b.w / 2)), Math.round(at[1] - (b.y + b.h / 2))]
}
const ghost = computed<CircuitNode | null>(() => {
const p = ed.placing.value
if (!p || !cursor.value) return null
const [x, y] = originFor(p, cursor.value)
return { id: 'ghost', kind: p.kind, chip: p.chip, x, y, label: p.kind === 'note' ? 'Note' : p.kind === 'input' ? '?' : undefined }
/** Pins of everything on the canvas, for a new part to land on. */
const allPins = computed(() => dropPins(def.value, def.value.nodes, n => shapes.value.get(n.id)!))
/** Alt held while placing: just place, connect nothing. */
const altDown = ref(false)
/**
* Where a new part goes (being placed or dragged in from the parts list):
* at the mouse, or a square over so its free pins land on pins they can
* join, with the wires that makes.
*/
function landing(p: { kind: CircuitNode['kind']; chip?: string }, at: Pt, alt: boolean) {
const [x, y] = originFor(p, at)
const node: CircuitNode = { id: 'ghost', kind: p.kind, chip: p.chip, x, y, label: p.kind === 'note' ? 'Note' : p.kind === 'input' ? '?' : undefined }
const snap = alt ? null : dropLinks(dropPins(def.value, [node], n => ed.shape(n)), allPins.value, 1)
if (snap) {
node.x += snap.shift[0]
node.y += snap.shift[1]
}
return { node, links: snap?.links ?? [] }
}
const ghostLanding = computed(() => {
const p = ed.placing.value ?? ed.dragPart.value
return p && cursor.value ? landing(p, cursor.value, altDown.value) : null
})
const ghost = computed<CircuitNode | null>(() => ghostLanding.value?.node ?? null)
function onDragOver(e: DragEvent) {
if (!ed.dragPart.value) return
cursor.value = toWorld(e)
altDown.value = e.altKey
}
function onDragLeave(e: DragEvent) {
// Leaving the canvas, not just moving from one part of it to another.
if (!root.value?.contains(e.relatedTarget as Node | null)) cursor.value = null
}
// ── Cable buttons on a selected part ────────────────────────────────
/**
* One selected component (or panel, or hex display) gets a cable button
* beside its outputs and its inputs: a cable straight onto those pins.
*/
const cableButtons = computed(() => {
if (drag.value || ed.selection.value.length !== 1 || ed.linking.value || ed.placing.value) return []
const n = nodeMap.value.get(ed.selection.value[0]!)
if (!n) return []
const choices = ed.cableChoices(n)
const s = shapes.value.get(n.id)!
const out: { side: 'out' | 'in'; x: number; y: number }[] = []
const mid = (ps: { dy: number }[]) => (Math.min(...ps.map(p => p.dy)) + Math.max(...ps.map(p => p.dy))) / 2
const outs = s.outputs.filter(p => !p.bus)
const ins = s.inputs.filter(p => !p.bus)
if (choices.out.length && outs.length) out.push({ side: 'out', x: n.x + Math.max(...outs.map(p => p.dx)) + 1.3, y: n.y + mid(outs) })
if (choices.in.length && ins.length) out.push({ side: 'in', x: n.x + Math.min(...ins.map(p => p.dx)) - 1.3, y: n.y + mid(ins) })
return out
})
/** A cable button: with one way to do it, it is done; with several, they are offered. */
function onCableButton(side: 'out' | 'in', e: PointerEvent) {
const n = nodeMap.value.get(ed.selection.value[0]!)
if (!n) return
const groups = ed.cableChoices(n)[side]
const run = (pins: string[]) => (side === 'out' ? ed.cableOut(n.id, pins) : ed.cableIn(n.id, pins))
if (groups.length === 1) return run(groups[0]!.pins)
menu.value = {
x: e.clientX + 6,
y: e.clientY + 6,
entries: [
{ head: side === 'out' ? 'Cable from outputs' : 'Cable into inputs' },
...groups.map(g => ({ label: g.label, note: `${g.pins.length} wires`, icon: side === 'out' ? 'lucide:merge' : 'lucide:split', run: () => run(g.pins) })),
],
}
}
function onDrop(e: DragEvent) {
const raw = e.dataTransfer?.getData('application/x-logigate')
ed.dragPart.value = null
if (!raw) return
const p = JSON.parse(raw) as { kind: CircuitNode['kind']; chip?: string }
if (p.chip && !ed.canPlace(p.chip)) return ed.notify('A component cannot contain itself', 'error')
if (!ed.canPlaceKind(p.kind)) return
const [x, y] = originFor(p, toWorld(e))
ed.addNode(p, x, y)
const { node, links } = landing(p, toWorld(e), e.altKey)
ed.addNode(p, node.x, node.y, links)
}
// ── Pointer interaction ─────────────────────────────────────────────
@ -388,13 +457,15 @@ function onPointerDown(e: PointerEvent) {
ed.placing.value = null
return ed.notify('A component cannot contain itself', 'error')
}
const [x, y] = originFor(placing, w)
ed.addNode(placing, x, y)
const { node, links } = landing(placing, w, e.altKey)
ed.addNode(placing, node.x, node.y, links)
if (!e.shiftKey && !placing.keep) ed.placing.value = null
return
}
const target = e.target as Element
const cableEl = target.closest('[data-cable]')
if (cableEl) return onCableButton(cableEl.getAttribute('data-cable') as 'out' | 'in', e)
const widenEl = target.closest('[data-inputs]')
if (widenEl) {
// + or − under a selected gate: one input more or less.
@ -535,6 +606,7 @@ function onWireDown(e: PointerEvent, el: Element, w: Pt) {
function onPointerMove(e: PointerEvent) {
const w = toWorld(e)
cursor.value = w
altDown.value = e.altKey
const d = drag.value
if (!d) return
switch (d.kind) {
@ -1187,6 +1259,13 @@ function plugNear(n: CircuitNode): { part: string; rings: Pt[] } | null {
/** Pins a dragged part will connect to when dropped, shown as green rings. */
const dropRings = computed(() => {
const g = ghostLanding.value
if (g?.links.length) {
return g.links.map(l => {
const end = l.from.node === 'ghost' ? { ...l.to, dir: 'in' } : { ...l.from, dir: 'out' }
return allPins.value.find(p => p.node === end.node && p.pin === end.pin && p.dir === end.dir)!
}).filter(Boolean)
}
const d = drag.value
if (d?.kind === 'move' && d.plug) return d.plug.rings.map(([x, y]) => ({ x, y }))
if (d?.kind !== 'move' || !d.snap || !d.still) return []
@ -1249,7 +1328,8 @@ defineExpose({ fit, zoomAt })
@pointerleave="cursor = null"
@wheel.prevent="onWheel"
@contextmenu.prevent
@dragover.prevent
@dragover.prevent="onDragOver"
@dragleave="onDragLeave"
@drop.prevent="onDrop"
>
<svg width="100%" height="100%">
@ -1391,6 +1471,17 @@ defineExpose({ fit, zoomAt })
</template>
</g>
<circle v-for="(p, i) in dropRings" :key="`d${i}`" :cx="p.x * G" :cy="p.y * G" r="7" class="drop-ring" />
<g
v-for="c in cableButtons"
:key="c.side"
class="cable-btn"
:data-cable="c.side"
:transform="`translate(${c.x * G} ${c.y * G})${c.side === 'in' ? ' scale(-1 1)' : ''}`"
>
<title>{{ c.side === 'out' ? 'Cable from these outputs' : 'Cable into these inputs' }}</title>
<circle r="9" />
<path d="M-4.5 -4.5L1.5 0M-4.5 0H1.5M-4.5 4.5L1.5 0M1.5 0H5" />
</g>
<g class="targets">
<circle v-for="(t, i) in targets" :key="`t${i}`" :cx="t.x * G" :cy="t.y * G" r="5.5" class="pin-target" :class="{ taken: !t.free }" />

View File

@ -23,7 +23,8 @@ const SHORTCUTS: [string, string][] = [
['Mouse wheel', 'Zoom'],
['N, I, O, L, B, C, H, T, P, X', 'Place NAND, input, output, lamp, button, clock, hex display, note, input panel, pixel'],
['Select wires, Ctrl+G', 'Bundle them into one cable; an end whose wires all meet one part plugs straight into it'],
['Right click a component, Cable from outputs', 'A cable plugged onto S0–S3 (or any group); drop its free end on the next part\'s pins'],
['Select a component, cable button beside its pins', 'A cable plugged onto S0–S3 (or any group); drop its free end on the next part\'s pins'],
['Drag a part from the list onto pins', 'It lands on them and connects (green rings show where); Alt just places it'],
['Drag a plugged cable end away', 'Pull it out; drop its pins on a part\'s pins to plug it in again'],
['Drag a part onto a pin', 'Connects there when dropped (a green ring shows where); hold Alt to just place it'],
['Drag a wire by its end', 'Moves that end to another pin (grab it near the pin, or by the small circle)'],

View File

@ -61,6 +61,7 @@ function onDragStart(e: DragEvent, kind: NodeKind, chip?: string) {
}
e.dataTransfer?.setData('application/x-logigate', JSON.stringify({ kind, chip }))
if (e.dataTransfer) e.dataTransfer.effectAllowed = 'copy'
ed.dragPart.value = { kind, chip }
}
const solved = computed(() => new Set(ed.project.value.solved))
@ -117,6 +118,7 @@ const started = computed(() => new Map(ed.project.value.components.filter(d => d
:draggable="ed.canPlaceKind(item.kind)"
@click="pick(item.kind)"
@dragstart="onDragStart($event, item.kind)"
@dragend="ed.dragPart.value = null"
>
<span v-if="item.kind === 'nand'" class="nand-badge">&amp;</span>
<Icon v-else :name="item.icon" class="size-4 shrink-0 text-(--muted)" />
@ -144,6 +146,7 @@ const started = computed(() => new Map(ed.project.value.components.filter(d => d
:draggable="ed.canPlace(d.id)"
@click="pick('chip', d.id)"
@dragstart="onDragStart($event, 'chip', d.id)"
@dragend="ed.dragPart.value = null"
>
<Icon :name="d.challenge && solved.has(d.challenge) ? 'lucide:badge-check' : 'lucide:box'" class="size-4 shrink-0" :class="d.challenge && solved.has(d.challenge) ? 'text-(--on)' : 'text-(--muted)'" />
<span class="grow truncate">{{ d.name }}</span>

View File

@ -438,7 +438,11 @@ function create() {
}
// ── Editing ───────────────────────────────────────────────────────
function addNode(p: Placing, x: number, y: number): CircuitNode {
/** A part being dragged in from the parts list, so the canvas can show where it would connect. */
const dragPart = ref<Placing | null>(null)
/** Places a part; `links` are wires to make at once, with "ghost" standing for the new part. */
function addNode(p: Placing, x: number, y: number, links: Link[] = []): CircuitNode {
const node: CircuitNode = { id: uid('n'), kind: p.kind, x, y }
if (p.chip) node.chip = p.chip
if (p.kind === 'input' || p.kind === 'output') {
@ -455,10 +459,13 @@ function create() {
if (p.kind === 'panel') node.rows = newPanelRows()
if (p.kind === 'bundle' || p.kind === 'split') node.bits = 4
def.value.nodes.push(node)
const swap = (r: PinRef) => (r.node === 'ghost' ? { node: node.id, pin: r.pin } : r)
const made = links.filter(l => addWire(swap(l.from), swap(l.to))).length
selection.value = [node.id]
wireSel.value = []
commit()
play('place')
play(made ? 'connect' : 'place')
if (made) notify(`Placed and connected ${made} wire${made === 1 ? '' : 's'}`)
return node
}
@ -852,13 +859,23 @@ function create() {
const d = def.value
const kinds = new Map(d.nodes.map(x => [x.id, x]))
const cabled = new Set(d.wires.filter(w => w.from.node === n.id && kinds.get(w.to.node)?.plug === n.id).map(w => w.from.pin))
const fed = new Set(d.wires.filter(w => w.to.node === n.id).map(w => w.to.pin))
// Inputs already fed by a plugged cable are taken; inputs with a plain wire can take a cable (the wire goes into it).
const fed = new Set(d.wires.filter(w => w.to.node === n.id && kinds.get(w.from.node)?.plug === n.id).map(w => w.to.pin))
const outs = s.outputs.filter(p => !p.bus).sort((a, b) => a.dy - b.dy)
const ins = n.kind === 'panel' ? [] : s.inputs.filter(p => !p.bus).sort((a, b) => a.dy - b.dy)
return { out: pinGroups(outs, k => !cabled.has(k)), in: pinGroups(ins, k => !fed.has(k)) }
}
/**
* A cable from some of a part's outputs. When each of them already has
* one wire, those wires go into the cable (both ends plug in where they
* can); otherwise a new cable starts there with a free end.
*/
function cableOut(nodeId: string, pins: string[]) {
const wires = def.value.wires.filter(w => w.from.node === nodeId && pins.includes(w.from.pin))
const per = new Map<string, number>()
for (const w of wires) per.set(w.from.pin, (per.get(w.from.pin) ?? 0) + 1)
if (wires.length >= 2 && pins.every(p => per.get(p) === 1)) return bundleSelected(wires.map(w => w.id))
const res = cableFromPins(def.value, nodeId, pins, getDef.value)
if (!res.ok) return notify(res.error, 'error')
selection.value = [res.split.id]
@ -867,7 +884,10 @@ function create() {
notify(`Cable with ${res.split.bits} wires: drag its free end onto the pins where they go`)
}
/** A cable into some of a part's inputs: their wires go into it when they all have one, else a new cable into the free ones. */
function cableIn(nodeId: string, pins: string[]) {
const wires = def.value.wires.filter(w => w.to.node === nodeId && pins.includes(w.to.pin))
if (wires.length >= 2 && wires.length === pins.length) return bundleSelected(wires.map(w => w.id))
const res = cableIntoPins(def.value, nodeId, pins, getDef.value)
if (!res.ok) return notify(res.error, 'error')
selection.value = [res.bundle.id]
@ -1975,6 +1995,7 @@ function create() {
unplugEnd,
setPitch,
addCablePanel,
dragPart,
cableChoices,
cableOut,
cableIn,

View File

@ -0,0 +1,9 @@
// A new release was deployed while this tab was open: offer a reload, so
// nobody keeps working in an old version. The project is saved on every
// change, so reloading loses nothing.
export default defineNuxtPlugin(nuxtApp => {
const ready = useState('update-ready', () => false)
nuxtApp.hooks.hook('app:manifest:update', () => {
ready.value = true
})
})

View File

@ -7,6 +7,9 @@ export default defineNuxtConfig({
// The editor lives in the browser (canvas, localStorage), so no SSR.
ssr: false,
// Look for a new release every minute, so an open tab can offer a reload.
experimental: { checkOutdatedBuildInterval: 60_000 },
modules: ['@nuxt/fonts', '@nuxt/icon'],
fonts: {