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
|
|
|
<script setup lang="ts">
|
2026-10-23 10:43:08 +00:00
|
|
|
// The search box at the mouse (Space, /, Shift+A or Ctrl+K): parts to place
|
|
|
|
|
// right there, and things to do. Empty, it shows the parts used lately and
|
|
|
|
|
// the common actions; typing narrows both. Arrows choose, Enter takes it.
|
|
|
|
|
import { matchScore } from '~/lib/match'
|
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
|
|
|
import type { NodeKind } from '~/lib/logic/types'
|
|
|
|
|
|
|
|
|
|
const props = defineProps<{ x: number; y: number }>()
|
2026-10-23 10:43:08 +00:00
|
|
|
const emit = defineEmits<{ pick: [p: { kind: NodeKind; chip?: string }]; fit: []; close: [] }>()
|
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
|
|
|
|
2026-10-23 10:43:08 +00:00
|
|
|
const ed = useEditor()
|
|
|
|
|
const { search, recentParts } = useParts()
|
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 query = ref('')
|
|
|
|
|
const at = ref(0)
|
|
|
|
|
const input = ref<HTMLInputElement>()
|
|
|
|
|
const el = ref<HTMLElement>()
|
2026-10-23 10:43:08 +00:00
|
|
|
|
|
|
|
|
interface Action {
|
|
|
|
|
id: string
|
|
|
|
|
label: string
|
|
|
|
|
icon: string
|
|
|
|
|
keys?: string
|
|
|
|
|
/** Other words it is found by. */
|
|
|
|
|
aka?: string
|
|
|
|
|
/** Only offered when this holds. */
|
|
|
|
|
when?: () => boolean
|
|
|
|
|
run: () => void
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const ACTIONS: Action[] = [
|
|
|
|
|
{ id: 'new-comp', label: 'Create a new component', icon: 'lucide:square-plus', aka: 'new part chip block', run: () => ed.createComponent() },
|
|
|
|
|
{
|
|
|
|
|
id: 'package',
|
|
|
|
|
label: 'Make a component from the selection',
|
|
|
|
|
icon: 'lucide:package',
|
|
|
|
|
aka: 'group package extract',
|
|
|
|
|
when: () => ed.selection.value.length > 1,
|
|
|
|
|
run: () => ed.packageSelected('Part'),
|
|
|
|
|
},
|
|
|
|
|
{ id: 'find', label: 'Find anything in the project', icon: 'lucide:search', keys: 'Ctrl+F', aka: 'search where used', run: () => (ed.dialog.value = 'search') },
|
|
|
|
|
{ id: 'table', label: 'Truth table', icon: 'lucide:table', aka: 'test outputs', run: () => (ed.dialog.value = 'table') },
|
|
|
|
|
{ id: 'fit', label: 'Fit the circuit to the screen', icon: 'lucide:scan', keys: 'F', aka: 'zoom view', run: () => emit('fit') },
|
2026-10-23 12:57:16 +00:00
|
|
|
{ id: 'tidy', label: 'Tidy this circuit', icon: 'lucide:wand-sparkles', aka: 'wires clean route layout', when: () => ed.def.value.wires.length > 0, run: () => ed.tidyAll() },
|
|
|
|
|
{ id: 'tidy-all', label: 'Tidy every circuit', icon: 'lucide:sparkles', aka: 'wires clean route layout all components', run: () => ed.tidyEverything() },
|
2026-10-23 10:43:08 +00:00
|
|
|
{ id: 'examples', label: 'Add example parts', icon: 'lucide:book-open', aka: 'library not and or adder counter', run: () => ed.loadExamples() },
|
A public library of components: publish yours, add everybody's
"Publish to the library…" in the menu on a circuit's name (or Space)
sends the component with every component it uses and their connector
types, under your leaderboard name. The server checks it like any
project, refuses what is missing, inside itself, nested too deep or too
big to run, and counts its transistors and pins itself. Publishing again
from the same browser makes the next version of the same entry; only that
browser holds the entry's key, so only it can update or remove it.
Challenge circuits and puzzle solutions stay private.
The Library (Components in the bottom bar, Space, the main menu) lists
every entry, newest first, searchable by name, description and author,
with a picture of its box, its transistors, pins and what comes along.
Add brings an entry into the open project and starts placing it: what the
project has in exactly that form already is used as it is, the rest comes
with new ids, a taken name gets a number, connector types join one with
the same lines. The This panel says where a component came from and
offers a newer version, which replaces it in place. A campaign only adds
what is built from parts it has earned, and its challenges take nothing
from the library.
Components keep an optional "from" mark; projects without it load and
compute as before.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 17:14:46 +00:00
|
|
|
{ id: 'library', label: 'Library: components everyone published', icon: 'lucide:library-big', aka: 'public shared community download import browse', run: () => (ed.dialog.value = 'library') },
|
|
|
|
|
{
|
|
|
|
|
id: 'lib-publish',
|
|
|
|
|
label: 'Publish to the library',
|
|
|
|
|
icon: 'lucide:book-up',
|
|
|
|
|
aka: 'share upload public community',
|
|
|
|
|
when: () => !ed.libraryProblem.value && !ed.ownEntry(ed.def.value),
|
|
|
|
|
run: () => (ed.dialog.value = 'library-publish'),
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 'lib-update',
|
|
|
|
|
label: 'Update in the library',
|
|
|
|
|
icon: 'lucide:book-up',
|
|
|
|
|
aka: 'publish share upload new version public',
|
|
|
|
|
when: () => !ed.libraryProblem.value && !!ed.ownEntry(ed.def.value),
|
|
|
|
|
run: () => (ed.dialog.value = 'library-publish'),
|
|
|
|
|
},
|
2026-10-23 10:43:08 +00:00
|
|
|
{ id: 'connector', label: 'New connector type', icon: 'lucide:plug', aka: 'cable hdmi rj45 bus port', when: () => ed.canPlaceKind('portin'), run: () => ed.addConnector() },
|
|
|
|
|
{ id: 'undo', label: 'Undo', icon: 'lucide:undo-2', keys: 'Ctrl+Z', when: () => ed.canUndo.value, run: () => ed.undo() },
|
|
|
|
|
{ id: 'print', label: 'Print or save as PDF', icon: 'lucide:printer', keys: 'Ctrl+P', aka: 'sheet export', run: () => ed.exportSheet('print') },
|
|
|
|
|
{ id: 'settings', label: 'Settings', icon: 'lucide:settings', aka: 'symbols sound wires options', run: () => (ed.dialog.value = 'settings') },
|
|
|
|
|
{ id: 'help', label: 'How to play', icon: 'lucide:circle-help', keys: '?', aka: 'help shortcuts keys', run: () => (ed.showHelp.value = true) },
|
|
|
|
|
{ id: 'menu', label: 'Menu: save, load, main menu', icon: 'lucide:menu', keys: 'Esc', aka: 'pause quit', run: () => ed.pause() },
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
type Item = { type: 'part'; id: string; kind: NodeKind; chip?: string; label: string; icon: string; note?: string } | { type: 'action'; id: string; act: Action; label: string; icon: string; note?: string }
|
|
|
|
|
|
|
|
|
|
const partItem = (p: { kind: NodeKind; chip?: string; name: string; icon: string }, note?: string): Item => ({
|
|
|
|
|
type: 'part',
|
|
|
|
|
id: `p:${p.chip ?? p.kind}`,
|
|
|
|
|
kind: p.kind,
|
|
|
|
|
chip: p.chip,
|
|
|
|
|
label: p.name,
|
|
|
|
|
icon: p.icon,
|
|
|
|
|
note,
|
|
|
|
|
})
|
|
|
|
|
const actItem = (a: Action): Item => ({ type: 'action', id: `a:${a.id}`, act: a, label: a.label, icon: a.icon, note: a.keys })
|
|
|
|
|
const offered = () => ACTIONS.filter(a => !a.when || a.when())
|
|
|
|
|
|
|
|
|
|
/** Sections to show: parts first, then actions. */
|
|
|
|
|
const sections = computed(() => {
|
|
|
|
|
const q = query.value.trim()
|
|
|
|
|
if (!q) {
|
|
|
|
|
const recent = recentParts.value.map(r => partItem(r, 'recent'))
|
|
|
|
|
const parts = recent.length ? recent : search('', 6).map(h => partItem(h, h.group))
|
|
|
|
|
return [
|
|
|
|
|
{ title: recent.length ? 'Recent parts' : 'Parts', items: parts },
|
|
|
|
|
{ title: 'Actions', items: offered().slice(0, 7).map(actItem) },
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
const parts = search(q, 8).map(h => partItem(h, h.group))
|
|
|
|
|
const acts = offered()
|
|
|
|
|
.map(a => ({ a, s: Math.max(matchScore(a.label, q.toLowerCase()), matchScore(a.aka ?? '', q.toLowerCase()) * 0.8) }))
|
|
|
|
|
.filter(x => x.s > 0)
|
|
|
|
|
.sort((x, y) => y.s - x.s)
|
|
|
|
|
.slice(0, 5)
|
|
|
|
|
.map(x => actItem(x.a))
|
|
|
|
|
return [
|
|
|
|
|
{ title: 'Parts', items: parts },
|
|
|
|
|
{ title: 'Actions', items: acts },
|
|
|
|
|
].filter(s => s.items.length)
|
|
|
|
|
})
|
|
|
|
|
const flat = computed(() => sections.value.flatMap(s => s.items))
|
|
|
|
|
const indexOf = (it: Item) => flat.value.indexOf(it)
|
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
|
|
|
watch(query, () => (at.value = 0))
|
|
|
|
|
|
2026-10-23 10:43:08 +00:00
|
|
|
function take(it: Item | undefined) {
|
|
|
|
|
if (!it) return
|
|
|
|
|
if (it.type === 'part') return emit('pick', { kind: it.kind, chip: it.chip })
|
|
|
|
|
emit('close')
|
|
|
|
|
it.act.run()
|
|
|
|
|
}
|
|
|
|
|
|
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 pos = ref({ left: props.x, top: props.y })
|
|
|
|
|
onMounted(() => {
|
|
|
|
|
input.value?.focus()
|
|
|
|
|
const r = el.value!.getBoundingClientRect()
|
2026-10-23 10:43:08 +00:00
|
|
|
pos.value = { left: Math.max(8, Math.min(props.x, window.innerWidth - r.width - 8)), top: Math.max(8, Math.min(props.y, window.innerHeight - 440)) }
|
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
|
|
|
window.addEventListener('pointerdown', outside, true)
|
|
|
|
|
})
|
|
|
|
|
onBeforeUnmount(() => window.removeEventListener('pointerdown', outside, true))
|
|
|
|
|
|
|
|
|
|
function outside(e: Event) {
|
|
|
|
|
if (!el.value?.contains(e.target as Node)) emit('close')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function onKey(e: KeyboardEvent) {
|
|
|
|
|
e.stopPropagation()
|
2026-10-23 10:43:08 +00:00
|
|
|
const n = flat.value.length
|
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
|
|
|
if (e.key === 'ArrowDown' || e.key === 'ArrowUp') {
|
|
|
|
|
e.preventDefault()
|
|
|
|
|
if (n) at.value = (at.value + (e.key === 'ArrowDown' ? 1 : -1) + n) % n
|
2026-10-23 10:43:08 +00:00
|
|
|
nextTick(() => el.value?.querySelector('.item.active')?.scrollIntoView({ block: 'nearest' }))
|
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
|
|
|
} else if (e.key === 'Enter') {
|
|
|
|
|
e.preventDefault()
|
2026-10-23 10:43:08 +00:00
|
|
|
take(flat.value[at.value])
|
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
|
|
|
} else if (e.key === 'Escape') {
|
|
|
|
|
e.preventDefault()
|
|
|
|
|
emit('close')
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<template>
|
|
|
|
|
<Teleport to="body">
|
|
|
|
|
<div ref="el" class="quick-add" :style="{ left: `${pos.left}px`, top: `${pos.top}px` }" @keydown="onKey">
|
|
|
|
|
<div class="search part-search">
|
2026-10-23 10:43:08 +00:00
|
|
|
<Icon name="lucide:search" class="size-3.5 text-(--muted)" />
|
|
|
|
|
<input ref="input" v-model="query" placeholder="Find a part or an action…" />
|
|
|
|
|
</div>
|
|
|
|
|
<div class="quick-list">
|
|
|
|
|
<template v-for="s in sections" :key="s.title">
|
|
|
|
|
<p class="quick-head">{{ s.title }}</p>
|
|
|
|
|
<ul class="items">
|
|
|
|
|
<li v-for="it in s.items" :key="it.id">
|
|
|
|
|
<button class="item" :class="{ active: indexOf(it) === at }" @pointerenter="at = indexOf(it)" @click="take(it)">
|
|
|
|
|
<span v-if="it.type === 'part' && it.kind === 'nand'" class="nand-badge">&</span>
|
|
|
|
|
<Icon v-else :name="it.icon" class="size-4 shrink-0" :class="it.type === 'action' ? 'text-(--accent)' : 'text-(--muted)'" />
|
|
|
|
|
<span class="grow truncate">{{ it.label }}</span>
|
|
|
|
|
<kbd v-if="it.type === 'action' && it.note">{{ it.note }}</kbd>
|
|
|
|
|
<span v-else-if="it.note" class="group-tag">{{ it.note }}</span>
|
|
|
|
|
</button>
|
|
|
|
|
</li>
|
|
|
|
|
</ul>
|
|
|
|
|
</template>
|
|
|
|
|
<p v-if="!flat.length" class="hint px-3 pb-2">Nothing called "{{ query.trim() }}" here.</p>
|
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
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</Teleport>
|
|
|
|
|
</template>
|