feat(manager): the floor plan editor reworked; Management -> Tables on the page rule; area colours

- Floor editor: one toolbar over the map and the panels (grid on / off, grid resolution Ultra high
  ... Very low, edit the shape, Fit width / Whole plan, undo, save), panels top-aligned and sticky.
- The floor's shape: a '+' on the edge under the pointer, press to add a corner (and drag it);
  resting on a corner shows a bubble to remove it (never below 3).
- Areas: resize handles on the sides and corners, a colour (pastel, see-through; floor_items.color,
  migration 0041), the name repeated in the corner when tables cover it (live maps too).
- Labels can be clicked again after they're placed (transparent fill, not none).
- Management -> Tables: <Page> with the tabs above (?tab=), the list as a container, toolbar
  buttons one height.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-20 15:17:45 +02:00
co-authored by Claude Opus 5.5
parent 476c55abc0
commit 244e93f827
17 changed files with 389 additions and 111 deletions
+3 -2
View File
@@ -5,7 +5,7 @@
// Styles are inline with @xenia/ui tokens, so it fits the apps with and without Tailwind.
import { useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react'
import { useTranslation } from '@xenia/i18n'
import { plansFor, splitTables, toneOf, TONES } from './geometry.js'
import { coveredAreas, plansFor, splitTables, toneOf, TONES } from './geometry.js'
import { Floor, Item, TableShape } from './Shapes.jsx'
const ZOOMS = [0.25, 0.35, 0.5, 0.75, 1, 1.25, 1.5, 2, 3]
@@ -88,6 +88,7 @@ export function FloorView({ data, zone = null, onPick, mediaBase = '', height =
</div>
)
}
const covered = coveredAreas(plan.items, placed, i => i.id)
// the scale on screen now: a fit is worked out from the space there is
const fitWidth = size.width ? size.width / plan.width : 1
const fitAll = size.width && size.height ? Math.min(size.width / plan.width, size.height / plan.height) : fitWidth
@@ -113,7 +114,7 @@ export function FloorView({ data, zone = null, onPick, mediaBase = '', height =
<svg viewBox={`0 0 ${plan.width} ${plan.height}`} role="img" aria-label={plan.name}
style={{ display: 'block', margin: zoom === 'all' ? '0 auto' : undefined, width: `${Math.max(1, plan.width * scale)}px`, height: `${Math.max(1, plan.height * scale)}px`, touchAction: 'pan-x pan-y pinch-zoom' }}>
<Floor plan={plan} mediaBase={mediaBase} />
{plan.items.map(i => <Item key={i.id} item={i} label={t('floorMap.bar')} />)}
{plan.items.map(i => <Item key={i.id} item={i} label={t('floorMap.bar')} corner={covered.has(i.id)} />)}
{placed.map(table => (
<TableShape key={table.id} table={table} now={now} role="button" tabIndex={0} style={{ cursor: 'pointer' }}
aria-label={`${table.name}: ${t(`floorMap.state.${toneOf(table)}`)}`} data-testid="floor-table"
+17 -7
View File
@@ -1,7 +1,7 @@
// The pieces of a floor plan as SVG (plan step 6.8): the floor (outline, grid, background
// picture), the walls / bar / labels / areas, and a table with its chairs and what it shows.
// Colours are @xenia/ui tokens (CSS variables), so the same drawing works in every app.
import { chairs, durationText, outlineOf, peopleText, pointsAttr, TONES, toneOf } from './geometry.js'
import { chairs, durationText, itemFontSize, outlineOf, peopleText, pointsAttr, TONES, toneOf } from './geometry.js'
/** The floor: background picture, the floor's shape, and the grid (when asked). */
export function Floor({ plan, showGrid = false, mediaBase = '' }) {
@@ -31,25 +31,35 @@ export function Floor({ plan, showGrid = false, mediaBase = '' }) {
const ITEM_LOOK = {
wall: { fill: 'var(--x-ink-2)', stroke: 'none' },
bar: { fill: 'var(--x-surface-3)', stroke: 'var(--x-ink-3)' },
label: { fill: 'none', stroke: 'none' },
label: { fill: 'transparent', stroke: 'none' }, // transparent, not none: a label can be clicked
area: { fill: 'var(--x-surface-2)', stroke: 'var(--x-line-strong)', dash: '8 6' },
}
/** A wall, the bar, a label or an area. */
export function Item({ item, selected = false, label, ...rest }) {
/**
* A wall, the bar, a label or an area. An area may have a colour (drawn see-through, 2026-11-20);
* `corner`: its name is covered by tables, so it shows in the top-left corner as well.
*/
export function Item({ item, selected = false, label, corner = false, ...rest }) {
const look = ITEM_LOOK[item.kind] ?? ITEM_LOOK.area
const w = item.width
const h = item.height
const text = item.text || (item.kind === 'bar' ? label : '')
const colour = item.kind === 'area' && item.color ? item.color : null
const fs = text ? itemFontSize(item, text) : 0
return (
<g transform={`translate(${item.x} ${item.y}) rotate(${item.rotation || 0})`} {...rest}>
<rect x={-w / 2} y={-h / 2} width={w} height={h} rx={item.kind === 'wall' ? 2 : 8}
fill={look.fill} stroke={selected ? 'var(--x-accent)' : look.stroke} strokeWidth={selected ? 4 : 2} strokeDasharray={selected ? undefined : look.dash} />
fill={colour ?? look.fill} fillOpacity={colour ? 0.3 : undefined}
stroke={selected ? 'var(--x-accent)' : colour ?? look.stroke} strokeOpacity={colour && !selected ? 0.9 : undefined}
strokeWidth={selected ? 4 : 2} strokeDasharray={selected ? undefined : look.dash} />
{item.kind === 'label' && selected && <rect x={-w / 2} y={-h / 2} width={w} height={h} fill="none" stroke="var(--x-accent)" strokeWidth="2" strokeDasharray="6 4" />}
{text && (
<text x="0" y="0" textAnchor="middle" dominantBaseline="central" fill="var(--x-ink-2)" pointerEvents="none"
fontSize={Math.max(12, Math.min(28, h * 0.5, (w / Math.max(text.length, 1)) * 1.6))} fontWeight="600"
transform={`rotate(${-(item.rotation || 0)})`}>{text}</text>
fontSize={fs} fontWeight="600" transform={`rotate(${-(item.rotation || 0)})`}>{text}</text>
)}
{text && corner && (
<text x={-w / 2 + 10} y={-h / 2 + 10 + Math.min(16, fs) / 2} dominantBaseline="central" fill="var(--x-ink-2)" pointerEvents="none"
fontSize={Math.min(16, fs)} fontWeight="700" data-testid="floor-area-corner">{text}</text>
)}
</g>
)
+73
View File
@@ -137,3 +137,76 @@ export function toPlan(svg, clientX, clientY) {
const vb = svg.viewBox.baseVal
return [vb.x + ((clientX - r.left) / r.width) * vb.width, vb.y + ((clientY - r.top) / r.height) * vb.height]
}
// ── 2026-11-20: grid resolution, area colours, adding corners on an edge, resizing ──────────
/** The grid's resolution: a name for each cell size (ultra high = small cells, very precise). */
export const GRID_LEVELS = [['ultraHigh', 20], ['high', 40], ['normal', 50], ['low', 80], ['veryLow', 100]]
/** The colours an area can have (pastel; drawn see-through). Data, like the categories' colours. */
export const AREA_COLOURS = ['#93c5fd', '#86efac', '#fcd34d', '#f9a8d4', '#c4b5fd', '#fdba74', '#5eead4', '#cbd5e1']
/** The point of segment a–b nearest to p, and how far it is: { x, y, d, t }. */
export function nearestOnSegment([ax, ay], [bx, by], [px, py]) {
const dx = bx - ax
const dy = by - ay
const len = dx * dx + dy * dy
const t = len ? clamp(((px - ax) * dx + (py - ay) * dy) / len, 0, 1) : 0
const x = ax + t * dx
const y = ay + t * dy
return { x, y, t, d: Math.hypot(px - x, py - y) }
}
/** The floor's edge nearest to a point: { index (the corner it starts at), x, y, d }. */
export function nearestEdge(points, p) {
let best = null
points.forEach((a, i) => {
const n = nearestOnSegment(a, points[(i + 1) % points.length], p)
if (!best || n.d < best.d) best = { index: i, ...n }
})
return best
}
/** A corner added on edge `i` (after corner i) at a point (on the grid when there is one). */
export function addCornerAt(points, i, x, y, plan) {
const grid = plan?.grid_on ? plan.grid_size : 0
const out = [...points]
out.splice(i + 1, 0, [clamp(snap(x, grid), 0, plan?.width ?? x), clamp(snap(y, grid), 0, plan?.height ?? y)])
return out
}
/** Drag a side or corner of an unrotated box: handle is a mix of 'n' 's' 'e' 'w'; the opposite side stays. */
export function resizeBox(thing, handle, px, py, plan, min = 20) {
const grid = plan?.grid_on ? plan.grid_size : 0
let left = thing.x - thing.width / 2
let right = thing.x + thing.width / 2
let top = thing.y - thing.height / 2
let bottom = thing.y + thing.height / 2
const at = v => (grid ? snap(v, grid) : Math.round(v))
if (handle.includes('w')) left = Math.min(at(clamp(px, 0, plan.width)), right - min)
if (handle.includes('e')) right = Math.max(at(clamp(px, 0, plan.width)), left + min)
if (handle.includes('n')) top = Math.min(at(clamp(py, 0, plan.height)), bottom - min)
if (handle.includes('s')) bottom = Math.max(at(clamp(py, 0, plan.height)), top + min)
return { x: (left + right) / 2, y: (top + bottom) / 2, width: right - left, height: bottom - top }
}
/** The size of an item's text (as Item draws it). */
export const itemFontSize = (item, text) => Math.max(12, Math.min(28, item.height * 0.5, (item.width / Math.max(text.length, 1)) * 1.6))
const boxOf = t => ({ l: t.x - (t.width || 80) / 2, r: t.x + (t.width || 80) / 2, t: t.y - (t.height || 80) / 2, b: t.y + (t.height || 80) / 2 })
const overlaps = (a, b) => a.l < b.r && b.l < a.r && a.t < b.b && b.t < a.b
/** The keys / ids of the areas whose name is covered by a table or another thing: those show
* their name in a corner too. things: the plan's items; tables: placed tables. */
export function coveredAreas(items, tables, keyOf = i => i.key ?? i.id) {
const out = new Set()
for (const a of items) {
if (a.kind !== 'area' || !a.text) continue
const fs = itemFontSize(a, a.text)
const w = a.text.length * fs * 0.6
const label = { l: a.x - w / 2, r: a.x + w / 2, t: a.y - fs * 0.6, b: a.y + fs * 0.6 }
const others = [...tables, ...items.filter(i => i !== a && i.kind !== 'area')]
if (others.some(o => overlaps(label, boxOf(o)))) out.add(keyOf(a))
}
return out
}
+17 -3
View File
@@ -2585,10 +2585,10 @@
"tableCount_one": "{{count}} τραπέζι",
"tableCount_other": "{{count}} τραπέζια",
"grid": "Πλέγμα",
"gridSize": "Μέγεθος πλέγματος",
"gridSize": "Ανάλυση πλέγματος",
"gridCell": "Κελιά των {{size}}",
"editShape": "Αλλαγή σχήματος χώρου",
"shapeHint": "Σύρετε τις γωνίες για να πάρει ο χώρος το πραγματικό του σχήμα (Γ, βεράντα…). Επιλέξτε μια γωνία για να προσθέσετε μία μετά από αυτή ή να την αφαιρέσετε.",
"shapeHint": "Σύρετε μια γωνία για να τη μετακινήσετε. Πάνω σε μια πλευρά φαίνεται ένα +: πατήστε εκεί για νέα γωνία (και σύρετέ τη). Σταθείτε σε μια γωνία για να την αφαιρέσετε.",
"shapeTitle": "Το σχήμα του χώρου",
"cornerCount_one": "{{count}} γωνία",
"cornerCount_other": "{{count}} γωνίες",
@@ -2632,7 +2632,21 @@
"rotateLeft": "Στροφή αριστερά 15°",
"rotateRight": "Στροφή δεξιά 15°",
"takeOff": "Βγάλτε το από την κάτοψη",
"removeThing": "Αφαίρεση"
"removeThing": "Αφαίρεση",
"gridLevels": {
"ultraHigh": "Πολύ υψηλή",
"high": "Υψηλή",
"normal": "Κανονική",
"low": "Χαμηλή",
"veryLow": "Πολύ χαμηλή"
},
"fit": "Προσαρμογή",
"fitWidth": "Στο πλάτος",
"fitAll": "Όλο το σχέδιο",
"shapeHowTo": "Ένας χώρος έχει τουλάχιστον 3 γωνίες.",
"colour": "Χρώμα",
"noColour": "Κανένα",
"areaResizeHint": "Σύρετε τις λαβές στις πλευρές και τις γωνίες για να αλλάξετε το μέγεθος."
},
"orders": {
"back": "Πίσω",
+18 -4
View File
@@ -2585,15 +2585,15 @@
"tableCount_one": "{{count}} table",
"tableCount_other": "{{count}} tables",
"grid": "Grid",
"gridSize": "Grid size",
"gridSize": "Grid resolution",
"gridCell": "Cells of {{size}}",
"editShape": "Edit the floor's shape",
"shapeHint": "Drag the corners to give the floor its real shape (an L, a terrace…). Pick a corner to add one after it or remove it.",
"shapeHint": "Drag a corner to move it. On an edge a + shows: press there to add a corner (and drag it). Rest on a corner to remove it.",
"shapeTitle": "The floor's shape",
"cornerCount_one": "{{count}} corner",
"cornerCount_other": "{{count}} corners",
"addCorner": "Add a corner after it",
"removeCorner": "Remove the corner",
"removeCorner": "Remove this corner",
"rectangle": "Back to a rectangle",
"canvas": "The floor plan: drag the tables and things; arrow keys move the selected one",
"keysHint": "Arrow keys move what's selected (one grid cell, or 5; with Shift 1), Delete takes it off, Escape lets go.",
@@ -2632,7 +2632,21 @@
"rotateLeft": "Turn left 15°",
"rotateRight": "Turn right 15°",
"takeOff": "Take it off the plan",
"removeThing": "Remove"
"removeThing": "Remove",
"gridLevels": {
"ultraHigh": "Ultra high",
"high": "High",
"normal": "Normal",
"low": "Low",
"veryLow": "Very low"
},
"fit": "Fit",
"fitWidth": "Fit width",
"fitAll": "Whole plan",
"shapeHowTo": "A floor has at least 3 corners.",
"colour": "Colour",
"noColour": "None",
"areaResizeHint": "Drag the handles on its sides and corners to resize it."
},
"orders": {
"back": "Back",