R Packed panels, Tab adds rows, flyouts at the pointer, steady top bar

Combining switches, buttons, lamps or outputs into a panel, and merging
panels, puts the rows right under each other (space 0). Tab in the last
row's name of a panel, or the last line of a connector type, adds the
next one once it is filled in. The bottom bar's lists open centred above
the pointer. The top bar keeps the width it has with both panels open,
centred, so it no longer grows and shrinks with the panels.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Fabian @ Blax Software 2026-10-22 22:47:38 +02:00
parent 6398381550
commit 24bc66f798
7 changed files with 54 additions and 32 deletions

View File

@ -64,6 +64,9 @@ kbd {
.workspace {
--left: 272px;
--right: 280px;
/* The top bar keeps the width it has with both panels open, centred, whatever is open. */
--bar-inset: calc(280px + 12px);
position: relative;
display: grid;
grid-template-columns: var(--left) 1fr;
min-height: 0;
@ -112,6 +115,7 @@ kbd {
@media (max-width: 820px) {
.workspace,
.workspace.has-selection {
--bar-inset: 12px;
grid-template-columns: 1fr;
grid-template-rows: 1fr 40%;
}
@ -4489,9 +4493,10 @@ table.board {
.top-dock {
position: absolute;
top: 10px;
left: 12px;
right: 12px;
left: var(--bar-inset);
right: var(--bar-inset);
z-index: 30;
container-type: inline-size;
pointer-events: none;
}

View File

@ -41,11 +41,11 @@ watch(
<EditorInspector v-if="ed.panelOpen.value" />
<EditorRail v-else />
<main class="stage">
<EditorToolbar />
<EditorCanvas />
<EditorBottomBar />
</main>
<EditorSelectionPanel v-if="hasSelection" />
<EditorToolbar />
</div>
</template>
<Transition name="fade">

View File

@ -31,12 +31,19 @@ const open = ref<string | null>(null)
const anchor = ref(0)
let timer: ReturnType<typeof setTimeout> | undefined
function show(id: string, e: Event) {
const dock = ref<HTMLElement>()
/** Where the list opens: centred above the pointer, kept inside the canvas. */
function anchorAt(x: number) {
const r = dock.value!.getBoundingClientRect()
const half = 130
anchor.value = Math.min(Math.max(x - r.left, half), Math.max(half, r.width - half))
}
function show(id: string, e: PointerEvent) {
clearTimeout(timer)
const el = e.currentTarget as HTMLElement
const go = () => {
if (open.value !== id) anchorAt(e.clientX)
open.value = id
anchor.value = el.offsetLeft + el.offsetWidth / 2
}
// Moving along the bar switches at once; the first one waits a moment.
if (open.value) go()
@ -52,13 +59,12 @@ function stay() {
clearTimeout(timer)
}
function toggle(id: string, e: Event) {
function toggle(id: string, e: MouseEvent) {
if (open.value === id) open.value = null
else {
clearTimeout(timer)
const el = e.currentTarget as HTMLElement
anchorAt(e.clientX)
open.value = id
anchor.value = el.offsetLeft + el.offsetWidth / 2
}
}
@ -95,7 +101,7 @@ onBeforeUnmount(() => window.removeEventListener('keydown', onKey, true))
</script>
<template>
<div class="bottom-dock" @pointerdown.stop>
<div ref="dock" class="bottom-dock" @pointerdown.stop>
<Transition name="flyout">
<div v-if="open" class="flyout" :style="{ left: `${anchor}px` }" @pointerenter="stay" @pointerleave="leave">
<!-- Built-in parts -->

View File

@ -55,6 +55,15 @@ function remove(i: number) {
save()
}
/** Tab in the last line's name, once it is filled in, adds a line and goes on to it. */
function lineTab(i: number, e: KeyboardEvent) {
const lines = type.value?.lines
if (e.shiftKey || !lines || i !== lines.length - 1 || !(e.target as HTMLInputElement).value.trim()) return
e.preventDefault()
setLine(i, e)
addLine()
}
function addLine() {
const lines = type.value?.lines
if (!lines || lines.length >= 64) return
@ -107,7 +116,7 @@ const forward = computed(() => type.value?.lines.filter(l => !l.back).length ??
<ul class="conn-lines">
<li v-for="(l, i) in type.lines" :key="i">
<span class="conn-index">{{ i }}</span>
<input :value="l.name" maxlength="24" @change="setLine(i, $event)" @keydown.enter="($event.target as HTMLInputElement).blur()" />
<input :value="l.name" maxlength="24" @change="setLine(i, $event)" @keydown.tab="lineTab(i, $event)" @keydown.enter="($event.target as HTMLInputElement).blur()" />
<button
class="btn-sm conn-dir"
:class="{ back: l.back }"

View File

@ -213,6 +213,16 @@ function setRowLabel(row: PanelRow, e: Event) {
ed.commit()
}
/** Tab in the last row's name, once it is filled in, adds a row and goes on to it. */
function tabOn(row: PanelRow, i: number, e: KeyboardEvent) {
const input = e.target as HTMLInputElement
if (e.shiftKey || n.value.attach || i !== (n.value.rows?.length ?? 0) - 1 || !input.value.trim()) return
e.preventDefault()
setRowLabel(row, e)
ed.addRow(n.value)
nextTick(() => document.querySelector<HTMLInputElement>('.panel-rows > li:last-child > input')?.focus())
}
/** Rows showing their extra settings (key, colour, spacing, order). */
const openRows = ref(new Set<string>())
function toggleRow(id: string) {
@ -442,7 +452,7 @@ function setRowHz(row: PanelRow, e: Event) {
>
<Icon :name="openRows.has(r.id) ? 'lucide:chevron-down' : 'lucide:chevron-right'" class="size-3.5" />
</button>
<input :value="r.label ?? ''" :placeholder="rowLabel({ ...r, label: undefined }, i)" title="Name" @change="setRowLabel(r, $event)" />
<input :value="r.label ?? ''" :placeholder="rowLabel({ ...r, label: undefined }, i)" title="Name" @change="setRowLabel(r, $event)" @keydown.tab="tabOn(r, i, $event)" />
<select v-if="!outPanel" :value="r.type" title="Kind" @change="ed.setRowType(r, ($event.target as HTMLSelectElement).value as PanelControl)">
<option v-for="c in CONTROLS" :key="c.value" :value="c.value">{{ c.label }}</option>
</select>

View File

@ -4,7 +4,7 @@
// input, an output panel on its right a row per output. A docked panel moves
// with its component and follows it when the component gains or loses pins.
import { chipPins, panelOffsets, rowPin, shapeOf, type DefLookup } from './geometry'
import { chipPins, rowPin, shapeOf, type DefLookup } from './geometry'
import { pinName } from './labels'
import { lookup, uid } from './ops'
import type { CircuitNode, ComponentDef, PanelRow, Project } from './types'
@ -177,7 +177,7 @@ export function detachPanel(panel: CircuitNode) {
/**
* Joins panels into one: the top one keeps its rows, the others' rows follow
* below in order, keeping their spacing, with their wires. The joined panel
* below in order, packed without gaps, with their wires. The joined panel
* is free (no longer docked). Returns it with the pin keys that changed
* (old → new), so circuits that place this one can keep their wires; null
* for fewer than two panels.
@ -190,16 +190,11 @@ export function mergePanels(def: ComponentDef, ids: string[]): { panel: CircuitN
if (panels.length < 2) return null
const [target, ...rest] = panels as [CircuitNode, ...CircuitNode[]]
const rows = target.rows ?? []
const at = panelOffsets(rows)
rows.forEach((r, i) => (r.dy = at[i]!))
let bottom = at.length ? at[at.length - 1]! : -1
const used = new Set(rows.map(r => r.id))
const renamed = new Map<string, string>()
for (const p of rest) {
const theirs = p.rows ?? []
const off = panelOffsets(theirs)
const shift = bottom + 1 - (off[0] ?? 0)
theirs.forEach((r, i) => {
theirs.forEach(r => {
const id = used.has(r.id) ? uid('r') : r.id
used.add(id)
for (const w of def.wires) {
@ -207,10 +202,11 @@ export function mergePanels(def: ComponentDef, ids: string[]): { panel: CircuitN
if (w.to.node === p.id && w.to.pin === r.id) w.to = { node: target.id, pin: id }
}
renamed.set(rowPin(p.id, r.id), rowPin(target.id, id))
rows.push({ ...r, id, dy: off[i]! + shift })
rows.push({ ...r, id })
})
if (theirs.length) bottom = rows[rows.length - 1]!.dy!
}
// One row under the other, no space between.
for (const r of rows) delete r.dy
target.rows = rows
delete target.attach
delete target.skip
@ -226,8 +222,7 @@ const SINKS = new Set(['output', 'lamp'])
/**
* Turns separate switches, buttons and clocks into one input panel, or
* output pins and lamps into one output panel: a row each, top to bottom,
* with their names, settings and wires. Rows keep their distance where the
* parts were spread out. Returns the panel and the pin keys that changed
* with their names, settings and wires, packed without gaps. Returns the panel and the pin keys that changed
* (old → new) for circuits that place this one; null when the parts are
* not all of one side or fewer than two.
*/
@ -240,11 +235,8 @@ export function combineIntoPanel(def: ComponentDef, ids: string[], get: DefLooku
const pinKind = out ? 'output' : 'input'
if (!sel.some(n => n.kind === pinKind)) panel.inner = true
const renamed = new Map<string, string>()
let prev = -1
for (const n of sel) {
const dy = Math.max(prev + 1, n.y - sel[0]!.y)
prev = dy
const row: PanelRow = { id: n.id, type: n.kind === 'button' ? 'button' : n.kind === 'clock' ? 'clock' : 'switch', dy }
const row: PanelRow = { id: n.id, type: n.kind === 'button' ? 'button' : n.kind === 'clock' ? 'clock' : 'switch' }
const label = n.label?.trim()
if (label && !n.autoLabel) row.label = label
else if (label) row.name = label

View File

@ -29,8 +29,8 @@ describe('merging input panels', () => {
expect(res.panel.attach).toBeUndefined()
const rows = res.panel.rows!
expect(rows.map(r => r.label)).toEqual(['A0', 'B0', 'B1'])
// Spacing kept: B1 was two rows under B0.
expect(panelOffsets(rows)).toEqual([0, 1, 3])
// Packed: B1 was two rows under B0, now right below it.
expect(panelOffsets(rows)).toEqual([0, 1, 2])
// The wire from B1 now leaves the merged panel; the clashing row id got a new one.
const w2 = def.wires.find(w => w.id === 'w2')!
expect(w2.from.node).toBe('p1')
@ -159,8 +159,8 @@ describe('combining parts into a panel', () => {
['B', 'switch', false, ''],
['GO', 'button', false, ''],
])
// Spread-out parts keep their distance; B and GO were one row apart.
expect(panelOffsets(panel.rows!)).toEqual([0, 3, 4])
// Packed without gaps, though A and B were three rows apart.
expect(panelOffsets(panel.rows!)).toEqual([0, 1, 2])
expect(def.wires[0]!.from).toEqual({ node: panel.id, pin: 'a' })
expect(res.renamed.get("a")).toBe(`${panel.id}:a`)
expect(def.nodes.some(n => ['a', 'b', 'go'].includes(n.id))).toBe(false)