From 55bba95098b711c1fb341bfe53e3af5e145704e8 Mon Sep 17 00:00:00 2001 From: "Fabian @ Blax Software" Date: Fri, 23 Oct 2026 12:59:16 +0200 Subject: [PATCH] R panel rows editor: drag to reorder, add above or below, gaps you can see, no folded settings Each row is one line: a grip to drag it, its colour (click for the next), its name, switch / button / clock as three icons, its key (or Hz for a clock), remove. Pointing between two rows offers to add a row there or more or less space; empty rows show as that much dashed space. Alt + up or down in a name moves the row. Rows keep their wires when moved. Co-Authored-By: Claude Opus 5.5 (1M context) --- app/assets/css/main.css | 300 +++++++++++++++++++++---- app/components/editor/NodeSettings.vue | 228 ++++++++++++------- app/composables/useEditor.ts | 18 +- app/lib/logic/panels.ts | 37 ++- tests/panels.test.ts | 43 +++- 5 files changed, 504 insertions(+), 122 deletions(-) diff --git a/app/assets/css/main.css b/app/assets/css/main.css index 6d42455..d738f2f 100644 --- a/app/assets/css/main.css +++ b/app/assets/css/main.css @@ -2121,63 +2121,264 @@ kbd { } /* ── Panel rows in the inspector ────────────────────────────────── */ -.panel-rows { - display: grid; - gap: 4px; - margin-bottom: 6px; -} - -.panel-rows li { +/* Rows of a panel: one line each, a grip to drag, space between rows to add to. */ +.rows-head { display: flex; align-items: center; - gap: 4px; + justify-content: space-between; + margin-bottom: 4px; } -.panel-rows input, -.panel-rows select { - min-width: 0; - flex: 1; -} - -.panel-rows input.hz { - flex: 0 0 56px; -} - -.panel-rows li { - flex-wrap: wrap; -} - -.panel-rows li.open { - padding-bottom: 4px; - border-bottom: 1px solid var(--border); -} - -.panel-rows .icon-btn.active { - color: var(--text); -} - -.panel-rows .row-more { +.rows-all { display: flex; - flex: 1 0 100%; - flex-wrap: wrap; align-items: center; - gap: 6px 8px; - padding-left: 26px; + gap: 2px; font-size: 11px; color: var(--muted); } -.panel-rows .row-more label { - display: flex; - align-items: center; - gap: 4px; +.kind-btn { + display: grid; + place-items: center; + width: 22px; + height: 22px; + border-radius: 5px; + color: var(--muted); } -.panel-rows .row-more input { - flex: 0 0 40px; - width: 40px; - padding: 2px 4px; +.kind-btn:hover { + background: var(--panel-2); + color: var(--text); +} + +.panel-rows { + display: flex; + flex-direction: column; + margin-bottom: 6px; + user-select: none; +} + +.panel-rows li.row { + position: relative; + display: flex; + align-items: center; + gap: 3px; + min-height: 30px; + border-radius: 6px; +} + +.panel-rows li.row.lifted { + opacity: 0.45; +} + +.panel-rows li.row.drop-above::before, +.panel-rows li.row.drop-below::after { + content: ''; + position: absolute; + left: 0; + right: 0; + height: 2px; + border-radius: 1px; + background: var(--accent); +} + +.panel-rows li.row.drop-above::before { + top: -3px; +} + +.panel-rows li.row.drop-below::after { + bottom: -3px; +} + +.row-grip { + display: grid; + place-items: center; + width: 12px; + height: 26px; + flex-shrink: 0; + color: var(--muted); + cursor: grab; + touch-action: none; +} + +.panel-rows.dragging, +.panel-rows.dragging .row-grip { + cursor: grabbing; +} + +.row-grip:hover { + color: var(--text); +} + +.row-color { + width: 14px; + height: 14px; + flex-shrink: 0; + border-radius: 50%; + outline: 1px solid var(--border); +} + +.row-color.none { + outline: 0; +} + +.row-color.lamp-swatch:hover { + outline: 2px solid var(--text); +} + +.panel-rows input { + min-width: 0; + padding: 4px 6px; +} + +.panel-rows .row-name { + flex: 1; +} + +.kind-toggle { + display: flex; + flex-shrink: 0; + padding: 1px; + border: 1px solid var(--border); + border-radius: 6px; + background: var(--panel-2); +} + +.kind-toggle button { + display: grid; + place-items: center; + width: 20px; + height: 22px; + border-radius: 4px; + color: var(--muted); +} + +.kind-toggle button:hover { + color: var(--text); +} + +.kind-toggle button.on { + background: rgb(76 194 255 / 0.18); + color: var(--accent); +} + +.panel-rows .row-side { + flex: 0 0 32px; + width: 32px; + padding: 4px 2px; text-align: center; + font-size: 11px; +} + +.panel-rows .key-input { + cursor: pointer; + text-transform: uppercase; +} + +.panel-rows .key-input::placeholder { + text-transform: none; +} + +/* Between two rows: thin until pointed at; empty rows show as that much space. */ +.row-between { + position: relative; + height: 8px; + display: flex; + align-items: center; + justify-content: flex-end; +} + +.row-between.spaced { + height: calc(var(--gap) * 9px + 8px); + margin: 2px 0; + border: 1px dashed var(--border); + border-radius: 6px; +} + +.gap-label { + padding-right: 8px; + font-size: 10px; + color: var(--muted); +} + +.between-tools { + position: absolute; + z-index: 2; + left: 50%; + top: 50%; + display: flex; + gap: 2px; + padding: 2px; + transform: translate(-50%, -50%); + background: var(--panel); + border: 1px solid var(--border); + border-radius: 7px; + box-shadow: 0 4px 14px rgb(0 0 0 / 0.4); + opacity: 0; + pointer-events: none; + transition: opacity 0.1s; +} + +.row-between:not(.end)::before { + content: ''; + position: absolute; + left: 18px; + right: 0; + top: 50%; + height: 1px; + background: var(--accent); + opacity: 0; +} + +.panel-rows:not(.dragging) .row-between:hover .between-tools, +.row-between:focus-within .between-tools { + opacity: 1; + pointer-events: auto; +} + +.panel-rows:not(.dragging) .row-between:not(.spaced):hover::before { + opacity: 0.6; +} + +.between-tools button { + display: flex; + align-items: center; + gap: 3px; + padding: 2px 7px; + border-radius: 5px; + font-size: 11px; + font-weight: 600; + color: var(--muted); + white-space: nowrap; +} + +.between-tools button:hover { + background: var(--panel-2); + color: var(--text); +} + +.row-between.end { + height: auto; + justify-content: flex-start; + margin-top: 4px; +} + +.add-row { + display: flex; + align-items: center; + gap: 5px; + width: 100%; + padding: 5px 8px; + border: 1px dashed var(--border); + border-radius: 6px; + font-size: 12px; + font-weight: 600; + color: var(--muted); +} + +.add-row:hover { + border-color: var(--accent); + color: var(--text); } .swatches.mini { @@ -5169,3 +5370,14 @@ button.tile:hover { bottom: calc(40% + 14px); } } + +.panel-rows .row-side.hz { + appearance: textfield; + -moz-appearance: textfield; +} + +.panel-rows .row-side.hz::-webkit-inner-spin-button, +.panel-rows .row-side.hz::-webkit-outer-spin-button { + -webkit-appearance: none; + margin: 0; +} diff --git a/app/components/editor/NodeSettings.vue b/app/components/editor/NodeSettings.vue index bc5e980..8264315 100644 --- a/app/components/editor/NodeSettings.vue +++ b/app/components/editor/NodeSettings.vue @@ -13,10 +13,10 @@ import { LAMP_COLORS, WIRE_COLORS, type CircuitNode, type NodeKind, type PanelCo const props = defineProps<{ node: CircuitNode }>() const ed = useEditor() -const CONTROLS: { value: PanelControl; label: string }[] = [ - { value: 'switch', label: 'Switch' }, - { value: 'button', label: 'Button' }, - { value: 'clock', label: 'Clock' }, +const CONTROLS: { value: PanelControl; label: string; icon: string }[] = [ + { value: 'switch', label: 'Switch', icon: 'lucide:toggle-left' }, + { value: 'button', label: 'Button', icon: 'lucide:circle-dot' }, + { value: 'clock', label: 'Clock', icon: 'lucide:audio-waveform' }, ] const HINTS: Record = { @@ -34,7 +34,7 @@ const HINTS: Record = { tag: 'Wire a signal into it and give it a name. Every "Use signal" with that name in this circuit carries the same signal, without a wire. Names stay inside this circuit.', ref: 'Carries the signal of the "Send signal" with the same name in this circuit. Select it to see all places that signal goes.', outpanel: 'A lamp per row, named after what it shows. Inside a component its rows are output pins, top to bottom with the other outputs. Each row passes its signal on to the right.', - panel: 'Click a row on the canvas to flip its switch or hold its button, or press its key. Rows without a name take the name of the pin they are wired to. Open a row (the arrow) for its key, colour, spacing and order.', + panel: 'Click a row on the canvas to flip its switch or hold its button, or press its key. Rows without a name take the name of the pin they are wired to. Drag a row by its grip to move it; point between two rows to add one there or change the space.', } const n = computed(() => props.node) @@ -219,17 +219,70 @@ function tabOn(row: PanelRow, i: number, e: KeyboardEvent) { 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('.panel-rows > li:last-child > input')?.focus()) + addAt(n.value.rows?.length ?? 0) } -/** Rows showing their extra settings (key, colour, spacing, order). */ -const openRows = ref(new Set()) -function toggleRow(id: string) { - const s = new Set(openRows.value) - if (!s.delete(id)) s.add(id) - openRows.value = s +const rowList = ref() +const focusRow = (id: string) => nextTick(() => rowList.value?.querySelector(`[data-row-id="${id}"] .row-name`)?.focus()) + +/** A new row at a place in the order, its name ready to type. */ +function addAt(index: number) { + const row = ed.insertRow(n.value, index) + if (row) focusRow(row.id) } + +/** The row's colour: a click takes the next one, Shift + click the one before. */ +function nextColor(row: PanelRow, e: MouseEvent) { + const order = [undefined, ...LAMP_COLORS] + const k = order.indexOf(row.color) + ed.setRowColor(row, order[(k + (e.shiftKey ? -1 : 1) + order.length) % order.length]) +} + +/** Alt + ↑/↓ in a row's name moves the row. */ +function moveByKey(i: number, e: KeyboardEvent) { + if (!e.altKey || n.value.attach) return + const to = i + (e.key === 'ArrowUp' ? -1 : 1) + const row = n.value.rows?.[i] + if (!row || to < 0 || to >= (n.value.rows?.length ?? 0)) return + e.preventDefault() + ed.moveRowTo(n.value, i, to) + focusRow(row.id) +} + +// Dragging a row by its grip: a line shows where it goes; dropping moves it there. +const rowDrag = ref<{ from: number; before: number } | null>(null) +function startRowDrag(from: number, e: PointerEvent) { + if (n.value.attach) return + e.preventDefault() + rowDrag.value = { from, before: from } + const move = (ev: PointerEvent) => { + const items = [...(rowList.value?.querySelectorAll('li.row') ?? [])] + let before = items.length + for (let k = 0; k < items.length; k++) { + const r = items[k]!.getBoundingClientRect() + if (ev.clientY < r.top + r.height / 2) { + before = k + break + } + } + rowDrag.value = { from, before } + } + const up = () => { + window.removeEventListener('pointermove', move) + window.removeEventListener('pointerup', up) + const d = rowDrag.value + rowDrag.value = null + if (d) ed.moveRowTo(n.value, d.from, d.before > d.from ? d.before - 1 : d.before) + } + window.addEventListener('pointermove', move) + window.addEventListener('pointerup', up) +} +/** Where the drop line shows: above row k, or (k = rows) below the last. */ +const dropAt = computed(() => { + const d = rowDrag.value + return d && d.before !== d.from && d.before !== d.from + 1 ? d.before : null +}) + const rowGaps = computed(() => { const at = panelOffsets(n.value.rows ?? []) return at.map((y, i) => (i ? y - at[i - 1]! - 1 : 0)) @@ -441,73 +494,98 @@ function setRowHz(row: PanelRow, e: Event) {

- Rows -
    -
  • - - - - - -
    - - - - - + +
    +
      + +
    • +
    -
    - - -