2026-10-22 16:59:56 +00:00
< script setup lang = "ts" >
// Edit a connector type of your own, like HDMI or RJ45: its name, colour and
// lines. A line runs out → in (from an "out" port to an "in" port), or back.
// Every port and cable of this type follows the changes.
import { WIRE _COLORS , type ConnectorType , type WireColor } from '~/lib/logic/types'
const ed = useEditor ( )
const close = ( ) => ( ed . dialog . value = null )
const type = computed < ConnectorType | undefined > ( ( ) => ed . project . value . connectors ? . find ( c => c . id === ed . connectorFor . value ) )
const uses = computed ( ( ) => ( type . value ? ed . connectorUses ( type . value . id ) : 0 ) )
const confirmDelete = ref ( false )
/** Every change is one step to undo, and reaches every port of this type. */
const save = ( ) => ed . commit ( )
function setName ( e : Event ) {
if ( ! type . value ) return
type . value . name = ( e . target as HTMLInputElement ) . value . trim ( ) . slice ( 0 , 40 ) || 'Connector'
save ( )
}
function setColor ( c : WireColor | undefined ) {
if ( ! type . value ) return
if ( c ) type . value . color = c
else delete type . value . color
save ( )
}
function setLine ( i : number , e : Event ) {
const line = type . value ? . lines [ i ]
if ( ! line ) return
line . name = ( e . target as HTMLInputElement ) . value . trim ( ) . slice ( 0 , 24 ) || ` L ${ i } `
save ( )
}
function flip ( i : number ) {
const line = type . value ? . lines [ i ]
if ( ! line ) return
if ( line . back ) delete line . back
else line . back = true
save ( )
}
function move ( i : number , by : number ) {
const lines = type . value ? . lines
if ( ! lines || i + by < 0 || i + by >= lines . length ) return
const [ l ] = lines . splice ( i , 1 )
lines . splice ( i + by , 0 , l ! )
save ( )
}
function remove ( i : number ) {
type . value ? . lines . splice ( i , 1 )
save ( )
}
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>
2026-10-22 20:47:38 +00:00
/** 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 ( )
}
2026-10-22 16:59:56 +00:00
function addLine ( ) {
const lines = type . value ? . lines
if ( ! lines || lines . length >= 64 ) return
// Continue a series: D0, D1 → D2.
const last = lines . at ( - 1 ) ? . name ? ? 'D-1'
const m = /^(.*?)(\d+)$/ . exec ( last )
lines . push ( { name : m ? ` ${ m [ 1 ] } ${ Number ( m [ 2 ] ) + 1 } ` : ` L ${ lines . length } ` } )
save ( )
nextTick ( ( ) => document . querySelector < HTMLInputElement > ( '.conn-lines li:last-child input' ) ? . select ( ) )
}
function remove _type ( ) {
if ( ! type . value ) return
ed . removeConnector ( type . value . id )
}
const forward = computed ( ( ) => type . value ? . lines . filter ( l => ! l . back ) . length ? ? 0 )
< / script >
< template >
< div class = "modal-backdrop" @click.self ="close" >
< div v-if ="type" class="modal conn-modal" role="dialog" aria-labelledby="conn-title" >
< div class = "flex items-start justify-between gap-4" >
< div >
< h2 id = "conn-title" > Connector type < / h2 >
< p class = "hint mt-1" >
A cable of this type joins an < strong > out < / strong > port to an < strong > in < / strong > port and carries all its lines .
{ { uses ? ` Used by ${ uses } port ${ uses === 1 ? '' : 's' } ; they follow every change. ` : 'Not used yet: place its ports from the Connectors list.' } }
< / p >
< / div >
< button class = "tb-btn" title = "Close" @click ="close" > < Icon name = "lucide:x" class = "size-4" / > < / button >
< / div >
< div class = "sel-row mt-4" >
< label class = "field grow" >
< span > Name < / span >
< input :value ="type.name" maxlength = "40" placeholder = "e.g. HDMI, RJ45, Bus" @change ="setName" @ keydown.enter = " ( $ event.target as HTMLInputElement ) .blur ( ) " / >
< / label >
< / div >
< div class = "field" >
< span > Colour of its cables < / span >
< div class = "swatches" >
< button class = "swatch none" : class = "{ active: !type.color }" title = "Default: grey" @click ="setColor(undefined)" / >
< button v -for = " c in WIRE_COLORS " :key ="c" class = "swatch" : class = "[`c-${c}`, { active: type.color === c }]" :title ="c" @click ="setColor(c)" / >
< / div >
< / div >
< div class = "field" >
< span > Lines ( { { forward } } out → in , { { type . lines . length - forward } } back ) < / span >
< ul class = "conn-lines" >
< li v-for ="(l, i) in type.lines" :key ="i" >
< span class = "conn-index" > { { i } } < / span >
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>
2026-10-22 20:47:38 +00:00
< input :value ="l.name" maxlength = "24" @ change = "setLine(i, $event)" @ keydown.tab = " lineTab ( i , $ event ) " @ keydown.enter = " ( $ event.target as HTMLInputElement ) .blur ( ) " / >
2026-10-22 16:59:56 +00:00
< button
class = "btn-sm conn-dir"
: class = "{ back: l.back }"
: title = "l.back ? 'Runs back: from the in port to the out port (like an acknowledge or hot-plug line). Click to turn it around.' : 'Runs from the out port to the in port. Click to make it a line back.'"
@ click = "flip(i)"
>
{ { l . back ? '← back' : 'out → in' } }
< / button >
< button class = "icon-btn" title = "Move up" : disabled = "i === 0" @ click = "move(i, -1)" > < Icon name = "lucide:arrow-up" class = "size-3.5" / > < / button >
< button class = "icon-btn" title = "Move down" : disabled = "i === type.lines.length - 1" @ click = "move(i, 1)" > < Icon name = "lucide:arrow-down" class = "size-3.5" / > < / button >
< button class = "icon-btn danger" title = "Remove this line" @click ="remove(i)" > < Icon name = "lucide:x" class = "size-3.5" / > < / button >
< / li >
< / ul >
< button class = "btn-sm self-start" : disabled = "type.lines.length >= 64" @click ="addLine" > < Icon name = "lucide:plus" class = "size-3.5" / > Add line < / button >
< p v-if ="uses" class="hint mt-2" > Ports and cables match lines by their place in this list : moving a line moves what it carries. < / p >
< / div >
< div class = "mt-4 flex items-center gap-2" >
< button class = "btn btn-primary" @click ="close" > Done < / button >
< span class = "grow" / >
< button v-if ="!confirmDelete" class="btn btn-ghost" :disabled="uses > 0" :title="uses ? 'Still used by ports' : ''" @click="confirmDelete = true" >
< Icon name = "lucide:trash-2" class = "size-4" / > Delete type
< / button >
< button v -else class = "btn btn-danger" @click ="remove_type" > Really delete ? < / button >
< / div >
< / div >
< / div >
< / template >