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:
parent
6398381550
commit
24bc66f798
|
|
@ -64,6 +64,9 @@ kbd {
|
||||||
.workspace {
|
.workspace {
|
||||||
--left: 272px;
|
--left: 272px;
|
||||||
--right: 280px;
|
--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;
|
display: grid;
|
||||||
grid-template-columns: var(--left) 1fr;
|
grid-template-columns: var(--left) 1fr;
|
||||||
min-height: 0;
|
min-height: 0;
|
||||||
|
|
@ -112,6 +115,7 @@ kbd {
|
||||||
@media (max-width: 820px) {
|
@media (max-width: 820px) {
|
||||||
.workspace,
|
.workspace,
|
||||||
.workspace.has-selection {
|
.workspace.has-selection {
|
||||||
|
--bar-inset: 12px;
|
||||||
grid-template-columns: 1fr;
|
grid-template-columns: 1fr;
|
||||||
grid-template-rows: 1fr 40%;
|
grid-template-rows: 1fr 40%;
|
||||||
}
|
}
|
||||||
|
|
@ -4489,9 +4493,10 @@ table.board {
|
||||||
.top-dock {
|
.top-dock {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 10px;
|
top: 10px;
|
||||||
left: 12px;
|
left: var(--bar-inset);
|
||||||
right: 12px;
|
right: var(--bar-inset);
|
||||||
z-index: 30;
|
z-index: 30;
|
||||||
|
container-type: inline-size;
|
||||||
pointer-events: none;
|
pointer-events: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -41,11 +41,11 @@ watch(
|
||||||
<EditorInspector v-if="ed.panelOpen.value" />
|
<EditorInspector v-if="ed.panelOpen.value" />
|
||||||
<EditorRail v-else />
|
<EditorRail v-else />
|
||||||
<main class="stage">
|
<main class="stage">
|
||||||
<EditorToolbar />
|
|
||||||
<EditorCanvas />
|
<EditorCanvas />
|
||||||
<EditorBottomBar />
|
<EditorBottomBar />
|
||||||
</main>
|
</main>
|
||||||
<EditorSelectionPanel v-if="hasSelection" />
|
<EditorSelectionPanel v-if="hasSelection" />
|
||||||
|
<EditorToolbar />
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<Transition name="fade">
|
<Transition name="fade">
|
||||||
|
|
|
||||||
|
|
@ -31,12 +31,19 @@ const open = ref<string | null>(null)
|
||||||
const anchor = ref(0)
|
const anchor = ref(0)
|
||||||
let timer: ReturnType<typeof setTimeout> | undefined
|
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)
|
clearTimeout(timer)
|
||||||
const el = e.currentTarget as HTMLElement
|
|
||||||
const go = () => {
|
const go = () => {
|
||||||
|
if (open.value !== id) anchorAt(e.clientX)
|
||||||
open.value = id
|
open.value = id
|
||||||
anchor.value = el.offsetLeft + el.offsetWidth / 2
|
|
||||||
}
|
}
|
||||||
// Moving along the bar switches at once; the first one waits a moment.
|
// Moving along the bar switches at once; the first one waits a moment.
|
||||||
if (open.value) go()
|
if (open.value) go()
|
||||||
|
|
@ -52,13 +59,12 @@ function stay() {
|
||||||
clearTimeout(timer)
|
clearTimeout(timer)
|
||||||
}
|
}
|
||||||
|
|
||||||
function toggle(id: string, e: Event) {
|
function toggle(id: string, e: MouseEvent) {
|
||||||
if (open.value === id) open.value = null
|
if (open.value === id) open.value = null
|
||||||
else {
|
else {
|
||||||
clearTimeout(timer)
|
clearTimeout(timer)
|
||||||
const el = e.currentTarget as HTMLElement
|
anchorAt(e.clientX)
|
||||||
open.value = id
|
open.value = id
|
||||||
anchor.value = el.offsetLeft + el.offsetWidth / 2
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -95,7 +101,7 @@ onBeforeUnmount(() => window.removeEventListener('keydown', onKey, true))
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="bottom-dock" @pointerdown.stop>
|
<div ref="dock" class="bottom-dock" @pointerdown.stop>
|
||||||
<Transition name="flyout">
|
<Transition name="flyout">
|
||||||
<div v-if="open" class="flyout" :style="{ left: `${anchor}px` }" @pointerenter="stay" @pointerleave="leave">
|
<div v-if="open" class="flyout" :style="{ left: `${anchor}px` }" @pointerenter="stay" @pointerleave="leave">
|
||||||
<!-- Built-in parts -->
|
<!-- Built-in parts -->
|
||||||
|
|
|
||||||
|
|
@ -55,6 +55,15 @@ function remove(i: number) {
|
||||||
save()
|
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() {
|
function addLine() {
|
||||||
const lines = type.value?.lines
|
const lines = type.value?.lines
|
||||||
if (!lines || lines.length >= 64) return
|
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">
|
<ul class="conn-lines">
|
||||||
<li v-for="(l, i) in type.lines" :key="i">
|
<li v-for="(l, i) in type.lines" :key="i">
|
||||||
<span class="conn-index">{{ i }}</span>
|
<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
|
<button
|
||||||
class="btn-sm conn-dir"
|
class="btn-sm conn-dir"
|
||||||
:class="{ back: l.back }"
|
:class="{ back: l.back }"
|
||||||
|
|
|
||||||
|
|
@ -213,6 +213,16 @@ function setRowLabel(row: PanelRow, e: Event) {
|
||||||
ed.commit()
|
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). */
|
/** Rows showing their extra settings (key, colour, spacing, order). */
|
||||||
const openRows = ref(new Set<string>())
|
const openRows = ref(new Set<string>())
|
||||||
function toggleRow(id: 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" />
|
<Icon :name="openRows.has(r.id) ? 'lucide:chevron-down' : 'lucide:chevron-right'" class="size-3.5" />
|
||||||
</button>
|
</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)">
|
<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>
|
<option v-for="c in CONTROLS" :key="c.value" :value="c.value">{{ c.label }}</option>
|
||||||
</select>
|
</select>
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
// input, an output panel on its right a row per output. A docked panel moves
|
// 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.
|
// 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 { pinName } from './labels'
|
||||||
import { lookup, uid } from './ops'
|
import { lookup, uid } from './ops'
|
||||||
import type { CircuitNode, ComponentDef, PanelRow, Project } from './types'
|
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
|
* 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
|
* 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
|
* (old → new), so circuits that place this one can keep their wires; null
|
||||||
* for fewer than two panels.
|
* for fewer than two panels.
|
||||||
|
|
@ -190,16 +190,11 @@ export function mergePanels(def: ComponentDef, ids: string[]): { panel: CircuitN
|
||||||
if (panels.length < 2) return null
|
if (panels.length < 2) return null
|
||||||
const [target, ...rest] = panels as [CircuitNode, ...CircuitNode[]]
|
const [target, ...rest] = panels as [CircuitNode, ...CircuitNode[]]
|
||||||
const rows = target.rows ?? []
|
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 used = new Set(rows.map(r => r.id))
|
||||||
const renamed = new Map<string, string>()
|
const renamed = new Map<string, string>()
|
||||||
for (const p of rest) {
|
for (const p of rest) {
|
||||||
const theirs = p.rows ?? []
|
const theirs = p.rows ?? []
|
||||||
const off = panelOffsets(theirs)
|
theirs.forEach(r => {
|
||||||
const shift = bottom + 1 - (off[0] ?? 0)
|
|
||||||
theirs.forEach((r, i) => {
|
|
||||||
const id = used.has(r.id) ? uid('r') : r.id
|
const id = used.has(r.id) ? uid('r') : r.id
|
||||||
used.add(id)
|
used.add(id)
|
||||||
for (const w of def.wires) {
|
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 }
|
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))
|
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
|
target.rows = rows
|
||||||
delete target.attach
|
delete target.attach
|
||||||
delete target.skip
|
delete target.skip
|
||||||
|
|
@ -226,8 +222,7 @@ const SINKS = new Set(['output', 'lamp'])
|
||||||
/**
|
/**
|
||||||
* Turns separate switches, buttons and clocks into one input panel, or
|
* 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,
|
* 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
|
* with their names, settings and wires, packed without gaps. Returns the panel and the pin keys that changed
|
||||||
* parts were spread out. Returns the panel and the pin keys that changed
|
|
||||||
* (old → new) for circuits that place this one; null when the parts are
|
* (old → new) for circuits that place this one; null when the parts are
|
||||||
* not all of one side or fewer than two.
|
* 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'
|
const pinKind = out ? 'output' : 'input'
|
||||||
if (!sel.some(n => n.kind === pinKind)) panel.inner = true
|
if (!sel.some(n => n.kind === pinKind)) panel.inner = true
|
||||||
const renamed = new Map<string, string>()
|
const renamed = new Map<string, string>()
|
||||||
let prev = -1
|
|
||||||
for (const n of sel) {
|
for (const n of sel) {
|
||||||
const dy = Math.max(prev + 1, n.y - sel[0]!.y)
|
const row: PanelRow = { id: n.id, type: n.kind === 'button' ? 'button' : n.kind === 'clock' ? 'clock' : 'switch' }
|
||||||
prev = dy
|
|
||||||
const row: PanelRow = { id: n.id, type: n.kind === 'button' ? 'button' : n.kind === 'clock' ? 'clock' : 'switch', dy }
|
|
||||||
const label = n.label?.trim()
|
const label = n.label?.trim()
|
||||||
if (label && !n.autoLabel) row.label = label
|
if (label && !n.autoLabel) row.label = label
|
||||||
else if (label) row.name = label
|
else if (label) row.name = label
|
||||||
|
|
|
||||||
|
|
@ -29,8 +29,8 @@ describe('merging input panels', () => {
|
||||||
expect(res.panel.attach).toBeUndefined()
|
expect(res.panel.attach).toBeUndefined()
|
||||||
const rows = res.panel.rows!
|
const rows = res.panel.rows!
|
||||||
expect(rows.map(r => r.label)).toEqual(['A0', 'B0', 'B1'])
|
expect(rows.map(r => r.label)).toEqual(['A0', 'B0', 'B1'])
|
||||||
// Spacing kept: B1 was two rows under B0.
|
// Packed: B1 was two rows under B0, now right below it.
|
||||||
expect(panelOffsets(rows)).toEqual([0, 1, 3])
|
expect(panelOffsets(rows)).toEqual([0, 1, 2])
|
||||||
// The wire from B1 now leaves the merged panel; the clashing row id got a new one.
|
// 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')!
|
const w2 = def.wires.find(w => w.id === 'w2')!
|
||||||
expect(w2.from.node).toBe('p1')
|
expect(w2.from.node).toBe('p1')
|
||||||
|
|
@ -159,8 +159,8 @@ describe('combining parts into a panel', () => {
|
||||||
['B', 'switch', false, ''],
|
['B', 'switch', false, ''],
|
||||||
['GO', 'button', false, ''],
|
['GO', 'button', false, ''],
|
||||||
])
|
])
|
||||||
// Spread-out parts keep their distance; B and GO were one row apart.
|
// Packed without gaps, though A and B were three rows apart.
|
||||||
expect(panelOffsets(panel.rows!)).toEqual([0, 3, 4])
|
expect(panelOffsets(panel.rows!)).toEqual([0, 1, 2])
|
||||||
expect(def.wires[0]!.from).toEqual({ node: panel.id, pin: 'a' })
|
expect(def.wires[0]!.from).toEqual({ node: panel.id, pin: 'a' })
|
||||||
expect(res.renamed.get("a")).toBe(`${panel.id}:a`)
|
expect(res.renamed.get("a")).toBe(`${panel.id}:a`)
|
||||||
expect(def.nodes.some(n => ['a', 'b', 'go'].includes(n.id))).toBe(false)
|
expect(def.nodes.some(n => ['a', 'b', 'go'].includes(n.id))).toBe(false)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue