A right-click menu for parts, wires and the canvas, "Wire them all to" as cards, plugged latches in plain greys
- Right click (or the menu key) shows what can be done with what is under the pointer: one part (open, rename, change to, inputs, colour, speed, panels, unpack, plug and unplug, cable colour), several parts (wire them all to with live preview, connect one by one, switches, change all, arrange, keep only, make a component), wires (bundle, colour, whole signal, straighten, remove cable) or empty canvas (paste here, add a part here, select all, fit, tidy, undo); right drag still moves the view
- "Wire them all to": a card per part, each fit a strip of its pins, and which wire goes where for the fit pointed at
- Plugged cable ends no longer look selected: grey connector, steel clips
- Icons named in menus are bundled for the browser too
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-21 10:33:30 +00:00
|
|
|
|
// What the context menu offers for what was right-clicked: one part, several
|
|
|
|
|
|
// parts, wires, or the empty canvas. Every entry runs the same store action
|
|
|
|
|
|
// as the matching button in the side panel.
|
|
|
|
|
|
|
|
|
|
|
|
import { byPosition, sharedFamily, typeKey, type Arrange } from '~/lib/logic/bulk'
|
|
|
|
|
|
import { cableOf } from '~/lib/logic/cables'
|
A Loxone-style working aids: named signals, inverted inputs, a project check, values on cables, search, printable sheets; wire ends move by dragging
- Send signal / Use signal: name a signal (CLK, RESET) once and use it anywhere in the circuit without a wire; selecting one lights up all of them, a use with no sender shows dashed
- Inverted inputs: Alt + click an input (or the menu/settings) puts a bubble on it; it reads the signal inverted through one NAND, counted in every transistor total
- Check (Circuit tab): open inputs, parts that drive nothing, duplicate pin names, unsent or doubly sent signals, loops that never settle; click one to show it. Open inputs get an orange marker on the canvas. Components no other circuit uses are listed with a delete
- Cables show the number they carry (= 13 · 0x0D); hovering a wire tells where it runs and its value
- Ctrl+F finds parts, signals, panel rows, notes and components in every circuit, with where each component is used
- Ctrl+P prints the circuit as a sheet with a title block on white paper (or save as PDF); also as an SVG file
- + and − under a selected gate change its number of inputs; swaps keep bubbles in place
- Drag a wire by its end to move that end to another pin; drop a dragged wire on another wire to tap its signal or feed what it fed
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-21 11:26:59 +00:00
|
|
|
|
import { INVERTIBLE } from '~/lib/logic/compile'
|
A right-click menu for parts, wires and the canvas, "Wire them all to" as cards, plugged latches in plain greys
- Right click (or the menu key) shows what can be done with what is under the pointer: one part (open, rename, change to, inputs, colour, speed, panels, unpack, plug and unplug, cable colour), several parts (wire them all to with live preview, connect one by one, switches, change all, arrange, keep only, make a component), wires (bundle, colour, whole signal, straighten, remove cable) or empty canvas (paste here, add a part here, select all, fit, tidy, undo); right drag still moves the view
- "Wire them all to": a card per part, each fit a strip of its pins, and which wire goes where for the fit pointed at
- Plugged cable ends no longer look selected: grey connector, steel clips
- Icons named in menus are bundled for the browser too
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-21 10:33:30 +00:00
|
|
|
|
import { cableBits, chipPins, type Pt } from '~/lib/logic/geometry'
|
|
|
|
|
|
import { SINK_KINDS, SOURCE_KINDS } from '~/lib/logic/ops'
|
|
|
|
|
|
import { KIND_NAMES } from '~/lib/logic/progress'
|
|
|
|
|
|
import { LAMP_COLORS, WIRE_COLORS, type CircuitNode, type NodeKind } from '~/lib/logic/types'
|
|
|
|
|
|
import { baseOf, gateFamily, inputCount } from '~/lib/logic/wide'
|
|
|
|
|
|
|
|
|
|
|
|
export interface MenuSwatch {
|
|
|
|
|
|
color: string
|
|
|
|
|
|
title: string
|
|
|
|
|
|
active: boolean
|
|
|
|
|
|
run: () => void
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export interface MenuItem {
|
|
|
|
|
|
label: string
|
|
|
|
|
|
icon?: string
|
|
|
|
|
|
/** Shortcut shown on the right. */
|
|
|
|
|
|
keys?: string
|
|
|
|
|
|
/** Muted text after the label. */
|
|
|
|
|
|
note?: string
|
|
|
|
|
|
run?: () => void
|
|
|
|
|
|
danger?: boolean
|
|
|
|
|
|
disabled?: boolean
|
|
|
|
|
|
checked?: boolean
|
|
|
|
|
|
children?: MenuItem[]
|
|
|
|
|
|
/** A row of colour dots instead of a line. */
|
|
|
|
|
|
swatches?: MenuSwatch[]
|
|
|
|
|
|
/** A text field; Enter runs it with what was typed. */
|
|
|
|
|
|
input?: { placeholder: string; submit: (text: string) => void }
|
|
|
|
|
|
/** Pointing at it (for fits: shows them on the canvas). */
|
|
|
|
|
|
hover?: (on: boolean) => void
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** A heading (no action) or a divider between groups. */
|
|
|
|
|
|
export type MenuEntry = MenuItem | { head: string } | 'sep'
|
|
|
|
|
|
|
|
|
|
|
|
export type MenuTarget = { kind: 'selection' } | { kind: 'canvas'; at: Pt }
|
|
|
|
|
|
|
|
|
|
|
|
export interface CanvasOps {
|
|
|
|
|
|
fit: () => void
|
|
|
|
|
|
place: (kind: NodeKind, at: Pt) => void
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const LAMP_HEX: Record<string, string> = { yellow: '#ffd34d', red: '#ff5c5c', green: '#3ddc84', blue: '#4dabff', white: '#f4f6fa' }
|
A finer component boxes, a regrouped parts list with keyboard search, a real green for wires and cables
- Box designer: drag pins up or down to open gaps between groups; size (+/−) and turn (R) lamps, displays, screens and drawings; pixels belong to named screens, each placed on its own; displays of the components inside can be shown on the box (off unless ticked); a list of everything the box can show, each optional; the box grows to hold what it shows
- Lamps and displays deep inside placed components light up on the box
- Parts list: one search box for parts and components (letters in order match too), recently placed parts first, grouped Logic / Inputs / Outputs / Wiring / Notes, then components by group; groups fold away
- Keys: / searches the parts list (Enter starts placing), Shift+A or Ctrl+K adds a part at the mouse
- Wires and cables get a green; the default swatch shows grey, as the default really is
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-22 04:48:42 +00:00
|
|
|
|
const WIRE_HEX: Record<string, string> = { red: '#ff5c5c', orange: '#ff9f43', yellow: '#ffd93d', green: '#3ddc84', blue: '#4dabff', purple: '#b388ff', pink: '#ff7ac6' }
|
|
|
|
|
|
/** The default wire colour: grey, like an unlit wire or a cable's sleeve. */
|
|
|
|
|
|
const DEFAULT_WIRE = 'linear-gradient(135deg, transparent 45%, #8592a3 45% 55%, transparent 55%), #3b4554'
|
A right-click menu for parts, wires and the canvas, "Wire them all to" as cards, plugged latches in plain greys
- Right click (or the menu key) shows what can be done with what is under the pointer: one part (open, rename, change to, inputs, colour, speed, panels, unpack, plug and unplug, cable colour), several parts (wire them all to with live preview, connect one by one, switches, change all, arrange, keep only, make a component), wires (bundle, colour, whole signal, straighten, remove cable) or empty canvas (paste here, add a part here, select all, fit, tidy, undo); right drag still moves the view
- "Wire them all to": a card per part, each fit a strip of its pins, and which wire goes where for the fit pointed at
- Plugged cable ends no longer look selected: grey connector, steel clips
- Icons named in menus are bundled for the browser too
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-21 10:33:30 +00:00
|
|
|
|
|
|
|
|
|
|
const ARRANGE: { how: Arrange; label: string; icon: string }[] = [
|
|
|
|
|
|
{ how: 'left', label: 'Line up on the left', icon: 'lucide:align-start-vertical' },
|
|
|
|
|
|
{ how: 'right', label: 'Line up on the right', icon: 'lucide:align-end-vertical' },
|
|
|
|
|
|
{ how: 'top', label: 'Line up at the top', icon: 'lucide:align-start-horizontal' },
|
|
|
|
|
|
{ how: 'bottom', label: 'Line up at the bottom', icon: 'lucide:align-end-horizontal' },
|
|
|
|
|
|
{ how: 'spread-y', label: 'Spread top to bottom', icon: 'lucide:align-vertical-space-around' },
|
|
|
|
|
|
{ how: 'spread-x', label: 'Spread left to right', icon: 'lucide:align-horizontal-space-around' },
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
const ADD: { kind: NodeKind; label: string; icon: string; keys?: string }[] = [
|
|
|
|
|
|
{ kind: 'nand', label: 'NAND', icon: 'lucide:square-function', keys: 'N' },
|
|
|
|
|
|
{ kind: 'input', label: 'Input', icon: 'lucide:toggle-left', keys: 'I' },
|
|
|
|
|
|
{ kind: 'output', label: 'Output', icon: 'lucide:log-out', keys: 'O' },
|
|
|
|
|
|
{ kind: 'lamp', label: 'Lamp', icon: 'lucide:lightbulb', keys: 'L' },
|
|
|
|
|
|
{ kind: 'button', label: 'Push button', icon: 'lucide:circle-dot', keys: 'B' },
|
|
|
|
|
|
{ kind: 'clock', label: 'Clock', icon: 'lucide:audio-waveform', keys: 'C' },
|
|
|
|
|
|
{ kind: 'panel', label: 'Input panel', icon: 'lucide:sliders-vertical', keys: 'P' },
|
2026-10-21 12:38:59 +00:00
|
|
|
|
{ kind: 'outpanel', label: 'Output panel', icon: 'lucide:list-checks' },
|
A right-click menu for parts, wires and the canvas, "Wire them all to" as cards, plugged latches in plain greys
- Right click (or the menu key) shows what can be done with what is under the pointer: one part (open, rename, change to, inputs, colour, speed, panels, unpack, plug and unplug, cable colour), several parts (wire them all to with live preview, connect one by one, switches, change all, arrange, keep only, make a component), wires (bundle, colour, whole signal, straighten, remove cable) or empty canvas (paste here, add a part here, select all, fit, tidy, undo); right drag still moves the view
- "Wire them all to": a card per part, each fit a strip of its pins, and which wire goes where for the fit pointed at
- Plugged cable ends no longer look selected: grey connector, steel clips
- Icons named in menus are bundled for the browser too
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-21 10:33:30 +00:00
|
|
|
|
{ kind: 'hex', label: 'Hex display', icon: 'lucide:binary', keys: 'H' },
|
A Loxone-style working aids: named signals, inverted inputs, a project check, values on cables, search, printable sheets; wire ends move by dragging
- Send signal / Use signal: name a signal (CLK, RESET) once and use it anywhere in the circuit without a wire; selecting one lights up all of them, a use with no sender shows dashed
- Inverted inputs: Alt + click an input (or the menu/settings) puts a bubble on it; it reads the signal inverted through one NAND, counted in every transistor total
- Check (Circuit tab): open inputs, parts that drive nothing, duplicate pin names, unsent or doubly sent signals, loops that never settle; click one to show it. Open inputs get an orange marker on the canvas. Components no other circuit uses are listed with a delete
- Cables show the number they carry (= 13 · 0x0D); hovering a wire tells where it runs and its value
- Ctrl+F finds parts, signals, panel rows, notes and components in every circuit, with where each component is used
- Ctrl+P prints the circuit as a sheet with a title block on white paper (or save as PDF); also as an SVG file
- + and − under a selected gate change its number of inputs; swaps keep bubbles in place
- Drag a wire by its end to move that end to another pin; drop a dragged wire on another wire to tap its signal or feed what it fed
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-21 11:26:59 +00:00
|
|
|
|
{ kind: 'tag', label: 'Send signal', icon: 'lucide:flag' },
|
|
|
|
|
|
{ kind: 'ref', label: 'Use signal', icon: 'lucide:tag' },
|
A right-click menu for parts, wires and the canvas, "Wire them all to" as cards, plugged latches in plain greys
- Right click (or the menu key) shows what can be done with what is under the pointer: one part (open, rename, change to, inputs, colour, speed, panels, unpack, plug and unplug, cable colour), several parts (wire them all to with live preview, connect one by one, switches, change all, arrange, keep only, make a component), wires (bundle, colour, whole signal, straighten, remove cable) or empty canvas (paste here, add a part here, select all, fit, tidy, undo); right drag still moves the view
- "Wire them all to": a card per part, each fit a strip of its pins, and which wire goes where for the fit pointed at
- Plugged cable ends no longer look selected: grey connector, steel clips
- Icons named in menus are bundled for the browser too
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-21 10:33:30 +00:00
|
|
|
|
{ kind: 'note', label: 'Note', icon: 'lucide:sticky-note', keys: 'T' },
|
|
|
|
|
|
]
|
|
|
|
|
|
|
2026-10-21 12:38:59 +00:00
|
|
|
|
const NAMED = ['input', 'output', 'lamp', 'button', 'clock', 'hex', 'note', 'panel', 'outpanel', 'chip', 'tag', 'ref']
|
A right-click menu for parts, wires and the canvas, "Wire them all to" as cards, plugged latches in plain greys
- Right click (or the menu key) shows what can be done with what is under the pointer: one part (open, rename, change to, inputs, colour, speed, panels, unpack, plug and unplug, cable colour), several parts (wire them all to with live preview, connect one by one, switches, change all, arrange, keep only, make a component), wires (bundle, colour, whole signal, straighten, remove cable) or empty canvas (paste here, add a part here, select all, fit, tidy, undo); right drag still moves the view
- "Wire them all to": a card per part, each fit a strip of its pins, and which wire goes where for the fit pointed at
- Plugged cable ends no longer look selected: grey connector, steel clips
- Icons named in menus are bundled for the browser too
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-21 10:33:30 +00:00
|
|
|
|
|
|
|
|
|
|
export function useMenu() {
|
|
|
|
|
|
const ed = useEditor()
|
|
|
|
|
|
|
|
|
|
|
|
const nodesOf = (ids: string[]) => {
|
|
|
|
|
|
const set = new Set(ids)
|
|
|
|
|
|
return ed.def.value.nodes.filter(n => set.has(n.id))
|
|
|
|
|
|
}
|
|
|
|
|
|
const partName = (n: CircuitNode) =>
|
|
|
|
|
|
n.kind === 'chip' ? (n.chip && ed.getDef.value(n.chip)?.name) || 'Missing component' : (KIND_NAMES[n.kind] ?? n.kind)
|
|
|
|
|
|
const wired = (ids: string[]) => {
|
|
|
|
|
|
const set = new Set(ids)
|
|
|
|
|
|
return ed.def.value.wires.some(w => set.has(w.from.node) || set.has(w.to.node))
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function rename(id: string) {
|
|
|
|
|
|
ed.selection.value = [id]
|
|
|
|
|
|
ed.wireSel.value = []
|
|
|
|
|
|
ed.labelFocus.value++
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** Other parts the same pins fit: NAND and components with as many inputs and outputs, or the switch and lamp kinds. */
|
|
|
|
|
|
function swapChoices(nodes: CircuitNode[]): MenuItem[] {
|
|
|
|
|
|
const fam = sharedFamily(nodes)
|
|
|
|
|
|
const current = new Set(nodes.map(typeKey))
|
|
|
|
|
|
const swapTo = (target: { kind: NodeKind; chip?: string }) => () => ed.swapMany(nodes.map(n => n.id), target)
|
|
|
|
|
|
if (fam === 'source' || fam === 'sink') {
|
|
|
|
|
|
return (fam === 'source' ? SOURCE_KINDS : SINK_KINDS).map(k => ({
|
|
|
|
|
|
label: KIND_NAMES[k] ?? k,
|
|
|
|
|
|
checked: current.size === 1 && current.has(k),
|
|
|
|
|
|
run: swapTo({ kind: k }),
|
|
|
|
|
|
}))
|
|
|
|
|
|
}
|
|
|
|
|
|
if (fam !== 'logic') return []
|
|
|
|
|
|
const pins = nodes.map(n => (n.kind === 'nand' ? [2, 1] : n.chip && ed.getDef.value(n.chip) ? [chipPins(ed.getDef.value(n.chip)!).inputs.length, chipPins(ed.getDef.value(n.chip)!).outputs.length] : [0, 0]))
|
|
|
|
|
|
const [ins, outs] = pins[0]!
|
|
|
|
|
|
if (pins.some(p => p[0] !== ins || p[1] !== outs)) return []
|
|
|
|
|
|
const out: MenuItem[] = []
|
|
|
|
|
|
if (ins === 2 && outs === 1) out.push({ label: 'NAND', checked: current.size === 1 && current.has('nand'), run: swapTo({ kind: 'nand' }) })
|
|
|
|
|
|
for (const d of ed.project.value.components) {
|
|
|
|
|
|
if (d.id === ed.def.value.id || !ed.canPlace(d.id)) continue
|
|
|
|
|
|
const p = chipPins(d)
|
|
|
|
|
|
if (p.inputs.length !== ins || p.outputs.length !== outs) continue
|
|
|
|
|
|
out.push({ label: d.name, checked: current.size === 1 && current.has(`chip:${d.id}`), run: swapTo({ kind: 'chip', chip: d.id }) })
|
|
|
|
|
|
}
|
|
|
|
|
|
return out.length > 1 ? out : []
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function common(ids: string[]): MenuEntry[] {
|
|
|
|
|
|
return [
|
|
|
|
|
|
'sep',
|
|
|
|
|
|
{ label: 'Copy', icon: 'lucide:copy', keys: 'Ctrl+C', run: () => ed.copy() },
|
|
|
|
|
|
{ label: 'Duplicate', icon: 'lucide:copy-plus', keys: 'Ctrl+D', run: () => ed.duplicate() },
|
|
|
|
|
|
{ label: 'Unlink all', icon: 'lucide:unlink', disabled: !wired(ids), run: () => ed.unlink(ids) },
|
|
|
|
|
|
'sep',
|
|
|
|
|
|
{ label: 'Delete', icon: 'lucide:trash-2', keys: 'Del', danger: true, run: () => ed.deleteSelected() },
|
|
|
|
|
|
]
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function oneNode(n: CircuitNode): MenuEntry[] {
|
|
|
|
|
|
const get = ed.getDef.value
|
|
|
|
|
|
const out: MenuEntry[] = [{ head: n.label?.trim() && !n.autoLabel ? `${partName(n)} · ${n.label.trim()}` : partName(n) }]
|
BF input panels are component inputs, cable ends plug in more reliably; A merge panels, hex pass-through, design a component's box
- Inside a component, the switch and button rows of its input panels are now input pins (in order with the other inputs, named after the rows); "Rows are component inputs" can be turned off per panel to keep the old fixed switches
- Select input panels, Merge: one panel with all rows, spacing and wires kept; circuits that place this one keep their wires
- Cable ends plug in more often: bundling orders the wires by the part a side runs to, an end with only some wires on a part still plugs, an end placed by hand next to the pins plugs, and dragging an end near its part shows green rings and plugs it on drop
- Hex displays pass their four bits on (outputs on the right), so they can sit in the middle of a bus
- Design the box: move lamps, displays, the screen and the name on a component's box, draw lines, boxes, circles and text in six colours, size it, leave things off; every placed copy shows it
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-21 11:49:29 +00:00
|
|
|
|
if (n.kind === 'chip' && n.chip) {
|
|
|
|
|
|
out.push(
|
|
|
|
|
|
{ label: 'Open component', icon: 'lucide:log-in', keys: 'Enter', run: () => ed.open(n.chip!) },
|
|
|
|
|
|
{ label: 'Design its box', icon: 'lucide:pen-tool', run: () => ed.designFace(n.chip!) },
|
|
|
|
|
|
)
|
|
|
|
|
|
}
|
A right-click menu for parts, wires and the canvas, "Wire them all to" as cards, plugged latches in plain greys
- Right click (or the menu key) shows what can be done with what is under the pointer: one part (open, rename, change to, inputs, colour, speed, panels, unpack, plug and unplug, cable colour), several parts (wire them all to with live preview, connect one by one, switches, change all, arrange, keep only, make a component), wires (bundle, colour, whole signal, straighten, remove cable) or empty canvas (paste here, add a part here, select all, fit, tidy, undo); right drag still moves the view
- "Wire them all to": a card per part, each fit a strip of its pins, and which wire goes where for the fit pointed at
- Plugged cable ends no longer look selected: grey connector, steel clips
- Icons named in menus are bundled for the browser too
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-21 10:33:30 +00:00
|
|
|
|
if (n.kind === 'input') out.push({ label: n.on ? 'Switch off' : 'Switch on', icon: n.on ? 'lucide:toggle-right' : 'lucide:toggle-left', run: () => ed.toggleInput(n) })
|
|
|
|
|
|
if (NAMED.includes(n.kind)) out.push({ label: n.kind === 'note' ? 'Edit text' : 'Rename', icon: 'lucide:pencil', keys: 'Double-click', run: () => rename(n.id) })
|
|
|
|
|
|
const swaps = swapChoices([n])
|
|
|
|
|
|
if (swaps.length) out.push({ label: 'Change to', icon: 'lucide:replace', children: swaps })
|
|
|
|
|
|
const base = baseOf(n, get)
|
|
|
|
|
|
if (base && gateFamily(get, base)) {
|
|
|
|
|
|
const now = inputCount(n, get)
|
|
|
|
|
|
out.push({
|
|
|
|
|
|
label: 'Inputs',
|
|
|
|
|
|
icon: 'lucide:list-plus',
|
|
|
|
|
|
note: String(now),
|
|
|
|
|
|
children: [2, 3, 4, 5, 6, 8].map(k => ({ label: `${k} inputs`, checked: k === now, run: () => ed.setInputs(n, k) })),
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
A Loxone-style working aids: named signals, inverted inputs, a project check, values on cables, search, printable sheets; wire ends move by dragging
- Send signal / Use signal: name a signal (CLK, RESET) once and use it anywhere in the circuit without a wire; selecting one lights up all of them, a use with no sender shows dashed
- Inverted inputs: Alt + click an input (or the menu/settings) puts a bubble on it; it reads the signal inverted through one NAND, counted in every transistor total
- Check (Circuit tab): open inputs, parts that drive nothing, duplicate pin names, unsent or doubly sent signals, loops that never settle; click one to show it. Open inputs get an orange marker on the canvas. Components no other circuit uses are listed with a delete
- Cables show the number they carry (= 13 · 0x0D); hovering a wire tells where it runs and its value
- Ctrl+F finds parts, signals, panel rows, notes and components in every circuit, with where each component is used
- Ctrl+P prints the circuit as a sheet with a title block on white paper (or save as PDF); also as an SVG file
- + and − under a selected gate change its number of inputs; swaps keep bubbles in place
- Drag a wire by its end to move that end to another pin; drop a dragged wire on another wire to tap its signal or feed what it fed
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-21 11:26:59 +00:00
|
|
|
|
if (INVERTIBLE.has(n.kind)) {
|
|
|
|
|
|
const inv = new Set(n.invert ?? [])
|
|
|
|
|
|
const pins = ed.shape(n).inputs
|
|
|
|
|
|
if (pins.length) {
|
|
|
|
|
|
out.push({
|
|
|
|
|
|
label: 'Invert input',
|
|
|
|
|
|
icon: 'lucide:circle-dot',
|
|
|
|
|
|
note: inv.size ? String(inv.size) : undefined,
|
|
|
|
|
|
keys: 'Alt+click',
|
|
|
|
|
|
children: pins.map((p, i) => ({
|
|
|
|
|
|
label: p.label || (n.kind === 'nand' ? 'AB'[i]! : 'In'),
|
|
|
|
|
|
checked: inv.has(p.key),
|
|
|
|
|
|
run: () => ed.toggleInvert(n, p.key),
|
|
|
|
|
|
})),
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
A right-click menu for parts, wires and the canvas, "Wire them all to" as cards, plugged latches in plain greys
- Right click (or the menu key) shows what can be done with what is under the pointer: one part (open, rename, change to, inputs, colour, speed, panels, unpack, plug and unplug, cable colour), several parts (wire them all to with live preview, connect one by one, switches, change all, arrange, keep only, make a component), wires (bundle, colour, whole signal, straighten, remove cable) or empty canvas (paste here, add a part here, select all, fit, tidy, undo); right drag still moves the view
- "Wire them all to": a card per part, each fit a strip of its pins, and which wire goes where for the fit pointed at
- Plugged cable ends no longer look selected: grey connector, steel clips
- Icons named in menus are bundled for the browser too
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-21 10:33:30 +00:00
|
|
|
|
if (n.kind === 'lamp' || n.kind === 'hex' || n.kind === 'pixel') {
|
|
|
|
|
|
out.push({
|
|
|
|
|
|
label: 'Colour',
|
|
|
|
|
|
swatches: [undefined, ...LAMP_COLORS].map(c => ({
|
|
|
|
|
|
color: c ? LAMP_HEX[c]! : n.kind === 'hex' ? LAMP_HEX.red! : LAMP_HEX.yellow!,
|
|
|
|
|
|
title: c ?? 'Default',
|
|
|
|
|
|
active: n.color === c,
|
|
|
|
|
|
run: () => ed.patchMany([n.id], { color: c }),
|
|
|
|
|
|
})),
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
if (n.kind === 'clock') {
|
|
|
|
|
|
out.push({
|
|
|
|
|
|
label: 'Speed',
|
|
|
|
|
|
icon: 'lucide:gauge',
|
|
|
|
|
|
note: n.hz ? `${n.hz} Hz` : 'top bar',
|
|
|
|
|
|
children: [
|
|
|
|
|
|
{ label: 'Follow the top bar', checked: n.hz === undefined, run: () => ed.patchMany([n.id], { hz: undefined }, true) },
|
|
|
|
|
|
...[0.5, 1, 2, 5, 10, 30, 100].map(hz => ({ label: `${hz} Hz`, checked: n.hz === hz, run: () => ed.patchMany([n.id], { hz }, true) })),
|
|
|
|
|
|
],
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
if (n.kind === 'note') {
|
|
|
|
|
|
out.push({
|
|
|
|
|
|
label: 'Size',
|
|
|
|
|
|
icon: 'lucide:type',
|
|
|
|
|
|
children: [
|
|
|
|
|
|
{ label: 'Small', checked: n.size === 'sm', run: () => ed.patchMany([n.id], { size: 'sm' }) },
|
|
|
|
|
|
{ label: 'Normal', checked: !n.size, run: () => ed.patchMany([n.id], { size: undefined }) },
|
|
|
|
|
|
{ label: 'Large', checked: n.size === 'lg', run: () => ed.patchMany([n.id], { size: 'lg' }) },
|
|
|
|
|
|
],
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
if (n.kind === 'chip' && n.chip && get(n.chip)) {
|
|
|
|
|
|
const pins = chipPins(get(n.chip)!)
|
|
|
|
|
|
const docked = ed.def.value.nodes.some(x => x.kind === 'panel' && x.attach === n.id)
|
|
|
|
|
|
out.push('sep')
|
2026-10-21 12:38:59 +00:00
|
|
|
|
const dockedOut = ed.def.value.nodes.some(x => x.kind === 'outpanel' && x.attach === n.id)
|
A right-click menu for parts, wires and the canvas, "Wire them all to" as cards, plugged latches in plain greys
- Right click (or the menu key) shows what can be done with what is under the pointer: one part (open, rename, change to, inputs, colour, speed, panels, unpack, plug and unplug, cable colour), several parts (wire them all to with live preview, connect one by one, switches, change all, arrange, keep only, make a component), wires (bundle, colour, whole signal, straighten, remove cable) or empty canvas (paste here, add a part here, select all, fit, tidy, undo); right drag still moves the view
- "Wire them all to": a card per part, each fit a strip of its pins, and which wire goes where for the fit pointed at
- Plugged cable ends no longer look selected: grey connector, steel clips
- Icons named in menus are bundled for the browser too
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-21 10:33:30 +00:00
|
|
|
|
if (pins.inputs.length && !docked) out.push({ label: 'Attach input panel', icon: 'lucide:sliders-vertical', run: () => ed.addPanel(n.id) })
|
2026-10-21 12:38:59 +00:00
|
|
|
|
if (pins.outputs.length && !dockedOut) out.push({ label: 'Attach output panel', icon: 'lucide:list-checks', run: () => ed.addPanel(n.id, 'out') })
|
A right-click menu for parts, wires and the canvas, "Wire them all to" as cards, plugged latches in plain greys
- Right click (or the menu key) shows what can be done with what is under the pointer: one part (open, rename, change to, inputs, colour, speed, panels, unpack, plug and unplug, cable colour), several parts (wire them all to with live preview, connect one by one, switches, change all, arrange, keep only, make a component), wires (bundle, colour, whole signal, straighten, remove cable) or empty canvas (paste here, add a part here, select all, fit, tidy, undo); right drag still moves the view
- "Wire them all to": a card per part, each fit a strip of its pins, and which wire goes where for the fit pointed at
- Plugged cable ends no longer look selected: grey connector, steel clips
- Icons named in menus are bundled for the browser too
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-21 10:33:30 +00:00
|
|
|
|
if (pins.inputs.length) out.push({ label: 'Wire inputs one by one', icon: 'lucide:cable', run: () => ed.startLinking([n.id], 'in') })
|
|
|
|
|
|
if (pins.outputs.length) out.push({ label: 'Wire outputs one by one', icon: 'lucide:cable', run: () => ed.startLinking([n.id], 'out') })
|
|
|
|
|
|
out.push(
|
|
|
|
|
|
{ label: 'Unpack into parts', icon: 'lucide:ungroup', run: () => ed.unpack(n.id) },
|
|
|
|
|
|
{ label: 'Make independent copy', icon: 'lucide:copy-plus', run: () => ed.makeIndependent(n.id) },
|
|
|
|
|
|
)
|
|
|
|
|
|
}
|
2026-10-21 12:13:24 +00:00
|
|
|
|
const cables = ed.cableChoices(n)
|
|
|
|
|
|
if (cables.out.length || cables.in.length) out.push('sep')
|
|
|
|
|
|
if (cables.out.length) {
|
|
|
|
|
|
out.push({
|
|
|
|
|
|
label: 'Cable from outputs',
|
|
|
|
|
|
icon: 'lucide:merge',
|
|
|
|
|
|
children: cables.out.map(g => ({ label: g.label, note: `${g.pins.length} wires`, run: () => ed.cableOut(n.id, g.pins) })),
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
if (cables.in.length) {
|
|
|
|
|
|
out.push({
|
|
|
|
|
|
label: 'Cable into inputs',
|
|
|
|
|
|
icon: 'lucide:split',
|
|
|
|
|
|
children: cables.in.map(g => ({ label: g.label, note: `${g.pins.length} wires`, run: () => ed.cableIn(n.id, g.pins) })),
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
2026-10-21 12:38:59 +00:00
|
|
|
|
if (n.kind === 'panel' || n.kind === 'outpanel') {
|
A right-click menu for parts, wires and the canvas, "Wire them all to" as cards, plugged latches in plain greys
- Right click (or the menu key) shows what can be done with what is under the pointer: one part (open, rename, change to, inputs, colour, speed, panels, unpack, plug and unplug, cable colour), several parts (wire them all to with live preview, connect one by one, switches, change all, arrange, keep only, make a component), wires (bundle, colour, whole signal, straighten, remove cable) or empty canvas (paste here, add a part here, select all, fit, tidy, undo); right drag still moves the view
- "Wire them all to": a card per part, each fit a strip of its pins, and which wire goes where for the fit pointed at
- Plugged cable ends no longer look selected: grey connector, steel clips
- Icons named in menus are bundled for the browser too
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-21 10:33:30 +00:00
|
|
|
|
out.push('sep')
|
|
|
|
|
|
if (!n.attach) out.push({ label: 'Add row', icon: 'lucide:plus', run: () => ed.addRow(n) })
|
|
|
|
|
|
else out.push({ label: 'Detach from component', icon: 'lucide:link-2-off', run: () => ed.undock(n) })
|
2026-10-21 12:38:59 +00:00
|
|
|
|
out.push({ label: 'Wire rows one by one', icon: 'lucide:cable', disabled: !n.rows?.length, run: () => ed.startLinking([n.id], n.kind === 'outpanel' ? 'in' : 'out') })
|
|
|
|
|
|
if (n.kind === 'panel' && (n.rows?.length ?? 0) > 1) {
|
|
|
|
|
|
out.push({
|
|
|
|
|
|
label: 'All rows',
|
|
|
|
|
|
icon: 'lucide:rows-3',
|
|
|
|
|
|
children: [
|
|
|
|
|
|
{ label: 'Switches', run: () => ed.setRowsType(n, 'switch') },
|
|
|
|
|
|
{ label: 'Buttons', run: () => ed.setRowsType(n, 'button') },
|
|
|
|
|
|
{ label: 'Clocks', run: () => ed.setRowsType(n, 'clock') },
|
|
|
|
|
|
],
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
A right-click menu for parts, wires and the canvas, "Wire them all to" as cards, plugged latches in plain greys
- Right click (or the menu key) shows what can be done with what is under the pointer: one part (open, rename, change to, inputs, colour, speed, panels, unpack, plug and unplug, cable colour), several parts (wire them all to with live preview, connect one by one, switches, change all, arrange, keep only, make a component), wires (bundle, colour, whole signal, straighten, remove cable) or empty canvas (paste here, add a part here, select all, fit, tidy, undo); right drag still moves the view
- "Wire them all to": a card per part, each fit a strip of its pins, and which wire goes where for the fit pointed at
- Plugged cable ends no longer look selected: grey connector, steel clips
- Icons named in menus are bundled for the browser too
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-21 10:33:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
if (n.kind === 'bundle' || n.kind === 'split') out.push('sep', ...cableEnd(n))
|
A Loxone-style working aids: named signals, inverted inputs, a project check, values on cables, search, printable sheets; wire ends move by dragging
- Send signal / Use signal: name a signal (CLK, RESET) once and use it anywhere in the circuit without a wire; selecting one lights up all of them, a use with no sender shows dashed
- Inverted inputs: Alt + click an input (or the menu/settings) puts a bubble on it; it reads the signal inverted through one NAND, counted in every transistor total
- Check (Circuit tab): open inputs, parts that drive nothing, duplicate pin names, unsent or doubly sent signals, loops that never settle; click one to show it. Open inputs get an orange marker on the canvas. Components no other circuit uses are listed with a delete
- Cables show the number they carry (= 13 · 0x0D); hovering a wire tells where it runs and its value
- Ctrl+F finds parts, signals, panel rows, notes and components in every circuit, with where each component is used
- Ctrl+P prints the circuit as a sheet with a title block on white paper (or save as PDF); also as an SVG file
- + and − under a selected gate change its number of inputs; swaps keep bubbles in place
- Drag a wire by its end to move that end to another pin; drop a dragged wire on another wire to tap its signal or feed what it fed
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-21 11:26:59 +00:00
|
|
|
|
if (n.kind === 'tag' || n.kind === 'ref') {
|
|
|
|
|
|
const name = n.label?.trim() ?? ''
|
|
|
|
|
|
const sender = ed.def.value.nodes.find(x => x.kind === 'tag' && x.label?.trim() === name)
|
|
|
|
|
|
out.push('sep')
|
|
|
|
|
|
if (n.kind === 'tag') out.push({ label: 'Use this signal here', icon: 'lucide:tag', disabled: !name, run: () => ed.useSignal(n) })
|
|
|
|
|
|
else out.push({ label: 'Go to where it is sent', icon: 'lucide:locate-fixed', disabled: !sender, run: () => ed.focusNode(sender!.id) })
|
|
|
|
|
|
out.push({ label: 'Select every place of this signal', icon: 'lucide:scan-search', disabled: !name, run: () => ed.selectSignal(name) })
|
|
|
|
|
|
}
|
A right-click menu for parts, wires and the canvas, "Wire them all to" as cards, plugged latches in plain greys
- Right click (or the menu key) shows what can be done with what is under the pointer: one part (open, rename, change to, inputs, colour, speed, panels, unpack, plug and unplug, cable colour), several parts (wire them all to with live preview, connect one by one, switches, change all, arrange, keep only, make a component), wires (bundle, colour, whole signal, straighten, remove cable) or empty canvas (paste here, add a part here, select all, fit, tidy, undo); right drag still moves the view
- "Wire them all to": a card per part, each fit a strip of its pins, and which wire goes where for the fit pointed at
- Plugged cable ends no longer look selected: grey connector, steel clips
- Icons named in menus are bundled for the browser too
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-21 10:33:30 +00:00
|
|
|
|
return [...out, ...common([n.id])]
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function cableEnd(n: CircuitNode): MenuEntry[] {
|
|
|
|
|
|
const out: MenuEntry[] = []
|
|
|
|
|
|
const feed = n.kind === 'split' ? ed.def.value.wires.find(w => w.to.node === n.id) : undefined
|
|
|
|
|
|
const bundle = n.kind === 'bundle' ? n : feed ? cableOf(ed.def.value, feed) : undefined
|
|
|
|
|
|
if (n.plug) out.push({ label: 'Unplug', icon: 'lucide:unplug', run: () => ed.unplugEnd(n) })
|
|
|
|
|
|
else {
|
|
|
|
|
|
const part = ed.plugTarget(n)
|
|
|
|
|
|
if (part) out.push({ label: `Plug into ${part.label?.trim() && !part.autoLabel ? part.label.trim() : partName(part)}`, icon: 'lucide:plug', run: () => ed.plugEnd(n) })
|
|
|
|
|
|
}
|
|
|
|
|
|
if (n.kind === 'bundle' && !n.plug) {
|
|
|
|
|
|
const fed = new Set(ed.def.value.wires.filter(w => w.to.node === n.id).map(w => w.to.pin))
|
|
|
|
|
|
if (fed.size < cableBits(n)) out.push({ label: 'Attach input panel', icon: 'lucide:sliders-vertical', run: () => ed.addCablePanel(n.id) })
|
|
|
|
|
|
}
|
|
|
|
|
|
if (bundle) {
|
|
|
|
|
|
const sleeve = ed.def.value.wires.find(w => w.from.node === bundle.id)?.color
|
|
|
|
|
|
out.push(
|
|
|
|
|
|
{
|
|
|
|
|
|
label: 'Sleeve colour',
|
|
|
|
|
|
swatches: [undefined, ...WIRE_COLORS].map(c => ({
|
A finer component boxes, a regrouped parts list with keyboard search, a real green for wires and cables
- Box designer: drag pins up or down to open gaps between groups; size (+/−) and turn (R) lamps, displays, screens and drawings; pixels belong to named screens, each placed on its own; displays of the components inside can be shown on the box (off unless ticked); a list of everything the box can show, each optional; the box grows to hold what it shows
- Lamps and displays deep inside placed components light up on the box
- Parts list: one search box for parts and components (letters in order match too), recently placed parts first, grouped Logic / Inputs / Outputs / Wiring / Notes, then components by group; groups fold away
- Keys: / searches the parts list (Enter starts placing), Shift+A or Ctrl+K adds a part at the mouse
- Wires and cables get a green; the default swatch shows grey, as the default really is
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-22 04:48:42 +00:00
|
|
|
|
color: c ? WIRE_HEX[c]! : DEFAULT_WIRE,
|
A right-click menu for parts, wires and the canvas, "Wire them all to" as cards, plugged latches in plain greys
- Right click (or the menu key) shows what can be done with what is under the pointer: one part (open, rename, change to, inputs, colour, speed, panels, unpack, plug and unplug, cable colour), several parts (wire them all to with live preview, connect one by one, switches, change all, arrange, keep only, make a component), wires (bundle, colour, whole signal, straighten, remove cable) or empty canvas (paste here, add a part here, select all, fit, tidy, undo); right drag still moves the view
- "Wire them all to": a card per part, each fit a strip of its pins, and which wire goes where for the fit pointed at
- Plugged cable ends no longer look selected: grey connector, steel clips
- Icons named in menus are bundled for the browser too
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-21 10:33:30 +00:00
|
|
|
|
title: c ?? 'Default',
|
|
|
|
|
|
active: sleeve === c,
|
|
|
|
|
|
run: () => ed.setCableColor(bundle.id, c),
|
|
|
|
|
|
})),
|
|
|
|
|
|
},
|
|
|
|
|
|
{ label: 'Remove cable', icon: 'lucide:split', run: () => ed.removeCable(bundle.id) },
|
|
|
|
|
|
)
|
|
|
|
|
|
}
|
|
|
|
|
|
return out
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function manyNodes(nodes: CircuitNode[]): MenuEntry[] {
|
|
|
|
|
|
const ids = nodes.map(n => n.id)
|
|
|
|
|
|
const out: MenuEntry[] = [{ head: `${nodes.length} parts` }]
|
|
|
|
|
|
const fits = fitItems()
|
|
|
|
|
|
if (fits.length) out.push({ label: 'Wire them all to', icon: 'lucide:cable', children: fits })
|
|
|
|
|
|
out.push({ label: 'Connect one by one', icon: 'lucide:list-ordered', run: () => ed.startLinking() })
|
2026-10-21 12:38:59 +00:00
|
|
|
|
if (nodes.every(n => n.kind === 'panel') || nodes.every(n => n.kind === 'outpanel')) {
|
|
|
|
|
|
out.push({ label: 'Merge into one panel', icon: 'lucide:combine', run: () => ed.mergeSelectedPanels() })
|
|
|
|
|
|
}
|
|
|
|
|
|
const inKinds = ['input', 'button', 'clock']
|
|
|
|
|
|
const outKinds = ['output', 'lamp']
|
|
|
|
|
|
if (nodes.every(n => inKinds.includes(n.kind)) || nodes.every(n => outKinds.includes(n.kind))) {
|
|
|
|
|
|
const outs = nodes.every(n => outKinds.includes(n.kind))
|
|
|
|
|
|
out.push({
|
|
|
|
|
|
label: outs ? 'Combine into an output panel' : 'Combine into an input panel',
|
|
|
|
|
|
icon: outs ? 'lucide:list-checks' : 'lucide:sliders-vertical',
|
|
|
|
|
|
run: () => ed.combineSelected(),
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
A right-click menu for parts, wires and the canvas, "Wire them all to" as cards, plugged latches in plain greys
- Right click (or the menu key) shows what can be done with what is under the pointer: one part (open, rename, change to, inputs, colour, speed, panels, unpack, plug and unplug, cable colour), several parts (wire them all to with live preview, connect one by one, switches, change all, arrange, keep only, make a component), wires (bundle, colour, whole signal, straighten, remove cable) or empty canvas (paste here, add a part here, select all, fit, tidy, undo); right drag still moves the view
- "Wire them all to": a card per part, each fit a strip of its pins, and which wire goes where for the fit pointed at
- Plugged cable ends no longer look selected: grey connector, steel clips
- Icons named in menus are bundled for the browser too
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-21 10:33:30 +00:00
|
|
|
|
if (nodes.every(n => n.kind === 'input')) {
|
|
|
|
|
|
out.push({
|
|
|
|
|
|
label: 'Switches',
|
|
|
|
|
|
icon: 'lucide:toggle-right',
|
|
|
|
|
|
children: [
|
|
|
|
|
|
{ label: 'All off (0)', run: () => ed.setSwitches(ids, false) },
|
|
|
|
|
|
{ label: 'All on (1)', run: () => ed.setSwitches(ids, true) },
|
|
|
|
|
|
{ label: 'Flip each', run: () => ed.setSwitches(ids, 'flip') },
|
|
|
|
|
|
],
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
const swaps = swapChoices(nodes)
|
|
|
|
|
|
if (swaps.length) out.push({ label: 'Change all to', icon: 'lucide:replace', children: swaps })
|
|
|
|
|
|
if (nodes.every(n => n.kind === 'lamp' || n.kind === 'hex' || n.kind === 'pixel')) {
|
|
|
|
|
|
const now = new Set(nodes.map(n => n.color))
|
|
|
|
|
|
out.push({
|
|
|
|
|
|
label: 'Colour',
|
|
|
|
|
|
swatches: [undefined, ...LAMP_COLORS].map(c => ({
|
|
|
|
|
|
color: c ? LAMP_HEX[c]! : LAMP_HEX.yellow!,
|
|
|
|
|
|
title: c ?? 'Default',
|
|
|
|
|
|
active: now.size === 1 && now.has(c),
|
|
|
|
|
|
run: () => ed.patchMany(ids, { color: c }),
|
|
|
|
|
|
})),
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
out.push({
|
|
|
|
|
|
label: 'Arrange',
|
|
|
|
|
|
icon: 'lucide:layout-grid',
|
|
|
|
|
|
children: ARRANGE.map(a => ({ label: a.label, icon: a.icon, run: () => ed.arrangeSelected(a.how) })),
|
|
|
|
|
|
})
|
|
|
|
|
|
const types = new Map<string, { name: string; ids: string[] }>()
|
|
|
|
|
|
for (const n of nodes) {
|
|
|
|
|
|
const k = typeKey(n)
|
|
|
|
|
|
const t = types.get(k) ?? { name: partName(n), ids: [] }
|
|
|
|
|
|
t.ids.push(n.id)
|
|
|
|
|
|
types.set(k, t)
|
|
|
|
|
|
}
|
|
|
|
|
|
if (types.size > 1) {
|
|
|
|
|
|
out.push({
|
|
|
|
|
|
label: 'Keep only',
|
|
|
|
|
|
icon: 'lucide:filter',
|
|
|
|
|
|
children: [...types.values()].map(t => ({ label: t.name, note: String(t.ids.length), run: () => ed.selectOnly(t.ids) })),
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
out.push({ label: 'Make a component', icon: 'lucide:package', input: { placeholder: 'Make a component…', submit: name => ed.packageSelected(name || 'Part') } })
|
|
|
|
|
|
return [...out, ...common(ids)]
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** Every way the selection fits, nearest first; pointing at one shows it on the canvas. */
|
|
|
|
|
|
function fitItems(): MenuItem[] {
|
|
|
|
|
|
const out: (MenuItem & { dist: number })[] = []
|
|
|
|
|
|
ed.fits.value.forEach((f, spot) => {
|
|
|
|
|
|
const part = ed.def.value.nodes.find(n => n.id === f.part)
|
|
|
|
|
|
const k = f.mine.length
|
|
|
|
|
|
for (let start = 0; start + k <= f.pins.length; start++) {
|
|
|
|
|
|
const a = f.pins[start]!
|
|
|
|
|
|
const b = f.pins[start + k - 1]!
|
|
|
|
|
|
out.push({
|
|
|
|
|
|
label: `${a.label || start + 1}–${b.label || start + k}`,
|
|
|
|
|
|
note: part ? (part.label?.trim() && !part.autoLabel ? part.label.trim() : partName(part)) : '',
|
|
|
|
|
|
icon: 'lucide:arrow-right-left',
|
|
|
|
|
|
dist: Math.hypot(a.x - f.from[0], (a.y + b.y) / 2 - f.from[1]),
|
|
|
|
|
|
run: () => ed.connectFit(spot, start),
|
|
|
|
|
|
hover: on => (ed.fitHover.value = on ? { spot, start } : null),
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
return out.sort((a, b) => a.dist - b.dist).slice(0, 10)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function wires(): MenuEntry[] {
|
|
|
|
|
|
const list = ed.selectedWires.value
|
|
|
|
|
|
const kinds = new Map(ed.def.value.nodes.map(n => [n.id, n.kind]))
|
|
|
|
|
|
const cable = list.length === 1 && kinds.get(list[0]!.from.node) === 'bundle' ? list[0] : undefined
|
|
|
|
|
|
const out: MenuEntry[] = [{ head: cable ? 'Cable' : list.length === 1 ? 'Wire' : `${list.length} wires` }]
|
|
|
|
|
|
if (list.length >= 2) {
|
|
|
|
|
|
out.push(
|
|
|
|
|
|
{ label: 'Bundle into cable', icon: 'lucide:merge', keys: 'Ctrl+G', run: () => ed.bundleSelected() },
|
|
|
|
|
|
{ label: 'Place the ends yourself', icon: 'lucide:move', keys: 'Ctrl+Shift+G', run: () => ed.startCable() },
|
|
|
|
|
|
)
|
|
|
|
|
|
}
|
|
|
|
|
|
if (list.length === 1) out.push({ label: 'Select the whole signal', icon: 'lucide:git-branch', keys: 'Double-click', run: () => ed.selectNet(list[0]!.id) })
|
|
|
|
|
|
const colors = new Set(list.map(w => w.color))
|
|
|
|
|
|
out.push({
|
|
|
|
|
|
label: cable ? 'Sleeve colour' : 'Colour',
|
|
|
|
|
|
swatches: [undefined, ...WIRE_COLORS].map(c => ({
|
A finer component boxes, a regrouped parts list with keyboard search, a real green for wires and cables
- Box designer: drag pins up or down to open gaps between groups; size (+/−) and turn (R) lamps, displays, screens and drawings; pixels belong to named screens, each placed on its own; displays of the components inside can be shown on the box (off unless ticked); a list of everything the box can show, each optional; the box grows to hold what it shows
- Lamps and displays deep inside placed components light up on the box
- Parts list: one search box for parts and components (letters in order match too), recently placed parts first, grouped Logic / Inputs / Outputs / Wiring / Notes, then components by group; groups fold away
- Keys: / searches the parts list (Enter starts placing), Shift+A or Ctrl+K adds a part at the mouse
- Wires and cables get a green; the default swatch shows grey, as the default really is
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-22 04:48:42 +00:00
|
|
|
|
color: c ? WIRE_HEX[c]! : DEFAULT_WIRE,
|
A right-click menu for parts, wires and the canvas, "Wire them all to" as cards, plugged latches in plain greys
- Right click (or the menu key) shows what can be done with what is under the pointer: one part (open, rename, change to, inputs, colour, speed, panels, unpack, plug and unplug, cable colour), several parts (wire them all to with live preview, connect one by one, switches, change all, arrange, keep only, make a component), wires (bundle, colour, whole signal, straighten, remove cable) or empty canvas (paste here, add a part here, select all, fit, tidy, undo); right drag still moves the view
- "Wire them all to": a card per part, each fit a strip of its pins, and which wire goes where for the fit pointed at
- Plugged cable ends no longer look selected: grey connector, steel clips
- Icons named in menus are bundled for the browser too
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-21 10:33:30 +00:00
|
|
|
|
title: c ?? 'Default',
|
|
|
|
|
|
active: colors.size === 1 && colors.has(c),
|
|
|
|
|
|
run: () => ed.setWireColor(c),
|
|
|
|
|
|
})),
|
|
|
|
|
|
})
|
|
|
|
|
|
if (list.some(w => w.pts?.length)) out.push({ label: 'Straighten (route automatically)', icon: 'lucide:spline', run: () => ed.autoRoute() })
|
|
|
|
|
|
if (cable) out.push({ label: 'Remove cable', icon: 'lucide:split', run: () => ed.removeCable(cable.from.node) })
|
|
|
|
|
|
out.push('sep', { label: 'Delete', icon: 'lucide:trash-2', keys: 'Del', danger: true, run: () => ed.deleteSelected() })
|
|
|
|
|
|
return out
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function canvas(at: Pt, ops: CanvasOps): MenuEntry[] {
|
|
|
|
|
|
return [
|
|
|
|
|
|
{ label: 'Paste here', icon: 'lucide:clipboard-paste', keys: 'Ctrl+V', disabled: !ed.hasClip.value, run: () => ed.paste(at) },
|
|
|
|
|
|
{
|
|
|
|
|
|
label: 'Add here',
|
|
|
|
|
|
icon: 'lucide:plus',
|
|
|
|
|
|
children: ADD.filter(a => ed.canPlaceKind(a.kind)).map(a => ({ label: a.label, icon: a.icon, keys: a.keys, run: () => ops.place(a.kind, at) })),
|
|
|
|
|
|
},
|
|
|
|
|
|
'sep',
|
|
|
|
|
|
{ label: 'Select all', icon: 'lucide:box-select', keys: 'Ctrl+A', disabled: !ed.def.value.nodes.length, run: () => ed.selectAll() },
|
|
|
|
|
|
{ label: 'Fit to screen', icon: 'lucide:scan', keys: 'F', run: ops.fit },
|
2026-10-23 12:57:16 +00:00
|
|
|
|
{ label: 'Tidy this circuit', icon: 'lucide:wand-sparkles', disabled: !ed.def.value.wires.length, run: () => ed.tidyAll() },
|
|
|
|
|
|
{ label: 'Tidy every circuit', icon: 'lucide:sparkles', run: () => ed.tidyEverything() },
|
A Loxone-style working aids: named signals, inverted inputs, a project check, values on cables, search, printable sheets; wire ends move by dragging
- Send signal / Use signal: name a signal (CLK, RESET) once and use it anywhere in the circuit without a wire; selecting one lights up all of them, a use with no sender shows dashed
- Inverted inputs: Alt + click an input (or the menu/settings) puts a bubble on it; it reads the signal inverted through one NAND, counted in every transistor total
- Check (Circuit tab): open inputs, parts that drive nothing, duplicate pin names, unsent or doubly sent signals, loops that never settle; click one to show it. Open inputs get an orange marker on the canvas. Components no other circuit uses are listed with a delete
- Cables show the number they carry (= 13 · 0x0D); hovering a wire tells where it runs and its value
- Ctrl+F finds parts, signals, panel rows, notes and components in every circuit, with where each component is used
- Ctrl+P prints the circuit as a sheet with a title block on white paper (or save as PDF); also as an SVG file
- + and − under a selected gate change its number of inputs; swaps keep bubbles in place
- Drag a wire by its end to move that end to another pin; drop a dragged wire on another wire to tap its signal or feed what it fed
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-21 11:26:59 +00:00
|
|
|
|
{ label: 'Find…', icon: 'lucide:search', keys: 'Ctrl+F', run: () => (ed.dialog.value = 'search') },
|
|
|
|
|
|
{ label: 'Print sheet / PDF', icon: 'lucide:printer', keys: 'Ctrl+P', disabled: !ed.def.value.nodes.length, run: () => ed.exportSheet('print') },
|
A right-click menu for parts, wires and the canvas, "Wire them all to" as cards, plugged latches in plain greys
- Right click (or the menu key) shows what can be done with what is under the pointer: one part (open, rename, change to, inputs, colour, speed, panels, unpack, plug and unplug, cable colour), several parts (wire them all to with live preview, connect one by one, switches, change all, arrange, keep only, make a component), wires (bundle, colour, whole signal, straighten, remove cable) or empty canvas (paste here, add a part here, select all, fit, tidy, undo); right drag still moves the view
- "Wire them all to": a card per part, each fit a strip of its pins, and which wire goes where for the fit pointed at
- Plugged cable ends no longer look selected: grey connector, steel clips
- Icons named in menus are bundled for the browser too
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-21 10:33:30 +00:00
|
|
|
|
'sep',
|
|
|
|
|
|
{ label: 'Undo', icon: 'lucide:undo-2', keys: 'Ctrl+Z', disabled: !ed.canUndo.value, run: () => ed.undo() },
|
|
|
|
|
|
{ label: 'Redo', icon: 'lucide:redo-2', keys: 'Ctrl+Shift+Z', disabled: !ed.canRedo.value, run: () => ed.redo() },
|
|
|
|
|
|
]
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** The menu for the current selection, or for a spot on the empty canvas. */
|
|
|
|
|
|
function build(target: MenuTarget, ops: CanvasOps): MenuEntry[] {
|
|
|
|
|
|
if (target.kind === 'canvas') return canvas(target.at, ops)
|
|
|
|
|
|
const nodes = nodesOf(ed.selection.value).sort(byPosition)
|
|
|
|
|
|
if (nodes.length === 1) return oneNode(nodes[0]!)
|
|
|
|
|
|
if (nodes.length > 1) return manyNodes(nodes)
|
|
|
|
|
|
if (ed.wireSel.value.length) return wires()
|
|
|
|
|
|
return []
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return { build }
|
|
|
|
|
|
}
|