diff --git a/docs/README.md b/docs/README.md index a4834fa..ac425f5 100644 --- a/docs/README.md +++ b/docs/README.md @@ -49,6 +49,7 @@ The manager calls the API **same-origin, with relative paths**. The waiter app r | `install.sh` | Site installer. **Writes its own copy of the proxy config.** | | `docker-compose.yml` / `docker-compose.dev.yml` | Prod (pull images) / dev override (build + expose ports) | | `package.json`, `package-lock.json`, `packages/` | **npm workspace** for the frontends (D-15): `waiter_pwa`, `manager_dashboard` and the shared `packages/{ui,i18n,api,access}` (imported from source, no build step). One lockfile at this root; the apps have none of their own. | +| `packages/ui/` | Shared design tokens, Tailwind preset and base components (CS-16). Visual check: `npm run dev:manager` → `/ui-gallery` | | `.dockerignore` | The frontend images build with **`client-services/` as context** (`-f waiter_pwa/Dockerfile .`), so this file decides what Docker sees. The backend still builds from `local_backend/`. | --- @@ -144,7 +145,7 @@ The native plugins (`@capacitor/*`, `@capgo/*`) are pinned to **exact** versions ## Testing Automated tests cover the native-app/LAN work and licensing. See **[tests/e2e/README.md](../tests/e2e/README.md)**. -- **Unit (seconds):** `python -m pytest tests -q` in `local_backend/`, and `npm test` in `waiter_pwa/`. +- **Unit (seconds):** `python -m pytest tests -q` in `local_backend/`, `npm test` in `waiter_pwa/`, and `npm test -w @xenia/ui` at the workspace root. - **End-to-end:** `node run-all.mjs` in `tests/e2e/`. That covers install.sh, licensing with a real cloud, browser modes, and the Android emulator suites. `--no-android` skips the emulator. **CS-11. Tests follow the code.** When you change something a test covers (licensing, LAN IP, TLS, pairing, rediscovery, bundles, install.sh, the proxy config), run its suite and update the test in the same commit. Run `node run-all.mjs` before every release. @@ -160,6 +161,9 @@ Use `core.access.deps.require("..")` (or `require_any`, `p Paired devices (D-8, `routers/devices.py`, `core/access/context.py`) send `X-Xenia-Device: `; a device may only use keys matching its app's `DeviceApp.scope` (plus `.*`) and only reach routes of those modules. A new device app with user logins must declare `.access`. Device-only endpoints use `require_device("")`; users log in on a device with `POST /api/auth/login {client: "terminal"}`, and that session only works together with the device's header. Manager override (D-10, `core/access/override.py`): mark a key `Perm(..., overridable=True)` and a user without it gets `access.override_possible`; the client gets a manager's one-time token from `POST /api/access/override {key, username, pin}` and retries with `X-Xenia-Override`. `require()` routes handle it in `check()`; an endpoint with its own rule calls `require_override(request, db, key, target="order:12")` where the rule says no, **after** its other checks (a used token is spent). +**CS-16. Shared UI lives in `packages/ui` and never restyles an app** (branch `platform-v2`, D-15, §9). +Design tokens are CSS variables prefixed `--x-` (`packages/ui/src/tokens.css`), components use `.x-*` classes (`src/components.css`); neither file has element selectors, resets or anything that applies outside `.x-*` (the waiter keeps its own `--bg`/`--text`…; the manager's Tailwind classes keep their meaning). Theme comes from `data-theme` (`light`/`dark`/`system`) and `data-venue-theme` on ``. Tailwind apps use `@xenia/ui/tailwind-preset` (adds `bg-surface`, `text-ink-2`, `rounded-control`… only). A colour change must pass `npm test -w @xenia/ui` (WCAG AA for every pair the components use, every venue theme, light and dark). Components take their visible text as props with English defaults until `@xenia/i18n` (2.4). New components get a section in `packages/ui/gallery/Gallery.jsx` (dev-only `/ui-gallery` in the manager) and checks in `tests/e2e/ui.mjs`. + **CS-15. Support access is a challenge code, never a password** (branch `platform-v2`, D-16). There is no master account. A site's `SUPPORT_SECRET` (env only) comes from `tools/support_code.py --site-secret `, derived from the builder's master key in `%USERPROFILE%\.xenia\support_master_key.txt` (outside the repo, back it up). The derivation lives in `local_backend/core/support_codes.py` (stdlib only, the tool loads it by path) and is re-implemented for the e2e suites in `tests/e2e/lib/support.mjs`; `tests/test_support.py` pins a vector both must match. The e2e backends log in through support access (`login()` in `lib/proc.mjs`). diff --git a/manager_dashboard/package.json b/manager_dashboard/package.json index 7790b2b..71279e4 100644 --- a/manager_dashboard/package.json +++ b/manager_dashboard/package.json @@ -10,6 +10,7 @@ }, "dependencies": { "@tanstack/react-query": "^5.62.0", + "@xenia/ui": "^0.0.0", "axios": "^1.7.9", "lucide-react": "^1.14.0", "qrcode.react": "^4.2.0", diff --git a/manager_dashboard/src/App.jsx b/manager_dashboard/src/App.jsx index 5451d60..43d721f 100644 --- a/manager_dashboard/src/App.jsx +++ b/manager_dashboard/src/App.jsx @@ -1,4 +1,4 @@ -import { useEffect, useState } from 'react' +import { lazy, Suspense, useEffect, useState } from 'react' import { BrowserRouter, Routes, Route, Navigate, useNavigate } from 'react-router-dom' import useAuthStore from './store/authStore' import AppLayout from './layouts/AppLayout' @@ -54,6 +54,9 @@ import SettingsPage from './pages/Settings/SettingsPage' import NotesPage from './pages/NotesPage' import PermissionGuard from './components/PermissionGuard' +// @xenia/ui visual check page, dev builds only (left out of production bundles) +const UiGallery = import.meta.env.DEV ? lazy(() => import('@xenia/ui/gallery')) : null + function Spinner() { return (
@@ -109,6 +112,7 @@ export default function App() { } /> + {UiGallery && } />} } /> } /> diff --git a/manager_dashboard/src/main.jsx b/manager_dashboard/src/main.jsx index 4d57aa5..d913bb7 100644 --- a/manager_dashboard/src/main.jsx +++ b/manager_dashboard/src/main.jsx @@ -3,6 +3,7 @@ import ReactDOM from 'react-dom/client' import { QueryClient, QueryClientProvider } from '@tanstack/react-query' import { Toaster } from 'react-hot-toast' import App from './App.jsx' +import '@xenia/ui/styles.css' // shared tokens + component styles (.x-*), no global rules import './index.css' const queryClient = new QueryClient({ diff --git a/manager_dashboard/tailwind.config.js b/manager_dashboard/tailwind.config.js index 732c650..923dce7 100644 --- a/manager_dashboard/tailwind.config.js +++ b/manager_dashboard/tailwind.config.js @@ -1,5 +1,9 @@ +import xenia from '@xenia/ui/tailwind-preset' + /** @type {import('tailwindcss').Config} */ export default { + // Shared design tokens (bg-surface, text-ink-2, rounded-control…); adds names only + presets: [xenia], content: ['./index.html', './src/**/*.{js,jsx}'], theme: { extend: { diff --git a/package-lock.json b/package-lock.json index b08190f..88a7893 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,6 +16,7 @@ "version": "0.0.0", "dependencies": { "@tanstack/react-query": "^5.62.0", + "@xenia/ui": "^0.0.0", "axios": "^1.7.9", "lucide-react": "^1.14.0", "qrcode.react": "^4.2.0", @@ -2880,7 +2881,11 @@ }, "packages/ui": { "name": "@xenia/ui", - "version": "0.0.0" + "version": "0.0.0", + "peerDependencies": { + "react": "^19.0.0", + "react-dom": "^19.0.0" + } }, "waiter_pwa": { "version": "0.0.0", @@ -2890,6 +2895,7 @@ "@capacitor/core": "8.5.2", "@capgo/capacitor-updater": "8.51.25", "@tanstack/react-query": "^5.100.11", + "@xenia/ui": "^0.0.0", "axios": "^1.15.1", "dexie": "^4.4.2", "qr-scanner": "^1.4.2", diff --git a/packages/ui/gallery/Gallery.jsx b/packages/ui/gallery/Gallery.jsx new file mode 100644 index 0000000..8c411a2 --- /dev/null +++ b/packages/ui/gallery/Gallery.jsx @@ -0,0 +1,167 @@ +// Visual check page for @xenia/ui (plan step 2.3). Dev builds only: the manager mounts +// it at /ui-gallery under `import.meta.env.DEV` (moves to the terminal dev build in 3.1). +// Sets data-theme / data-venue-theme on while open and restores them on leave. +import { useEffect, useState } from 'react' +import { + Button, Dialog, EmptyState, Field, IconButton, InfoTip, Input, PinPad, Select, Sheet, + Spinner, Switch, Textarea, ToastProvider, useToast, +} from '../src/index.js' +import '../src/styles.css' + +const THEMES = ['light', 'dark', 'system'] +const VENUES = ['teal', 'amber', 'blue', 'violet', 'rose'] + +const Plus = () => ( + +) +const Trash = () => ( + +) +const Inbox = () => ( + +) + +const page = { + minHeight: '100vh', background: 'var(--x-canvas)', color: 'var(--x-ink)', + fontFamily: 'var(--x-font-sans)', fontSize: 'var(--x-text-body)', padding: 'var(--x-space-6)', +} +const card = { + background: 'var(--x-surface)', border: '1px solid var(--x-line)', borderRadius: 'var(--x-radius-card)', + boxShadow: 'var(--x-shadow-raised)', padding: 'var(--x-space-6)', marginBottom: 'var(--x-space-6)', +} +const row = { display: 'flex', flexWrap: 'wrap', gap: 'var(--x-space-3)', alignItems: 'center' } +const h2 = { margin: '0 0 var(--x-space-4)', fontSize: 'var(--x-text-title)', fontWeight: 600 } + +function Section({ title, children }) { + return

