feat(signage): stacks, menu and text widgets, widget order (owner review 2)
- Stacks: horizontal / vertical, 2-6 parts with % shares; each part shows a widget, a stack one level deep, or a whole Slides-library slide - Menu widget (a board's list in its box), text widget, weather for tomorrow / the day after and in picture / degrees / both styles - Widgets' order (arrows, drag with a drop line), drawn in list order; arrow keys move the picked widget from its card too - Server: extras by widget path (QR links, menus, embedded slides), POST /preview/slide, resolve(keep_hidden) so hidden products stay greyed in the editor's list; screens told when an embedded slide changes - Editor rows tidied: framed sliders, colours as fields, text look on one row, Switch boxed toggles from its whole frame Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -4,13 +4,17 @@
|
||||
// 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'
|
||||
// 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.
|
||||
import { useEffect, 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
|
||||
// where the arrow keys belong to the control (typing, lists, sliders, choices)
|
||||
const OWN_KEYS = 'input, textarea, select, [contenteditable="true"], [role="slider"], [role="radio"], [role="option"], [role="listbox"], [role="combobox"], [role="menu"], [role="menuitem"], [role="tab"], [role="spinbutton"], [role="dialog"] *'
|
||||
|
||||
export default function WidgetCanvas({ boxRef, widgets, selected, onSelect, onPlace, label }) {
|
||||
const { t } = useTranslation('manager')
|
||||
@@ -65,21 +69,28 @@ export default function WidgetCanvas({ boxRef, widgets, selected, onSelect, onPl
|
||||
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]))
|
||||
}
|
||||
// the keys, on the whole page while a widget is picked
|
||||
useEffect(() => {
|
||||
if (selected == 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 }
|
||||
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]))
|
||||
}
|
||||
window.addEventListener('keydown', on)
|
||||
return () => window.removeEventListener('keydown', on)
|
||||
}, [selected, widgets, rects, onPlace, onSelect])
|
||||
|
||||
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)}
|
||||
<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'}`}
|
||||
|
||||
Reference in New Issue
Block a user