feat(signage): venue badges, widgets' own look, widgets placed inside stacks, Save and leave, shared controls (owner review 5)

- Badges: the venue's list (setting signage.badges: names el/en, colours, an icon from a food and
  drink set) edited under Signage -> "Message & settings"; sent with the venue to screens and
  previews; several badges per product (MenuList.badges lists, a single one still read) in the
  shared multiple Dropdown; a board's badge colour / text colour override them (None = each own).
- Widgets: colour, background plate, font, bold / italic / underline, text size, QR colours;
  widgets in a stack's part get every setting, vertical alignment, and a custom box inside their
  place, picked (stack, then widget) and dragged on the preview (selection by path "2.1.0").
- Menu slides: vertical alignment of the list (board_valign); "Where the list sits" is now
  "Horizontal alignment".
- Message of the day: one component in the settings tab, on the Overview and from its widget.
- Leaving a slide with changes: "Save and leave" (ConfirmDialog altLabel).
- @xenia/ui: ColourField (with colour.js helpers), FieldRow (framed only while wrapped), Slider,
  IconPicker, Segmented multiple; native selects on the Overview and signage replaced by Dropdown,
  the device settings' colour input by ColourField.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-21 14:17:27 +02:00
co-authored by Claude Opus 5.5
parent aaa0914778
commit aa3fe85053
51 changed files with 1378 additions and 432 deletions
@@ -7,9 +7,12 @@
// Owner review 2 (2026-11-21): the arrow keys move the picked widget wherever it was picked (here
// or on its card below), unless you are typing or using a control that takes the arrows itself;
// Delete (or Backspace) removes it (owner review 3; "Undo changes" brings it back).
// Owner review 5 (2026-11-21): widgets inside a stack's parts too. Pick the stack, then click a
// widget in it: it moves and sizes inside its place (it can't leave the stack; its box is % of its
// place). The picked widget is a path: "2", or "2.1.0" (stack 2, part 1, its first widget).
import { useEffect, useLayoutEffect, useRef, useState } from 'react'
import { useTranslation } from '@xenia/i18n'
import { boxFromRect, moveBox, resizeBox, snapBox } from './signageLogic'
import { boxFromRect, moveBox, resizeBox, snapBox, stackOf, widgetAt } from './signageLogic'
const HANDLES = ['nw', 'n', 'ne', 'e', 'se', 's', 'sw', 'w']
const CURSOR = { n: 'ns-resize', s: 'ns-resize', e: 'ew-resize', w: 'ew-resize', nw: 'nwse-resize', se: 'nwse-resize', ne: 'nesw-resize', sw: 'nesw-resize' }
@@ -22,32 +25,57 @@ export default function WidgetCanvas({ boxRef, widgets, selected, onSelect, onPl
const [rects, setRects] = useState({})
const [guides, setGuides] = useState([])
const last = useRef('')
// where each widget is drawn now (the clock ticks, texts change): measured after every render
// (on purpose without deps; it only sets state when something moved)
// where each widget (and each stack place) is drawn now (the clock ticks, texts change): measured
// after every render (on purpose without deps; it only sets state when something moved). Widgets
// of a library slide drawn inside a part are not this slide's: left out.
// eslint-disable-next-line react-hooks/exhaustive-deps
useLayoutEffect(() => {
const box = boxRef.current
if (!box) return
const frame = box.getBoundingClientRect()
const out = {}
for (const el of box.querySelectorAll('[data-widget]')) {
const r = el.getBoundingClientRect()
out[el.getAttribute('data-widget')] = boxFromRect(r, frame)
for (const el of box.querySelectorAll('[data-widget], [data-place]')) {
if (el.closest('[data-embedded]')) continue
const r = boxFromRect(el.getBoundingClientRect(), frame)
if (el.hasAttribute('data-widget')) out[el.getAttribute('data-widget')] = r
if (el.hasAttribute('data-place')) out[`place:${el.getAttribute('data-place')}`] = r
}
const key = JSON.stringify(out)
if (key !== last.current) { last.current = key; setRects(out) }
})
const start = (e, i, handle = null) => {
const sel = selected != null ? String(selected) : null
// a widget's box in its own frame: the slide's (%), or its place's for a widget in a stack
const own = path => {
const w = widgetAt(widgets, path)
if (w?.position === 'custom' && w.box) return w.box
const r = rects[path]
const place = stackOf(path) != null ? rects[`place:${path}`] : null
if (!r || stackOf(path) == null) return r || null
if (!place) return null
return { x: (r.x - place.x) / place.w * 100, y: (r.y - place.y) / place.h * 100, w: r.w / place.w * 100, h: r.h / place.h * 100 }
}
// …and where that is on the slide (for the outline)
const onSlide = path => {
const b = own(path)
const place = stackOf(path) != null ? rects[`place:${path}`] : null
if (!b || !place) return b
return { x: place.x + b.x * place.w / 100, y: place.y + b.y * place.h / 100, w: b.w * place.w / 100, h: b.h * place.h / 100 }
}
const start = (e, path, handle = null) => {
e.preventDefault()
e.stopPropagation()
onSelect(i)
onSelect(path)
e.currentTarget.closest('[data-testid="signage-canvas"]')?.focus({ preventScroll: true })
const box = boxRef.current
const w = widgets[i]
const base = w?.position === 'custom' && w.box ? w.box : rects[i]
const base = own(path)
if (!box || !base) return
const { width, height } = box.getBoundingClientRect()
const inside = stackOf(path) != null
const frame = box.getBoundingClientRect()
const place = inside ? rects[`place:${path}`] : { w: 100, h: 100 }
const width = frame.width * place.w / 100
const height = frame.height * place.h / 100
const x0 = e.clientX
const y0 = e.clientY
let moved = false
@@ -57,9 +85,10 @@ export default function WidgetCanvas({ boxRef, widgets, selected, onSelect, onPl
const dx = (ev.clientX - x0) / width * 100
const dy = (ev.clientY - y0) / height * 100
const next = handle ? resizeBox(base, handle, dx, dy) : moveBox(base, dx, dy)
if (inside) { onPlace(path, next); return }
const snapped = snapBox(next, handle)
setGuides(snapped.guides)
onPlace(i, snapped.box)
onPlace(path, snapped.box)
}
const up = () => {
window.removeEventListener('pointermove', move)
@@ -72,50 +101,61 @@ export default function WidgetCanvas({ boxRef, widgets, selected, onSelect, onPl
// the keys, on the whole page while a widget is picked
useEffect(() => {
if (selected == null) return undefined
if (sel == null) return undefined
const on = e => {
if (e.defaultPrevented || e.altKey || e.ctrlKey || e.metaKey) return
if (e.target instanceof Element && e.target.closest(OWN_KEYS)) return
if (e.key === 'Escape') { onSelect(null); return }
if ((e.key === 'Delete' || e.key === 'Backspace') && onRemove) { e.preventDefault(); onRemove(selected); return }
if ((e.key === 'Delete' || e.key === 'Backspace') && onRemove) { e.preventDefault(); onRemove(sel); return }
const step = e.shiftKey ? 2 : 0.5
const d = { ArrowLeft: [-step, 0], ArrowRight: [step, 0], ArrowUp: [0, -step], ArrowDown: [0, step] }[e.key]
if (!d) return
e.preventDefault()
const w = widgets[selected]
const base = w?.position === 'custom' && w.box ? w.box : rects[selected]
if (base) onPlace(selected, moveBox(base, d[0], d[1]))
const base = own(sel)
if (base) onPlace(sel, moveBox(base, d[0], d[1]))
}
window.addEventListener('keydown', on)
return () => window.removeEventListener('keydown', on)
}, [selected, widgets, rects, onPlace, onSelect, onRemove])
})
const sel = selected != null ? (widgets[selected]?.position === 'custom' && widgets[selected].box) || rects[selected] : null
// what can be picked: the slide's widgets, and the widgets of the stack picked (or of the stack
// a picked widget sits in), drawn over it
const pickable = Object.keys(rects).filter(k => !k.startsWith('place:')).filter(k => {
const parent = stackOf(k)
return parent == null || (sel != null && (sel === parent || sel.startsWith(`${parent}.`)))
}).sort((a, b) => a.split('.').length - b.split('.').length)
const box = sel != null ? onSlide(sel) : null
const picked = widgetAt(widgets, sel)
return (
<div className="absolute inset-0 outline-none" tabIndex={0} onPointerDown={() => onSelect(null)}
role="application" aria-label={label} data-testid="signage-canvas">
{widgets.map((w, i) => rects[i] && (
<div key={i} className={`absolute cursor-move rounded-sm ${selected === i ? '' : 'hover:outline hover:outline-2 hover:outline-accent/60'}`}
style={{ left: `${rects[i].x}%`, top: `${rects[i].y}%`, width: `${rects[i].w}%`, height: `${rects[i].h}%` }}
onPointerDown={e => start(e, i)} data-testid="signage-canvas-widget" data-index={i} data-kind={w.kind} />
))}
{pickable.map(k => {
const w = widgetAt(widgets, k)
if (!w) return null
const r = rects[k]
return (
<div key={k} className={`absolute cursor-move rounded-sm ${sel === k ? '' : 'hover:outline hover:outline-2 hover:outline-accent/60'}`}
style={{ left: `${r.x}%`, top: `${r.y}%`, width: `${r.w}%`, height: `${r.h}%` }}
onPointerDown={e => start(e, k)} data-testid="signage-canvas-widget" data-index={k} data-kind={w.kind} />
)
})}
{guides.map(g => {
const [axis, at] = g.split(':')
return <div key={g} className="absolute bg-accent pointer-events-none" data-testid="signage-canvas-guide"
style={axis === 'x' ? { left: `${at}%`, top: 0, bottom: 0, width: 1 } : { top: `${at}%`, left: 0, right: 0, height: 1 }} />
})}
{sel && (
{box && picked && (
<div className="absolute pointer-events-none outline outline-2 outline-accent" data-testid="signage-canvas-selected"
style={{ left: `${sel.x}%`, top: `${sel.y}%`, width: `${sel.w}%`, height: `${sel.h}%` }}>
<span className={`absolute left-0 whitespace-nowrap rounded-sm bg-accent text-accent-fg text-caption font-semibold px-1.5 py-0.5 ${sel.y < 8 ? 'top-full mt-2' : 'bottom-full mb-2'}`}>
{t(`signage.widgets.kinds.${widgets[selected]?.kind}`)}
style={{ left: `${box.x}%`, top: `${box.y}%`, width: `${box.w}%`, height: `${box.h}%` }}>
<span className={`absolute left-0 whitespace-nowrap rounded-sm bg-accent text-accent-fg text-caption font-semibold px-1.5 py-0.5 ${box.y < 8 ? 'top-full mt-2' : 'bottom-full mb-2'}`}>
{t(`signage.widgets.kinds.${picked.kind === 'stack' ? (picked.direction === 'column' ? 'vstack' : 'hstack') : picked.kind}`)}
</span>
{HANDLES.map(h => (
<span key={h} className="absolute pointer-events-auto bg-surface border-2 border-accent rounded-[3px]" data-testid={`signage-handle-${h}`}
style={{ width: SIZE, height: SIZE, cursor: CURSOR[h],
left: h.includes('w') ? -SIZE / 2 : h.includes('e') ? `calc(100% - ${SIZE / 2}px)` : `calc(50% - ${SIZE / 2}px)`,
top: h.includes('n') ? -SIZE / 2 : h.includes('s') ? `calc(100% - ${SIZE / 2}px)` : `calc(50% - ${SIZE / 2}px)` }}
onPointerDown={e => start(e, selected, h)} />
onPointerDown={e => start(e, sel, h)} />
))}
</div>
)}