feat(signage): menus play whole rounds, seconds fields with − / +, widget limit setting, widgets as big as their content (owner review 6)
- A menu board with pages plays whole rounds (menuMs rounds its seconds up); the editor says how long it really plays under "Seconds on screen", the card and the playlist total use it. - Seconds on screen / per page: shared NumberInput (− / +, may be emptied: an error under the field and Save blocked until filled; 1 s at least, server ge=1). - Performance (Signage -> Message & settings): widgets per slide (signage.max_widgets, 10 recommended, up to 50), checked by the server (signage.too_many_widgets) and the editor. - Text, clock, date, QR, weather, logo placed by hand: the box is exactly the content (its height x text size sets the size, the width follows; handles scale keeping the shape; text size grows the box); a slide's widget may run off the slide while 5 % stays on it. - Slider: the value as close to the slider as the frame's padding; floor and table-colour sliders use the shared Slider. Timeline cards' ring no longer clipped; larger playlist buttons. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+2
-1
@@ -51,7 +51,8 @@ Every page is on `<Page>` except Inventory → Stock (a placeholder). Two-column
|
||||
| A small panel under a button | `Popover` (`open`, `anchor` = the button's ref, `onClose`) | a colour picker, an "Add…" menu. Drawn over everything (portal), flips above, stays inside the window: **never an `absolute` panel inside a section** (it is clipped and makes the section scroll) |
|
||||
| A colour (a venue's: data) | `ColourField` (`auto`, `opacity`, `presets`) | a field with its swatch and code; its panel (over the page) has 12 ready colours, the picker, the opacity (`#rrggbbaa`) and the code. `auto` = a first choice that leaves it to something else ("As the slide"). **Never** a bare `<input type="color">` |
|
||||
| An icon from a set | `IconPicker` (`icons` = { key: component }) | a field showing the icon; a grid of the set over the page, "No icon" first |
|
||||
| A slider with its value | `Slider` (`suffix`) | framed and as tall as the fields beside it |
|
||||
| A whole number (seconds, counts) | `NumberInput` (`min`, `max`, `suffix`) | − / + on its sides, as tall as an input; it may be emptied while typing (`onChange(null)`): the form shows the error and blocks saving. **Never** clamp on every key (the user can't clear the field) |
|
||||
| A slider with its value | `Slider` (`suffix`) | framed and as tall as the fields beside it; the value sits as close to it as the frame's padding. **Never** a bare `<input type="range">` |
|
||||
| Fields that should wrap | `FieldRow` (`min`, `shade` on every other row) | each field keeps its least width; a row that wraps is framed (and tinted with `shade`), a row on one line looks like any row |
|
||||
| Toggles that go together (bold / italic / underline) | `Segmented multiple` | value is an array |
|
||||
| A toggle filter (a state) | `FilterChip` (`tone`, `count`) | |
|
||||
|
||||
@@ -110,6 +110,7 @@ CODES: dict[str, tuple[int, str]] = {
|
||||
"signage.not_a_screen": (404, "Device {device_id} isn't a signage screen."),
|
||||
"signage.schedule_unknown": (404, "Schedule {schedule_id} not found."),
|
||||
"signage.not_a_video": (422, "Pick a video for this slide."),
|
||||
"signage.too_many_widgets": (422, "A slide holds at most {max} widgets (Signage → Message & settings → Performance)."),
|
||||
"signage.content_invalid": (422, "This slide's setting isn't valid ({field}: {reason})."),
|
||||
"signage.order_mismatch": (409, "The playlist changed in the meantime. Reload it and try again."),
|
||||
"signage.weather_offline": (503, "The weather service can't be reached: the venue's server needs internet for it."),
|
||||
|
||||
@@ -49,6 +49,8 @@ from services.ws_bus import broadcast_sync
|
||||
router = APIRouter()
|
||||
KEY = "signage.manage"
|
||||
MESSAGE = "signage.message"
|
||||
MAX_WIDGETS = "signage.max_widgets" # widgets a slide may hold (owner review 6: Performance; 10 recommended)
|
||||
MAX_WIDGETS_CAP = 50 # never more, whatever the setting
|
||||
HEX = r"^#[0-9a-fA-F]{6}([0-9a-fA-F]{2})?$" # #rrggbb, or #rrggbbaa (see-through, 2026-11-21)
|
||||
TIME = r"^([01]\d|2[0-3]):[0-5]\d$"
|
||||
DATE = r"^\d{4}-\d{2}-\d{2}$"
|
||||
@@ -130,7 +132,7 @@ class MenuList(_Strict):
|
||||
# pages (the player pages through what doesn't fit, 5.5b)
|
||||
columns: int = Field(default=2, ge=1, le=3)
|
||||
page_size: Optional[int] = Field(default=None, ge=3, le=60) # items per page; None = as many as fit
|
||||
page_seconds: int = Field(default=10, ge=3, le=120)
|
||||
page_seconds: int = Field(default=10, ge=1, le=120)
|
||||
font: Font = "sans"
|
||||
text_colour: str = Field(default="#ffffff", pattern=HEX)
|
||||
accent_colour: str = Field(default="#f59e0b", pattern=HEX) # page dots; headings and prices until their own
|
||||
@@ -183,19 +185,20 @@ class MenuList(_Strict):
|
||||
|
||||
|
||||
class Box(_Strict):
|
||||
"""Where a widget moved by hand sits (2026-11-21): % of the slide's width / height."""
|
||||
x: float = Field(ge=0, le=100)
|
||||
y: float = Field(ge=0, le=100)
|
||||
w: float = Field(ge=2, le=100)
|
||||
h: float = Field(ge=2, le=100)
|
||||
"""Where a widget moved by hand sits (2026-11-21): % of the slide's (or its stack place's) width /
|
||||
height. Owner review 6: it may run off the slide, as long as a strip of it (5 %) stays on it to
|
||||
grab it back; a text, clock, QR… is as big as its content (its height sets the size)."""
|
||||
x: float = Field(ge=-100, le=100)
|
||||
y: float = Field(ge=-100, le=100)
|
||||
w: float = Field(ge=1, le=100)
|
||||
h: float = Field(ge=1, le=100)
|
||||
|
||||
@model_validator(mode="after")
|
||||
def _inside(self):
|
||||
# kept on the slide: a box never runs past its right or bottom edge
|
||||
self.w = round(min(self.w, 100), 2)
|
||||
self.h = round(min(self.h, 100), 2)
|
||||
self.x = round(min(self.x, 100 - self.w), 2)
|
||||
self.y = round(min(self.y, 100 - self.h), 2)
|
||||
self.x = round(min(max(self.x, 5 - self.w), 95), 2)
|
||||
self.y = round(min(max(self.y, 5 - self.h), 95), 2)
|
||||
return self
|
||||
|
||||
|
||||
@@ -324,13 +327,13 @@ class TextContent(_Strict):
|
||||
text_colour: str = Field(default="#ffffff", pattern=HEX)
|
||||
text_size: int = Field(default=100, ge=50, le=250) # %
|
||||
background: Background = Field(default_factory=Background)
|
||||
widgets: List[Widget] = Field(default_factory=list, max_length=10)
|
||||
widgets: List[Widget] = Field(default_factory=list, max_length=MAX_WIDGETS_CAP) # the venue's limit: _content
|
||||
|
||||
|
||||
class BlankContent(_Strict):
|
||||
"""A blank slide (2026-11-21): only its background and its widgets."""
|
||||
background: Background = Field(default_factory=Background)
|
||||
widgets: List[Widget] = Field(default_factory=list, max_length=10)
|
||||
widgets: List[Widget] = Field(default_factory=list, max_length=MAX_WIDGETS_CAP) # the venue's limit: _content
|
||||
|
||||
|
||||
class MenuContent(MenuList):
|
||||
@@ -341,7 +344,7 @@ class MenuContent(MenuList):
|
||||
board_align: Literal["left", "center", "right"] = "left" # where a narrower list sits, and its title
|
||||
board_valign: Literal["top", "middle", "bottom"] = "top" # where a shorter list sits (owner review 5)
|
||||
background: Background = Field(default_factory=Background)
|
||||
widgets: List[Widget] = Field(default_factory=list, max_length=10)
|
||||
widgets: List[Widget] = Field(default_factory=list, max_length=MAX_WIDGETS_CAP) # the venue's limit: _content
|
||||
|
||||
|
||||
CONTENT = {"image": ImageContent, "video": VideoContent, "text": TextContent, "menu": MenuContent, "blank": BlankContent}
|
||||
@@ -364,7 +367,7 @@ class PlaylistUpdate(BaseModel):
|
||||
|
||||
class SlideFields(BaseModel):
|
||||
name: Optional[str] = Field(default=None, max_length=80)
|
||||
duration_s: Optional[int] = Field(default=None, ge=2, le=3600)
|
||||
duration_s: Optional[int] = Field(default=None, ge=1, le=3600)
|
||||
transition: Optional[Transition] = None # None: the playlist's
|
||||
video_to_end: Optional[bool] = None
|
||||
enabled: Optional[bool] = None
|
||||
@@ -566,6 +569,9 @@ def _content(db, kind: str, raw: dict | None) -> dict:
|
||||
first = e.errors()[0]
|
||||
raise XeniaError("signage.content_invalid", field=".".join(str(x) for x in first["loc"]), reason=first["msg"])
|
||||
data = model.model_dump()
|
||||
most = max_widgets(db)
|
||||
if len(data.get("widgets") or []) > most:
|
||||
raise XeniaError("signage.too_many_widgets", max=most)
|
||||
from models.media import Media
|
||||
for mid in media_ids(data):
|
||||
m = db.get(Media, mid)
|
||||
@@ -1240,6 +1246,31 @@ def put_message(body: MessageBody, db: Session = Depends(get_db), user=Depends(r
|
||||
return {"text": (body.text or "").strip() or None}
|
||||
|
||||
|
||||
def max_widgets(db) -> int:
|
||||
"""How many widgets a slide may hold: the venue's setting (Performance), 10 until it changes it."""
|
||||
try:
|
||||
return max(1, min(MAX_WIDGETS_CAP, int(_setting(db, MAX_WIDGETS, "10") or 10)))
|
||||
except ValueError:
|
||||
return 10
|
||||
|
||||
|
||||
class PerformanceBody(BaseModel):
|
||||
max_widgets: int = Field(ge=1, le=MAX_WIDGETS_CAP)
|
||||
|
||||
|
||||
@router.get("/performance")
|
||||
def get_performance(db: Session = Depends(get_db), user=Depends(require(KEY))):
|
||||
"""Limits that keep the TVs smooth (owner review 6): widgets per slide (10 recommended)."""
|
||||
return {"max_widgets": max_widgets(db), "recommended": 10, "cap": MAX_WIDGETS_CAP}
|
||||
|
||||
|
||||
@router.put("/performance")
|
||||
def put_performance(body: PerformanceBody, db: Session = Depends(get_db), user=Depends(require(KEY))):
|
||||
_save_setting(db, MAX_WIDGETS, str(body.max_widgets))
|
||||
db.commit()
|
||||
return {"max_widgets": body.max_widgets, "recommended": 10, "cap": MAX_WIDGETS_CAP}
|
||||
|
||||
|
||||
class BadgesBody(BaseModel):
|
||||
badges: list = Field(default_factory=list)
|
||||
|
||||
|
||||
@@ -77,9 +77,12 @@ def test_blank_slides_and_widgets_placed_by_hand(client, owner_h):
|
||||
p = playlist(client, owner_h)
|
||||
s = slide(client, owner_h, p["id"], "blank", content={"widgets": [
|
||||
{"kind": "clock", "position": "custom", "box": {"x": 90, "y": 5, "w": 20, "h": 10}, "align": "right"},
|
||||
{"kind": "date", "position": "top-left", "size": "custom", "box": {"x": 1, "y": 1, "w": 5, "h": 5}}]})
|
||||
clock, date = s["content"]["widgets"]
|
||||
assert clock["size"] == "custom" and clock["box"] == {"x": 80, "y": 5, "w": 20, "h": 10} and clock["align"] == "right" # kept on the slide
|
||||
{"kind": "date", "position": "top-left", "size": "custom", "box": {"x": 1, "y": 1, "w": 5, "h": 5}},
|
||||
{"kind": "text", "text": "Big", "position": "custom", "box": {"x": 99, "y": -50, "w": 30, "h": 20}}]})
|
||||
clock, date, big = s["content"]["widgets"]
|
||||
# owner review 6: a box may run off the slide (here past the right edge), a strip of it stays on it
|
||||
assert clock["size"] == "custom" and clock["box"] == {"x": 90, "y": 5, "w": 20, "h": 10} and clock["align"] == "right"
|
||||
assert big["box"] == {"x": 95, "y": -15, "w": 30, "h": 20}
|
||||
assert date["size"] == "medium" and date["box"] is None # a corner: no box, a real size
|
||||
r = client.put(f"/api/signage/slides/{s['id']}", headers=owner_h, json={"content": {"widgets": [{"kind": "clock", "position": "custom"}]}})
|
||||
assert err(r) == "signage.content_invalid" # placed by hand needs its box
|
||||
|
||||
@@ -173,3 +173,19 @@ def test_the_venues_badges_and_a_widgets_own_look(client, owner_h, menu, screens
|
||||
url = f"/api/signage/playlists/{p['id']}/slides"
|
||||
for bad in ({"badges": {sid: ["a", "b", "c", "d", "e"]}}, {"board_valign": "centre"}, {"widgets": [{"kind": "clock", "text_size": 400}]}):
|
||||
assert err(client.post(url, headers=owner_h, json={"kind": "menu", "content": bad})) == "signage.content_invalid", bad
|
||||
|
||||
|
||||
def test_how_many_widgets_a_slide_may_hold_is_the_venues(client, owner_h):
|
||||
"""Owner review 6 (2026-11-21): 10 widgets a slide (recommended), more when the venue allows them
|
||||
(Signage → Message & settings → Performance), never over 50; a menu with pages may now turn them
|
||||
every second."""
|
||||
assert client.get("/api/signage/performance", headers=owner_h).json() == {"max_widgets": 10, "recommended": 10, "cap": 50}
|
||||
p = playlist(client, owner_h)
|
||||
url = f"/api/signage/playlists/{p['id']}/slides"
|
||||
eleven = [{"kind": "clock"}] * 11
|
||||
assert err(client.post(url, headers=owner_h, json={"kind": "blank", "content": {"widgets": eleven}})) == "signage.too_many_widgets"
|
||||
assert client.put("/api/signage/performance", headers=owner_h, json={"max_widgets": 12}).json()["max_widgets"] == 12
|
||||
assert client.post(url, headers=owner_h, json={"kind": "blank", "content": {"widgets": eleven}}).status_code == 201
|
||||
assert err(client.put("/api/signage/performance", headers=owner_h, json={"max_widgets": 51})) is not None
|
||||
s = slide(client, owner_h, p["id"], "menu", content={"page_seconds": 1}, duration_s=1)
|
||||
assert s["content"]["page_seconds"] == 1 and s["duration_s"] == 1
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
import { useEffect, useState } from 'react'
|
||||
import { RotateCcw } from 'lucide-react'
|
||||
import { useTranslation } from '@xenia/i18n'
|
||||
import { Button, Dialog, Field, Input, Spinner, Switch } from '@xenia/ui'
|
||||
import { Button, Dialog, Field, Input, Slider, Spinner, Switch } from '@xenia/ui'
|
||||
import { SettingsCard } from './SettingsCard'
|
||||
import { buildColour, mergeColours, parseColour, readJson, setSlot } from './settingsLogic'
|
||||
import { useSettings } from './useSettings'
|
||||
@@ -137,9 +137,7 @@ function ColourDialog({ slot, value, title, onClose, onSave }) {
|
||||
<Input value={hex} spellCheck={false} className="font-mono" onChange={e => setHex(e.target.value.trim())} data-testid="colour-hex" />
|
||||
</span>
|
||||
</Field>
|
||||
<Field label={`${t('settings.colours.opacity')} · ${Math.round(alpha * 100)}%`}>
|
||||
<input type="range" min={0} max={1} step={0.01} value={alpha} onChange={e => setAlpha(Number(e.target.value))} className="w-full accent-accent" />
|
||||
</Field>
|
||||
<Slider label={t('settings.colours.opacity')} value={Math.round(alpha * 100)} min={0} max={100} suffix="%" onChange={v => setAlpha(v / 100)} />
|
||||
<Field label={t('settings.colours.quick')}>
|
||||
<span className="flex flex-wrap gap-1.5">
|
||||
{(QUICK_SWATCHES[slot] ?? []).map(c => (
|
||||
|
||||
@@ -23,7 +23,7 @@ import {
|
||||
nearestEdge, outlineOf, removeCorner, resizeBox, toPlan,
|
||||
} from '@xenia/floorplan'
|
||||
import { useTranslation } from '@xenia/i18n'
|
||||
import { Button, Dialog, Dropdown, Field, IconButton, Input, Segmented, Stepper, Switch, cx } from '@xenia/ui'
|
||||
import { Button, Dialog, Dropdown, Field, IconButton, Input, Segmented, Slider, Stepper, Switch, cx } from '@xenia/ui'
|
||||
import MediaField from '../media/MediaField'
|
||||
import * as api from './floorApi'
|
||||
import { WALL_THICKNESS, addItem, addable, cellOf, find, fitOutline, layoutBody, layoutOf, nudge, placeTable, planBody, remove, resizeCells, rotate, sameLayout, toCells, update } from './editorLogic'
|
||||
@@ -329,9 +329,8 @@ export default function FloorEditor({ plan: saved, data, groups, onSaved, onDele
|
||||
</div>
|
||||
<MediaField value={form.background} onChange={img => setF('background', img)} label={t('floor.background')} testid="floor-background" />
|
||||
{form.background && (
|
||||
<label className="grid gap-1 text-label text-ink-2">{t('floor.backgroundOpacity', { value: Math.round((form.background_opacity ?? 0.6) * 100) })}
|
||||
<input type="range" min="0.1" max="1" step="0.05" value={form.background_opacity ?? 0.6} onChange={e => setF('background_opacity', Number(e.target.value))} />
|
||||
</label>
|
||||
<Slider label={t('floor.backgroundOpacityLabel')} value={Math.round((form.background_opacity ?? 0.6) * 100)} min={10} max={100} step={5} suffix="%"
|
||||
onChange={v => setF('background_opacity', v / 100)} />
|
||||
)}
|
||||
<Button size="sm" variant="ghost" icon={<Trash2 size={16} />} onClick={() => setDeleting(true)} className="justify-self-start text-danger-ink">{t('floor.delete')}</Button>
|
||||
</Panel>
|
||||
|
||||
@@ -20,7 +20,7 @@ import { AlignCenter, AlignLeft, AlignRight, AlignVerticalJustifyCenter, AlignVe
|
||||
import { MENU_LANGUAGES, SALES_POINTS } from '@xenia/access'
|
||||
import { useFormat, useLanguage, useTranslation } from '@xenia/i18n'
|
||||
import { badgeName } from '@xenia/signage'
|
||||
import { Dropdown, Field, IconButton, Input, Segmented, Slider, Switch } from '@xenia/ui'
|
||||
import { Dropdown, Field, IconButton, Input, NumberInput, Segmented, Slider, Switch } from '@xenia/ui'
|
||||
import client from '../../api/client'
|
||||
import { boardOrder, moveGroup, moveItem, toggled } from './signageLogic'
|
||||
import { useBadges } from './useBadges'
|
||||
@@ -227,8 +227,9 @@ export default function MenuEditor({ slide, onChange, media, onMedia, misfit = [
|
||||
<Input inputMode="numeric" value={c.page_size ? String(c.page_size) : ''} placeholder={board ? '8' : t('signage.menu.auto')}
|
||||
onChange={e => { const n = digits(e.target.value); setC({ page_size: n ? Math.min(60, Math.max(3, n)) : null }) }} data-testid="signage-menu-per-page" />
|
||||
</Field>
|
||||
<Field label={t('signage.menu.pageSeconds')} hint={t('signage.menu.pageSecondsHint')}>
|
||||
<Input inputMode="numeric" value={String(c.page_seconds || 10)} onChange={e => setC({ page_seconds: Math.min(120, Math.max(3, digits(e.target.value) || 3)) })} />
|
||||
<Field label={t('signage.menu.pageSeconds')} hint={c.page_seconds == null ? undefined : t('signage.menu.pageSecondsHint')}
|
||||
error={c.page_seconds === null ? t('signage.secondsEmpty') : undefined}>
|
||||
<NumberInput value={c.page_seconds === undefined ? 10 : c.page_seconds} min={1} max={120} suffix="s" onChange={v => setC({ page_seconds: v })} data-testid="signage-page-seconds" />
|
||||
</Field>
|
||||
</div>
|
||||
</Section>
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
// Signage → Message & settings → Performance (owner review 6, 2026-11-21): how many widgets a slide
|
||||
// may hold. 10 is strongly recommended: every widget is drawn on the TV many times a second, and
|
||||
// small TV computers slow down with many; the venue may still allow more (up to 50).
|
||||
import { useEffect, useState } from 'react'
|
||||
import toast from 'react-hot-toast'
|
||||
import { AlertTriangle } from 'lucide-react'
|
||||
import { errorMessage } from '@xenia/api'
|
||||
import { useTranslation } from '@xenia/i18n'
|
||||
import { Button, Field, NumberInput } from '@xenia/ui'
|
||||
import * as api from './signageApi'
|
||||
import { setPerformance, usePerformance } from './usePerformance'
|
||||
|
||||
export default function PerformanceSettings() {
|
||||
const { t } = useTranslation('manager')
|
||||
const saved = usePerformance()
|
||||
const [most, setMost] = useState(saved.max_widgets)
|
||||
const [busy, setBusy] = useState(false)
|
||||
useEffect(() => { setMost(saved.max_widgets) }, [saved.max_widgets])
|
||||
const save = async () => {
|
||||
setBusy(true)
|
||||
try { setPerformance(await api.putPerformance({ max_widgets: most })); toast.success(t('settings.saved')) }
|
||||
catch (err) { toast.error(errorMessage(err, t)) }
|
||||
setBusy(false)
|
||||
}
|
||||
const over = most != null && most > saved.recommended
|
||||
return (
|
||||
<section className="rounded-card border border-line bg-surface p-4 grid gap-3" data-testid="signage-performance">
|
||||
<h2 className="text-body font-semibold text-ink">{t('signage.performance.title')}</h2>
|
||||
<p className="text-label text-ink-2">{t('signage.performance.hint', { n: saved.recommended })}</p>
|
||||
<div className="flex flex-wrap items-end gap-2">
|
||||
<Field label={t('signage.performance.maxWidgets')} className="w-48" error={most == null ? t('signage.performance.empty') : undefined}>
|
||||
<NumberInput value={most} min={1} max={saved.cap} onChange={setMost} data-testid="signage-max-widgets" />
|
||||
</Field>
|
||||
<Button loading={busy} disabled={most == null || most === saved.max_widgets} onClick={save} data-testid="signage-performance-save">{t('fees.save')}</Button>
|
||||
{most !== saved.recommended && (
|
||||
<Button variant="ghost" onClick={() => setMost(saved.recommended)}>{t('signage.performance.backTo', { n: saved.recommended })}</Button>
|
||||
)}
|
||||
</div>
|
||||
{over && (
|
||||
<p className="text-label text-warning-ink flex items-start gap-1.5" data-testid="signage-performance-warning">
|
||||
<AlertTriangle size={16} className="shrink-0 mt-0.5" aria-hidden="true" />{t('signage.performance.warning', { n: saved.recommended })}
|
||||
</p>
|
||||
)}
|
||||
</section>
|
||||
)
|
||||
}
|
||||
@@ -14,7 +14,8 @@ import { errorMessage } from '@xenia/api'
|
||||
import { useTranslation } from '@xenia/i18n'
|
||||
import { Button, Dialog, Dropdown, Field, IconButton, Input, Spinner, Textarea, useConfirm } from '@xenia/ui'
|
||||
import * as api from './signageApi'
|
||||
import { mediaEntry, mediaLookup, misfits, moved, slideBody, totalSeconds, TRANSITIONS, windowParts } from './signageLogic'
|
||||
import { mediaEntry, mediaLookup, misfits, moved, secondsMissing, slideBody, totalSeconds, TRANSITIONS, windowParts } from './signageLogic'
|
||||
import { playSeconds } from './timing'
|
||||
import AddSlideDialog, { KIND_ICON } from './AddSlideDialog'
|
||||
import SlideEditor, { SlideBasics } from './SlideEditor'
|
||||
import SlidePreview from './SlidePreview'
|
||||
@@ -92,6 +93,7 @@ export default function PlaylistEditor({ playlistId, onChanged, onDeleted }) {
|
||||
const how = await confirm({ title: t('signage.discardTitle'), body: t('signage.discard'), confirmLabel: t('signage.discardYes'), tone: 'danger',
|
||||
altLabel: t('signage.saveAndLeave'), testId: 'signage-discard' })
|
||||
if (how !== 'alt') return how
|
||||
if (secondsMissing(draft)) { toast.error(t('signage.secondsEmpty')); return false }
|
||||
return (await run(() => api.updateSlide(draft.id, slideBody(draft)), t('settings.saved'))) != null
|
||||
}
|
||||
const pick = async s => {
|
||||
@@ -133,7 +135,7 @@ export default function PlaylistEditor({ playlistId, onChanged, onDeleted }) {
|
||||
const made = await run(() => api.addSlide(pl.id, body), t('signage.added'))
|
||||
if (made) await load(made.id)
|
||||
}
|
||||
const total = totalSeconds(pl.slides, media)
|
||||
const total = totalSeconds(pl.slides, media, s => playSeconds(s, pl.orientation))
|
||||
const marker = i => drag && drag.at === i && drag.at !== drag.from && drag.at !== drag.from + 1
|
||||
|
||||
return (
|
||||
@@ -163,7 +165,7 @@ export default function PlaylistEditor({ playlistId, onChanged, onDeleted }) {
|
||||
|
||||
{/* the timeline: cards of one size, scrolling sideways; a line shows where a dragged card lands */}
|
||||
<section className="min-w-0 rounded-card border border-line bg-surface-2 p-3" aria-label={t('signage.timeline')}>
|
||||
<ol className="flex gap-3 overflow-x-auto px-2 pb-2 snap-x" data-testid="signage-timeline" onDragLeave={e => { if (!e.currentTarget.contains(e.relatedTarget)) setDrag(d => (d ? { ...d, at: null } : d)) }}>
|
||||
<ol className="flex gap-3 overflow-x-auto p-1.5 pb-2.5 snap-x scroll-px-1.5" data-testid="signage-timeline" onDragLeave={e => { if (!e.currentTarget.contains(e.relatedTarget)) setDrag(d => (d ? { ...d, at: null } : d)) }}>
|
||||
{pl.slides.map((s, i) => {
|
||||
const Icon = KIND_ICON[s.kind] || ImageIcon
|
||||
const parts = windowParts(s)
|
||||
@@ -189,7 +191,7 @@ export default function PlaylistEditor({ playlistId, onChanged, onDeleted }) {
|
||||
{bad[s.id] && <AlertTriangle size={14} className="text-warning-ink shrink-0" aria-label={t('signage.misfit')} data-testid="signage-card-misfit" />}
|
||||
</span>
|
||||
<span className="text-caption text-ink-3 truncate">
|
||||
{s.kind === 'video' && s.video_to_end ? t('signage.toTheEnd') : t('signage.seconds', { count: s.duration_s })}
|
||||
{s.kind === 'video' && s.video_to_end ? t('signage.toTheEnd') : t('signage.seconds', { count: playSeconds(s, pl.orientation) })}
|
||||
{!s.enabled && <> · {t('signage.off')}</>}
|
||||
{parts.map(p => <span key={p.key}> · {p.key === 'days' ? p.params.days.map(d => t(`signage.weekdays.${d}`)).join(' ') : t(`signage.window.${p.key}`, p.params)}</span>)}
|
||||
</span>
|
||||
@@ -217,7 +219,7 @@ export default function PlaylistEditor({ playlistId, onChanged, onDeleted }) {
|
||||
{/* the picked slide: its basics beside its preview (one height), then what it shows */}
|
||||
{draft ? <>
|
||||
<section className="grid gap-6 lg:grid-cols-2 items-stretch rounded-card border border-line bg-surface shadow-raised p-card min-w-0" data-testid="signage-slide-top">
|
||||
<SlideBasics slide={draft} onChange={setDraft} />
|
||||
<SlideBasics slide={draft} onChange={setDraft} orientation={pl.orientation} />
|
||||
<FitPreview orientation={pl.orientation}>
|
||||
<SlidePreview slide={draft} media={mediaLookup(media)} venue={venue} orientation={pl.orientation} playing editor={editor} />
|
||||
</FitPreview>
|
||||
@@ -227,7 +229,7 @@ export default function PlaylistEditor({ playlistId, onChanged, onDeleted }) {
|
||||
misfit={draftBad} widget={widget} onWidget={setWidget} />
|
||||
</section>
|
||||
<div className="flex flex-wrap gap-2 items-center sticky bottom-0 bg-canvas py-2 z-10">
|
||||
<Button loading={busy} disabled={!dirty} onClick={() => run(() => api.updateSlide(draft.id, slideBody(draft)), t('settings.saved'))}
|
||||
<Button loading={busy} disabled={!dirty || secondsMissing(draft)} onClick={() => run(() => api.updateSlide(draft.id, slideBody(draft)), t('settings.saved'))}
|
||||
data-testid="signage-slide-save">{t('fees.save')}</Button>
|
||||
<Button variant="secondary" disabled={!dirty || busy} onClick={() => setDraft(structuredClone(saved))}>{t('signage.undo')}</Button>
|
||||
{dirty && <span className="text-label text-ink-3">{t('display.looks.unsaved')}</span>}
|
||||
|
||||
@@ -57,10 +57,10 @@ export default function SignagePage() {
|
||||
<li key={p.id}>
|
||||
<button type="button" onClick={() => setCurrent(p.id)} aria-current={p.id === current ? 'true' : undefined}
|
||||
data-testid="signage-playlist-item" data-name={p.name}
|
||||
className={`w-full text-left px-3 py-2 rounded-control border flex items-center gap-2 transition-colors duration-fast
|
||||
className={`w-full text-left px-3 min-h-control rounded-control border flex items-center gap-2.5 transition-colors duration-fast
|
||||
${p.id === current ? 'border-accent bg-accent-soft text-accent-ink' : 'border-line bg-surface hover:bg-surface-2 text-ink'}`}>
|
||||
<Icon size={16} aria-label={t(`signage.orientations.${p.orientation}`)} />
|
||||
<span className="flex-1 min-w-0 truncate text-label font-medium">{p.name}</span>
|
||||
<span className="flex-1 min-w-0 truncate text-body font-medium">{p.name}</span>
|
||||
<span className="text-caption text-ink-3">{p.slide_count}</span>
|
||||
</button>
|
||||
</li>
|
||||
|
||||
@@ -10,6 +10,7 @@ import { useFormat, useLanguage, useTranslation } from '@xenia/i18n'
|
||||
import { Button, Dropdown, Field, Input, Spinner } from '@xenia/ui'
|
||||
import BadgesSettings from './BadgesSettings'
|
||||
import MessageOfTheDay from './MessageOfTheDay'
|
||||
import PerformanceSettings from './PerformanceSettings'
|
||||
import * as api from './signageApi'
|
||||
|
||||
export default function SignageSettingsTab() {
|
||||
@@ -87,6 +88,7 @@ export default function SignageSettingsTab() {
|
||||
</section>
|
||||
|
||||
<BadgesSettings />
|
||||
<PerformanceSettings />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -9,17 +9,36 @@
|
||||
// font, size in a frame, colour as a field that opens its colours).
|
||||
import { AlignCenter, AlignLeft, AlignRight, AlignVerticalJustifyCenter, AlignVerticalJustifyEnd, AlignVerticalJustifyStart } from 'lucide-react'
|
||||
import { useTranslation } from '@xenia/i18n'
|
||||
import { ColourField, Dropdown, Field, FilterChip, Input, Segmented, Slider, Switch, Textarea } from '@xenia/ui'
|
||||
import { ColourField, Dropdown, Field, FilterChip, Input, NumberInput, Segmented, Slider, Switch, Textarea } from '@xenia/ui'
|
||||
import { pagesOn, playSeconds } from './timing'
|
||||
import { FONT_KEYS, TRANSITIONS } from './signageLogic'
|
||||
import { BackgroundField, MediaPick, Section } from './SignageFields'
|
||||
import MenuEditor from './MenuEditor'
|
||||
import WidgetsEditor from './WidgetsEditor'
|
||||
|
||||
/**
|
||||
* How long a menu board really plays (owner review 6): whole rounds of its pages, so its seconds on
|
||||
* screen are rounded up; said under the field when they differ (with why).
|
||||
*/
|
||||
function PlayNote({ slide, orientation }) {
|
||||
const { t } = useTranslation('manager')
|
||||
if (slide.kind !== 'menu' || slide.duration_s == null || slide.content?.page_seconds == null) return null
|
||||
const pages = pagesOn(slide, orientation)
|
||||
const real = playSeconds(slide, orientation)
|
||||
if (pages <= 1 || real === slide.duration_s) return null
|
||||
const per = slide.content.page_seconds || 10
|
||||
return (
|
||||
<p className="sm:col-span-2 -mt-2 text-caption text-info-ink bg-info-soft rounded-control px-3 py-2" data-testid="signage-play-note" data-seconds={real}>
|
||||
{t('signage.playNote', { real, rounds: real / (pages * per), pages, per, set: slide.duration_s })}
|
||||
</p>
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* The slide's basics: name (unless `showName` is off: the Slides library has its own), show it or
|
||||
* not, its transition, seconds on screen (or a video to its end), and when it shows.
|
||||
*/
|
||||
export function SlideBasics({ slide, onChange, showName = true }) {
|
||||
export function SlideBasics({ slide, onChange, showName = true, orientation = 'landscape' }) {
|
||||
const { t } = useTranslation('manager')
|
||||
const set = patch => onChange({ ...slide, ...patch })
|
||||
const days = slide.days || []
|
||||
@@ -39,11 +58,11 @@ export function SlideBasics({ slide, onChange, showName = true }) {
|
||||
options={[{ value: '', label: t('signage.transitionDefault') }, ...TRANSITIONS.map(x => ({ value: x, label: t(`signage.transitions.${x}`) }))]} />
|
||||
</Field>
|
||||
{!toEnd && (
|
||||
<Field label={t('signage.duration')}>
|
||||
<Input inputMode="numeric" value={String(slide.duration_s ?? 10)} data-testid="signage-duration"
|
||||
onChange={e => set({ duration_s: Math.min(3600, Number(e.target.value.replace(/\D/g, '')) || 0) })} />
|
||||
<Field label={t('signage.duration')} error={slide.duration_s == null ? t('signage.secondsEmpty') : undefined}>
|
||||
<NumberInput value={slide.duration_s} min={1} max={3600} suffix="s" onChange={v => set({ duration_s: v })} data-testid="signage-duration" />
|
||||
</Field>
|
||||
)}
|
||||
{!toEnd && <PlayNote slide={slide} orientation={orientation} />}
|
||||
{slide.kind === 'video' && (
|
||||
<Switch boxed className="sm:col-span-2" checked={!!slide.video_to_end} onChange={on => set({ video_to_end: on })} label={t('signage.videoToEnd')}
|
||||
description={t('signage.videoToEndHint')} data-testid="signage-video-to-end" />
|
||||
|
||||
@@ -11,7 +11,7 @@ import { errorMessage } from '@xenia/api'
|
||||
import { useTranslation } from '@xenia/i18n'
|
||||
import { Button, EmptyState, Field, IconButton, Input, Pane, Segmented, Spinner, Textarea, useConfirm } from '@xenia/ui'
|
||||
import * as api from './signageApi'
|
||||
import { mediaEntry, mediaLookup, misfits, savedBody } from './signageLogic'
|
||||
import { mediaEntry, mediaLookup, misfits, savedBody, secondsMissing } from './signageLogic'
|
||||
import AddSlideDialog, { KIND_ICON } from './AddSlideDialog'
|
||||
import SlideEditor, { SlideBasics } from './SlideEditor'
|
||||
import SlidePreview from './SlidePreview'
|
||||
@@ -126,7 +126,7 @@ function SavedSlideEditor({ id, venue, onClose }) {
|
||||
if (dirty) {
|
||||
const how = await confirm({ title: t('signage.discardTitle'), body: t('signage.discard'), confirmLabel: t('signage.discardYes'), tone: 'danger',
|
||||
altLabel: t('signage.saveAndLeave'), testId: 'signage-discard' })
|
||||
if (!how || (how === 'alt' && (!draft.name?.trim() || !(await save())))) return
|
||||
if (!how || (how === 'alt' && (!draft.name?.trim() || secondsMissing(draft) || !(await save())))) return
|
||||
}
|
||||
onClose()
|
||||
}
|
||||
@@ -140,7 +140,7 @@ function SavedSlideEditor({ id, venue, onClose }) {
|
||||
<h2 className="text-body-lg font-semibold text-ink truncate flex-1 min-w-0">{draft.name || t('signage.library.untitled')}</h2>
|
||||
{dirty && <span className="text-label text-ink-3 hidden xl:inline">{t('display.looks.unsaved')}</span>}
|
||||
<Button variant="secondary" disabled={!dirty || busy} onClick={() => setDraft(d => ({ ...structuredClone(saved), menu: d.menu }))}>{t('signage.undo')}</Button>
|
||||
<Button loading={busy} disabled={!dirty || !draft.name?.trim()} onClick={save} data-testid="signage-saved-save">{t('fees.save')}</Button>
|
||||
<Button loading={busy} disabled={!dirty || !draft.name?.trim() || secondsMissing(draft)} onClick={save} data-testid="signage-saved-save">{t('fees.save')}</Button>
|
||||
</div>
|
||||
}>
|
||||
<div className="p-card grid gap-6 content-start">
|
||||
@@ -167,7 +167,7 @@ function SavedSlideEditor({ id, venue, onClose }) {
|
||||
</Pane>
|
||||
<Pane header={<h3 className="px-card py-card-y text-body font-semibold text-ink">{t('signage.library.settings')}</h3>}>
|
||||
<div className="p-card grid gap-7 content-start">
|
||||
<SlideBasics slide={draft} onChange={setDraft} showName={false} />
|
||||
<SlideBasics slide={draft} onChange={setDraft} showName={false} orientation={draft.orientation} />
|
||||
<SlideEditor slide={draft} onChange={setDraft} media={media} onMedia={item => setMedia(m => ({ ...m, [String(item.id)]: mediaEntry(item) }))}
|
||||
misfit={draftBad} widget={widget} onWidget={setWidget} />
|
||||
</div>
|
||||
|
||||
@@ -10,9 +10,13 @@
|
||||
// Owner review 5 (2026-11-21): widgets inside a stack's parts too. Pick the stack, then click a
|
||||
// widget in it: it moves and sizes inside its place (it can't leave the stack; its box is % of its
|
||||
// place). The picked widget is a path: "2", or "2.1.0" (stack 2, part 1, its first widget).
|
||||
// Owner review 6: a text, clock, QR… placed by hand is exactly as big as what it shows (its box is
|
||||
// its content: sized by its handles keeping its shape; its text size makes it bigger too); a slide's
|
||||
// widget may be moved off the slide as long as a strip of it stays to grab it back.
|
||||
import { useEffect, useLayoutEffect, useRef, useState } from 'react'
|
||||
import { useTranslation } from '@xenia/i18n'
|
||||
import { boxFromRect, moveBox, resizeBox, snapBox, stackOf, widgetAt } from './signageLogic'
|
||||
import { TIGHT } from '@xenia/signage'
|
||||
import { boxFromRect, moveBox, moveLoose, resizeBox, scaleBox, snapBox, stackOf, widgetAt } 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' }
|
||||
@@ -46,9 +50,10 @@ export default function WidgetCanvas({ boxRef, widgets, selected, onSelect, onPl
|
||||
|
||||
const sel = selected != null ? String(selected) : null
|
||||
// a widget's box in its own frame: the slide's (%), or its place's for a widget in a stack
|
||||
const tight = path => TIGHT.includes(widgetAt(widgets, path)?.kind)
|
||||
const own = path => {
|
||||
const w = widgetAt(widgets, path)
|
||||
if (w?.position === 'custom' && w.box) return w.box
|
||||
if (w?.position === 'custom' && w.box && !tight(path)) return w.box
|
||||
const r = rects[path]
|
||||
const place = stackOf(path) != null ? rects[`place:${path}`] : null
|
||||
if (!r || stackOf(path) == null) return r || null
|
||||
@@ -63,6 +68,16 @@ export default function WidgetCanvas({ boxRef, widgets, selected, onSelect, onPl
|
||||
return { x: place.x + b.x * place.w / 100, y: place.y + b.y * place.h / 100, w: b.w * place.w / 100, h: b.h * place.h / 100 }
|
||||
}
|
||||
|
||||
// what is stored for a tight widget: where it sits and its height before its text size (the
|
||||
// height scaled as the drawn one was, so it never creeps); others: the box as drawn
|
||||
const stored = (path, from, to) => {
|
||||
const w = widgetAt(widgets, path)
|
||||
if (!tight(path)) return to
|
||||
const ts = (w.text_size || 100) / 100
|
||||
const h0 = w.position === 'custom' && w.box ? w.box.h : from.h / ts
|
||||
return { ...to, h: Math.max(1, Math.round(h0 * (to.h / from.h) * 100) / 100) }
|
||||
}
|
||||
|
||||
const start = (e, path, handle = null) => {
|
||||
e.preventDefault()
|
||||
e.stopPropagation()
|
||||
@@ -84,11 +99,12 @@ export default function WidgetCanvas({ boxRef, widgets, selected, onSelect, onPl
|
||||
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)
|
||||
if (inside) { onPlace(path, next); return }
|
||||
const shaped = tight(path)
|
||||
const next = handle ? (shaped ? scaleBox(base, handle, dx, dy) : resizeBox(base, handle, dx, dy)) : inside ? moveBox(base, dx, dy) : moveLoose(base, dx, dy)
|
||||
if (inside || (handle && shaped)) { onPlace(path, stored(path, base, next)); return }
|
||||
const snapped = snapBox(next, handle)
|
||||
setGuides(snapped.guides)
|
||||
onPlace(path, snapped.box)
|
||||
onPlace(path, stored(path, base, snapped.box))
|
||||
}
|
||||
const up = () => {
|
||||
window.removeEventListener('pointermove', move)
|
||||
@@ -112,7 +128,7 @@ export default function WidgetCanvas({ boxRef, widgets, selected, onSelect, onPl
|
||||
if (!d) return
|
||||
e.preventDefault()
|
||||
const base = own(sel)
|
||||
if (base) onPlace(sel, moveBox(base, d[0], d[1]))
|
||||
if (base) onPlace(sel, stored(sel, base, (stackOf(sel) != null ? moveBox : moveLoose)(base, d[0], d[1])))
|
||||
}
|
||||
window.addEventListener('keydown', on)
|
||||
return () => window.removeEventListener('keydown', on)
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
// 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 10 (the server's limit).
|
||||
// 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,
|
||||
@@ -28,6 +28,7 @@ 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'
|
||||
@@ -52,6 +53,7 @@ function useLibrary() {
|
||||
|
||||
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 => {
|
||||
@@ -129,7 +131,7 @@ export default function WidgetsEditor({ widgets = [], onChange, media, onMedia,
|
||||
)
|
||||
})}
|
||||
{line(widgets.length)}
|
||||
{widgets.length < 10 && (
|
||||
{widgets.length < most && (
|
||||
<div className="flex flex-wrap items-center gap-1.5">
|
||||
{[...WIDGET_KINDS, 'hstack', 'vstack'].map(k => {
|
||||
const Icon = ICON[k]
|
||||
@@ -141,6 +143,7 @@ export default function WidgetsEditor({ widgets = [], onChange, media, onMedia,
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
{widgets.length >= most && <p className="text-caption text-ink-3" data-testid="signage-widgets-full">{t('signage.widgets.full', { count: most })}</p>}
|
||||
</Section>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -46,3 +46,7 @@ export const refreshWeather = () => client.post('/api/signage/weather/refresh').
|
||||
// the venue's badges (owner review 5): their names, colours and icons
|
||||
export const getBadges = () => client.get('/api/signage/badges').then(data)
|
||||
export const putBadges = badges => client.put('/api/signage/badges', { badges }).then(data)
|
||||
|
||||
// limits that keep the TVs smooth (owner review 6): widgets per slide
|
||||
export const getPerformance = () => client.get('/api/signage/performance').then(data)
|
||||
export const putPerformance = body => client.put('/api/signage/performance', body).then(data)
|
||||
|
||||
@@ -77,18 +77,30 @@ export function windowParts(slide) {
|
||||
}
|
||||
|
||||
/** The playlist's total time for one round (videos to their end count by their length if known). */
|
||||
export function totalSeconds(slides, media) {
|
||||
export function totalSeconds(slides, media, secondsOf = s => s.duration_s || 10) {
|
||||
let total = 0
|
||||
for (const s of slides || []) {
|
||||
if (!s.enabled) continue
|
||||
if (s.kind === 'video' && s.video_to_end) {
|
||||
const ms = media?.[String(s.content?.media_id)]?.duration_ms
|
||||
total += ms ? Math.round(ms / 1000) : s.duration_s || 10
|
||||
} else total += s.duration_s || 10
|
||||
} else total += secondsOf(s)
|
||||
}
|
||||
return total
|
||||
}
|
||||
|
||||
/** A seconds field left empty (owner review 6: it may be emptied while typing; the slide can't be
|
||||
* saved until it is filled): seconds on screen, a menu board's or a menu widget's seconds per page. */
|
||||
export function secondsMissing(slide) {
|
||||
if (!slide) return false
|
||||
if (slide.duration_s == null && !(slide.kind === 'video' && slide.video_to_end)) return true
|
||||
const c = slide.content || {}
|
||||
if (slide.kind === 'menu' && c.page_seconds === null) return true
|
||||
const boards = ws => (ws || []).some(w => (w.kind === 'menu' && w.board?.page_seconds === null)
|
||||
|| (w.cells || []).some(x => boards(x.widgets || (x.widget ? [x.widget] : []))))
|
||||
return boards(c.widgets)
|
||||
}
|
||||
|
||||
/** Move the item at `from` to `to` in a copy of `list`. */
|
||||
export function moved(list, from, to) {
|
||||
const out = [...list]
|
||||
@@ -233,6 +245,28 @@ export function resizeBox(b, handle, dx, dy, min = MIN_BOX) {
|
||||
return { x: round(x), y: round(y), w: round(w), h: round(h) }
|
||||
}
|
||||
|
||||
/** A box moved off the slide as far as a strip of it (5 %) stays on it, to grab it back (owner review 6). */
|
||||
export function moveLoose(b, dx, dy) {
|
||||
return { ...b, x: round(clamp(b.x + dx, 5 - b.w, 95)), y: round(clamp(b.y + dy, 5 - b.h, 95)) }
|
||||
}
|
||||
|
||||
/**
|
||||
* A box that is exactly its content (a text, a clock, a QR…; owner review 6) scaled from a handle:
|
||||
* it keeps its shape (width and height grow together); the handle's opposite corner or edge stays.
|
||||
* `aspect` = the box's width / height in % of the slide (as measured). A side handle scales by its
|
||||
* own direction, a corner by the larger of the two.
|
||||
*/
|
||||
export function scaleBox(b, handle, dx, dy, aspect = b.w / b.h, min = 1) {
|
||||
const byW = handle.includes('e') ? (b.w + dx) / b.w : handle.includes('w') ? (b.w - dx) / b.w : null
|
||||
const byH = handle.includes('s') ? (b.h + dy) / b.h : handle.includes('n') ? (b.h - dy) / b.h : null
|
||||
const k = byW == null ? byH : byH == null ? byW : Math.max(byW, byH)
|
||||
const h = Math.max(min, b.h * k)
|
||||
const w = h * aspect
|
||||
const x = handle.includes('w') ? b.x + b.w - w : handle.includes('e') ? b.x : b.x + (b.w - w) / 2
|
||||
const y = handle.includes('n') ? b.y + b.h - h : handle.includes('s') ? b.y : b.y + (b.h - h) / 2
|
||||
return { x: round(x), y: round(y), w: round(w), h: round(h) }
|
||||
}
|
||||
|
||||
/**
|
||||
* A moved box pulled onto the slide's edges and middle lines when it comes within `near` %:
|
||||
* → { box, guides: ['x:50', 'y:0', …] } (the lines it sits on, for the editor to draw).
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
// How long a slide really plays (owner review 6, 2026-11-21): a menu board with pages plays whole
|
||||
// rounds of them, so its seconds on screen are rounded up (the TV does the same: menuMs).
|
||||
import { boardPages, menuMs } from '@xenia/signage'
|
||||
|
||||
/** A menu board's pages on a TV of this shape (1 when it fits, or without its products yet). */
|
||||
export function pagesOn(slide, orientation = 'landscape') {
|
||||
if (slide?.kind !== 'menu' || !slide.menu) return 1
|
||||
const [w, h] = orientation === 'portrait' ? [1080, 1920] : [1920, 1080]
|
||||
return Math.max(1, boardPages(slide, 0, w, h).length)
|
||||
}
|
||||
|
||||
/** The seconds a slide stays on a TV of this shape. */
|
||||
export function playSeconds(slide, orientation = 'landscape') {
|
||||
if (slide?.kind !== 'menu') return slide?.duration_s || 10
|
||||
return Math.round(menuMs({ ...slide, duration_s: slide.duration_s || 10 }, pagesOn(slide, orientation)) / 1000)
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
// The venue's signage limits (owner review 6, 2026-11-21: widgets per slide, 10 recommended), read
|
||||
// once for the page; saving them (Message & settings → Performance) updates every editor at once.
|
||||
import { useEffect, useState } from 'react'
|
||||
import * as api from './signageApi'
|
||||
|
||||
const DEFAULTS = { max_widgets: 10, recommended: 10, cap: 50 }
|
||||
let cache = null
|
||||
const listeners = new Set()
|
||||
|
||||
export function setPerformance(p) {
|
||||
cache = p
|
||||
listeners.forEach(f => f(p))
|
||||
}
|
||||
|
||||
export function usePerformance() {
|
||||
const [p, setP] = useState(cache || DEFAULTS)
|
||||
useEffect(() => {
|
||||
listeners.add(setP)
|
||||
if (!cache) api.getPerformance().then(setPerformance).catch(() => {})
|
||||
return () => { listeners.delete(setP) }
|
||||
}, [])
|
||||
return p
|
||||
}
|
||||
@@ -102,3 +102,17 @@ test('the Slides library: what is saved, and a copy for a playlist', async () =>
|
||||
assert.equal(saved.content.widgets[0].kind, 'name') // a copy, never the kept slide
|
||||
})
|
||||
|
||||
|
||||
test('owner review 6: a box off the slide (a strip stays), a tight box scaled keeping its shape', async () => {
|
||||
const { moveLoose, scaleBox, secondsMissing } = await import('../src/pages/signage/signageLogic.js')
|
||||
assert.deepEqual(moveLoose({ x: 50, y: 10, w: 20, h: 10 }, 60, -30), { x: 95, y: -5, w: 20, h: 10 })
|
||||
assert.deepEqual(moveLoose({ x: 50, y: 10, w: 20, h: 10 }, -100, 0), { x: -15, y: 10, w: 20, h: 10 })
|
||||
assert.deepEqual(scaleBox({ x: 10, y: 10, w: 20, h: 10 }, 'se', 20, 0), { x: 10, y: 10, w: 40, h: 20 }) // twice as wide → twice as tall
|
||||
assert.deepEqual(scaleBox({ x: 10, y: 10, w: 20, h: 10 }, 'n', 0, -10), { x: 0, y: 0, w: 40, h: 20 }) // the bottom stays, centred across
|
||||
assert.deepEqual(scaleBox({ x: 10, y: 10, w: 20, h: 10 }, 'nw', 10, 2), { x: 14, y: 12, w: 16, h: 8 }) // a corner: the larger of the two (0.5, 0.8)
|
||||
assert.equal(secondsMissing({ kind: 'menu', duration_s: 10, content: { page_seconds: null } }), true)
|
||||
assert.equal(secondsMissing({ kind: 'text', duration_s: null, content: {} }), true)
|
||||
assert.equal(secondsMissing({ kind: 'video', video_to_end: true, duration_s: null, content: {} }), false)
|
||||
assert.equal(secondsMissing({ kind: 'blank', duration_s: 5, content: { widgets: [{ kind: 'stack', cells: [{ widgets: [{ kind: 'menu', board: { page_seconds: null } }] }] }] } }), true)
|
||||
assert.equal(secondsMissing({ kind: 'menu', duration_s: 5, content: { page_seconds: 3 } }), false)
|
||||
})
|
||||
|
||||
@@ -189,7 +189,8 @@
|
||||
"weather_offline": "Η υπηρεσία καιρού δεν είναι διαθέσιμη: ο διακομιστής του καταστήματος χρειάζεται internet γι' αυτήν.",
|
||||
"schedule_unknown": "Το πρόγραμμα {{schedule_id}} δεν βρέθηκε.",
|
||||
"scene_unknown": "Αυτή η σκηνή δεν υπάρχει πια.",
|
||||
"screen_unknown": "Αυτή η οθόνη δεν υπάρχει πια."
|
||||
"screen_unknown": "Αυτή η οθόνη δεν υπάρχει πια.",
|
||||
"too_many_widgets": "Μια διαφάνεια έχει το πολύ {{max}} widgets (Προβολή → Μήνυμα & ρυθμίσεις → Απόδοση)."
|
||||
},
|
||||
"menu_tablet": {
|
||||
"no_table": "Αυτό το tablet δεν είναι σε τραπέζι, οπότε δεν καλεί σερβιτόρο.",
|
||||
|
||||
@@ -1557,7 +1557,9 @@
|
||||
"textSize": "Μέγεθος κειμένου",
|
||||
"qrColour": "Χρώμα κωδικού QR",
|
||||
"qrBackground": "Φόντο κωδικού QR",
|
||||
"changeMessage": "Αλλαγή μηνύματος"
|
||||
"changeMessage": "Αλλαγή μηνύματος",
|
||||
"full_one": "Αυτή η διαφάνεια έχει τα περισσότερα widgets που επιτρέπονται ({{count}}). Προβολή → Μήνυμα & ρυθμίσεις → Απόδοση.",
|
||||
"full_other": "Αυτή η διαφάνεια έχει τα περισσότερα widgets που επιτρέπονται ({{count}}). Προβολή → Μήνυμα & ρυθμίσεις → Απόδοση."
|
||||
},
|
||||
"tabs": {
|
||||
"playlists": "Λίστες",
|
||||
@@ -1768,6 +1770,16 @@
|
||||
"removeTitle": "Αφαίρεση του σήματος «{{name}}»;",
|
||||
"removeBody": "Οι πίνακες που το χρησιμοποιούν σταματούν να το δείχνουν. Τίποτα δεν αλλάζει μέχρι να αποθηκεύσετε.",
|
||||
"needName": "Κάθε σήμα χρειάζεται όνομα (στα ελληνικά ή στα αγγλικά)."
|
||||
},
|
||||
"secondsEmpty": "Συμπληρώστε τα δευτερόλεπτα (1 ή περισσότερα) για να αποθηκεύσετε.",
|
||||
"playNote": "Παίζει {{real}} δλ., όχι {{set}} δλ.: ένα μενού με σελίδες παίζει ολόκληρους γύρους ({{rounds}} × {{pages}} σελίδες των {{per}} δλ.), ώστε να μη σταματά στη μέση.",
|
||||
"performance": {
|
||||
"title": "Απόδοση",
|
||||
"hint": "Πόσα widgets μπορεί να έχει μια διαφάνεια. Συνιστούμε έντονα {{n}}: κάθε widget ξανασχεδιάζεται συνεχώς στην τηλεόραση, και οι μικροί υπολογιστές των τηλεοράσεων καθυστερούν με πολλά.",
|
||||
"maxWidgets": "Widgets ανά διαφάνεια",
|
||||
"empty": "Συμπληρώστε έναν αριθμό (1 ή περισσότερα).",
|
||||
"backTo": "Πίσω στα {{n}}",
|
||||
"warning": "Πάνω από {{n}} widgets μπορεί να κάνουν τις τηλεοράσεις να κολλάνε (διαφάνειες που αλλάζουν αργά, βίντεο που κόβονται). Ελέγξτε τις οθόνες σας αφού τα προσθέσετε."
|
||||
}
|
||||
},
|
||||
"overview": {
|
||||
@@ -2855,7 +2867,6 @@
|
||||
"width": "Πλάτος",
|
||||
"height": "Ύψος",
|
||||
"background": "Εικόνα φόντου",
|
||||
"backgroundOpacity": "Ένταση: {{value}}%",
|
||||
"table": "Τραπέζι {{name}}",
|
||||
"shape": "Σχήμα",
|
||||
"shapes": {
|
||||
@@ -2896,7 +2907,8 @@
|
||||
"decimal": ",",
|
||||
"length": "Μήκος",
|
||||
"thickness": "Πάχος",
|
||||
"cellsHint": "Σε κελιά του πλέγματος (ανά μισό κελί): ένα κελί είναι το μέγεθος του πλέγματος, οπότε τα μεγέθη ακολουθούν την ανάλυσή του. Ή σύρετε τις λαβές στις πλευρές και τις γωνίες."
|
||||
"cellsHint": "Σε κελιά του πλέγματος (ανά μισό κελί): ένα κελί είναι το μέγεθος του πλέγματος, οπότε τα μεγέθη ακολουθούν την ανάλυσή του. Ή σύρετε τις λαβές στις πλευρές και τις γωνίες.",
|
||||
"backgroundOpacityLabel": "Ένταση"
|
||||
},
|
||||
"orders": {
|
||||
"back": "Πίσω",
|
||||
|
||||
@@ -189,7 +189,8 @@
|
||||
"weather_offline": "The weather service can't be reached: the venue's server needs internet for it.",
|
||||
"schedule_unknown": "Schedule {{schedule_id}} not found.",
|
||||
"scene_unknown": "That scene doesn't exist any more.",
|
||||
"screen_unknown": "That screen doesn't exist any more."
|
||||
"screen_unknown": "That screen doesn't exist any more.",
|
||||
"too_many_widgets": "A slide holds at most {{max}} widgets (Signage → Message & settings → Performance)."
|
||||
},
|
||||
"menu_tablet": {
|
||||
"no_table": "This tablet isn't at a table, so it can't call a waiter.",
|
||||
|
||||
@@ -1557,7 +1557,9 @@
|
||||
"textSize": "Text size",
|
||||
"qrColour": "QR code colour",
|
||||
"qrBackground": "QR code background",
|
||||
"changeMessage": "Change the message"
|
||||
"changeMessage": "Change the message",
|
||||
"full_one": "This slide holds the most widgets allowed ({{count}}). Signage → Message & settings → Performance.",
|
||||
"full_other": "This slide holds the most widgets allowed ({{count}}). Signage → Message & settings → Performance."
|
||||
},
|
||||
"tabs": {
|
||||
"playlists": "Playlists",
|
||||
@@ -1768,6 +1770,16 @@
|
||||
"removeTitle": "Remove the badge \"{{name}}\"?",
|
||||
"removeBody": "Boards that use it stop showing it. Nothing changes until you save.",
|
||||
"needName": "Every badge needs a name (in Greek or in English)."
|
||||
},
|
||||
"secondsEmpty": "Fill in the seconds (1 or more) to save.",
|
||||
"playNote": "Plays {{real}} s, not {{set}} s: a menu with pages plays whole rounds ({{rounds}} × {{pages}} pages of {{per}} s), so it never stops in the middle of one.",
|
||||
"performance": {
|
||||
"title": "Performance",
|
||||
"hint": "How many widgets a slide may hold. We strongly recommend {{n}}: every widget is redrawn on the TV all the time, and small TV computers slow down with many.",
|
||||
"maxWidgets": "Widgets per slide",
|
||||
"empty": "Fill in a number (1 or more).",
|
||||
"backTo": "Back to {{n}}",
|
||||
"warning": "More than {{n}} widgets can make the TVs stutter (slides turning late, videos jerking). Check your screens after you add them."
|
||||
}
|
||||
},
|
||||
"overview": {
|
||||
@@ -2855,7 +2867,6 @@
|
||||
"width": "Width",
|
||||
"height": "Height",
|
||||
"background": "Background picture",
|
||||
"backgroundOpacity": "How strong: {{value}}%",
|
||||
"table": "Table {{name}}",
|
||||
"shape": "Shape",
|
||||
"shapes": {
|
||||
@@ -2896,7 +2907,8 @@
|
||||
"decimal": ".",
|
||||
"length": "Length",
|
||||
"thickness": "Thickness",
|
||||
"cellsHint": "In grid cells (by half cells): a cell is the grid's size, so sizes follow the grid resolution. Or drag the handles on its sides and corners."
|
||||
"cellsHint": "In grid cells (by half cells): a cell is the grid's size, so sizes follow the grid resolution. Or drag the handles on its sides and corners.",
|
||||
"backgroundOpacityLabel": "How strong"
|
||||
},
|
||||
"orders": {
|
||||
"back": "Back",
|
||||
|
||||
@@ -6,7 +6,7 @@ import { Cloud, CloudFog, CloudLightning, CloudMoon, CloudRain, CloudSnow, Cloud
|
||||
import { QRCodeSVG } from 'qrcode.react'
|
||||
import { BADGE_ICONS } from './badges'
|
||||
import { useFormat, useTranslation } from '@xenia/i18n'
|
||||
import { badgeColours, badgeName, cellWidgets, fitUnit, FONTS, itemBadges, menuLook, menuPages, pageAt, priceChars, textWidth, visibleGroups, weatherIcon, widgetAlign } from './logic'
|
||||
import { badgeColours, badgeName, cellWidgets, TIGHT, fitUnit, FONTS, itemBadges, menuLook, menuPages, pageAt, priceChars, textWidth, visibleGroups, weatherIcon, widgetAlign } from './logic'
|
||||
|
||||
/** A slide's background: a colour, or a photo (cover / contain) with a darkening layer. */
|
||||
export function Background({ bg, media }) {
|
||||
@@ -165,6 +165,7 @@ const CORNER = {
|
||||
'bottom-right': { bottom: '3cqmin', right: '3cqmin', alignItems: 'flex-end' },
|
||||
}
|
||||
const SELF = { left: 'flex-start', center: 'center', right: 'flex-end' }
|
||||
const placedBy = w => (w.position === 'custom' && w.box ? (TIGHT.includes(w.kind) ? 'tight' : true) : false)
|
||||
const VSELF = { top: 'flex-start', middle: 'center', bottom: 'flex-end', auto: 'center' }
|
||||
/** A widget's own colour and the plate behind it (owner review 5); `pad`: a plate that hugs it. */
|
||||
const plate = (w, pad) => ({
|
||||
@@ -186,7 +187,7 @@ export function Widgets({ widgets, media, venue, now, colour, extras, embed }) {
|
||||
const fmt = useFormat()
|
||||
if (!widgets?.length) return null
|
||||
const ctx = { media, venue, now, fmt, extras: extras || {}, embed }
|
||||
const shown = widgets.map((w, i) => [w, i, widgetBody(w, ctx, w.position === 'custom' && !!w.box, String(i))]).filter(([, , body]) => body)
|
||||
const shown = widgets.map((w, i) => [w, i, widgetBody(w, ctx, placedBy(w), String(i))]).filter(([, , body]) => body)
|
||||
const bar = where => shown.filter(([w]) => w.position === where)
|
||||
const bars = [['top-bar', { top: 0 }], ['bottom-bar', { bottom: 0 }]]
|
||||
return (
|
||||
@@ -201,6 +202,16 @@ export function Widgets({ widgets, media, venue, now, colour, extras, embed }) {
|
||||
</div>
|
||||
))}
|
||||
{shown.filter(([w]) => CORNER[w.position] || (w.position === 'custom' && w.box)).map(([w, i, body]) => {
|
||||
if (w.position === 'custom' && TIGHT.includes(w.kind)) {
|
||||
// as big as what it shows, from its box's top-left corner (it may run off the slide)
|
||||
return (
|
||||
<div key={i} data-widget={i} className="absolute" data-testid="signage-w-box" data-tight=""
|
||||
style={{ left: `${w.box.x}%`, top: `${w.box.y}%`, width: 'max-content', color: colour || '#fff', display: 'flex', flexDirection: 'column',
|
||||
alignItems: SELF[widgetAlign(w)], textAlign: widgetAlign(w), ...plate(w, true) }}>
|
||||
{body}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
if (w.position === 'custom') {
|
||||
return (
|
||||
<div key={i} data-widget={i} className="absolute" data-testid="signage-w-box"
|
||||
@@ -226,8 +237,10 @@ const OBJECT_POSITION = { left: 'left center', center: 'center', right: 'right c
|
||||
|
||||
/**
|
||||
* What one widget shows, or null when it has nothing to show. Sizes are "usual units" (cqmin of
|
||||
* the slide at size medium); `fit`: the widget fills its own box instead (fitUnit). `path`: the
|
||||
* widget's place in the slide ("2", "2.1" inside a stack), for its extras.
|
||||
* the slide at size medium); `fit`: the widget fills its place instead (fitUnit: a stack's part);
|
||||
* fit 'tight' (owner review 6): placed by hand, its box is exactly its content: the box's height
|
||||
* (× its text size) sets the size and its width follows. `path`: the widget's place in the slide
|
||||
* ("2", "2.1.0" inside a stack), for its extras.
|
||||
*/
|
||||
function widgetBody(w, ctx, fit, path) {
|
||||
const { media, venue, now, fmt, extras } = ctx
|
||||
@@ -238,6 +251,7 @@ function widgetBody(w, ctx, fit, path) {
|
||||
// in a box of its own the box sets the size: its text size can only make it smaller there
|
||||
const unit = (height, width) => {
|
||||
if (!fit) return n => `${+(n * s).toFixed(3)}cqmin`
|
||||
if (fit === 'tight') return n => `${+(n * (w.box.h / height) * ts).toFixed(4)}cqh`
|
||||
const f = fitUnit(height, width)
|
||||
return n => f(n * Math.min(1, ts))
|
||||
}
|
||||
@@ -255,6 +269,7 @@ function widgetBody(w, ctx, fit, path) {
|
||||
if (w.kind === 'logo') {
|
||||
const m = media(w.media_id)
|
||||
if (!m) return null
|
||||
if (fit === 'tight') return <img src={m.src} alt="" style={{ height: `${+(w.box.h * ts).toFixed(4)}cqh`, width: 'auto', display: 'block' }} data-testid="signage-w-logo" />
|
||||
return fit
|
||||
? <img src={m.src} alt="" style={{ width: '100%', height: '100%', objectFit: 'contain', objectPosition: OBJECT_POSITION[widgetAlign(w)] }} data-testid="signage-w-logo" />
|
||||
: <img src={m.src} alt="" style={{ height: `${9 * s}cqmin`, maxWidth: `${30 * s}cqmin`, objectFit: 'contain' }} data-testid="signage-w-logo" />
|
||||
@@ -381,12 +396,15 @@ function Stack({ w, path, ctx }) {
|
||||
const wp = `${cp}.${k}`
|
||||
const own = cw.position === 'custom' && cw.box
|
||||
const align = cw.align && cw.align !== 'auto' ? cw.align : 'center'
|
||||
const body = widgetBody(cw, ctx, true, wp)
|
||||
const body = widgetBody(cw, ctx, own && TIGHT.includes(cw.kind) ? 'tight' : true, wp)
|
||||
return (
|
||||
<div key={k} style={{ flex: '1 1 0%', minWidth: 0, minHeight: 0, overflow: 'hidden', containerType: 'size', position: 'relative',
|
||||
...(own ? {} : { display: 'flex', alignItems: VSELF[cw.vertical] || 'center', justifyContent: SELF[align], textAlign: align }) }}
|
||||
data-testid="signage-stack-place" data-place={wp}>
|
||||
{body && (own ? (
|
||||
{body && (own && TIGHT.includes(cw.kind) ? (
|
||||
<div data-widget={wp} style={{ position: 'absolute', left: `${cw.box.x}%`, top: `${cw.box.y}%`, width: 'max-content', display: 'flex', flexDirection: 'column',
|
||||
alignItems: SELF[align], textAlign: align, ...plate(cw, true) }} data-testid="signage-w-box" data-tight="">{body}</div>
|
||||
) : own ? (
|
||||
<div data-widget={wp} style={{ position: 'absolute', left: `${cw.box.x}%`, top: `${cw.box.y}%`, width: `${cw.box.w}%`, height: `${cw.box.h}%`,
|
||||
containerType: 'size', display: 'flex', alignItems: VSELF[cw.vertical] || 'center', justifyContent: SELF[align], textAlign: align, ...plate(cw) }}
|
||||
data-testid="signage-w-box">{body}</div>
|
||||
|
||||
@@ -130,7 +130,7 @@ export function nextSlide(slides, current, local) {
|
||||
/** How long a slide stays, in ms; null = until its video ends (with a safety limit in the player). */
|
||||
export function slideMs(slide) {
|
||||
if (slide.kind === 'video' && slide.video_to_end) return null
|
||||
return Math.max(2, slide.duration_s || 10) * 1000
|
||||
return Math.max(1, slide.duration_s || 10) * 1000
|
||||
}
|
||||
|
||||
/** The frame's size and turn for a screen: CSS for the box that holds the slides. */
|
||||
@@ -215,14 +215,17 @@ export function menuPages(groups, perPage, headings = true) {
|
||||
|
||||
/** A menu slide's time: every page for its seconds, at least the slide's own time. */
|
||||
export function menuMs(slide, pageCount) {
|
||||
const per = Math.max(3, slide.content?.page_seconds || 10) * 1000
|
||||
return Math.max(slideMs(slide), pageCount > 1 ? pageCount * per : 0)
|
||||
// owner review 6 (2026-11-21): a board with pages plays whole rounds of them, never cut in the
|
||||
// middle: its seconds on screen rounded up to the next full round (10 s, 2 pages of 3 s → 12 s)
|
||||
if (!(pageCount > 1)) return slideMs(slide)
|
||||
const round = pageCount * Math.max(1, slide.content?.page_seconds || 10) * 1000
|
||||
return Math.max(1, Math.ceil(slideMs(slide) / round)) * round
|
||||
}
|
||||
|
||||
/** The page on screen `elapsedMs` into the slide (the pages go round while the slide lasts). */
|
||||
export function pageAt(pageCount, pageSeconds, elapsedMs) {
|
||||
if (pageCount <= 1 || !(elapsedMs > 0)) return 0 // the clock's last tick may be just before the slide began
|
||||
return Math.floor(elapsedMs / (Math.max(3, pageSeconds || 10) * 1000)) % pageCount // round and round while the slide lasts
|
||||
return Math.floor(elapsedMs / (Math.max(1, pageSeconds || 10) * 1000)) % pageCount // round and round while the slide lasts
|
||||
}
|
||||
|
||||
/** A weather code (WMO, as Open-Meteo sends it) → an icon name for the widget. */
|
||||
@@ -258,6 +261,10 @@ export function visibleGroups(groups) {
|
||||
|
||||
// ── widgets placed by hand (owner 2026-11-21) ─────────────────────────────────
|
||||
|
||||
/** Widgets whose box, placed by hand, is exactly their content (owner review 6): its height (× the
|
||||
* widget's text size) sets the size, its width follows. A menu or a stack fills its box. */
|
||||
export const TIGHT = ['logo', 'name', 'date', 'clock', 'message', 'text', 'qr', 'weather']
|
||||
|
||||
/** The slide kinds that carry widgets. */
|
||||
export const WIDGET_HOSTS = ['text', 'menu', 'blank']
|
||||
|
||||
|
||||
@@ -101,6 +101,11 @@ test('a menu slide stays for all its pages; the page on screen', () => {
|
||||
const slide = { kind: 'menu', duration_s: 10, content: { page_seconds: 8 } }
|
||||
assert.equal(menuMs(slide, 1), 10_000)
|
||||
assert.equal(menuMs(slide, 3), 24_000)
|
||||
// owner review 6: whole rounds only (10 s, 2 pages of 3 s → 2 rounds of 6 s = 12 s; 7 s of 2 × 3 s → 12 s; 12 s → 12 s)
|
||||
assert.equal(menuMs({ kind: 'menu', duration_s: 10, content: { page_seconds: 3 } }, 2), 12_000)
|
||||
assert.equal(menuMs({ kind: 'menu', duration_s: 7, content: { page_seconds: 3 } }, 2), 12_000)
|
||||
assert.equal(menuMs({ kind: 'menu', duration_s: 12, content: { page_seconds: 3 } }, 2), 12_000)
|
||||
assert.equal(menuMs({ kind: 'menu', duration_s: 2, content: { page_seconds: 5 } }, 3), 15_000)
|
||||
assert.equal(pageAt(3, 8, 0), 0)
|
||||
assert.equal(pageAt(3, 8, 8_100), 1)
|
||||
assert.equal(pageAt(3, 8, 16_500), 2)
|
||||
|
||||
@@ -475,13 +475,35 @@
|
||||
.x-field-row--wrapped { border-color: var(--x-line); background: var(--x-surface); }
|
||||
.x-field-row--wrapped.x-field-row--shade { background: var(--x-surface-2); }
|
||||
|
||||
/* ── NumberInput (2026-11-21): a whole number with − / + on its sides ──────────── */
|
||||
.x-number {
|
||||
display: flex; align-items: stretch; width: 100%; min-width: 0; min-height: var(--x-control-md); box-sizing: border-box;
|
||||
border: var(--x-border-width) solid var(--x-line-strong); border-radius: var(--x-radius-control); background: var(--x-surface); overflow: hidden;
|
||||
}
|
||||
.x-number--sm { min-height: var(--x-control-sm); }
|
||||
.x-number:hover:not(.x-number--disabled) { border-color: var(--x-ink-3); }
|
||||
.x-number--focus { border-color: var(--x-accent); box-shadow: var(--x-focus-ring); }
|
||||
.x-number--invalid { border-color: var(--x-danger); }
|
||||
.x-number--invalid.x-number--focus { box-shadow: 0 0 0 3px rgb(var(--x-danger-rgb) / 0.3); }
|
||||
.x-number--disabled { background: var(--x-surface-2); }
|
||||
.x-number__btn {
|
||||
flex-shrink: 0; width: var(--x-control-sm); display: grid; place-items: center; border: 0; background: none; color: var(--x-ink-2); cursor: pointer;
|
||||
}
|
||||
.x-number__btn:hover:not(:disabled) { background: var(--x-surface-2); color: var(--x-ink); }
|
||||
.x-number__btn:disabled { opacity: 0.4; cursor: default; }
|
||||
.x-number__input {
|
||||
flex: 1; min-width: 0; width: 100%; border: 0; outline: none; background: transparent; color: var(--x-ink);
|
||||
font: inherit; font-size: var(--x-text-body); text-align: center; font-variant-numeric: tabular-nums;
|
||||
}
|
||||
.x-number__suffix { align-self: center; padding-right: var(--x-space-1); color: var(--x-ink-3); font-size: var(--x-text-label); }
|
||||
|
||||
/* ── Slider (2026-11-21): framed like a field, its value beside it ──────────────── */
|
||||
.x-slider {
|
||||
min-height: var(--x-control-md); display: flex; align-items: center; gap: var(--x-space-3); padding: 0 var(--x-space-3);
|
||||
border: var(--x-border-width) solid var(--x-line); border-radius: var(--x-radius-control); background: var(--x-surface);
|
||||
}
|
||||
.x-slider__input { flex: 1; min-width: 0; accent-color: var(--x-accent); }
|
||||
.x-slider__value { width: 3rem; text-align: right; font-size: var(--x-text-label); color: var(--x-ink-2); font-variant-numeric: tabular-nums; }
|
||||
.x-slider__value { flex-shrink: 0; text-align: right; font-size: var(--x-text-label); color: var(--x-ink-2); font-variant-numeric: tabular-nums; }
|
||||
|
||||
/* ── ColourField (2026-11-21): a colour as a field; its panel over the page ──────── */
|
||||
.x-swatch {
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
import { useState } from 'react'
|
||||
import { cx } from '../internal/cx.js'
|
||||
import { useLabels } from './labels.js'
|
||||
|
||||
const Icon = ({ d }) => (
|
||||
<svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" strokeWidth="2.25" strokeLinecap="round" aria-hidden="true"><path d={d} /></svg>
|
||||
)
|
||||
|
||||
/**
|
||||
* A whole number typed or stepped with − / + on its sides (2026-11-21), as tall as an input.
|
||||
* <NumberInput value={seconds} min={1} max={3600} onChange={setSeconds} suffix="s" />
|
||||
* The field may be emptied while typing: onChange(null). The form shows its own error for an empty
|
||||
* value and keeps it from being saved. A value over `max` is brought down; under `min`, brought up
|
||||
* when the field is left. Inside a <Field> it takes the field's id.
|
||||
*/
|
||||
export function NumberInput({ value, onChange, min = 0, max = Infinity, step = 1, suffix, size = 'md', invalid = false, disabled = false, className, id, ...rest }) {
|
||||
const labels = useLabels()
|
||||
const [focus, setFocus] = useState(false)
|
||||
const n = value === '' || value == null ? null : Number(value)
|
||||
const clamp = v => Math.min(max, Math.max(min, v))
|
||||
const stepBy = d => onChange?.(clamp((n ?? min) + d))
|
||||
return (
|
||||
<span className={cx('x-number', `x-number--${size}`, (invalid || rest['aria-invalid']) && 'x-number--invalid', focus && 'x-number--focus', disabled && 'x-number--disabled', className)}>
|
||||
<button type="button" className="x-number__btn" onClick={() => stepBy(-step)} disabled={disabled || (n != null && n <= min)} aria-label={labels.decrease} tabIndex={-1}>
|
||||
<Icon d="M5 12h14" />
|
||||
</button>
|
||||
<input id={id} type="text" inputMode="numeric" className="x-number__input" value={n == null ? '' : String(n)} disabled={disabled}
|
||||
aria-invalid={invalid || undefined}
|
||||
onChange={e => {
|
||||
const digits = e.target.value.replace(/\D/g, '')
|
||||
onChange?.(digits === '' ? null : Math.min(max, Number(digits)))
|
||||
}}
|
||||
onFocus={() => setFocus(true)}
|
||||
onBlur={() => { setFocus(false); if (n != null && n < min) onChange?.(min) }}
|
||||
onKeyDown={e => {
|
||||
if (e.key === 'ArrowUp') { e.preventDefault(); stepBy(step) }
|
||||
if (e.key === 'ArrowDown') { e.preventDefault(); stepBy(-step) }
|
||||
}}
|
||||
{...rest} />
|
||||
{suffix && <span className="x-number__suffix" aria-hidden="true">{suffix}</span>}
|
||||
<button type="button" className="x-number__btn" onClick={() => stepBy(step)} disabled={disabled || (n != null && n >= max)} aria-label={labels.increase} tabIndex={-1}>
|
||||
<Icon d="M12 5v14M5 12h14" />
|
||||
</button>
|
||||
</span>
|
||||
)
|
||||
}
|
||||
@@ -11,7 +11,8 @@ export function Slider({ label, value, min = 0, max = 100, step = 1, onChange, s
|
||||
<span className="x-slider">
|
||||
<input type="range" min={min} max={max} step={step} value={value} onChange={e => onChange?.(Number(e.target.value))}
|
||||
className="x-slider__input" aria-label={label} data-testid={testId} />
|
||||
<span className="x-slider__value">{value}{suffix}</span>
|
||||
{/* as wide as its widest value, no wider: the gap to it is the frame's padding (owner review 6) */}
|
||||
<span className="x-slider__value" style={{ minWidth: `${String(max).length + String(suffix).length}ch` }}>{value}{suffix}</span>
|
||||
</span>
|
||||
</Field>
|
||||
)
|
||||
|
||||
@@ -27,6 +27,7 @@ export { ColourField, Swatch } from './components/ColourField.jsx'
|
||||
export { COLOUR_PRESETS, joinAlpha, splitAlpha, typedColour } from './components/colour.js'
|
||||
export { FieldRow } from './components/FieldRow.jsx'
|
||||
export { Slider } from './components/Slider.jsx'
|
||||
export { NumberInput } from './components/NumberInput.jsx'
|
||||
export { IconPicker } from './components/IconPicker.jsx'
|
||||
export { Page, PageHeader, Pane, Toolbar, ToolbarSpacer } from './components/Page.jsx'
|
||||
export { SearchInput, FilterChip, Segmented, Tabs } from './components/Controls.jsx'
|
||||
|
||||
@@ -418,6 +418,12 @@ try {
|
||||
await mgr.mouse.down()
|
||||
await mgr.mouse.move(se.x + 60, se.y + 30, { steps: 5 })
|
||||
await mgr.mouse.up()
|
||||
r.check('2026-11-21 (6): a clock placed by hand is exactly as big as what it shows (its outline is the clock)',
|
||||
await waitFor(async () => {
|
||||
const box = await mgr.getByTestId('signage-preview').locator('[data-tight]').last().boundingBox()
|
||||
const sel = await mgr.getByTestId('signage-canvas-selected').boundingBox()
|
||||
return box && sel && Math.abs(box.width - sel.width) < 3 && Math.abs(box.height - sel.height) < 3
|
||||
}, 4000, 200) === true)
|
||||
r.check('2026-11-21: a widget dragged on the preview reads "Custom" in its card',
|
||||
(await mgr.locator('[data-testid="signage-widget"][data-selected="true"]').getByTestId('signage-widget-position').textContent()).includes('Custom'))
|
||||
await mgr.getByTestId('signage-slide-save').click()
|
||||
|
||||
Reference in New Issue
Block a user