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:
2026-11-21 09:44:23 +02:00
co-authored by Claude Opus 5.5
parent 83551714f7
commit 1b993e4573
23 changed files with 1231 additions and 377 deletions
@@ -1,19 +1,35 @@
// What the two slide editors share (a playlist's slide, a library slide; 2026-11-21): a menu
// board's draft resolved by the server for its preview, and the preview's widget handles.
// What the two slide editors share (a playlist's slide, a library slide; 2026-11-21): the draft
// resolved by the server for its preview, and the preview's widget handles.
import { useEffect, useState } from 'react'
import { WIDGET_HOSTS } from '@xenia/signage'
import * as api from './signageApi'
import { placeWidget } from './signageLogic'
/** A menu board's products as the server resolves the draft (only what changes the list counts). */
export function useMenuPreview(draft, setDraft) {
const c = draft?.kind === 'menu' ? draft.content || {} : null
const key = c ? JSON.stringify({ ...c, widgets: undefined, background: undefined }) : null
// what doesn't change what the server adds (where things sit, how they look): left out of the key
const LOOK = new Set(['box', 'position', 'size', 'align', 'background', 'text_colour', 'accent_colour', 'font', 'text_size',
'board_width', 'board_align', 'title', 'body', 'vertical', 'columns', 'page_seconds', 'direction', 'share', 'clock_seconds', 'date_style'])
/**
* The draft as the server resolves it for the preview (2026-11-21): a menu board's products
* (`menu`, hidden ones kept and marked) and its widgets' extras (a menu widget's products, a
* library slide inside a stack, QR links) with the media they show (`onMedia(map)`).
*/
export function useSlidePreview(draft, setDraft, onMedia) {
const host = draft && WIDGET_HOSTS.includes(draft.kind)
const key = host ? JSON.stringify([draft.kind, draft.content || {}], (k, v) => (LOOK.has(k) ? undefined : v)) : null
useEffect(() => {
if (!key) return undefined
const kind = draft.kind
const content = draft.content || {}
const h = setTimeout(() => {
api.previewMenu(JSON.parse(key)).then(r => setDraft(d => (d && d.kind === 'menu' ? { ...d, menu: r.menu } : d))).catch(() => {})
api.previewSlide(kind, content).then(r => {
if (r.media && Object.keys(r.media).length) onMedia?.(r.media)
setDraft(d => (d && d.kind === kind ? { ...d, extras: r.extras, ...(kind === 'menu' ? { menu: r.menu } : {}) } : d))
}).catch(() => {})
}, 400)
return () => clearTimeout(h)
// the key holds what counts in the draft
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [key, setDraft])
}