feat(signage): Slides library, widgets placed on the preview, blank slides, slide editor rework
- Slides library (Alembic 0044, /api/signage/library): slides kept with a name and a
description, added to playlists as copies ("Add a slide" → Your slides, "Keep in Slides"),
or shown alone as a screen's default (device config `slide`, played as "slide:<id>",
also as a schedule's fallback). Signage → Slides: gallery + a two-pane editor.
- Widgets moved and sized by hand on the preview (WidgetCanvas: handles, snapping, arrow
keys): position/size "custom" with a box the TV draws the same; alignment per widget.
- Blank slides (background + widgets); menu boards narrower and placed left/centre/right.
- Slide editor reworked: name | show, transition effect | seconds; sections; text look on
one row with ready colours; one card per widget, settings on one row.
- Questions inside the page (@xenia/ui ConfirmDialog/useConfirm), Switch boxed, Segmented
fill; the timeline's drop line; schedule lines run on weekdays or smart days, not both;
the playlist editor stays within 1080p with a long timeline.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,111 @@
|
||||
// Widgets moved and sized right on the slide's preview (owner 2026-11-21), the way areas are on the
|
||||
// floor editor: click one to pick it, drag it to move it, drag its handles (corners and sides) to
|
||||
// size it; arrow keys nudge the picked one (Shift: more), Escape lets it go. It snaps to the
|
||||
// slide's edges and middle lines (shown while it does). A widget moved or sized this way gets
|
||||
// position and size "custom" and its own box (% of the slide), which the TV draws the same.
|
||||
// It lies over SlidePreview's box and finds each widget by its `data-widget` (@xenia/signage).
|
||||
import { useLayoutEffect, useRef, useState } from 'react'
|
||||
import { useTranslation } from '@xenia/i18n'
|
||||
import { boxFromRect, moveBox, resizeBox, snapBox } 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' }
|
||||
const SIZE = 14 // a handle, px
|
||||
|
||||
export default function WidgetCanvas({ boxRef, widgets, selected, onSelect, onPlace, label }) {
|
||||
const { t } = useTranslation('manager')
|
||||
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)
|
||||
// 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)
|
||||
}
|
||||
const key = JSON.stringify(out)
|
||||
if (key !== last.current) { last.current = key; setRects(out) }
|
||||
})
|
||||
|
||||
const start = (e, i, handle = null) => {
|
||||
e.preventDefault()
|
||||
e.stopPropagation()
|
||||
onSelect(i)
|
||||
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]
|
||||
if (!box || !base) return
|
||||
const { width, height } = box.getBoundingClientRect()
|
||||
const x0 = e.clientX
|
||||
const y0 = e.clientY
|
||||
let moved = false
|
||||
const move = ev => {
|
||||
if (!moved && Math.abs(ev.clientX - x0) + Math.abs(ev.clientY - y0) < 3) return
|
||||
moved = true
|
||||
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)
|
||||
const snapped = snapBox(next, handle)
|
||||
setGuides(snapped.guides)
|
||||
onPlace(i, snapped.box)
|
||||
}
|
||||
const up = () => {
|
||||
window.removeEventListener('pointermove', move)
|
||||
window.removeEventListener('pointerup', up)
|
||||
setGuides([])
|
||||
}
|
||||
window.addEventListener('pointermove', move)
|
||||
window.addEventListener('pointerup', up)
|
||||
}
|
||||
|
||||
const key = e => {
|
||||
if (selected == null) return
|
||||
if (e.key === 'Escape') { onSelect(null); 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 sel = selected != null ? (widgets[selected]?.position === 'custom' && widgets[selected].box) || rects[selected] : null
|
||||
return (
|
||||
<div className="absolute inset-0 outline-none" tabIndex={0} onKeyDown={key} 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} />
|
||||
))}
|
||||
{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 && (
|
||||
<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}`)}
|
||||
</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)} />
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user