// The widgets of a text, menu or blank slide (plan step 5.6b; reworked 2026-11-21): logo or picture, // name, date, clock, message of the day, a text of its own, QR code, weather, a menu, and stacks. // Each in its own card: its name first, then its settings on one row (where, size, alignment, its // own options), what needs more room on the rows under it. Where / size read "Custom" once it was // moved or sized by hand on the preview (WidgetCanvas); picking a corner or a bar puts it back. The // card of the widget picked on the preview is highlighted (the page doesn't jump to it: the preview // stays in view while you drag). // Owner review 2 (2026-11-21): the widgets' order (arrows, or drag a card by its handle; a later // widget is drawn over an earlier one, and comes later in a bar); a text widget; weather for // tomorrow / the day after and in three styles; a menu widget (a board's list in its box); stacks: // parts side by side or one over the other, each its share (%), showing a widget, another stack (one // level deep) or a whole slide from the Slides library. // Owner review 3 (2026-11-21): a stack's parts sized by dragging the lines between them on its bar; // "Add a widget" beside what a part shows; Delete removes the picked widget (WidgetCanvas). // Owner review 4 (2026-11-21): a part holds several widgets, added with "Add a widget". // Owner review 5 (2026-11-21): each widget's own look ("Text and colours": colour, a plate behind // it, font, bold / italic / underline, text size; a QR code's colours); a widget in a stack's part // has every setting a slide's widget has, aligned both ways in its place or moved and sized there on // the preview (Custom); the message of the day changed from its widget. The picked widget is a path // ("2", "2.1.0": see WidgetCanvas). // Up to the venue's limit (10 recommended; Signage → Message & settings → Performance). import { Fragment, useEffect, useRef, useState } from 'react' import { AlignCenter, AlignLeft, AlignRight, AlignVerticalJustifyCenter, AlignVerticalJustifyEnd, AlignVerticalJustifyStart, ArrowDown, ArrowUp, Bold, Italic, Palette, RotateCcw, Underline, BookImage, CalendarDays, ChevronDown, Clock, CloudSun, Columns3, GripVertical, ImageIcon, LayoutList, MessageSquare, Plus, QrCode, Rows3, Store, Trash2, Type, UtensilsCrossed, } from 'lucide-react' import { cellWidgets, evenShares, setShare } from '@xenia/signage' import { useTranslation } from '@xenia/i18n' import { Button, ColourField, Dialog, Dropdown, Field, FieldRow, IconButton, Input, Popover, Segmented, Slider, Switch } from '@xenia/ui' import MessageOfTheDay from './MessageOfTheDay' import { usePerformance } from './usePerformance' import * as api from './signageApi' import MenuEditor from './MenuEditor' import { MediaPick, Section } from './SignageFields' import { CELL_KINDS, cellWidget, fillPlace, FONT_KEYS, WIDGET_COLOURS, moved, newWidget, pickedAfterMove, presetWidget, WEATHER_CHOICES, weatherChoice, WIDGET_KINDS, WIDGET_POSITIONS, } from './signageLogic' const ICON = { logo: ImageIcon, name: Store, date: CalendarDays, clock: Clock, message: MessageSquare, text: Type, qr: QrCode, weather: CloudSun, menu: UtensilsCrossed, hstack: Columns3, vstack: Rows3 } const iconOf = w => (w.kind === 'stack' ? (w.direction === 'column' ? Rows3 : Columns3) : ICON[w.kind] || LayoutList) const kindLabel = (t, w) => t(`signage.widgets.kinds.${w.kind === 'stack' ? (w.direction === 'column' ? 'vstack' : 'hstack') : w.kind}`) const ROW = 'grid gap-4 items-end grid-cols-[repeat(auto-fill,minmax(11rem,1fr))]' let library = null // the Slides library (for stacks' parts), read once function useLibrary() { const [list, setList] = useState(library || []) useEffect(() => { api.listSaved().then(r => { library = r.slides; setList(r.slides) }).catch(() => {}) }, []) return list } export default function WidgetsEditor({ widgets = [], onChange, media, onMedia, selected = null, onSelect, extras = {} }) { const { t } = useTranslation('manager') const most = usePerformance().max_widgets // the venue's limit (Performance; 10 recommended) const [drag, setDrag] = useState(null) // { from, at }: the card dragged and where it would land const set = (i, patch) => onChange(widgets.map((w, j) => (j === i ? { ...w, ...patch } : w))) const add = kind => { onChange([...widgets, newWidget(kind)]) onSelect?.(String(widgets.length)) } const move = (from, to) => { if (to < 0 || to >= widgets.length || from === to) return onChange(moved(widgets, from, to)) const top = selected != null && !String(selected).includes('.') ? Number(selected) : null onSelect?.(top == null ? null : String(pickedAfterMove(top, from, to))) } const over = (e, i) => { if (!drag) return e.preventDefault() const r = e.currentTarget.getBoundingClientRect() const at = e.clientY < r.top + r.height / 2 ? i : i + 1 if (at !== drag.at) setDrag(d => ({ ...d, at })) } const drop = () => { if (drag && drag.at != null) move(drag.from, drag.at > drag.from ? drag.at - 1 : drag.at) setDrag(null) } const line = i => drag && drag.at === i && drag.at !== drag.from && drag.at !== drag.from + 1 && (