{title}

{children}
+} + +function Demo() { + const toast = useToast() + const [theme, setTheme] = useState('light') + const [venue, setVenue] = useState('teal') + const [dialog, setDialog] = useState(false) + const [locked, setLocked] = useState(false) + const [sheet, setSheet] = useState(null) + const [on, setOn] = useState(true) + const [off, setOff] = useState(false) + const [name, setName] = useState('') + const [lang, setLang] = useState('el') + const [pinError, setPinError] = useState('') + const [unlocked, setUnlocked] = useState('') + + useEffect(() => { + const html = document.documentElement + const before = [html.getAttribute('data-theme'), html.getAttribute('data-venue-theme')] + html.setAttribute('data-theme', theme) + html.setAttribute('data-venue-theme', venue) + return () => { + before[0] == null ? html.removeAttribute('data-theme') : html.setAttribute('data-theme', before[0]) + before[1] == null ? html.removeAttribute('data-venue-theme') : html.setAttribute('data-venue-theme', before[1]) + } + }, [theme, venue]) + + const checkPin = pin => new Promise((resolve, reject) => setTimeout(() => { + if (pin === '1234') { setPinError(''); setUnlocked(`Unlocked at ${new Date().toLocaleTimeString()}`); resolve() } + else { setPinError('Wrong PIN'); reject(new Error('wrong')) } + }, 500)) + + return ( +
+
+

@xenia/ui gallery

+
+ setVenue(e.target.value)} options={VENUES.map(v => ({ value: v, label: `Venue: ${v}` }))} /> +
+
+ +
+
+ + + + + + + + + + +
+
+ +
+
+ + + + + + + +
+ setDialog(false)} title="Delete product?" + description="Freddo espresso will be removed from every category." + footer={<>} + > + + + setLocked(false)}>Done} + > + Escape and the backdrop don't close this one. + + setSheet(null)} title="Move order" + footer={} + > + setName(e.target.value)} placeholder="e.g. Freddo espresso" /> + + + + + The language staff screens start in. Each person can change their own.}> +