feat(signage): menu look part by part, board-only names, stack bar, Delete key (owner review 3)
- Menus (slides and widgets): headings / names / prices each with size, colour, font, bold / italic / underline and alignment; dots size, colour and style; line and letter spacing; photo size and shape (menuLook) - Names aligned right end together, prices in a page-wide column - Names for one board only (names, category_names) with a pencil on the board's list; the catalogue name stays for the waiters - Fixed: menu lists inherited the page's fixed line height (big text overlapped); a menu slide's list grew past the screen (no 2nd column) - Stacks: parts sized by dragging the lines on the bar; "Add a widget" - Delete / Backspace removes the picked widget Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -10,15 +10,18 @@
|
||||
// crossed eye (a green eye on the ones shown): a click shows / hides it; seconds per page explained;
|
||||
// the text's look on one row. `board` mode: the same editor for a menu widget's list (no background,
|
||||
// widgets, width or place; its own products per page).
|
||||
// Owner review 3 (2026-11-21): the look part by part (MenuLook: headings, names, prices, dots,
|
||||
// spacing, photos); a pencil beside each category and product on the board gives it a name for
|
||||
// this board only (the catalogue keeps its own: the waiters' names stay as they are).
|
||||
import { useEffect, useMemo, useState } from 'react'
|
||||
import { AlignCenter, AlignLeft, AlignRight, ArrowDown, ArrowUp, Eye, EyeOff, X } from 'lucide-react'
|
||||
import { AlignCenter, AlignLeft, AlignRight, ArrowDown, ArrowUp, Eye, EyeOff, Pencil, RotateCcw, X } from 'lucide-react'
|
||||
import { MENU_LANGUAGES, SALES_POINTS } from '@xenia/access'
|
||||
import { useFormat, useTranslation } from '@xenia/i18n'
|
||||
import { Dropdown, Field, IconButton, Input, Segmented, Select, Switch } from '@xenia/ui'
|
||||
import client from '../../api/client'
|
||||
import { BADGES, boardOrder, moveGroup, moveItem, toggled } from './signageLogic'
|
||||
import { BackgroundField, ColourField, Range, Section } from './SignageFields'
|
||||
import { TextLook } from './SlideEditor'
|
||||
import MenuLook from './MenuLook'
|
||||
import { BackgroundField, Range, Section } from './SignageFields'
|
||||
import WidgetsEditor from './WidgetsEditor'
|
||||
|
||||
let catalogue = null // categories and products, read once for every menu editor on the page
|
||||
@@ -52,6 +55,13 @@ export default function MenuEditor({ slide, onChange, media, onMedia, misfit = [
|
||||
const badges = c.badges || {}
|
||||
const digits = v => Number(String(v).replace(/\D/g, ''))
|
||||
const hidden = new Set(c.exclude_ids || [])
|
||||
// this board's own names: empty = the catalogue's again
|
||||
const rename = (key, id, name) => {
|
||||
const next = { ...(c[key] || {}) }
|
||||
if (name && name.trim()) next[String(id)] = name.trim()
|
||||
else delete next[String(id)]
|
||||
setC({ [key]: next })
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="grid gap-7" data-testid={testid}>
|
||||
@@ -120,7 +130,8 @@ export default function MenuEditor({ slide, onChange, media, onMedia, misfit = [
|
||||
<div key={`${g.category?.id ?? 'all'}`} className="grid gap-1" data-testid="signage-menu-group" data-name={g.category?.name ?? ''}>
|
||||
{g.category && (
|
||||
<div className="flex items-center gap-1">
|
||||
<span className="text-label font-semibold text-ink flex-1">{g.category.name}</span>
|
||||
<OwnName name={g.category.name} original={g.category.original} onSave={v => rename('category_names', g.category.id, v)}
|
||||
className="text-label font-semibold text-ink" testid="signage-category-name" />
|
||||
<IconButton size="sm" variant="ghost" label={t('display.earlier')} disabled={gi === 0} onClick={() => reorder(moveGroup(groups, gi, -1))} data-testid="signage-group-up"><ArrowUp size={14} /></IconButton>
|
||||
<IconButton size="sm" variant="ghost" label={t('display.later')} disabled={gi === groups.length - 1} onClick={() => reorder(moveGroup(groups, gi, 1))}><ArrowDown size={14} /></IconButton>
|
||||
</div>
|
||||
@@ -131,7 +142,8 @@ export default function MenuEditor({ slide, onChange, media, onMedia, misfit = [
|
||||
return (
|
||||
<li key={it.id} className="flex items-center gap-1.5 pl-2 rounded-control hover:bg-surface"
|
||||
data-testid="signage-menu-row" data-id={it.id} data-hidden={off ? 'true' : undefined}>
|
||||
<span className={`flex-1 min-w-0 truncate text-label ${off ? 'text-ink-3 opacity-70' : it.available ? 'text-ink' : 'text-ink-3 line-through'}`}>{it.name}</span>
|
||||
<OwnName name={it.name} original={it.original} onSave={v => rename('names', it.id, v)} testid="signage-item-name"
|
||||
className={`text-label ${off ? 'text-ink-3 opacity-70' : it.available ? 'text-ink' : 'text-ink-3 line-through'}`} />
|
||||
{off && <span className="text-caption text-ink-3">{t('signage.menu.hiddenTag')}</span>}
|
||||
{it.price != null && <span className={`text-caption tabular-nums ${off ? 'text-ink-3 opacity-70' : 'text-ink-2'}`}>{formatMoney(it.price)}</span>}
|
||||
<Select size="sm" value={badges[String(it.id)] || ''} aria-label={t('signage.menu.badge')} data-testid="signage-menu-badge" disabled={off}
|
||||
@@ -208,9 +220,7 @@ export default function MenuEditor({ slide, onChange, media, onMedia, misfit = [
|
||||
</div>
|
||||
</Section>
|
||||
|
||||
<TextLook c={c} setC={setC} align={false}>
|
||||
<ColourField compact label={t('signage.accent')} value={c.accent_colour || '#f59e0b'} onChange={v => setC({ accent_colour: v })} testid="signage-accent" />
|
||||
</TextLook>
|
||||
<MenuLook c={c} setC={setC} />
|
||||
{!board && <>
|
||||
<BackgroundField value={c.background} onChange={background => setC({ background })} media={media} onMedia={onMedia}
|
||||
misfit={misfit.includes(c.background?.media_id)} />
|
||||
@@ -220,3 +230,36 @@ export default function MenuEditor({ slide, onChange, media, onMedia, misfit = [
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* A category's or product's name on the board, with a pencil (shown on hover or focus) to give it a
|
||||
* name for this board only; the catalogue's name shows under it then, with a button to go back to it.
|
||||
*/
|
||||
function OwnName({ name, original, onSave, className = '', testid }) {
|
||||
const { t } = useTranslation('manager')
|
||||
const [edit, setEdit] = useState(null)
|
||||
if (edit != null) {
|
||||
const done = () => { onSave(edit); setEdit(null) }
|
||||
return (
|
||||
<span className="flex-1 min-w-0">
|
||||
<Input size="sm" autoFocus value={edit} maxLength={80} aria-label={t('signage.menu.ownName')} data-testid={`${testid}-input`}
|
||||
onChange={e => setEdit(e.target.value)} onBlur={done}
|
||||
onKeyDown={e => { if (e.key === 'Enter') done(); if (e.key === 'Escape') setEdit(null) }} />
|
||||
</span>
|
||||
)
|
||||
}
|
||||
return (
|
||||
<span className="group/name flex-1 min-w-0 flex items-center gap-1">
|
||||
<span className="min-w-0 grid">
|
||||
<span className={`truncate ${className}`} data-testid={testid}>{name}</span>
|
||||
{original && <span className="truncate text-caption text-ink-3" title={t('signage.menu.catalogueName')}>{t('signage.menu.catalogueNameIs', { name: original })}</span>}
|
||||
</span>
|
||||
<IconButton size="sm" variant="ghost" label={t('signage.menu.rename')} onClick={() => setEdit(name)} data-testid={`${testid}-edit`}
|
||||
className="opacity-0 group-hover/name:opacity-100 focus-visible:opacity-100 shrink-0"><Pencil size={13} /></IconButton>
|
||||
{original && (
|
||||
<IconButton size="sm" variant="ghost" label={t('signage.menu.renameBack')} onClick={() => onSave('')} data-testid={`${testid}-reset`}
|
||||
className="opacity-0 group-hover/name:opacity-100 focus-visible:opacity-100 shrink-0"><RotateCcw size={13} /></IconButton>
|
||||
)}
|
||||
</span>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,124 @@
|
||||
// A menu's look, part by part (owner review 3, 2026-11-21), for menu slides and menu widgets alike:
|
||||
// one row each for the headings, the product names and the prices (size, colour, font, bold /
|
||||
// italic / underline, alignment), the dots between name and price (size, colour, style), and the
|
||||
// spacing (line and letter spacing: empty = auto) with the photos' size and shape and the accent
|
||||
// (badges, page dots). The names' row sets the board's own text size, colour and font; headings and
|
||||
// prices follow them (the accent colour) until given their own. The player draws it (menuLook).
|
||||
import { AlignCenter, AlignLeft, AlignRight, Bold, Italic, Underline } from 'lucide-react'
|
||||
import { useTranslation } from '@xenia/i18n'
|
||||
import { Dropdown, Field, Input, Segmented } from '@xenia/ui'
|
||||
import { FONT_KEYS, MENU_COLOURS } from './signageLogic'
|
||||
import { ColourField, Range, Section } from './SignageFields'
|
||||
|
||||
const ROW = 'grid gap-3 items-end grid-cols-2 lg:grid-cols-[7rem_repeat(5,minmax(0,1fr))]'
|
||||
|
||||
export default function MenuLook({ c, setC }) {
|
||||
const { t } = useTranslation('manager')
|
||||
const base = c.text_size || 100
|
||||
const accent = c.accent_colour || MENU_COLOURS.accent
|
||||
const style = key => c[key] || {}
|
||||
const setStyle = (key, patch) => setC({ [key]: { ...style(key), ...patch } })
|
||||
const fontOptions = inherit => [...(inherit ? [{ value: '', label: t('signage.look.sameFont') }] : []), ...FONT_KEYS.map(x => ({ value: x, label: t(`signage.fonts.${x}`) }))]
|
||||
const num = (v, lo, hi) => {
|
||||
const n = Number(String(v).replace(',', '.'))
|
||||
return v === '' || Number.isNaN(n) ? null : Math.min(hi, Math.max(lo, n))
|
||||
}
|
||||
|
||||
/** A row for headings / names / prices: size, colour, font, style, alignment. */
|
||||
const partRow = (key, label, { size, colour, font, onSize, onColour, onFont, inherit, align }) => {
|
||||
const s = style(key)
|
||||
return (
|
||||
<div className={ROW} data-testid={`signage-look-${key}`}>
|
||||
<RowLabel>{label}</RowLabel>
|
||||
<Range label={t('signage.look.size')} value={size} min={50} max={300} step={10} suffix="%" onChange={onSize} testid={`signage-look-${key}-size`} />
|
||||
<ColourField compact label={t('signage.look.colour')} value={colour} onChange={onColour} testid={`signage-look-${key}-colour`} />
|
||||
<Field label={t('signage.look.font')}>
|
||||
<Dropdown value={font} onChange={onFont} options={fontOptions(inherit)} data-testid={`signage-look-${key}-font`} />
|
||||
</Field>
|
||||
<Field label={t('signage.look.style')}>
|
||||
<TextToggles s={s} onChange={patch => setStyle(key, patch)} testid={`signage-look-${key}`} />
|
||||
</Field>
|
||||
<Field label={t('signage.look.align')}>
|
||||
<Segmented value={s.align || align} onChange={v => setStyle(key, { align: v })} fill data-testid={`signage-look-${key}-align`}
|
||||
options={[['left', AlignLeft], ['center', AlignCenter], ['right', AlignRight]].map(([v, Icon]) => (
|
||||
{ value: v, icon: <Icon size={16} aria-hidden="true" />, ariaLabel: t(`signage.aligns.${v}`), testId: `signage-look-${key}-align-${v}` }))} />
|
||||
</Field>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const d = style('dot_style')
|
||||
return (
|
||||
<Section title={t('signage.textLook')} testid="signage-text-look">
|
||||
<div className="grid gap-5">
|
||||
{partRow('heading_style', t('signage.look.headings'), {
|
||||
size: style('heading_style').size || base, onSize: v => setStyle('heading_style', { size: v }),
|
||||
colour: style('heading_style').colour || accent, onColour: v => setStyle('heading_style', { colour: v }),
|
||||
font: style('heading_style').font || '', onFont: v => setStyle('heading_style', { font: v || null }), inherit: true,
|
||||
align: c.board_align || 'left',
|
||||
})}
|
||||
{partRow('item_style', t('signage.look.names'), {
|
||||
size: base, onSize: v => setC({ text_size: v }),
|
||||
colour: c.text_colour || MENU_COLOURS.text, onColour: v => setC({ text_colour: v }),
|
||||
font: c.font || 'sans', onFont: v => setC({ font: v }), inherit: false, align: 'left',
|
||||
})}
|
||||
{partRow('price_style', t('signage.look.prices'), {
|
||||
size: style('price_style').size || base, onSize: v => setStyle('price_style', { size: v }),
|
||||
colour: style('price_style').colour || accent, onColour: v => setStyle('price_style', { colour: v }),
|
||||
font: style('price_style').font || '', onFont: v => setStyle('price_style', { font: v || null }), inherit: true, align: 'right',
|
||||
})}
|
||||
<div className={ROW} data-testid="signage-look-dots">
|
||||
<RowLabel>{t('signage.look.dots')}</RowLabel>
|
||||
<Range label={t('signage.look.size')} value={d.size || 100} min={50} max={300} step={10} suffix="%" onChange={v => setStyle('dot_style', { size: v })} testid="signage-look-dots-size" />
|
||||
<ColourField compact label={t('signage.look.colour')} value={d.colour || c.text_colour || MENU_COLOURS.text} onChange={v => setStyle('dot_style', { colour: v })} testid="signage-look-dots-colour" />
|
||||
<Field label={t('signage.look.dotStyle')}>
|
||||
<Dropdown value={d.style || 'dotted'} onChange={v => setStyle('dot_style', { style: v })} data-testid="signage-look-dots-style"
|
||||
options={['dotted', 'dashed', 'solid', 'none'].map(x => ({ value: x, label: t(`signage.look.dotStyles.${x}`) }))} />
|
||||
</Field>
|
||||
</div>
|
||||
<div className={ROW} data-testid="signage-look-spacing">
|
||||
<RowLabel>{t('signage.look.spacing')}</RowLabel>
|
||||
<Field label={t('signage.look.lineHeight')}>
|
||||
<Input inputMode="decimal" value={c.line_height ?? ''} placeholder={t('signage.look.auto')} data-testid="signage-look-line-height"
|
||||
onChange={e => setC({ line_height: num(e.target.value, 0.8, 3) })} />
|
||||
</Field>
|
||||
<Field label={t('signage.look.letterSpacing')}>
|
||||
<Input inputMode="decimal" value={c.letter_spacing ?? ''} placeholder={t('signage.look.auto')} data-testid="signage-look-letter-spacing"
|
||||
onChange={e => setC({ letter_spacing: num(e.target.value, -0.1, 0.5) })} />
|
||||
</Field>
|
||||
{c.show_photos ? <>
|
||||
<Range label={t('signage.look.photoSize')} value={c.photo_size || 100} min={50} max={250} step={10} suffix="%" onChange={v => setC({ photo_size: v })} testid="signage-look-photo-size" />
|
||||
<Field label={t('signage.look.photoShape')}>
|
||||
<Dropdown value={c.photo_shape || 'rounded'} onChange={v => setC({ photo_shape: v })} data-testid="signage-look-photo-shape"
|
||||
options={['square', 'rounded', 'round'].map(x => ({ value: x, label: t(`signage.look.shapes.${x}`) }))} />
|
||||
</Field>
|
||||
</> : <><span className="hidden lg:block" /><span className="hidden lg:block" /></>}
|
||||
<ColourField compact label={t('signage.look.accent')} value={accent} onChange={v => setC({ accent_colour: v })} testid="signage-accent" />
|
||||
</div>
|
||||
<p className="text-caption text-ink-3 -mt-2">{t('signage.look.hint')}</p>
|
||||
</div>
|
||||
</Section>
|
||||
)
|
||||
}
|
||||
|
||||
function RowLabel({ children }) {
|
||||
return <span className="col-span-2 lg:col-span-1 lg:h-control flex items-center text-label font-semibold text-ink">{children}</span>
|
||||
}
|
||||
|
||||
/** Bold, italic, underline: three toggles as tall as a field. */
|
||||
function TextToggles({ s, onChange, testid }) {
|
||||
const { t } = useTranslation('manager')
|
||||
const items = [['bold', Bold, s.bold !== false], ['italic', Italic, !!s.italic], ['underline', Underline, !!s.underline]]
|
||||
return (
|
||||
<div className="h-control flex rounded-control border border-line bg-surface p-0.5 gap-0.5" role="group">
|
||||
{items.map(([k, Icon, on]) => (
|
||||
<button key={k} type="button" aria-pressed={on} aria-label={t(`signage.look.${k}`)} title={t(`signage.look.${k}`)}
|
||||
onClick={() => onChange({ [k]: !on })} data-testid={`${testid}-${k}`}
|
||||
className={`flex-1 grid place-items-center rounded-[calc(var(--x-radius-control)-2px)] transition-colors duration-fast
|
||||
${on ? 'bg-accent-soft text-accent-ink' : 'text-ink-2 hover:bg-surface-2'}`}>
|
||||
<Icon size={16} aria-hidden="true" />
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -44,7 +44,7 @@ export default function SlidePreview({ slide, media, venue, orientation = 'lands
|
||||
</div>
|
||||
{editor && slide && scale > 0 && WIDGET_HOSTS.includes(slide.kind) && (
|
||||
<WidgetCanvas boxRef={box} widgets={slide.content?.widgets || []} selected={editor.selected} onSelect={editor.onSelect}
|
||||
onPlace={editor.onPlace} label={editor.label} />
|
||||
onPlace={editor.onPlace} onRemove={editor.onRemove} label={editor.label} />
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
|
||||
@@ -5,7 +5,8 @@
|
||||
// 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).
|
||||
// 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.
|
||||
// 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).
|
||||
import { useEffect, useLayoutEffect, useRef, useState } from 'react'
|
||||
import { useTranslation } from '@xenia/i18n'
|
||||
import { boxFromRect, moveBox, resizeBox, snapBox } from './signageLogic'
|
||||
@@ -16,7 +17,7 @@ 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 }) {
|
||||
export default function WidgetCanvas({ boxRef, widgets, selected, onSelect, onPlace, onRemove, label }) {
|
||||
const { t } = useTranslation('manager')
|
||||
const [rects, setRects] = useState({})
|
||||
const [guides, setGuides] = useState([])
|
||||
@@ -76,6 +77,7 @@ export default function WidgetCanvas({ boxRef, widgets, selected, onSelect, onPl
|
||||
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 }
|
||||
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
|
||||
@@ -86,7 +88,7 @@ export default function WidgetCanvas({ boxRef, widgets, selected, onSelect, onPl
|
||||
}
|
||||
window.addEventListener('keydown', on)
|
||||
return () => window.removeEventListener('keydown', on)
|
||||
}, [selected, widgets, rects, onPlace, onSelect])
|
||||
}, [selected, widgets, rects, onPlace, onSelect, onRemove])
|
||||
|
||||
const sel = selected != null ? (widgets[selected]?.position === 'custom' && widgets[selected].box) || rects[selected] : null
|
||||
return (
|
||||
|
||||
@@ -10,10 +10,12 @@
|
||||
// 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).
|
||||
// Up to 10 (the server's limit).
|
||||
import { useEffect, useState } from 'react'
|
||||
import { Fragment, useEffect, useRef, useState } from 'react'
|
||||
import {
|
||||
AlignCenter, AlignLeft, AlignRight, ArrowDown, ArrowUp, CalendarDays, ChevronDown, Clock, CloudSun, Columns3, GripVertical,
|
||||
AlignCenter, AlignLeft, AlignRight, ArrowDown, ArrowUp, BookImage, CalendarDays, ChevronDown, Clock, CloudSun, Columns3, GripVertical,
|
||||
ImageIcon, LayoutList, MessageSquare, Plus, QrCode, Rows3, Store, Trash2, Type, UtensilsCrossed,
|
||||
} from 'lucide-react'
|
||||
import { evenShares, setShare } from '@xenia/signage'
|
||||
@@ -251,8 +253,10 @@ function MenuBoardFields({ w, set, extras, path }) {
|
||||
}
|
||||
|
||||
/**
|
||||
* A stack's parts: side by side or one over the other, how many (2–6), each its share (%; changing
|
||||
* one gives or takes from its neighbour, "even" splits them equally) and what it shows.
|
||||
* A stack's parts: side by side or one over the other, how many (2–6), their sizes (drag the lines
|
||||
* between them on the bar, or focus one and use the arrow keys; "Split evenly"), and what each
|
||||
* shows: a widget (picked from the list or with "Add a widget"), another stack (one level deep),
|
||||
* a slide from the Slides library, or nothing.
|
||||
*/
|
||||
function StackFields({ w, set, media, onMedia, extras, path, depth }) {
|
||||
const { t } = useTranslation('manager')
|
||||
@@ -261,6 +265,7 @@ function StackFields({ w, set, media, onMedia, extras, path, depth }) {
|
||||
const shares = cells.map(c => Math.round(c.share || 0))
|
||||
const setCells = next => set({ cells: next })
|
||||
const setCell = (j, patch) => setCells(cells.map((c, k) => (k === j ? { ...c, ...patch } : c)))
|
||||
const setShares = next => setCells(cells.map((c, k) => ({ ...c, share: next[k] })))
|
||||
const count = n => {
|
||||
const even = evenShares(n)
|
||||
setCells(Array.from({ length: n }, (_, k) => ({ ...(cells[k] || {}), share: even[k] })))
|
||||
@@ -272,6 +277,10 @@ function StackFields({ w, set, media, onMedia, extras, path, depth }) {
|
||||
else setCell(j, { widget: cellWidget(v), slide_id: null })
|
||||
}
|
||||
const kinds = [...CELL_KINDS, ...(depth === 0 ? ['hstack', 'vstack'] : [])]
|
||||
const label = c => {
|
||||
const v = shows(c)
|
||||
return !v ? t('signage.widgets.stack.nothing') : v === 'slide' ? (slides.find(x => x.id === c.slide_id)?.name || t('signage.widgets.stack.slide')) : t(`signage.widgets.kinds.${v}`)
|
||||
}
|
||||
return (
|
||||
<div className="grid gap-3 rounded-control border border-line bg-surface p-3" data-testid="signage-stack-editor" data-depth={depth}>
|
||||
<div className={ROW}>
|
||||
@@ -288,29 +297,26 @@ function StackFields({ w, set, media, onMedia, extras, path, depth }) {
|
||||
<Button variant="secondary" onClick={() => count(cells.length)} data-testid="signage-stack-even">{t('signage.widgets.stack.even')}</Button>
|
||||
</div>
|
||||
</div>
|
||||
{/* the parts as they share the stack */}
|
||||
<div className={`flex ${w.direction === 'column' ? 'flex-col h-20 w-32' : 'h-8'} gap-0.5 rounded-control overflow-hidden`} aria-hidden="true">
|
||||
{cells.map((c, j) => (
|
||||
<span key={j} style={{ flex: `${c.share || 1} 1 0%` }}
|
||||
className="grid place-items-center bg-accent-soft text-accent-ink text-caption font-semibold tabular-nums min-w-0 min-h-0">{shares[j]}%</span>
|
||||
))}
|
||||
</div>
|
||||
<ShareBar column={w.direction === 'column'} shares={shares} labels={cells.map(label)} onChange={setShares} />
|
||||
<p className="text-caption text-ink-3 -mt-1">{t('signage.widgets.stack.barHint')}</p>
|
||||
{cells.map((c, j) => {
|
||||
const cp = `${path}.${j}`
|
||||
const v = shows(c)
|
||||
const setW = patch => setCell(j, { widget: { ...c.widget, ...patch } })
|
||||
return (
|
||||
<div key={j} className="grid gap-3 rounded-control border border-line bg-surface-2 p-3" data-testid="signage-stack-cell-editor" data-index={j}>
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="text-label font-semibold text-ink">{t('signage.widgets.stack.partTitle', { n: j + 1 })}</span>
|
||||
<span className="text-caption text-ink-3 tabular-nums" data-testid="signage-stack-share">{shares[j]}%</span>
|
||||
</div>
|
||||
<div className={ROW}>
|
||||
<Field label={t('signage.widgets.stack.part', { n: j + 1 })}>
|
||||
<Input inputMode="numeric" value={String(shares[j])} data-testid="signage-stack-share"
|
||||
onChange={e => { const next = setShare(shares, j, e.target.value.replace(/\D/g, '')); setCells(cells.map((x, k) => ({ ...x, share: next[k] }))) }} />
|
||||
</Field>
|
||||
<Field label={t('signage.widgets.stack.shows')}>
|
||||
<Dropdown value={v} onChange={x => pick(j, x)} data-testid="signage-stack-shows"
|
||||
options={[{ value: '', label: t('signage.widgets.stack.nothing') },
|
||||
...kinds.map(k => ({ value: k, label: t(`signage.widgets.kinds.${k}`) })),
|
||||
{ value: 'slide', label: t('signage.widgets.stack.aSlide') }]} />
|
||||
</Field>
|
||||
<div className="flex items-end"><AddToPart kinds={kinds} onPick={x => pick(j, x)} filled={!!v} /></div>
|
||||
{c.slide_id != null || v === 'slide' ? (
|
||||
<Field label={t('signage.widgets.stack.slide')} className="col-span-2">
|
||||
<Dropdown value={c.slide_id != null ? String(c.slide_id) : ''} onChange={x => setCell(j, { slide_id: x ? Number(x) : null })} data-testid="signage-stack-slide"
|
||||
@@ -318,17 +324,105 @@ function StackFields({ w, set, media, onMedia, extras, path, depth }) {
|
||||
: [{ value: '', label: t('signage.widgets.stack.noSlides') }]} />
|
||||
</Field>
|
||||
) : c.widget && <>
|
||||
{c.widget.kind !== 'stack' && <AlignField w={c.widget} set={patch => setCell(j, { widget: { ...c.widget, ...patch } })} testid="signage-cell-align" />}
|
||||
<InlineFields w={c.widget} set={patch => setCell(j, { widget: { ...c.widget, ...patch } })} />
|
||||
{c.widget.kind !== 'stack' && <AlignField w={c.widget} set={setW} testid="signage-cell-align" />}
|
||||
<InlineFields w={c.widget} set={setW} />
|
||||
</>}
|
||||
</div>
|
||||
{c.widget && (
|
||||
<BelowFields w={c.widget} set={patch => setCell(j, { widget: { ...c.widget, ...patch } })} media={media} onMedia={onMedia}
|
||||
extras={extras} path={cp} depth={depth + 1} />
|
||||
)}
|
||||
{c.widget && <BelowFields w={c.widget} set={setW} media={media} onMedia={onMedia} extras={extras} path={cp} depth={depth + 1} />}
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* The stack's parts drawn to scale; the lines between them are dragged to change their sizes (the
|
||||
* two parts beside a line share their room, each keeps at least 5 %), or focused and moved with the
|
||||
* arrow keys (Shift: 5 %).
|
||||
*/
|
||||
function ShareBar({ column, shares, labels, onChange }) {
|
||||
const { t } = useTranslation('manager')
|
||||
const bar = useRef(null)
|
||||
const drag = (e, j) => {
|
||||
e.preventDefault()
|
||||
const el = bar.current
|
||||
if (!el) return
|
||||
const r = el.getBoundingClientRect()
|
||||
const len = column ? r.height : r.width
|
||||
const p0 = column ? e.clientY : e.clientX
|
||||
const start = [...shares]
|
||||
const move = ev => {
|
||||
const d = (((column ? ev.clientY : ev.clientX) - p0) / len) * 100
|
||||
onChange(setShare(start, j, start[j] + d))
|
||||
}
|
||||
const up = () => { window.removeEventListener('pointermove', move); window.removeEventListener('pointerup', up) }
|
||||
window.addEventListener('pointermove', move)
|
||||
window.addEventListener('pointerup', up)
|
||||
}
|
||||
const key = (e, j) => {
|
||||
const step = e.shiftKey ? 5 : 1
|
||||
const d = { ArrowLeft: -step, ArrowUp: -step, ArrowRight: step, ArrowDown: step }[e.key]
|
||||
if (d == null) return
|
||||
e.preventDefault()
|
||||
e.stopPropagation()
|
||||
onChange(setShare(shares, j, shares[j] + d))
|
||||
}
|
||||
return (
|
||||
<div ref={bar} className={`flex ${column ? 'flex-col h-40 w-full max-w-md' : 'h-14 w-full'} rounded-control overflow-hidden border border-line select-none`}
|
||||
data-testid="signage-stack-bar">
|
||||
{shares.map((sh, j) => (
|
||||
<Fragment key={j}>
|
||||
<span style={{ flex: `${sh} 1 0%` }} className="min-w-0 min-h-0 grid place-items-center content-center gap-0.5 bg-accent-soft text-accent-ink px-1 text-center">
|
||||
<span className="text-label font-semibold tabular-nums">{sh}%</span>
|
||||
<span className="text-caption truncate max-w-full">{labels[j]}</span>
|
||||
</span>
|
||||
{j < shares.length - 1 && (
|
||||
<span role="separator" tabIndex={0} aria-orientation={column ? 'horizontal' : 'vertical'} aria-valuenow={sh} aria-valuemin={5} aria-valuemax={95}
|
||||
aria-label={t('signage.widgets.stack.line', { a: j + 1, b: j + 2 })} onPointerDown={e => drag(e, j)} onKeyDown={e => key(e, j)}
|
||||
className={`relative shrink-0 bg-accent outline-none focus-visible:ring-2 focus-visible:ring-accent ring-offset-1 ${column ? 'h-1.5 cursor-row-resize' : 'w-1.5 cursor-col-resize'}
|
||||
after:absolute ${column ? 'after:-inset-y-2 after:inset-x-0' : 'after:-inset-x-2 after:inset-y-0'}`}
|
||||
data-testid="signage-stack-line" data-index={j} />
|
||||
)}
|
||||
</Fragment>
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
/** "Add a widget" to a part: every widget (and a slide from the Slides library) in a small panel. */
|
||||
function AddToPart({ kinds, onPick, filled }) {
|
||||
const { t } = useTranslation('manager')
|
||||
const [open, setOpen] = useState(false)
|
||||
const box = useRef(null)
|
||||
useEffect(() => {
|
||||
if (!open) return undefined
|
||||
const away = e => { if (!box.current?.contains(e.target)) setOpen(false) }
|
||||
const esc = e => { if (e.key === 'Escape') setOpen(false) }
|
||||
window.addEventListener('pointerdown', away)
|
||||
window.addEventListener('keydown', esc)
|
||||
return () => { window.removeEventListener('pointerdown', away); window.removeEventListener('keydown', esc) }
|
||||
}, [open])
|
||||
const choose = k => { onPick(k); setOpen(false) }
|
||||
return (
|
||||
<div ref={box} className="relative">
|
||||
<Button variant="secondary" icon={<Plus size={14} />} onClick={() => setOpen(o => !o)} aria-expanded={open} data-testid="signage-stack-add">
|
||||
{t(filled ? 'signage.widgets.stack.replace' : 'signage.widgets.stack.add')}
|
||||
</Button>
|
||||
{open && (
|
||||
<div className="absolute z-30 left-0 top-full mt-1.5 w-[22rem] grid grid-cols-2 gap-1.5 p-2 rounded-card border border-line bg-surface shadow-lg" role="menu">
|
||||
{[...kinds, 'slide'].map(k => {
|
||||
const Icon = k === 'slide' ? BookImage : ICON[k]
|
||||
return (
|
||||
<button key={k} type="button" role="menuitem" onClick={() => choose(k)} data-testid={`signage-stack-add-${k}`}
|
||||
className="flex items-center gap-2 px-2.5 py-2 rounded-control text-left text-label text-ink hover:bg-surface-2">
|
||||
<Icon size={15} className="text-ink-2 shrink-0" aria-hidden="true" />
|
||||
{k === 'slide' ? t('signage.widgets.stack.aSlide') : t(`signage.widgets.kinds.${k}`)}
|
||||
</button>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -306,3 +306,6 @@ export function toggleMonthDay(line, key) {
|
||||
const md = line.month_days || []
|
||||
return { month_days: md.includes(key) ? md.filter(x => x !== key) : [...md, key], days: [] }
|
||||
}
|
||||
|
||||
/** A menu's colours until the venue picks its own (the TV's data, as the player draws them). */
|
||||
export const MENU_COLOURS = { accent: '#f59e0b', text: '#ffffff' }
|
||||
|
||||
@@ -46,5 +46,9 @@ export function useWidgetEditor(setDraft, slideKey, label) {
|
||||
const ws = d?.content?.widgets || []
|
||||
return { ...d, content: { ...d.content, widgets: ws.map((w, j) => (j === i ? placeWidget(w, box) : w)) } }
|
||||
})
|
||||
return { widget, setWidget, editor: { selected: widget, onSelect: setWidget, onPlace, label } }
|
||||
const onRemove = i => {
|
||||
setDraft(d => ({ ...d, content: { ...d.content, widgets: (d?.content?.widgets || []).filter((_, j) => j !== i) } }))
|
||||
setWidget(null)
|
||||
}
|
||||
return { widget, setWidget, editor: { selected: widget, onSelect: setWidget, onPlace, onRemove, label } }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user