Initial import with Gitea Docker publishing
All checks were successful
Docker-Image veröffentlichen / publish (push) Successful in 1m44s
All checks were successful
Docker-Image veröffentlichen / publish (push) Successful in 1m44s
This commit is contained in:
commit
27924e55e9
9
.dockerignore
Normal file
9
.dockerignore
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
node_modules
|
||||||
|
styled-system
|
||||||
|
dist
|
||||||
|
.git
|
||||||
|
.env
|
||||||
|
.env.*
|
||||||
|
data
|
||||||
|
test-results
|
||||||
|
playwright-report
|
||||||
5
.env.example
Normal file
5
.env.example
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
ADMIN_USERNAME=admin
|
||||||
|
ADMIN_PASSWORD_HASH=
|
||||||
|
BIND_ADDRESS=127.0.0.1
|
||||||
|
HTTP_PORT=8090
|
||||||
|
COOKIE_SECURE=false
|
||||||
47
.gitea/workflows/publish-image.yml
Normal file
47
.gitea/workflows/publish-image.yml
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
name: Docker-Image veröffentlichen
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [main]
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
env:
|
||||||
|
REGISTRY: git.jfritzsche.de
|
||||||
|
IMAGE: git.jfritzsche.de/jf/syncova-links
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
publish:
|
||||||
|
if: github.ref == 'refs/heads/main'
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
timeout-minutes: 20
|
||||||
|
steps:
|
||||||
|
- name: Quellcode auschecken
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
|
|
||||||
|
- name: Docker-Image bauen
|
||||||
|
run: |
|
||||||
|
set -eu
|
||||||
|
docker build --pull \
|
||||||
|
--label "org.opencontainers.image.source=https://git.jfritzsche.de/jf/syncova-links" \
|
||||||
|
--label "org.opencontainers.image.revision=${GITHUB_SHA}" \
|
||||||
|
--tag "${IMAGE}:sha-${GITHUB_SHA}" \
|
||||||
|
--tag "${IMAGE}:latest" .
|
||||||
|
|
||||||
|
- name: Image in der Gitea-Registry veröffentlichen
|
||||||
|
env:
|
||||||
|
REGISTRY_KEY: ${{ secrets.REGISTRY_KEY }}
|
||||||
|
run: |
|
||||||
|
set -eu
|
||||||
|
: "${REGISTRY_KEY:?Das Actions-Secret REGISTRY_KEY fehlt}"
|
||||||
|
DOCKER_CONFIG="$(mktemp -d)"
|
||||||
|
export DOCKER_CONFIG
|
||||||
|
cleanup() {
|
||||||
|
docker logout "${REGISTRY}" >/dev/null 2>&1 || true
|
||||||
|
rm -rf -- "${DOCKER_CONFIG}"
|
||||||
|
}
|
||||||
|
trap cleanup EXIT
|
||||||
|
printf '%s' "${REGISTRY_KEY}" | docker login "${REGISTRY}" --username jf --password-stdin
|
||||||
|
docker push "${IMAGE}:sha-${GITHUB_SHA}"
|
||||||
|
docker push "${IMAGE}:latest"
|
||||||
9
.gitignore
vendored
Normal file
9
.gitignore
vendored
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
node_modules/
|
||||||
|
styled-system/
|
||||||
|
dist/
|
||||||
|
.env
|
||||||
|
.env.*
|
||||||
|
!.env.example
|
||||||
|
/data/
|
||||||
|
test-results/
|
||||||
|
playwright-report/
|
||||||
22
Dockerfile
Normal file
22
Dockerfile
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
FROM node:24-bookworm-slim AS build
|
||||||
|
WORKDIR /app
|
||||||
|
COPY package.json package-lock.json ./
|
||||||
|
RUN npm ci
|
||||||
|
COPY . .
|
||||||
|
RUN npm run build && npm prune --omit=dev
|
||||||
|
|
||||||
|
FROM node:24-bookworm-slim
|
||||||
|
WORKDIR /app
|
||||||
|
ENV NODE_ENV=production PORT=3000 DATA_DIR=/data
|
||||||
|
RUN mkdir /data && chown node:node /data
|
||||||
|
COPY --from=build /app/package.json ./
|
||||||
|
COPY --from=build /app/node_modules ./node_modules
|
||||||
|
COPY --from=build /app/dist ./dist
|
||||||
|
COPY server ./server
|
||||||
|
COPY scripts/hash-password.js ./scripts/hash-password.js
|
||||||
|
USER node
|
||||||
|
VOLUME ["/data"]
|
||||||
|
EXPOSE 3000
|
||||||
|
HEALTHCHECK --interval=10s --timeout=3s --start-period=5s \
|
||||||
|
CMD ["node", "-e", "fetch('http://127.0.0.1:3000/healthz').then(r=>process.exit(r.ok?0:1)).catch(()=>process.exit(1))"]
|
||||||
|
CMD ["node", "server/index.js"]
|
||||||
61
README.md
Normal file
61
README.md
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
# syncova-links
|
||||||
|
|
||||||
|
Selbst gehostete Linksammlungen mit einer öffentlichen Seite pro Abteilung. Die Startseite unter `/` listet alle Abteilungen und verlinkt ihre Seiten. Die Oberfläche ist auf Deutsch und verwendet Park UI. Beim ersten Start sind keine Abteilungen eingerichtet.
|
||||||
|
|
||||||
|
## Start mit Docker
|
||||||
|
|
||||||
|
1. Kopiere `.env.example` nach `.env` und setze `ADMIN_USERNAME`.
|
||||||
|
2. Erzeuge den Passwort-Hash im Projektordner. Das Skript fragt das Passwort verdeckt ab.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
node scripts/hash-password.js
|
||||||
|
```
|
||||||
|
|
||||||
|
Wenn Node.js lokal fehlt, kannst du denselben Befehl im Container ausführen.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
docker run --rm -it -v "${PWD}:/app:ro" -w /app node:24-bookworm-slim node scripts/hash-password.js
|
||||||
|
```
|
||||||
|
|
||||||
|
3. Kopiere die vollständige Ausgabe einschließlich `scrypt:` in `ADMIN_PASSWORD_HASH` in deiner `.env`. Starte die App.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
docker compose up -d --build
|
||||||
|
```
|
||||||
|
|
||||||
|
4. Öffne [http://localhost:8090](http://localhost:8090), melde dich an und lege eine Abteilung an. Deren öffentlicher Pfad lautet beispielsweise `/it`.
|
||||||
|
|
||||||
|
Die App bindet standardmäßig an `127.0.0.1`. `BIND_ADDRESS` und `HTTP_PORT` steuern die Veröffentlichung des Container-Ports. Für den Zugriff über einen HTTPS-Reverse-Proxy leite den Verkehr an Port 8090 weiter und setze `COOKIE_SECURE=true`. Nach Änderungen an der Laufzeitkonfiguration übernimmt `docker compose up -d` die neuen Werte.
|
||||||
|
|
||||||
|
Das Compose-Volume `links-data` enthält die SQLite-Datenbank samt Icons. `docker compose restart` und `docker compose down` erhalten das Volume. `docker compose down --volumes` löscht es. Für eine konsistente Dateisicherung stoppe den Container vor dem Kopieren des Volumes. Admin-Sitzungen laufen nach zwölf Stunden ab und enden beim Container-Neustart.
|
||||||
|
|
||||||
|
## Docker-Image aus Gitea
|
||||||
|
|
||||||
|
Der Gitea-Workflow baut das Image bei jedem Push auf `main` und veröffentlicht die Tags `latest` und `sha-<commit>`. Er verwendet das Repository-Secret `REGISTRY_KEY` für einen Registry-Token des Kontos `jf` mit Schreibzugriff auf Packages.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
docker pull git.jfritzsche.de/jf/syncova-links:latest
|
||||||
|
```
|
||||||
|
|
||||||
|
## Inhalte pflegen
|
||||||
|
|
||||||
|
Über das Mond- oder Sonnensymbol in der Kopfzeile wechselst du zwischen Hell- und Dunkelmodus. Bis zur ersten Auswahl folgt die App der Systemeinstellung. Die Auswahl gilt für diesen Browser.
|
||||||
|
|
||||||
|
- In **Abteilungen** kannst du Seiten anlegen, öffnen und löschen. Name, URL-Pfad und Standardansicht findest du unter **Seiteneinstellungen** auf der jeweiligen Seite. Beim Ändern des URL-Pfads wechselt die öffentliche Adresse.
|
||||||
|
- **Übernehmen** legt die Änderung im Bearbeitungsmodus ab. **Seite speichern** veröffentlicht alle Änderungen der Seite gemeinsam. Löscht du eine Gruppe, werden ihre Links zu den ungruppierten Links verschoben.
|
||||||
|
- Ziehe einen Griff auf ein markiertes Ablageziel. Mit der Tastatur aktivierst du den Griff per Eingabe- oder Leertaste, wechselst mit den Pfeiltasten zwischen Zielpositionen und bestätigst mit Eingabe oder Leertaste. Escape bricht ab. Auf Touchscreens kannst du Griff und Ablageziel antippen.
|
||||||
|
- Icons werden als PNG lokal gespeichert. Beim Upload sind PNG, JPEG, WebP, GIF und ICO bis 512 KB zulässig. Der Favicon-Abruf unterstützt dieselben Formate und setzt eine öffentliche HTTP(S)-Adresse voraus. Ohne eigenes Icon erhält ein Link das Standard-Icon.
|
||||||
|
|
||||||
|
## Abnahme ausführen
|
||||||
|
|
||||||
|
Der Browser-Test baut das Docker-Image, startet ein eigenes Compose-Projekt mit frischem Volume, prüft die Verwaltung und startet den Container neu. Er räumt seine Testressourcen anschließend auf. Vorhandene Daten werden durch das separate Projekt nicht verwendet. Der Test benötigt Docker Compose, Node.js 20.19.4 oder neuer und eine Internetverbindung für den Favicon-Abruf.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
npm ci
|
||||||
|
npx playwright install chromium
|
||||||
|
npm run test:e2e
|
||||||
|
```
|
||||||
|
|
||||||
|
Alternativ verwendet `PLAYWRIGHT_CHANNEL=chrome` oder `PLAYWRIGHT_CHANNEL=msedge` einen lokal installierten Browser.
|
||||||
|
|
||||||
|
Die Park-UI-Komponenten und Theme-Rezepte stammen aus der offiziellen [Park-UI-Registry](https://park-ui.com/docs/installation). Ihre MIT-Lizenz liegt unter `src/theme/LICENSE.park-ui`.
|
||||||
16
compose.yaml
Normal file
16
compose.yaml
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
services:
|
||||||
|
links:
|
||||||
|
build: .
|
||||||
|
init: true
|
||||||
|
restart: unless-stopped
|
||||||
|
ports:
|
||||||
|
- "${BIND_ADDRESS:-127.0.0.1}:${HTTP_PORT:-8090}:3000"
|
||||||
|
environment:
|
||||||
|
ADMIN_USERNAME: ${ADMIN_USERNAME:?ADMIN_USERNAME in .env setzen}
|
||||||
|
ADMIN_PASSWORD_HASH: ${ADMIN_PASSWORD_HASH:?ADMIN_PASSWORD_HASH in .env setzen}
|
||||||
|
COOKIE_SECURE: ${COOKIE_SECURE:-false}
|
||||||
|
volumes:
|
||||||
|
- links-data:/data
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
links-data:
|
||||||
14
index.html
Normal file
14
index.html
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="de">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
|
<meta name="color-scheme" content="light dark" />
|
||||||
|
<meta name="theme-color" content="#f6f7f2" />
|
||||||
|
<title>syncova-links</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="root"></div>
|
||||||
|
<script type="module" src="/src/main.jsx"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
7274
package-lock.json
generated
Normal file
7274
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
38
package.json
Normal file
38
package.json
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
{
|
||||||
|
"name": "syncova-links",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"scripts": {
|
||||||
|
"build": "panda codegen && vite build",
|
||||||
|
"start": "node server/index.js",
|
||||||
|
"hash-password": "node scripts/hash-password.js",
|
||||||
|
"test:e2e": "node scripts/acceptance.js"
|
||||||
|
},
|
||||||
|
"description": "Selbst gehostete Linksammlungen pro Abteilung",
|
||||||
|
"dependencies": {
|
||||||
|
"@ark-ui/react": "^5.40.0",
|
||||||
|
"@fontsource-variable/dm-sans": "^5.3.0",
|
||||||
|
"cheerio": "^1.2.0",
|
||||||
|
"express": "^5.3.0",
|
||||||
|
"icojs": "^0.23.0",
|
||||||
|
"ipaddr.js": "^2.5.0",
|
||||||
|
"lucide-react": "^1.73.0",
|
||||||
|
"react": "^19.3.1",
|
||||||
|
"react-dom": "^19.3.1",
|
||||||
|
"sharp": "^0.35.5",
|
||||||
|
"zod": "^4.6.7"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@pandacss/dev": "^1.12.2",
|
||||||
|
"@playwright/test": "^1.65.1",
|
||||||
|
"@vitejs/plugin-react": "^5.2.0",
|
||||||
|
"vite": "^7.3.8"
|
||||||
|
},
|
||||||
|
"overrides": {
|
||||||
|
"@ts-morph/common": {
|
||||||
|
"minimatch": "^11.0.1"
|
||||||
|
},
|
||||||
|
"postcss-selector-parser": "^7.1.6"
|
||||||
|
},
|
||||||
|
"type": "module",
|
||||||
|
"private": true
|
||||||
|
}
|
||||||
81
panda.config.ts
Normal file
81
panda.config.ts
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
import { defineConfig } from '@pandacss/dev'
|
||||||
|
import { animationStyles } from './src/theme/animation-styles'
|
||||||
|
import { conditions } from './src/theme/conditions'
|
||||||
|
import { globalCss } from './src/theme/global-css'
|
||||||
|
import { keyframes } from './src/theme/keyframes'
|
||||||
|
import { layerStyles } from './src/theme/layer-styles'
|
||||||
|
import { textStyles } from './src/theme/text-styles'
|
||||||
|
import { colors } from './src/theme/tokens/colors'
|
||||||
|
import { durations } from './src/theme/tokens/durations'
|
||||||
|
import { shadows } from './src/theme/tokens/shadows'
|
||||||
|
import { zIndex } from './src/theme/tokens/z-index'
|
||||||
|
import { jade } from './src/theme/colors/jade'
|
||||||
|
import { sage } from './src/theme/colors/sage'
|
||||||
|
import { red } from './src/theme/colors/red'
|
||||||
|
import { recipes, slotRecipes } from './src/theme/recipes'
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
preflight: true,
|
||||||
|
include: ['./src/**/*.{ts,tsx,js,jsx}'],
|
||||||
|
outdir: 'styled-system',
|
||||||
|
jsxFramework: 'react',
|
||||||
|
globalCss: globalCss.extend,
|
||||||
|
conditions,
|
||||||
|
staticCss: {
|
||||||
|
recipes: { segmentGroup: [{ size: ['sm'] }], button: [{ variant: ['solid', 'outline', 'plain'], size: ['xs', 'sm', 'md'] }] },
|
||||||
|
},
|
||||||
|
plugins: [{
|
||||||
|
name: 'Remove Panda preset colors',
|
||||||
|
hooks: {
|
||||||
|
'preset:resolved': ({ utils, preset, name }) =>
|
||||||
|
name === '@pandacss/preset-panda'
|
||||||
|
? utils.omit(preset, ['theme.tokens.colors', 'theme.semanticTokens.colors'])
|
||||||
|
: preset,
|
||||||
|
},
|
||||||
|
}],
|
||||||
|
theme: {
|
||||||
|
extend: {
|
||||||
|
animationStyles, keyframes, layerStyles, recipes, slotRecipes, textStyles,
|
||||||
|
tokens: { colors, durations, zIndex },
|
||||||
|
semanticTokens: {
|
||||||
|
colors: {
|
||||||
|
jade: {
|
||||||
|
...jade,
|
||||||
|
solid: {
|
||||||
|
bg: {
|
||||||
|
DEFAULT: { value: { _light: '#176449', _dark: '#8cdbb4' } },
|
||||||
|
hover: { value: { _light: '#104f3a', _dark: '#abe7ca' } },
|
||||||
|
},
|
||||||
|
fg: { DEFAULT: { value: { _light: '#ffffff', _dark: '#12281e' } } },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
gray: sage,
|
||||||
|
red: {
|
||||||
|
...red,
|
||||||
|
solid: {
|
||||||
|
bg: {
|
||||||
|
DEFAULT: { value: { _light: '#b12635', _dark: '#f48e97' } },
|
||||||
|
hover: { value: { _light: '#941d2a', _dark: '#ffadb4' } },
|
||||||
|
},
|
||||||
|
fg: { DEFAULT: { value: { _light: '#ffffff', _dark: '#321416' } } },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
canvas: { value: 'var(--canvas)' },
|
||||||
|
fg: {
|
||||||
|
DEFAULT: { value: '{colors.gray.12}' },
|
||||||
|
muted: { value: '{colors.gray.11}' },
|
||||||
|
subtle: { value: '{colors.gray.10}' },
|
||||||
|
},
|
||||||
|
border: { value: '{colors.gray.5}' },
|
||||||
|
error: { value: '{colors.red.11}' },
|
||||||
|
},
|
||||||
|
radii: {
|
||||||
|
l1: { value: '6px' },
|
||||||
|
l2: { value: '9px' },
|
||||||
|
l3: { value: '12px' },
|
||||||
|
},
|
||||||
|
shadows,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
14
playwright.config.js
Normal file
14
playwright.config.js
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
import { defineConfig } from '@playwright/test'
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
testDir: './tests',
|
||||||
|
timeout: 100_000,
|
||||||
|
reporter: 'list',
|
||||||
|
use: {
|
||||||
|
browserName: 'chromium',
|
||||||
|
channel: process.env.PLAYWRIGHT_CHANNEL || undefined,
|
||||||
|
baseURL: process.env.SYNCOVA_TEST_URL,
|
||||||
|
trace: 'retain-on-failure',
|
||||||
|
screenshot: 'only-on-failure',
|
||||||
|
},
|
||||||
|
})
|
||||||
1
postcss.config.cjs
Normal file
1
postcss.config.cjs
Normal file
@ -0,0 +1 @@
|
|||||||
|
module.exports = { plugins: { '@pandacss/dev/postcss': {} } }
|
||||||
59
scripts/acceptance.js
Normal file
59
scripts/acceptance.js
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
import { randomBytes, scryptSync } from 'node:crypto'
|
||||||
|
import { spawn } from 'node:child_process'
|
||||||
|
import { unlink, writeFile } from 'node:fs/promises'
|
||||||
|
import { createServer } from 'node:net'
|
||||||
|
import { tmpdir } from 'node:os'
|
||||||
|
import { join } from 'node:path'
|
||||||
|
import { passwordOptions } from '../server/auth.js'
|
||||||
|
|
||||||
|
const password = randomBytes(24).toString('hex')
|
||||||
|
const salt = randomBytes(16)
|
||||||
|
const hash = scryptSync(password, salt, 64, passwordOptions)
|
||||||
|
const project = 'syncova-test-' + randomBytes(5).toString('hex')
|
||||||
|
const envFile = join(tmpdir(), project + '.env')
|
||||||
|
const socket = createServer()
|
||||||
|
await new Promise((resolve, reject) => socket.once('error', reject).listen(0, '127.0.0.1', resolve))
|
||||||
|
const { port } = socket.address()
|
||||||
|
await new Promise((resolve) => socket.close(resolve))
|
||||||
|
const runtime = {
|
||||||
|
ADMIN_USERNAME: 'abnahme',
|
||||||
|
ADMIN_PASSWORD_HASH: `scrypt:${salt.toString('hex')}:${hash.toString('hex')}`,
|
||||||
|
BIND_ADDRESS: '127.0.0.1',
|
||||||
|
HTTP_PORT: String(port),
|
||||||
|
COOKIE_SECURE: 'false',
|
||||||
|
}
|
||||||
|
const env = {
|
||||||
|
...process.env,
|
||||||
|
SYNCOVA_TEST_PASSWORD: password,
|
||||||
|
SYNCOVA_TEST_URL: `http://127.0.0.1:${port}`,
|
||||||
|
SYNCOVA_TEST_PROJECT: project,
|
||||||
|
SYNCOVA_TEST_ENV: envFile,
|
||||||
|
}
|
||||||
|
for (const key of Object.keys(runtime)) delete env[key]
|
||||||
|
|
||||||
|
function run(command, args) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const child = spawn(command, args, { env, stdio: 'inherit' })
|
||||||
|
child.once('error', reject)
|
||||||
|
child.once('exit', (code) => code === 0 ? resolve() : reject(new Error(`${command} wurde mit Code ${code} beendet.`)))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const compose = ['compose', '--env-file', envFile, '-p', project, '-f', 'compose.yaml']
|
||||||
|
await writeFile(envFile, Object.entries(runtime).map(([key, value]) => key + '=' + value).join('\n') + '\n', {
|
||||||
|
flag: 'wx', mode: 0o600,
|
||||||
|
})
|
||||||
|
try {
|
||||||
|
await run('docker', [...compose, 'up', '--build', '--wait', '--wait-timeout', '60'])
|
||||||
|
await run(process.execPath, ['node_modules/@playwright/test/cli.js', 'test'])
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error.message)
|
||||||
|
process.exitCode = 1
|
||||||
|
await run('docker', [...compose, 'logs', '--tail', '40']).catch(() => {})
|
||||||
|
} finally {
|
||||||
|
await run('docker', [...compose, 'down', '--volumes', '--rmi', 'local']).catch((error) => {
|
||||||
|
console.error(error.message)
|
||||||
|
process.exitCode = 1
|
||||||
|
})
|
||||||
|
await unlink(envFile)
|
||||||
|
}
|
||||||
23
scripts/hash-password.js
Normal file
23
scripts/hash-password.js
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
import { randomBytes, scryptSync } from 'node:crypto'
|
||||||
|
import { createInterface } from 'node:readline/promises'
|
||||||
|
import { Writable } from 'node:stream'
|
||||||
|
import { passwordOptions } from '../server/auth.js'
|
||||||
|
|
||||||
|
function readPassword() {
|
||||||
|
if (!process.stdin.isTTY) {
|
||||||
|
throw new Error('Bitte in einem interaktiven Terminal ausführen.')
|
||||||
|
}
|
||||||
|
const hidden = new Writable({ write(_chunk, _encoding, callback) { callback() } })
|
||||||
|
const reader = createInterface({ input: process.stdin, output: hidden, terminal: true })
|
||||||
|
reader.on('SIGINT', () => { process.stderr.write('\n'); process.exit(130) })
|
||||||
|
process.stderr.write('Admin-Passwort: ')
|
||||||
|
return reader.question('').finally(() => { reader.close(); process.stderr.write('\n') })
|
||||||
|
}
|
||||||
|
|
||||||
|
const password = await readPassword()
|
||||||
|
if (!password || password.length > 1024) {
|
||||||
|
throw new Error('Bitte ein Passwort mit 1 bis 1024 Zeichen eingeben.')
|
||||||
|
}
|
||||||
|
const salt = randomBytes(16)
|
||||||
|
const hash = scryptSync(password, salt, 64, passwordOptions)
|
||||||
|
console.log(`scrypt:${salt.toString('hex')}:${hash.toString('hex')}`)
|
||||||
82
server/auth.js
Normal file
82
server/auth.js
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
import { createHash, randomBytes, scrypt, timingSafeEqual } from 'node:crypto'
|
||||||
|
import { promisify } from 'node:util'
|
||||||
|
|
||||||
|
export const passwordOptions = { N: 32768, r: 8, p: 1, maxmem: 64 * 1024 * 1024 }
|
||||||
|
const derive = promisify(scrypt)
|
||||||
|
const digest = (value) => createHash('sha256').update(value).digest()
|
||||||
|
const duration = 12 * 60 * 60 * 1000
|
||||||
|
const windowMs = 60_000
|
||||||
|
|
||||||
|
export function createAuth({ username, passwordHash, secure }) {
|
||||||
|
const match = /^scrypt:([a-f\d]{32}):([a-f\d]{128})$/.exec(passwordHash ?? '')
|
||||||
|
if (!username?.trim() || !match) {
|
||||||
|
throw new Error('ADMIN_USERNAME und ADMIN_PASSWORD_HASH müssen gültig konfiguriert sein.')
|
||||||
|
}
|
||||||
|
const expectedUser = digest(username)
|
||||||
|
const salt = Buffer.from(match[1], 'hex')
|
||||||
|
const expected = Buffer.from(match[2], 'hex')
|
||||||
|
const sessions = new Map()
|
||||||
|
const attempts = new Map()
|
||||||
|
let inFlight = 0
|
||||||
|
const cookie = {
|
||||||
|
httpOnly: true, secure, sameSite: 'strict', path: '/',
|
||||||
|
}
|
||||||
|
const cookieName = secure ? '__Host-syncova_session' : 'syncova_session'
|
||||||
|
const token = (req) => {
|
||||||
|
const match = req.headers.cookie?.split(';').map((item) => item.trim())
|
||||||
|
.find((item) => item.startsWith(cookieName + '='))
|
||||||
|
return match?.slice(cookieName.length + 1)
|
||||||
|
}
|
||||||
|
const active = (req) => {
|
||||||
|
const value = token(req)
|
||||||
|
return Boolean(value && (sessions.get(value) ?? 0) > Date.now())
|
||||||
|
}
|
||||||
|
setInterval(() => {
|
||||||
|
const now = Date.now()
|
||||||
|
for (const [value, expiry] of sessions) if (expiry <= now) sessions.delete(value)
|
||||||
|
for (const [ip, entry] of attempts) if (entry.until <= now) attempts.delete(ip)
|
||||||
|
}, windowMs).unref()
|
||||||
|
|
||||||
|
return {
|
||||||
|
active,
|
||||||
|
requireAdmin(req, res, next) {
|
||||||
|
if (!active(req)) return res.status(401).json({ error: 'Bitte zuerst anmelden.' })
|
||||||
|
next()
|
||||||
|
},
|
||||||
|
async login(req, res) {
|
||||||
|
const { username, password } = req.body ?? {}
|
||||||
|
if (typeof username !== 'string' || username.length > 256 ||
|
||||||
|
typeof password !== 'string' || password.length > 1024) {
|
||||||
|
return res.status(400).json({ error: 'Bitte Benutzername und Passwort eingeben.' })
|
||||||
|
}
|
||||||
|
const now = Date.now()
|
||||||
|
let entry = attempts.get(req.ip)
|
||||||
|
if (!entry || entry.until <= now) entry = { count: 0, until: now + windowMs }
|
||||||
|
if (entry.count >= 8 || inFlight >= 2 || (!attempts.has(req.ip) && attempts.size >= 4096)) {
|
||||||
|
return res.status(429).json({ error: 'Zu viele Anmeldeversuche. Bitte kurz warten.' })
|
||||||
|
}
|
||||||
|
entry.count += 1
|
||||||
|
attempts.set(req.ip, entry)
|
||||||
|
inFlight++
|
||||||
|
let result
|
||||||
|
try {
|
||||||
|
result = await derive(password, salt, expected.length, passwordOptions)
|
||||||
|
} finally {
|
||||||
|
inFlight--
|
||||||
|
}
|
||||||
|
if (!timingSafeEqual(digest(username), expectedUser) || !timingSafeEqual(result, expected)) {
|
||||||
|
return res.status(401).json({ error: 'Benutzername oder Passwort ist falsch.' })
|
||||||
|
}
|
||||||
|
attempts.delete(req.ip)
|
||||||
|
sessions.delete(token(req))
|
||||||
|
if (sessions.size >= 1024) sessions.delete(sessions.keys().next().value)
|
||||||
|
const value = randomBytes(32).toString('hex')
|
||||||
|
sessions.set(value, Date.now() + duration)
|
||||||
|
res.cookie(cookieName, value, { ...cookie, maxAge: duration }).json({ admin: true })
|
||||||
|
},
|
||||||
|
logout(req, res) {
|
||||||
|
sessions.delete(token(req))
|
||||||
|
res.clearCookie(cookieName, cookie).status(204).end()
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
147
server/icons.js
Normal file
147
server/icons.js
Normal file
@ -0,0 +1,147 @@
|
|||||||
|
import { lookup } from 'node:dns/promises'
|
||||||
|
import { request as http } from 'node:http'
|
||||||
|
import { request as https } from 'node:https'
|
||||||
|
import { isIP } from 'node:net'
|
||||||
|
import { loadBuffer } from 'cheerio'
|
||||||
|
import { decodeIco } from 'icojs'
|
||||||
|
import ipaddr from 'ipaddr.js'
|
||||||
|
import sharp from 'sharp'
|
||||||
|
import { httpUrl } from './model.js'
|
||||||
|
|
||||||
|
export const iconLimit = 512 * 1024
|
||||||
|
const imageOptions = { limitInputPixels: 4096 * 4096, failOn: 'warning' }
|
||||||
|
const globalIPv6 = ipaddr.parseCIDR('2000::/3')
|
||||||
|
const specialIPv6 = [ipaddr.parseCIDR('2001::/23'), ipaddr.parseCIDR('2002::/16')]
|
||||||
|
|
||||||
|
export async function normalizeIcon(buffer) {
|
||||||
|
const ico = buffer.length >= 22 && buffer.readUInt32LE(0) === 0x00010000
|
||||||
|
let image
|
||||||
|
if (ico) {
|
||||||
|
// Decode only the selected frame. Each ICO entry encodes dimensions in one byte.
|
||||||
|
const count = buffer.readUInt16LE(4)
|
||||||
|
if (!count || count > 64 || 6 + count * 16 > buffer.length) throw new Error('Ungültiges ICO.')
|
||||||
|
let entry = 6
|
||||||
|
for (let offset = 22; offset < 6 + count * 16; offset += 16) {
|
||||||
|
if ((buffer[offset] || 256) > (buffer[entry] || 256)) entry = offset
|
||||||
|
}
|
||||||
|
const size = buffer.readUInt32LE(entry + 8)
|
||||||
|
const offset = buffer.readUInt32LE(entry + 12)
|
||||||
|
if (size < 8 || offset < 6 + count * 16 || offset + size > buffer.length) throw new Error('Ungültiges ICO.')
|
||||||
|
const frame = buffer.subarray(offset, offset + size)
|
||||||
|
if (frame.subarray(0, 8).equals(Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]))) {
|
||||||
|
image = sharp(frame, imageOptions)
|
||||||
|
} else {
|
||||||
|
if (frame.length < 40 || frame.readUInt32LE(0) !== 40 ||
|
||||||
|
frame.readInt32LE(4) !== (buffer[entry] || 256) ||
|
||||||
|
Math.abs(frame.readInt32LE(8)) !== 2 * (buffer[entry + 1] || 256)) {
|
||||||
|
throw new Error('Ungültiges ICO.')
|
||||||
|
}
|
||||||
|
const header = Buffer.from(buffer.subarray(0, 22))
|
||||||
|
header.writeUInt16LE(1, 4)
|
||||||
|
buffer.copy(header, 6, entry, entry + 16)
|
||||||
|
header.writeUInt32LE(22, 18)
|
||||||
|
const [decoded] = await decodeIco(Buffer.concat([header, frame]), 'image/png')
|
||||||
|
image = sharp(Buffer.from(decoded.buffer), imageOptions)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const png = buffer.subarray(0, 8).equals(Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]))
|
||||||
|
const jpeg = buffer[0] === 255 && buffer[1] === 216 && buffer[2] === 255
|
||||||
|
const gif = ['GIF87a', 'GIF89a'].includes(buffer.toString('ascii', 0, 6))
|
||||||
|
const webp = buffer.toString('ascii', 0, 4) === 'RIFF' && buffer.toString('ascii', 8, 12) === 'WEBP'
|
||||||
|
if (!png && !jpeg && !gif && !webp) throw new Error('Unzulässiges Bildformat.')
|
||||||
|
image = sharp(buffer, imageOptions)
|
||||||
|
}
|
||||||
|
return image.resize(128, 128, { fit: 'inside', withoutEnlargement: true }).png().toBuffer()
|
||||||
|
}
|
||||||
|
|
||||||
|
function publicAddress(address) {
|
||||||
|
const ip = ipaddr.process(address)
|
||||||
|
if (ip.range() !== 'unicast') return false
|
||||||
|
return ip.kind() === 'ipv4' ||
|
||||||
|
(ip.match(globalIPv6) && !specialIPv6.some((subnet) => ip.match(subnet)))
|
||||||
|
}
|
||||||
|
|
||||||
|
async function resolvePublic(hostname, signal) {
|
||||||
|
const host = hostname.replace(/^\[|\]$/g, '')
|
||||||
|
if (isIP(host)) {
|
||||||
|
if (!publicAddress(host)) throw new Error('Interne Adresse.')
|
||||||
|
return { address: host, family: isIP(host) }
|
||||||
|
}
|
||||||
|
const { promise, resolve } = Promise.withResolvers()
|
||||||
|
const onAbort = () => resolve([])
|
||||||
|
signal.addEventListener('abort', onAbort, { once: true })
|
||||||
|
try {
|
||||||
|
const addresses = await Promise.race([lookup(host, { all: true }), promise])
|
||||||
|
signal.throwIfAborted()
|
||||||
|
if (!addresses.length || addresses.some(({ address }) => !publicAddress(address))) {
|
||||||
|
throw new Error('Interne oder ungültige Adresse.')
|
||||||
|
}
|
||||||
|
return addresses.find(({ family }) => family === 4) ?? addresses[0]
|
||||||
|
} finally {
|
||||||
|
signal.removeEventListener('abort', onAbort)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function download(url, signal, redirects = 0) {
|
||||||
|
signal.throwIfAborted()
|
||||||
|
if (redirects > 4) throw new Error('Zu viele Weiterleitungen.')
|
||||||
|
const pinned = await resolvePublic(url.hostname, signal)
|
||||||
|
const response = await new Promise((resolve, reject) => {
|
||||||
|
const request = url.protocol === 'https:' ? https : http
|
||||||
|
const req = request(url, {
|
||||||
|
agent: false,
|
||||||
|
signal,
|
||||||
|
lookup: (_host, options, callback) => options.all
|
||||||
|
? callback(null, [pinned])
|
||||||
|
: callback(null, pinned.address, pinned.family),
|
||||||
|
headers: { 'User-Agent': 'syncova-links/1.0', Accept: 'text/html,image/*;q=0.9,*/*;q=0.1' },
|
||||||
|
}, resolve)
|
||||||
|
req.on('error', reject)
|
||||||
|
req.end()
|
||||||
|
})
|
||||||
|
if ([301, 302, 303, 307, 308].includes(response.statusCode) && response.headers.location) {
|
||||||
|
response.destroy()
|
||||||
|
return download(httpUrl(new URL(response.headers.location, url).href), signal, redirects + 1)
|
||||||
|
}
|
||||||
|
if (response.statusCode !== 200 || Number(response.headers['content-length']) > iconLimit) {
|
||||||
|
response.destroy()
|
||||||
|
throw new Error('Antwort fehlgeschlagen oder zu groß.')
|
||||||
|
}
|
||||||
|
const chunks = []
|
||||||
|
let bytes = 0
|
||||||
|
for await (const chunk of response) {
|
||||||
|
bytes += chunk.length
|
||||||
|
if (bytes > iconLimit) throw new Error('Antwort zu groß.')
|
||||||
|
chunks.push(chunk)
|
||||||
|
}
|
||||||
|
return { url, body: Buffer.concat(chunks) }
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function fetchFavicon(value) {
|
||||||
|
const url = httpUrl(value)
|
||||||
|
const total = AbortSignal.timeout(10_000)
|
||||||
|
const get = (target) => download(target, AbortSignal.any([total, AbortSignal.timeout(3_500)]))
|
||||||
|
let page
|
||||||
|
try { page = await get(url) } catch { /* Try the conventional path. */ }
|
||||||
|
const finalUrl = page?.url ?? url
|
||||||
|
const candidates = new Set([new URL('/favicon.ico', finalUrl).href])
|
||||||
|
if (page) {
|
||||||
|
try { return await normalizeIcon(page.body) } catch { /* The page may contain icon links. */ }
|
||||||
|
const html = loadBuffer(page.body)
|
||||||
|
const base = html('base[href]').first().attr('href')
|
||||||
|
let baseUrl = finalUrl
|
||||||
|
try { if (base) baseUrl = new URL(base, finalUrl) } catch { /* Use the page URL. */ }
|
||||||
|
for (const element of html('link[rel][href]').toArray()) {
|
||||||
|
const rel = html(element).attr('rel').toLowerCase().split(/\s+/)
|
||||||
|
if (!rel.some((part) => ['icon', 'apple-touch-icon'].includes(part))) continue
|
||||||
|
try { candidates.add(httpUrl(new URL(html(element).attr('href'), baseUrl).href).href) } catch { /* Invalid link. */ }
|
||||||
|
if (candidates.size >= 5) break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const [fallback, ...declared] = candidates
|
||||||
|
for (const href of [...declared, fallback]) {
|
||||||
|
if (total.aborted) break
|
||||||
|
try { return await normalizeIcon((await get(new URL(href))).body) } catch { /* Try another icon. */ }
|
||||||
|
}
|
||||||
|
throw new Error('Kein verwendbares Favicon gefunden.')
|
||||||
|
}
|
||||||
107
server/index.js
Normal file
107
server/index.js
Normal file
@ -0,0 +1,107 @@
|
|||||||
|
import express from 'express'
|
||||||
|
import { fileURLToPath } from 'node:url'
|
||||||
|
import { join } from 'node:path'
|
||||||
|
import { createAuth } from './auth.js'
|
||||||
|
import { fetchFavicon, iconLimit, normalizeIcon } from './icons.js'
|
||||||
|
import { settings, update } from './model.js'
|
||||||
|
import { openStore, RequestError } from './store.js'
|
||||||
|
|
||||||
|
const { ADMIN_USERNAME, ADMIN_PASSWORD_HASH, COOKIE_SECURE, PORT, DATA_DIR } = process.env
|
||||||
|
const auth = createAuth({ username: ADMIN_USERNAME, passwordHash: ADMIN_PASSWORD_HASH, secure: COOKIE_SECURE === 'true' })
|
||||||
|
const store = openStore(DATA_DIR || './data')
|
||||||
|
const dist = fileURLToPath(new URL('../dist/', import.meta.url))
|
||||||
|
const app = express()
|
||||||
|
app.disable('x-powered-by')
|
||||||
|
app.use((req, res, next) => {
|
||||||
|
res.set({
|
||||||
|
'Content-Security-Policy': "default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self'; font-src 'self'; object-src 'none'; base-uri 'none'; frame-ancestors 'none'; form-action 'self'",
|
||||||
|
'X-Content-Type-Options': 'nosniff',
|
||||||
|
'Referrer-Policy': 'no-referrer',
|
||||||
|
})
|
||||||
|
next()
|
||||||
|
})
|
||||||
|
app.get('/healthz', (_req, res) => res.sendStatus(200))
|
||||||
|
app.use('/api', (_req, res, next) => {
|
||||||
|
res.set('Cache-Control', 'private, no-store')
|
||||||
|
next()
|
||||||
|
})
|
||||||
|
|
||||||
|
const json = express.json({ limit: '2mb' })
|
||||||
|
const binary = express.raw({ type: 'application/octet-stream', limit: iconLimit, inflate: false })
|
||||||
|
const write = (req, res, next) => {
|
||||||
|
if (req.get('x-syncova-request') !== '1' || ['cross-site', 'same-site'].includes(req.get('sec-fetch-site'))) {
|
||||||
|
throw new RequestError(403, 'Diese Anfrage ist nicht zulässig.')
|
||||||
|
}
|
||||||
|
next()
|
||||||
|
}
|
||||||
|
const adminWrite = [auth.requireAdmin, write]
|
||||||
|
|
||||||
|
function parse(schema, body) {
|
||||||
|
const result = schema.safeParse(body)
|
||||||
|
if (!result.success) {
|
||||||
|
const issue = result.error.issues[0]
|
||||||
|
const message = ['custom', 'invalid_format'].includes(issue.code) && !issue.message.startsWith('Invalid')
|
||||||
|
? issue.message
|
||||||
|
: 'Bitte prüfe die Pflichtfelder und die Länge deiner Eingaben.'
|
||||||
|
throw new RequestError(400, message)
|
||||||
|
}
|
||||||
|
return result.data
|
||||||
|
}
|
||||||
|
|
||||||
|
app.get('/api/session', (req, res) => res.json({ admin: auth.active(req) }))
|
||||||
|
app.post('/api/login', write, json, auth.login)
|
||||||
|
app.post('/api/logout', ...adminWrite, auth.logout)
|
||||||
|
app.get('/api/admin/pages', auth.requireAdmin, (_req, res) => res.json(store.list()))
|
||||||
|
app.get('/api/pages', (_req, res) => res.json(store.list().map(({ name, slug }) => ({ name, slug }))))
|
||||||
|
app.get('/api/pages/:slug', (req, res) => res.json(store.get(req.params.slug)))
|
||||||
|
app.post('/api/pages', ...adminWrite, json, (req, res) => res.status(201).json(store.create(parse(settings, req.body))))
|
||||||
|
app.put('/api/pages/:id', ...adminWrite, json, (req, res) => res.json(store.save(req.params.id, parse(update, req.body))))
|
||||||
|
app.delete('/api/pages/:id', ...adminWrite, (req, res) => {
|
||||||
|
store.remove(req.params.id)
|
||||||
|
res.status(204).end()
|
||||||
|
})
|
||||||
|
|
||||||
|
app.get('/api/icons/:id', (req, res) => {
|
||||||
|
const icon = store.icon(req.params.id)
|
||||||
|
if (!icon || (!icon.published && !auth.active(req))) return res.sendStatus(404)
|
||||||
|
res.type('png').send(Buffer.from(icon.png))
|
||||||
|
})
|
||||||
|
app.post('/api/icons/upload', ...adminWrite, binary, async (req, res) => {
|
||||||
|
if (!Buffer.isBuffer(req.body) || !req.body.length) throw new RequestError(400, 'Bitte wähle eine Bilddatei aus.')
|
||||||
|
let image
|
||||||
|
try { image = await normalizeIcon(req.body) } catch {
|
||||||
|
throw new RequestError(422, 'Das Icon muss ein gültiges PNG, JPEG, WebP, GIF oder ICO sein.')
|
||||||
|
}
|
||||||
|
res.status(201).json(store.addIcon(image))
|
||||||
|
})
|
||||||
|
let fetches = 0
|
||||||
|
app.post('/api/icons/favicon', ...adminWrite, json, async (req, res) => {
|
||||||
|
const url = req.body?.url
|
||||||
|
if (typeof url !== 'string' || url.length > 2048) throw new RequestError(400, 'Bitte gib eine gültige Link-Adresse ein.')
|
||||||
|
if (fetches >= 2) throw new RequestError(429, 'Zu viele laufende Abrufe. Bitte versuche es gleich erneut.')
|
||||||
|
fetches++
|
||||||
|
let image
|
||||||
|
try { image = await fetchFavicon(url) } catch {
|
||||||
|
throw new RequestError(422, 'Kein verwendbares Favicon gefunden. Der Link kann mit dem Standard-Icon gespeichert werden.')
|
||||||
|
} finally {
|
||||||
|
fetches--
|
||||||
|
}
|
||||||
|
res.status(201).json(store.addIcon(image))
|
||||||
|
})
|
||||||
|
app.use('/api', (_req, res) => res.status(404).json({ error: 'Diese Funktion wurde nicht gefunden.' }))
|
||||||
|
app.use('/assets', express.static(join(dist, 'assets'), { immutable: true, maxAge: '1y' }))
|
||||||
|
app.get(['/', '/:slug'], (_req, res) => res.sendFile(join(dist, 'index.html'), { maxAge: 0 }))
|
||||||
|
app.use((_req, res) => res.sendStatus(404))
|
||||||
|
app.use((error, _req, res, next) => {
|
||||||
|
if (res.headersSent) return next(error)
|
||||||
|
if (error instanceof RequestError) return res.status(error.status).json({ error: error.message })
|
||||||
|
if (error.status === 413) return res.status(413).json({ error: 'Die Datei oder Anfrage ist zu groß.' })
|
||||||
|
if (error.status >= 400 && error.status < 500) return res.status(error.status).json({ error: 'Ungültige Anfrage.' })
|
||||||
|
console.error(error)
|
||||||
|
res.status(500).json({ error: 'Die Anfrage konnte nicht verarbeitet werden.' })
|
||||||
|
})
|
||||||
|
const server = app.listen(Number(PORT || 3000), '0.0.0.0', () => {
|
||||||
|
console.log(`syncova-links hört auf Port ${server.address().port}`)
|
||||||
|
})
|
||||||
|
server.requestTimeout = 30_000
|
||||||
|
for (const signal of ['SIGTERM', 'SIGINT']) process.once(signal, () => server.close(() => process.exit(0)))
|
||||||
56
server/model.js
Normal file
56
server/model.js
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
import { z } from 'zod'
|
||||||
|
|
||||||
|
export function httpUrl(value) {
|
||||||
|
const url = new URL(value)
|
||||||
|
if (!['https:', 'http:'].includes(url.protocol) || url.username || url.password) {
|
||||||
|
throw new Error('Bitte eine HTTP- oder HTTPS-Adresse ohne Zugangsdaten eingeben.')
|
||||||
|
}
|
||||||
|
return url
|
||||||
|
}
|
||||||
|
|
||||||
|
const title = z.string().trim().min(1).max(120)
|
||||||
|
const id = z.uuid()
|
||||||
|
const link = z.object({
|
||||||
|
id,
|
||||||
|
title,
|
||||||
|
url: z.string().trim().max(2048).refine((value) => {
|
||||||
|
try { return Boolean(httpUrl(value)) } catch { return false }
|
||||||
|
}, 'Bitte eine gültige HTTP- oder HTTPS-Adresse eingeben.'),
|
||||||
|
description: z.string().trim().max(500),
|
||||||
|
icon: id.nullable(),
|
||||||
|
})
|
||||||
|
const links = z.array(link).max(200)
|
||||||
|
const zone = z.string().min(1).max(100).refine((value) => {
|
||||||
|
try { new Intl.DateTimeFormat('de', { timeZone: value }); return true } catch { return false }
|
||||||
|
}, 'Bitte eine gültige Zeitzone eingeben.')
|
||||||
|
|
||||||
|
export const settings = z.object({
|
||||||
|
name: title,
|
||||||
|
slug: z.string().trim().min(1).max(60)
|
||||||
|
.regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/, 'Der URL-Pfad darf Kleinbuchstaben, Zahlen und Bindestriche enthalten.')
|
||||||
|
.refine((value) => !['api', 'assets', 'healthz'].includes(value), 'Dieser URL-Pfad ist reserviert.'),
|
||||||
|
view: z.enum(['list', 'grid']),
|
||||||
|
})
|
||||||
|
|
||||||
|
export const layout = z.object({
|
||||||
|
loose: links,
|
||||||
|
blocks: z.array(z.discriminatedUnion('type', [
|
||||||
|
z.object({ id, type: z.literal('group'), title, links }),
|
||||||
|
z.object({ id, type: z.literal('text'), title: z.string().trim().max(120), text: z.string().max(5000) }),
|
||||||
|
z.object({ id, type: z.literal('clock'), timeZone: zone, hour12: z.boolean() }),
|
||||||
|
])).max(80),
|
||||||
|
}).refine(({ blocks, loose }) => {
|
||||||
|
const ids = [...loose.map((link) => link.id)]
|
||||||
|
for (const block of blocks) {
|
||||||
|
ids.push(block.id)
|
||||||
|
if (block.type === 'group') ids.push(...block.links.map((link) => link.id))
|
||||||
|
}
|
||||||
|
return ids.length <= 400 && new Set(ids).size === ids.length
|
||||||
|
}, 'Die Seite darf höchstens 400 eindeutige Einträge enthalten.')
|
||||||
|
|
||||||
|
export const update = settings.extend({ version: z.number().int().positive(), layout })
|
||||||
|
|
||||||
|
export function iconIds({ loose, blocks }) {
|
||||||
|
const links = [...loose, ...blocks.flatMap((block) => block.type === 'group' ? block.links : [])]
|
||||||
|
return new Set(links.map((link) => link.icon).filter(Boolean))
|
||||||
|
}
|
||||||
115
server/store.js
Normal file
115
server/store.js
Normal file
@ -0,0 +1,115 @@
|
|||||||
|
import { DatabaseSync } from 'node:sqlite'
|
||||||
|
import { join } from 'node:path'
|
||||||
|
import { mkdirSync } from 'node:fs'
|
||||||
|
import { randomUUID } from 'node:crypto'
|
||||||
|
import { iconIds } from './model.js'
|
||||||
|
|
||||||
|
const empty = JSON.stringify({ loose: [], blocks: [] })
|
||||||
|
const day = 24 * 60 * 60 * 1000
|
||||||
|
|
||||||
|
export class RequestError extends Error {
|
||||||
|
constructor(status, message) {
|
||||||
|
super(message)
|
||||||
|
this.status = status
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function openStore(directory) {
|
||||||
|
mkdirSync(directory, { recursive: true })
|
||||||
|
const db = new DatabaseSync(join(directory, 'syncova.sqlite'))
|
||||||
|
db.exec(`
|
||||||
|
PRAGMA journal_mode = WAL;
|
||||||
|
CREATE TABLE IF NOT EXISTS pages (
|
||||||
|
id TEXT PRIMARY KEY,
|
||||||
|
slug TEXT NOT NULL UNIQUE,
|
||||||
|
name TEXT NOT NULL,
|
||||||
|
view TEXT NOT NULL,
|
||||||
|
version INTEGER NOT NULL DEFAULT 1,
|
||||||
|
content TEXT NOT NULL
|
||||||
|
) STRICT;
|
||||||
|
CREATE TABLE IF NOT EXISTS icons (
|
||||||
|
id TEXT PRIMARY KEY,
|
||||||
|
created_at INTEGER NOT NULL,
|
||||||
|
png BLOB NOT NULL
|
||||||
|
) STRICT;
|
||||||
|
CREATE TABLE IF NOT EXISTS page_icons (
|
||||||
|
page_id TEXT NOT NULL REFERENCES pages(id) ON DELETE CASCADE,
|
||||||
|
icon_id TEXT NOT NULL REFERENCES icons(id),
|
||||||
|
PRIMARY KEY (page_id, icon_id)
|
||||||
|
) STRICT;
|
||||||
|
CREATE INDEX IF NOT EXISTS icon_references ON page_icons(icon_id);
|
||||||
|
`)
|
||||||
|
const pageBy = {
|
||||||
|
id: db.prepare('SELECT * FROM pages WHERE id = ?'),
|
||||||
|
slug: db.prepare('SELECT * FROM pages WHERE slug = ?'),
|
||||||
|
}
|
||||||
|
const list = db.prepare('SELECT name, slug, view, id FROM pages ORDER BY name COLLATE NOCASE, slug')
|
||||||
|
const insert = db.prepare('INSERT INTO pages (id, slug, name, view, content) VALUES (?, ?, ?, ?, ?)')
|
||||||
|
const edit = db.prepare('UPDATE pages SET slug = ?, name = ?, view = ?, content = ?, version = version + 1 WHERE id = ?')
|
||||||
|
const remove = db.prepare('DELETE FROM pages WHERE id = ?')
|
||||||
|
const clearIcons = db.prepare('DELETE FROM page_icons WHERE page_id = ?')
|
||||||
|
const addReference = db.prepare('INSERT INTO page_icons VALUES (?, ?)')
|
||||||
|
const icon = db.prepare(`
|
||||||
|
SELECT png, EXISTS (SELECT 1 FROM page_icons WHERE icon_id = icons.id) AS published
|
||||||
|
FROM icons WHERE id = ?
|
||||||
|
`)
|
||||||
|
const insertIcon = db.prepare('INSERT INTO icons VALUES (?, ?, ?)')
|
||||||
|
const pruneIcons = db.prepare(`
|
||||||
|
DELETE FROM icons WHERE created_at < ? AND NOT EXISTS (SELECT 1 FROM page_icons WHERE icon_id = icons.id)
|
||||||
|
`)
|
||||||
|
|
||||||
|
function get(key, value) {
|
||||||
|
const row = pageBy[key].get(value)
|
||||||
|
if (!row) throw new RequestError(404, 'Diese Abteilung wurde nicht gefunden.')
|
||||||
|
const { content, ...page } = row
|
||||||
|
return { ...page, layout: JSON.parse(content) }
|
||||||
|
}
|
||||||
|
function uniqueSlug(slug, id) {
|
||||||
|
const other = pageBy.slug.get(slug)
|
||||||
|
if (other && other.id !== id) throw new RequestError(409, 'Dieser URL-Pfad ist bereits vergeben.')
|
||||||
|
}
|
||||||
|
const prune = () => pruneIcons.run(Date.now() - day)
|
||||||
|
prune()
|
||||||
|
setInterval(prune, 60 * 60 * 1000).unref()
|
||||||
|
|
||||||
|
return {
|
||||||
|
list: () => list.all(),
|
||||||
|
get: (slug) => get('slug', slug),
|
||||||
|
create({ slug, name, view }) {
|
||||||
|
uniqueSlug(slug)
|
||||||
|
const id = randomUUID()
|
||||||
|
insert.run(id, slug, name, view, empty)
|
||||||
|
return get('id', id)
|
||||||
|
},
|
||||||
|
save(id, { slug, name, view, version, layout }) {
|
||||||
|
db.exec('BEGIN IMMEDIATE')
|
||||||
|
try {
|
||||||
|
const current = get('id', id)
|
||||||
|
if (current.version !== version) {
|
||||||
|
throw new RequestError(409, 'Die Seite wurde inzwischen geändert. Bitte lade sie neu.')
|
||||||
|
}
|
||||||
|
uniqueSlug(slug, id)
|
||||||
|
edit.run(slug, name, view, JSON.stringify(layout), id)
|
||||||
|
clearIcons.run(id)
|
||||||
|
for (const iconId of iconIds(layout)) {
|
||||||
|
if (!icon.get(iconId)) throw new RequestError(400, 'Ein Icon ist abgelaufen. Bitte lade es erneut.')
|
||||||
|
addReference.run(id, iconId)
|
||||||
|
}
|
||||||
|
db.exec('COMMIT')
|
||||||
|
} catch (error) {
|
||||||
|
db.exec('ROLLBACK')
|
||||||
|
throw error
|
||||||
|
}
|
||||||
|
return get('id', id)
|
||||||
|
},
|
||||||
|
remove(id) {
|
||||||
|
if (!remove.run(id).changes) throw new RequestError(404, 'Diese Abteilung wurde nicht gefunden.')
|
||||||
|
},
|
||||||
|
icon: (id) => icon.get(id),
|
||||||
|
addIcon(png) {
|
||||||
|
const id = randomUUID()
|
||||||
|
insertIcon.run(id, Date.now(), png)
|
||||||
|
return { id }
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
26
src/api.js
Normal file
26
src/api.js
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
export async function api(path, { method = 'GET', data, file } = {}) {
|
||||||
|
const headers = {}
|
||||||
|
if (method !== 'GET') headers['X-Syncova-Request'] = '1'
|
||||||
|
if (data !== undefined) headers['Content-Type'] = 'application/json'
|
||||||
|
if (file) headers['Content-Type'] = 'application/octet-stream'
|
||||||
|
const response = await fetch('/api' + path, {
|
||||||
|
method,
|
||||||
|
headers,
|
||||||
|
body: file ?? (data === undefined ? undefined : JSON.stringify(data)),
|
||||||
|
})
|
||||||
|
if (!response.ok) {
|
||||||
|
const result = await response.json().catch(() => ({}))
|
||||||
|
throw new Error(result.error ?? 'Die Anfrage konnte nicht verarbeitet werden.')
|
||||||
|
}
|
||||||
|
return response.status === 204 ? undefined : response.json()
|
||||||
|
}
|
||||||
|
|
||||||
|
export const iconUrl = (id) => '/api/icons/' + id
|
||||||
|
|
||||||
|
export function newId() {
|
||||||
|
const bytes = crypto.getRandomValues(new Uint8Array(16))
|
||||||
|
bytes[6] = (bytes[6] & 0x0f) | 0x40
|
||||||
|
bytes[8] = (bytes[8] & 0x3f) | 0x80
|
||||||
|
const hex = Array.from(bytes, (byte) => byte.toString(16).padStart(2, '0')).join('')
|
||||||
|
return [hex.slice(0, 8), hex.slice(8, 12), hex.slice(12, 16), hex.slice(16, 20), hex.slice(20)].join('-')
|
||||||
|
}
|
||||||
167
src/components/editor.jsx
Normal file
167
src/components/editor.jsx
Normal file
@ -0,0 +1,167 @@
|
|||||||
|
import { useEffect, useRef, useState } from 'react'
|
||||||
|
import { Check, Clock3, Eye, FolderPlus, Settings2, TextCursor, X } from 'lucide-react'
|
||||||
|
import { api } from '../api'
|
||||||
|
import { Button } from './ui/button'
|
||||||
|
import { BlockForm, LinkForm, PageForm } from './forms'
|
||||||
|
import { Modal } from './shared'
|
||||||
|
import { blockName, linksIn, PageContent } from './page-content'
|
||||||
|
|
||||||
|
function insertBefore(items, item, before) {
|
||||||
|
const index = before === undefined ? items.length : items.findIndex((entry) => entry.id === before)
|
||||||
|
items.splice(index, 0, item)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function Editor({ initial, onSave, exit, setDirty }) {
|
||||||
|
const [draft, setDraft] = useState(initial)
|
||||||
|
const [dialog, setDialog] = useState(null)
|
||||||
|
const [item, setItem] = useState(null)
|
||||||
|
const [hover, setHover] = useState(null)
|
||||||
|
const [saving, setSaving] = useState(false)
|
||||||
|
const [error, setError] = useState('')
|
||||||
|
const [status, setStatus] = useState('')
|
||||||
|
const root = useRef(null)
|
||||||
|
const dirty = JSON.stringify(draft) !== JSON.stringify(initial)
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!dirty) return
|
||||||
|
setDirty(true)
|
||||||
|
const prompt = (event) => { event.preventDefault(); event.returnValue = true }
|
||||||
|
window.addEventListener('beforeunload', prompt)
|
||||||
|
return () => {
|
||||||
|
window.removeEventListener('beforeunload', prompt)
|
||||||
|
setDirty(false)
|
||||||
|
}
|
||||||
|
}, [dirty, setDirty])
|
||||||
|
|
||||||
|
function mutate(change) {
|
||||||
|
setStatus('')
|
||||||
|
setDraft((current) => {
|
||||||
|
const updated = structuredClone(current)
|
||||||
|
change(updated.layout)
|
||||||
|
return updated
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function focusGrip(id) {
|
||||||
|
requestAnimationFrame(() => root.current?.querySelector(`[data-grip="${id}"]`)?.focus())
|
||||||
|
}
|
||||||
|
function cancel(focus = true) {
|
||||||
|
if (focus && item) focusGrip(item.id)
|
||||||
|
setItem(null)
|
||||||
|
setHover(null)
|
||||||
|
}
|
||||||
|
function pick(entry, mode) {
|
||||||
|
if (item?.id === entry.id && mode === 'keyboard') return cancel()
|
||||||
|
setStatus('')
|
||||||
|
setHover(null)
|
||||||
|
setItem({ ...entry, mode })
|
||||||
|
}
|
||||||
|
useEffect(() => {
|
||||||
|
if (item?.mode === 'keyboard') root.current?.querySelector('[data-drop]')?.focus()
|
||||||
|
}, [item])
|
||||||
|
|
||||||
|
function drop(target) {
|
||||||
|
if (!item) return
|
||||||
|
mutate((layout) => {
|
||||||
|
const source = item.type === 'block' ? layout.blocks : linksIn(layout, item.group)
|
||||||
|
const destination = item.type === 'block' ? layout.blocks : linksIn(layout, target.group)
|
||||||
|
const [entry] = source.splice(source.findIndex((entry) => entry.id === item.id), 1)
|
||||||
|
insertBefore(destination, entry, target.before)
|
||||||
|
})
|
||||||
|
setStatus(`${item.name} wurde verschoben.`)
|
||||||
|
cancel(item.mode === 'keyboard')
|
||||||
|
}
|
||||||
|
function handleKey(event) {
|
||||||
|
if (!item || dialog) return
|
||||||
|
if (event.key === 'Escape') {
|
||||||
|
event.preventDefault()
|
||||||
|
cancel()
|
||||||
|
}
|
||||||
|
if (item.mode === 'keyboard' && event.target.hasAttribute('data-drop') &&
|
||||||
|
['ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight'].includes(event.key)) {
|
||||||
|
event.preventDefault()
|
||||||
|
const targets = Array.from(root.current.querySelectorAll('[data-drop]'))
|
||||||
|
const step = ['ArrowUp', 'ArrowLeft'].includes(event.key) ? -1 : 1
|
||||||
|
const index = targets.indexOf(event.target)
|
||||||
|
targets[(targets.length + index + step) % targets.length]?.focus()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function save() {
|
||||||
|
setSaving(true)
|
||||||
|
setError('')
|
||||||
|
setStatus('')
|
||||||
|
try {
|
||||||
|
const page = await api('/pages/' + draft.id, { method: 'PUT', data: draft })
|
||||||
|
setDraft(page)
|
||||||
|
onSave(page)
|
||||||
|
setStatus('Seite gespeichert.')
|
||||||
|
} catch (failure) {
|
||||||
|
setError(failure.message)
|
||||||
|
} finally {
|
||||||
|
setSaving(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const close = () => setDialog(null)
|
||||||
|
const controls = {
|
||||||
|
dnd: { item, pick, cancel, drop, hover, setHover },
|
||||||
|
editLink: (group, initial) => setDialog({ kind: 'link', group, initial }),
|
||||||
|
deleteLink: (group, link) => setDialog({ kind: 'deleteLink', group, link }),
|
||||||
|
editBlock: (type, initial) => setDialog({ kind: 'block', type, initial }),
|
||||||
|
deleteBlock: (block) => setDialog({ kind: 'deleteBlock', block }),
|
||||||
|
}
|
||||||
|
|
||||||
|
return <main className="frame edit-frame" ref={root} onKeyDown={handleKey}>
|
||||||
|
<div className="page-heading">
|
||||||
|
<div><span className="path">/{draft.slug}</span><h1>{draft.name}</h1></div>
|
||||||
|
<div className="actions editor-heading-actions">
|
||||||
|
<Button variant="outline" disabled={saving} onClick={() => dirty ? setDialog({ kind: 'discard' }) : exit()}><Eye size={17} /> Öffentliche Ansicht</Button>
|
||||||
|
<Button colorPalette="jade" disabled={!dirty || Boolean(item)} loading={saving} onClick={save}><Check size={17} /> Seite speichern</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="editor-toolbar">
|
||||||
|
<div className="actions">
|
||||||
|
<Button variant="outline" size="sm" disabled={saving || Boolean(item)} onClick={() => controls.editBlock('group')}><FolderPlus size={16} /> Gruppe</Button>
|
||||||
|
<Button variant="outline" size="sm" disabled={saving || Boolean(item)} onClick={() => controls.editBlock('text')}><TextCursor size={16} /> Text-Widget</Button>
|
||||||
|
<Button variant="outline" size="sm" disabled={saving || Boolean(item)} onClick={() => controls.editBlock('clock')}><Clock3 size={16} /> Uhrzeit-Widget</Button>
|
||||||
|
</div>
|
||||||
|
<Button variant="plain" size="sm" disabled={saving || Boolean(item)} onClick={() => setDialog({ kind: 'settings' })}><Settings2 size={16} /> Seiteneinstellungen</Button>
|
||||||
|
</div>
|
||||||
|
<div className="editor-message" aria-live="polite">
|
||||||
|
{item ? <span>{item.name} · Ablageziel auswählen <Button size="xs" variant="plain" onClick={() => cancel()}><X size={15} /> Abbrechen</Button></span>
|
||||||
|
: <span>{status || (dirty ? 'Ungespeicherte Änderungen' : 'Zum Sortieren einen Ziehgriff ziehen oder auswählen.')}</span>}
|
||||||
|
</div>
|
||||||
|
{error && <p className="feedback error" role="alert">{error}</p>}
|
||||||
|
<fieldset disabled={saving} className="layout-fieldset">
|
||||||
|
<PageContent layout={draft.layout} view="list" controls={controls} />
|
||||||
|
</fieldset>
|
||||||
|
{dialog?.kind === 'settings' && <PageForm initial={draft} close={close} save={(settings) => {
|
||||||
|
setStatus('')
|
||||||
|
setDraft((current) => ({ ...current, ...settings }))
|
||||||
|
}} />}
|
||||||
|
{dialog?.kind === 'link' && <LinkForm initial={dialog.initial} close={close} save={(link) => mutate((layout) => {
|
||||||
|
const links = linksIn(layout, dialog.group)
|
||||||
|
if (dialog.initial) links[links.findIndex((entry) => entry.id === link.id)] = link
|
||||||
|
else links.push(link)
|
||||||
|
})} />}
|
||||||
|
{dialog?.kind === 'block' && <BlockForm type={dialog.type} initial={dialog.initial} close={close} save={(block) => mutate((layout) => {
|
||||||
|
if (dialog.initial) layout.blocks[layout.blocks.findIndex((entry) => entry.id === block.id)] = block
|
||||||
|
else layout.blocks.push(block)
|
||||||
|
})} />}
|
||||||
|
{dialog?.kind === 'deleteLink' && <Modal title="Link löschen" description={`„${dialog.link.title}“ beim Speichern von der Seite entfernen?`}
|
||||||
|
close={close} danger submitLabel="Link entfernen" save={() => mutate((layout) => {
|
||||||
|
const links = linksIn(layout, dialog.group)
|
||||||
|
links.splice(links.findIndex((entry) => entry.id === dialog.link.id), 1)
|
||||||
|
})} />}
|
||||||
|
{dialog?.kind === 'deleteBlock' && <Modal title={dialog.block.type === 'group' ? 'Gruppe löschen' : 'Widget löschen'}
|
||||||
|
description={dialog.block.type === 'group' ? 'Die Links der Gruppe werden zu den ungruppierten Links verschoben.'
|
||||||
|
: `„${blockName(dialog.block)}“ beim Speichern von der Seite entfernen?`}
|
||||||
|
close={close} danger submitLabel="Entfernen" save={() => mutate((layout) => {
|
||||||
|
const [block] = layout.blocks.splice(layout.blocks.findIndex((entry) => entry.id === dialog.block.id), 1)
|
||||||
|
if (block.type === 'group') layout.loose.push(...block.links)
|
||||||
|
})} />}
|
||||||
|
{dialog?.kind === 'discard' && <Modal title="Änderungen verwerfen" description="Seit dem letzten Speichern vorgenommene Änderungen gehen verloren."
|
||||||
|
close={close} danger submitLabel="Verwerfen" save={exit} />}
|
||||||
|
</main>
|
||||||
|
}
|
||||||
148
src/components/forms.jsx
Normal file
148
src/components/forms.jsx
Normal file
@ -0,0 +1,148 @@
|
|||||||
|
import { useId, useRef, useState } from 'react'
|
||||||
|
import { Download, FileImage, Upload, X } from 'lucide-react'
|
||||||
|
import { api, newId } from '../api'
|
||||||
|
import { Button } from './ui/button'
|
||||||
|
import { Choice, LinkIcon, Modal, TextField, slugify, viewItems } from './shared'
|
||||||
|
|
||||||
|
export function LoginForm({ close, onLogin }) {
|
||||||
|
const [username, setUsername] = useState('')
|
||||||
|
const [password, setPassword] = useState('')
|
||||||
|
return <Modal title="Anmelden" description="Melde dich an, um Abteilungen und ihre Inhalte zu verwalten."
|
||||||
|
submitLabel="Anmelden" close={close} save={async () => {
|
||||||
|
await api('/login', { method: 'POST', data: { username, password } })
|
||||||
|
onLogin()
|
||||||
|
}}>
|
||||||
|
<TextField label="Benutzername" value={username} onChange={setUsername} autoComplete="username" required maxLength={256} />
|
||||||
|
<TextField label="Passwort" type="password" value={password} onChange={setPassword} autoComplete="current-password" required maxLength={1024} />
|
||||||
|
</Modal>
|
||||||
|
}
|
||||||
|
|
||||||
|
export function PageForm({ initial, close, save }) {
|
||||||
|
const [name, setName] = useState(initial?.name ?? '')
|
||||||
|
const [slug, setSlug] = useState(initial?.slug ?? '')
|
||||||
|
const [customSlug, setCustomSlug] = useState(Boolean(initial))
|
||||||
|
const [view, setView] = useState(initial?.view ?? 'list')
|
||||||
|
return <Modal title={initial ? 'Seiteneinstellungen' : 'Abteilung anlegen'}
|
||||||
|
description="Der URL-Pfad bestimmt die öffentliche Adresse der Abteilungsseite."
|
||||||
|
submitLabel={initial ? 'Übernehmen' : 'Abteilung anlegen'} close={close}
|
||||||
|
validate={() => {
|
||||||
|
if (!name.trim()) throw new Error('Bitte gib einen Namen ein.')
|
||||||
|
if (!/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(slug)) throw new Error('Verwende für den URL-Pfad Kleinbuchstaben, Zahlen und Bindestriche.')
|
||||||
|
if (['api', 'assets', 'healthz'].includes(slug)) throw new Error('Dieser URL-Pfad ist reserviert.')
|
||||||
|
}}
|
||||||
|
save={() => save({ name: name.trim(), slug, view })}>
|
||||||
|
<TextField label="Name" value={name} onChange={(value) => {
|
||||||
|
setName(value)
|
||||||
|
if (!customSlug) setSlug(slugify(value))
|
||||||
|
}} required maxLength={120} placeholder="z. B. IT" />
|
||||||
|
<TextField label="URL-Pfad" value={slug} onChange={(value) => { setSlug(value); setCustomSlug(true) }}
|
||||||
|
required maxLength={60} autoCapitalize="none" spellCheck={false} help={slug ? '/' + slug : 'z. B. it'} />
|
||||||
|
<div className="control-stack">
|
||||||
|
<span className="control-label">Standardansicht</span>
|
||||||
|
<Choice label="Standardansicht" value={view} onChange={setView} items={viewItems} />
|
||||||
|
</div>
|
||||||
|
</Modal>
|
||||||
|
}
|
||||||
|
|
||||||
|
export function LinkForm({ initial, close, save }) {
|
||||||
|
const [title, setTitle] = useState(initial?.title ?? '')
|
||||||
|
const [url, setUrl] = useState(initial?.url ?? '')
|
||||||
|
const [description, setDescription] = useState(initial?.description ?? '')
|
||||||
|
const [icon, setIcon] = useState(initial?.icon ?? null)
|
||||||
|
const [work, setWork] = useState('')
|
||||||
|
const [message, setMessage] = useState('')
|
||||||
|
const input = useRef(null)
|
||||||
|
function validUrl() {
|
||||||
|
try {
|
||||||
|
const parsed = new URL(url.trim())
|
||||||
|
if (['http:', 'https:'].includes(parsed.protocol) && !parsed.username && !parsed.password) return parsed.href
|
||||||
|
} catch { /* The validation message applies. */ }
|
||||||
|
throw new Error('Bitte gib eine gültige HTTP- oder HTTPS-Adresse ein.')
|
||||||
|
}
|
||||||
|
async function chooseIcon(kind, file) {
|
||||||
|
setMessage('')
|
||||||
|
setWork(kind)
|
||||||
|
try {
|
||||||
|
const result = kind === 'upload'
|
||||||
|
? await api('/icons/upload', { method: 'POST', file })
|
||||||
|
: await api('/icons/favicon', { method: 'POST', data: { url: validUrl() } })
|
||||||
|
setIcon(result.id)
|
||||||
|
} catch (error) {
|
||||||
|
setMessage(error.message)
|
||||||
|
} finally {
|
||||||
|
setWork('')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return <Modal title={initial ? 'Link bearbeiten' : 'Link hinzufügen'} close={close} submitLabel="Übernehmen"
|
||||||
|
ready={!work} validate={() => { if (!title.trim()) throw new Error('Bitte gib einen Titel ein.'); validUrl() }}
|
||||||
|
save={() => save({ id: initial?.id ?? newId(), title: title.trim(), url: validUrl(), description: description.trim(), icon })}>
|
||||||
|
<TextField label="Titel" value={title} onChange={setTitle} required maxLength={120} />
|
||||||
|
<TextField label="URL" type="url" value={url} onChange={setUrl} required maxLength={2048} placeholder="https://…" />
|
||||||
|
<TextField label="Beschreibung (optional)" value={description} onChange={setDescription} multiline maxLength={500} rows={2} />
|
||||||
|
<div className="control-stack">
|
||||||
|
<span className="control-label">Icon (optional)</span>
|
||||||
|
<div className="icon-preview">
|
||||||
|
<LinkIcon id={icon} label={icon ? 'Icon-Vorschau' : ''} />
|
||||||
|
<div><strong>{icon ? 'Icon-Vorschau' : 'Standard-Icon'}</strong><small>PNG, JPEG, WebP, GIF oder ICO · bis 512 KB</small></div>
|
||||||
|
{icon && <Button variant="plain" size="xs" onClick={() => { setIcon(null); setMessage('') }} disabled={Boolean(work)}
|
||||||
|
aria-label="Icon entfernen"><X size={16} /></Button>}
|
||||||
|
</div>
|
||||||
|
<div className="actions">
|
||||||
|
<input hidden ref={input} type="file" aria-label="Icon-Datei" accept=".png,.jpg,.jpeg,.webp,.gif,.ico" onChange={(event) => {
|
||||||
|
const file = event.target.files[0]
|
||||||
|
event.target.value = ''
|
||||||
|
if (file?.size > 512 * 1024) setMessage('Die Datei ist zu groß. Maximal sind 512 KB erlaubt.')
|
||||||
|
else if (file) void chooseIcon('upload', file)
|
||||||
|
}} />
|
||||||
|
<Button size="sm" variant="outline" loading={work === 'upload'} disabled={Boolean(work)} onClick={() => input.current.click()}>
|
||||||
|
<Upload size={16} /> Icon hochladen
|
||||||
|
</Button>
|
||||||
|
<Button size="sm" variant="outline" loading={work === 'favicon'} disabled={!url || Boolean(work)} onClick={() => chooseIcon('favicon')}>
|
||||||
|
<Download size={16} /> Favicon abrufen
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
{message && <p className="feedback" role="status"><FileImage size={16} /> {message}</p>}
|
||||||
|
</div>
|
||||||
|
</Modal>
|
||||||
|
}
|
||||||
|
|
||||||
|
const timezoneChoices = ['UTC', ...Intl.supportedValuesOf('timeZone')]
|
||||||
|
|
||||||
|
export function BlockForm({ type, initial, close, save }) {
|
||||||
|
const [title, setTitle] = useState(initial?.title ?? '')
|
||||||
|
const [text, setText] = useState(initial?.text ?? '')
|
||||||
|
const [zone, setZone] = useState(initial?.timeZone ?? 'Europe/Berlin')
|
||||||
|
const [hour12, setHour12] = useState(initial?.hour12 ?? false)
|
||||||
|
const datalist = useId()
|
||||||
|
const name = { group: 'Gruppe', text: 'Text-Widget', clock: 'Uhrzeit-Widget' }[type]
|
||||||
|
function validate() {
|
||||||
|
if (type === 'group' && !title.trim()) throw new Error('Bitte gib einen Gruppennamen ein.')
|
||||||
|
if (type === 'clock') {
|
||||||
|
try { new Intl.DateTimeFormat('de', { timeZone: zone.trim() }) } catch {
|
||||||
|
throw new Error('Bitte gib eine gültige Zeitzone ein, z. B. Europe/Berlin.')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function submit() {
|
||||||
|
const id = initial?.id ?? newId()
|
||||||
|
if (type === 'group') save({ id, type, title: title.trim(), links: initial?.links ?? [] })
|
||||||
|
if (type === 'text') save({ id, type, title: title.trim(), text })
|
||||||
|
if (type === 'clock') save({ id, type, timeZone: zone.trim(), hour12 })
|
||||||
|
}
|
||||||
|
return <Modal title={name + (initial ? ' bearbeiten' : ' hinzufügen')} close={close} submitLabel="Übernehmen" save={submit} validate={validate}>
|
||||||
|
{type === 'group' && <TextField label="Gruppenname" value={title} onChange={setTitle} required maxLength={120} />}
|
||||||
|
{type === 'text' && <>
|
||||||
|
<TextField label="Überschrift (optional)" value={title} onChange={setTitle} maxLength={120} />
|
||||||
|
<TextField label="Text" value={text} onChange={setText} multiline rows={5} maxLength={5000} />
|
||||||
|
</>}
|
||||||
|
{type === 'clock' && <>
|
||||||
|
<TextField label="Zeitzone" list={datalist} value={zone} onChange={setZone} required maxLength={100} help="z. B. Europe/Berlin oder UTC" />
|
||||||
|
<datalist id={datalist}>{timezoneChoices.map((choice) => <option key={choice} value={choice} />)}</datalist>
|
||||||
|
<div className="control-stack">
|
||||||
|
<span className="control-label">Zeitformat</span>
|
||||||
|
<Choice label="Zeitformat" value={hour12 ? '12' : '24'} onChange={(value) => setHour12(value === '12')}
|
||||||
|
items={[{ value: '24', label: '24 Stunden' }, { value: '12', label: '12 Stunden' }]} />
|
||||||
|
</div>
|
||||||
|
</>}
|
||||||
|
</Modal>
|
||||||
|
}
|
||||||
142
src/components/page-content.jsx
Normal file
142
src/components/page-content.jsx
Normal file
@ -0,0 +1,142 @@
|
|||||||
|
import { useEffect, useMemo, useState } from 'react'
|
||||||
|
import { ArrowUpRight, Clock3, FolderOpen, GripVertical, Pencil, Plus, Trash2, Unlink } from 'lucide-react'
|
||||||
|
import { Button } from './ui/button'
|
||||||
|
import * as Card from './ui/card'
|
||||||
|
import { LinkIcon } from './shared'
|
||||||
|
|
||||||
|
export const blockName = (block) => block.title || (block.type === 'clock' ? `Uhrzeit · ${block.timeZone}` : 'Text-Widget')
|
||||||
|
export const linksIn = (layout, group) => group === null ? layout.loose : layout.blocks.find((block) => block.id === group).links
|
||||||
|
|
||||||
|
export function ActionIcon({ label, children, ...props }) {
|
||||||
|
return <Button variant="plain" size="xs" aria-label={label} title={label} {...props}>{children}</Button>
|
||||||
|
}
|
||||||
|
|
||||||
|
function Clock({ block }) {
|
||||||
|
const [now, setNow] = useState(() => new Date())
|
||||||
|
useEffect(() => {
|
||||||
|
const timer = setInterval(() => setNow(new Date()), 1000)
|
||||||
|
return () => clearInterval(timer)
|
||||||
|
}, [])
|
||||||
|
const format = useMemo(() => new Intl.DateTimeFormat('de-DE', {
|
||||||
|
timeZone: block.timeZone, hour: '2-digit', minute: '2-digit', second: '2-digit',
|
||||||
|
...(block.hour12 ? { hour12: true } : { hourCycle: 'h23' }),
|
||||||
|
}), [block.timeZone, block.hour12])
|
||||||
|
return <div className="clock-body">
|
||||||
|
<span className="clock-zone"><Clock3 size={17} /> {block.timeZone}</span>
|
||||||
|
<time dateTime={now.toISOString()}>{format.format(now)}</time>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
|
||||||
|
function Grip({ item, dnd }) {
|
||||||
|
return <ActionIcon className="grip" label={`${item.name} verschieben`} data-grip={item.id} draggable
|
||||||
|
aria-pressed={dnd.item?.id === item.id}
|
||||||
|
onClick={() => dnd.pick(item, 'keyboard')}
|
||||||
|
onDragStart={(event) => {
|
||||||
|
event.dataTransfer.effectAllowed = 'move'
|
||||||
|
event.dataTransfer.setData('text/plain', item.id)
|
||||||
|
dnd.pick(item, 'drag')
|
||||||
|
}}
|
||||||
|
onDragEnd={() => dnd.cancel(false)}>
|
||||||
|
<GripVertical size={17} />
|
||||||
|
</ActionIcon>
|
||||||
|
}
|
||||||
|
|
||||||
|
function Drop({ dnd, type, group, before, previous, label }) {
|
||||||
|
if (dnd.item?.type !== type) return null
|
||||||
|
const sameList = type === 'block' || group === dnd.item.group
|
||||||
|
if (sameList && (dnd.item.id === before || dnd.item.id === previous)) return null
|
||||||
|
const target = { group, before }
|
||||||
|
const key = `${type}:${group ?? ''}:${before ?? ''}`
|
||||||
|
return <div className="drop-slot" data-over={dnd.hover === key || undefined}
|
||||||
|
data-keyboard={dnd.item.mode === 'keyboard' || undefined}
|
||||||
|
onDragOver={(event) => {
|
||||||
|
event.preventDefault()
|
||||||
|
event.dataTransfer.dropEffect = 'move'
|
||||||
|
if (dnd.hover !== key) dnd.setHover(key)
|
||||||
|
}}
|
||||||
|
onDragLeave={(event) => {
|
||||||
|
if (!(event.relatedTarget instanceof Node) || !event.currentTarget.contains(event.relatedTarget)) dnd.setHover(null)
|
||||||
|
}}
|
||||||
|
onDrop={(event) => {
|
||||||
|
event.preventDefault()
|
||||||
|
dnd.drop(target)
|
||||||
|
}}>
|
||||||
|
<Button data-drop type="button" variant="plain" size="xs" tabIndex={dnd.item.mode === 'keyboard' ? 0 : -1}
|
||||||
|
onClick={() => dnd.drop(target)}>{label}</Button>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
|
||||||
|
function LinkRow({ link, group, editing, dnd, editLink, deleteLink }) {
|
||||||
|
const body = <>
|
||||||
|
<LinkIcon id={link.icon} />
|
||||||
|
<span className="link-copy"><strong>{link.title}</strong>{link.description && <small>{link.description}</small>}</span>
|
||||||
|
</>
|
||||||
|
if (!editing) return <Card.Root asChild className="link-card">
|
||||||
|
<a href={link.url} target="_blank" rel="noopener noreferrer">{body}<ArrowUpRight className="external-arrow" size={17} aria-hidden="true" /></a>
|
||||||
|
</Card.Root>
|
||||||
|
return <Card.Root className="link-card editable-link" data-moving={dnd.item?.id === link.id || undefined}>
|
||||||
|
<Grip item={{ type: 'link', group, id: link.id, name: link.title }} dnd={dnd} />
|
||||||
|
{body}
|
||||||
|
<div className="item-actions">
|
||||||
|
<ActionIcon label={`${link.title} bearbeiten`} disabled={Boolean(dnd.item)} onClick={() => editLink(group, link)}><Pencil size={15} /></ActionIcon>
|
||||||
|
<ActionIcon label={`${link.title} löschen`} disabled={Boolean(dnd.item)} onClick={() => deleteLink(group, link)}><Trash2 size={15} /></ActionIcon>
|
||||||
|
</div>
|
||||||
|
</Card.Root>
|
||||||
|
}
|
||||||
|
|
||||||
|
function LinkSet({ group, title, links, view, editing, dnd, editLink, deleteLink }) {
|
||||||
|
return <div className={`link-set ${view}${editing ? ' editing' : ''}`}>
|
||||||
|
{links.map((link, index) => <div className="link-position" key={link.id}>
|
||||||
|
{editing && <Drop dnd={dnd} type="link" group={group} before={link.id} previous={links[index - 1]?.id}
|
||||||
|
label={`${title} · Vor ${link.title} ablegen`} />}
|
||||||
|
<LinkRow {...{ link, group, editing, dnd, editLink, deleteLink }} />
|
||||||
|
</div>)}
|
||||||
|
{editing && <Drop dnd={dnd} type="link" group={group} previous={links.at(-1)?.id} label={`${title} · Am Ende ablegen`} />}
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
|
||||||
|
export function PageContent({ layout, view, controls }) {
|
||||||
|
const editing = Boolean(controls)
|
||||||
|
const { dnd, editLink, deleteLink, editBlock, deleteBlock } = controls ?? {}
|
||||||
|
function groupPanel({ id, title, links }, block) {
|
||||||
|
const ungrouped = id === null
|
||||||
|
return <section className="group-panel" aria-label={title}>
|
||||||
|
<div className="group-heading">
|
||||||
|
{editing && !ungrouped && <Grip item={{ type: 'block', id, name: title }} dnd={dnd} />}
|
||||||
|
<span className="section-icon">{ungrouped ? <Unlink size={17} /> : <FolderOpen size={17} />}</span>
|
||||||
|
<h2>{title}</h2>
|
||||||
|
{editing && <div className="item-actions">
|
||||||
|
<Button size="xs" variant="outline" disabled={Boolean(dnd.item)} onClick={() => editLink(id)} aria-label={`Link hinzufügen · ${title}`}><Plus size={16} /> Link</Button>
|
||||||
|
{!ungrouped && <>
|
||||||
|
<ActionIcon label={`${title} bearbeiten`} disabled={Boolean(dnd.item)} onClick={() => editBlock(block.type, block)}><Pencil size={15} /></ActionIcon>
|
||||||
|
<ActionIcon label={`${title} löschen`} disabled={Boolean(dnd.item)} onClick={() => deleteBlock(block)}><Trash2 size={15} /></ActionIcon>
|
||||||
|
</>}
|
||||||
|
</div>}
|
||||||
|
</div>
|
||||||
|
{editing && links.length === 0 && dnd.item?.type !== 'link' && <p className="empty-group">Noch keine Links</p>}
|
||||||
|
<LinkSet group={id} {...{ title, links, view, editing, dnd, editLink, deleteLink }} />
|
||||||
|
</section>
|
||||||
|
}
|
||||||
|
return <div className="page-content">
|
||||||
|
{(editing || layout.loose.length > 0) && groupPanel({ id: null, title: 'Ungruppierte Links', links: layout.loose })}
|
||||||
|
{layout.blocks.map((block, index) => <div key={block.id} data-moving={dnd?.item?.id === block.id || undefined}>
|
||||||
|
{editing && <Drop dnd={dnd} type="block" before={block.id} previous={layout.blocks[index - 1]?.id}
|
||||||
|
label={`Vor ${blockName(block)} ablegen`} />}
|
||||||
|
{block.type === 'group' ? groupPanel(block, block) : <Card.Root className={`widget ${block.type}-widget`}>
|
||||||
|
{editing && <div className="widget-tools">
|
||||||
|
<Grip item={{ type: 'block', id: block.id, name: blockName(block) }} dnd={dnd} />
|
||||||
|
<span>{block.type === 'clock' ? 'Uhrzeit-Widget' : 'Text-Widget'}</span>
|
||||||
|
<div className="item-actions">
|
||||||
|
<ActionIcon label={`${blockName(block)} bearbeiten`} disabled={Boolean(dnd.item)} onClick={() => editBlock(block.type, block)}><Pencil size={15} /></ActionIcon>
|
||||||
|
<ActionIcon label={`${blockName(block)} löschen`} disabled={Boolean(dnd.item)} onClick={() => deleteBlock(block)}><Trash2 size={15} /></ActionIcon>
|
||||||
|
</div>
|
||||||
|
</div>}
|
||||||
|
{block.type === 'clock' ? <Clock block={block} /> : <div className="text-body">
|
||||||
|
{block.title && <h2>{block.title}</h2>}
|
||||||
|
{block.text && <p>{block.text}</p>}
|
||||||
|
</div>}
|
||||||
|
</Card.Root>}
|
||||||
|
</div>)}
|
||||||
|
{editing && <Drop dnd={dnd} type="block" previous={layout.blocks.at(-1)?.id} label="Am Seitenende ablegen" />}
|
||||||
|
</div>
|
||||||
|
}
|
||||||
95
src/components/shared.jsx
Normal file
95
src/components/shared.jsx
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
import { useId, useState } from 'react'
|
||||||
|
import { Portal } from '@ark-ui/react/portal'
|
||||||
|
import { Grid2X2, Link2, List, X } from 'lucide-react'
|
||||||
|
import { Button } from './ui/button'
|
||||||
|
import * as Dialog from './ui/dialog'
|
||||||
|
import * as Field from './ui/field'
|
||||||
|
import * as SegmentGroup from './ui/segment-group'
|
||||||
|
import { Input } from './ui/input'
|
||||||
|
import { Textarea } from './ui/textarea'
|
||||||
|
import { iconUrl } from '../api'
|
||||||
|
|
||||||
|
export function Brand({ link = false }) {
|
||||||
|
const content = <><span className="brand-mark"><Link2 size={20} /></span><span>syncova<span className="brand-suffix">-links</span></span></>
|
||||||
|
return link ? <a href="/" className="brand">{content}</a> : <div className="brand">{content}</div>
|
||||||
|
}
|
||||||
|
|
||||||
|
export function TextField({ label, value, onChange, help, multiline, ...props }) {
|
||||||
|
const control = { value, onChange: (event) => onChange(event.target.value), ...props }
|
||||||
|
return <Field.Root required={props.required}>
|
||||||
|
<Field.Label>{label}</Field.Label>
|
||||||
|
{multiline ? <Textarea {...control} /> : <Input {...control} />}
|
||||||
|
{help && <Field.HelperText>{help}</Field.HelperText>}
|
||||||
|
</Field.Root>
|
||||||
|
}
|
||||||
|
|
||||||
|
export function Choice({ label, value, onChange, items }) {
|
||||||
|
return <SegmentGroup.Root className="choice" aria-label={label} value={value} onValueChange={({ value }) => onChange(value)} size="sm">
|
||||||
|
<SegmentGroup.Indicator />
|
||||||
|
<SegmentGroup.Items items={items} />
|
||||||
|
</SegmentGroup.Root>
|
||||||
|
}
|
||||||
|
|
||||||
|
export const viewItems = [
|
||||||
|
{ value: 'list', label: <><List size={16} /> Liste</> },
|
||||||
|
{ value: 'grid', label: <><Grid2X2 size={15} /> Kacheln</> },
|
||||||
|
]
|
||||||
|
|
||||||
|
export function Modal({ title, description, submitLabel, close, save, children, validate, ready = true, danger = false }) {
|
||||||
|
const [busy, setBusy] = useState(false)
|
||||||
|
const [error, setError] = useState('')
|
||||||
|
const formId = useId()
|
||||||
|
async function submit(event) {
|
||||||
|
event.preventDefault()
|
||||||
|
if (busy || !ready) return
|
||||||
|
setError('')
|
||||||
|
setBusy(true)
|
||||||
|
try {
|
||||||
|
validate?.()
|
||||||
|
await save()
|
||||||
|
close()
|
||||||
|
} catch (failure) {
|
||||||
|
setError(failure.message)
|
||||||
|
} finally {
|
||||||
|
setBusy(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return <Dialog.Root open onOpenChange={({ open }) => { if (!open && !busy) close() }}>
|
||||||
|
<Portal>
|
||||||
|
<Dialog.Backdrop className="dialog-backdrop" />
|
||||||
|
<Dialog.Positioner className="dialog-positioner">
|
||||||
|
<Dialog.Content className="dialog-panel">
|
||||||
|
<Dialog.Header>
|
||||||
|
<Dialog.Title>{title}</Dialog.Title>
|
||||||
|
{description && <Dialog.Description>{description}</Dialog.Description>}
|
||||||
|
<Dialog.CloseTrigger asChild>
|
||||||
|
<Button disabled={busy} size="xs" variant="plain" aria-label="Dialog schließen"><X size={18} /></Button>
|
||||||
|
</Dialog.CloseTrigger>
|
||||||
|
</Dialog.Header>
|
||||||
|
<Dialog.Body>
|
||||||
|
<form id={formId} onSubmit={submit} className="form-stack">
|
||||||
|
{children}
|
||||||
|
{error && <p className="feedback error" role="alert">{error}</p>}
|
||||||
|
</form>
|
||||||
|
</Dialog.Body>
|
||||||
|
<Dialog.Footer className="dialog-actions">
|
||||||
|
<Button variant="outline" onClick={close} disabled={busy}>Abbrechen</Button>
|
||||||
|
<Button type="submit" form={formId} colorPalette={danger ? 'red' : 'jade'} loading={busy} disabled={!ready}>{submitLabel}</Button>
|
||||||
|
</Dialog.Footer>
|
||||||
|
</Dialog.Content>
|
||||||
|
</Dialog.Positioner>
|
||||||
|
</Portal>
|
||||||
|
</Dialog.Root>
|
||||||
|
}
|
||||||
|
|
||||||
|
export function LinkIcon({ id, label = '' }) {
|
||||||
|
const [failed, setFailed] = useState(null)
|
||||||
|
return <span className="link-icon">
|
||||||
|
{id && failed !== id ? <img alt={label} src={iconUrl(id)} onError={() => setFailed(id)} /> : <Link2 aria-hidden="true" size={19} />}
|
||||||
|
</span>
|
||||||
|
}
|
||||||
|
|
||||||
|
export function slugify(name) {
|
||||||
|
return name.toLowerCase().replace(/ä/g, 'ae').replace(/ö/g, 'oe').replace(/ü/g, 'ue').replace(/ß/g, 'ss')
|
||||||
|
.normalize('NFD').replace(/[\u0300-\u036f]/g, '').replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '').slice(0, 60).replace(/-$/, '')
|
||||||
|
}
|
||||||
7
src/components/ui/absolute-center.tsx
Normal file
7
src/components/ui/absolute-center.tsx
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
import { ark } from '@ark-ui/react/factory'
|
||||||
|
import type { ComponentProps } from 'react'
|
||||||
|
import { styled } from 'styled-system/jsx'
|
||||||
|
import { absoluteCenter } from 'styled-system/recipes'
|
||||||
|
|
||||||
|
export type AbsoluteCenterProps = ComponentProps<typeof AbsoluteCenter>
|
||||||
|
export const AbsoluteCenter = styled(ark.div, absoluteCenter)
|
||||||
81
src/components/ui/button.tsx
Normal file
81
src/components/ui/button.tsx
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
'use client'
|
||||||
|
import { ark } from '@ark-ui/react/factory'
|
||||||
|
import { createContext, mergeProps } from '@ark-ui/react/utils'
|
||||||
|
import { type ComponentProps, forwardRef, useMemo } from 'react'
|
||||||
|
import { styled } from 'styled-system/jsx'
|
||||||
|
import { type ButtonVariantProps, button } from 'styled-system/recipes'
|
||||||
|
import { Group, type GroupProps } from './group'
|
||||||
|
import { Loader } from './loader'
|
||||||
|
|
||||||
|
interface ButtonLoadingProps {
|
||||||
|
/**
|
||||||
|
* If `true`, the button will show a loading spinner.
|
||||||
|
* @default false
|
||||||
|
*/
|
||||||
|
loading?: boolean | undefined
|
||||||
|
/**
|
||||||
|
* The text to show while loading.
|
||||||
|
*/
|
||||||
|
loadingText?: React.ReactNode | undefined
|
||||||
|
/**
|
||||||
|
* The spinner to show while loading.
|
||||||
|
*/
|
||||||
|
spinner?: React.ReactNode | undefined
|
||||||
|
/**
|
||||||
|
* The placement of the spinner
|
||||||
|
* @default "start"
|
||||||
|
*/
|
||||||
|
spinnerPlacement?: 'start' | 'end' | undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
type BaseButtonProps = ComponentProps<typeof BaseButton>
|
||||||
|
const BaseButton = styled(ark.button, button)
|
||||||
|
|
||||||
|
export interface ButtonProps extends BaseButtonProps, ButtonLoadingProps {}
|
||||||
|
|
||||||
|
export const Button = forwardRef<HTMLButtonElement, ButtonProps>(function Button(props, ref) {
|
||||||
|
const propsContext = useButtonPropsContext()
|
||||||
|
const buttonProps = useMemo(
|
||||||
|
() => mergeProps<ButtonProps>(propsContext, props),
|
||||||
|
[propsContext, props],
|
||||||
|
)
|
||||||
|
|
||||||
|
const { loading, loadingText, children, spinner, spinnerPlacement, ...rest } = buttonProps
|
||||||
|
return (
|
||||||
|
<BaseButton
|
||||||
|
type="button"
|
||||||
|
ref={ref}
|
||||||
|
{...rest}
|
||||||
|
data-loading={loading ? '' : undefined}
|
||||||
|
disabled={loading || rest.disabled}
|
||||||
|
>
|
||||||
|
{!props.asChild && loading ? (
|
||||||
|
<Loader spinner={spinner} text={loadingText} spinnerPlacement={spinnerPlacement}>
|
||||||
|
{children}
|
||||||
|
</Loader>
|
||||||
|
) : (
|
||||||
|
children
|
||||||
|
)}
|
||||||
|
</BaseButton>
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
export interface ButtonGroupProps extends GroupProps, ButtonVariantProps {}
|
||||||
|
|
||||||
|
export const ButtonGroup = forwardRef<HTMLDivElement, ButtonGroupProps>(
|
||||||
|
function ButtonGroup(props, ref) {
|
||||||
|
const [variantProps, otherProps] = useMemo(() => button.splitVariantProps(props), [props])
|
||||||
|
return (
|
||||||
|
<ButtonPropsProvider value={variantProps}>
|
||||||
|
<Group ref={ref} {...otherProps} />
|
||||||
|
</ButtonPropsProvider>
|
||||||
|
)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
const [ButtonPropsProvider, useButtonPropsContext] = createContext<ButtonVariantProps>({
|
||||||
|
name: 'ButtonPropsContext',
|
||||||
|
hookName: 'useButtonPropsContext',
|
||||||
|
providerName: '<PropsProvider />',
|
||||||
|
strict: false,
|
||||||
|
})
|
||||||
15
src/components/ui/card.tsx
Normal file
15
src/components/ui/card.tsx
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
'use client'
|
||||||
|
import { ark } from '@ark-ui/react/factory'
|
||||||
|
import type { ComponentProps } from 'react'
|
||||||
|
import { createStyleContext } from 'styled-system/jsx'
|
||||||
|
import { card } from 'styled-system/recipes'
|
||||||
|
|
||||||
|
const { withProvider, withContext } = createStyleContext(card)
|
||||||
|
|
||||||
|
export type RootProps = ComponentProps<typeof Root>
|
||||||
|
export const Root = withProvider(ark.div, 'root')
|
||||||
|
export const Header = withContext(ark.div, 'header')
|
||||||
|
export const Body = withContext(ark.div, 'body')
|
||||||
|
export const Footer = withContext(ark.h3, 'footer')
|
||||||
|
export const Title = withContext(ark.h3, 'title')
|
||||||
|
export const Description = withContext(ark.div, 'description')
|
||||||
37
src/components/ui/dialog.tsx
Normal file
37
src/components/ui/dialog.tsx
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
'use client'
|
||||||
|
import { Dialog, useDialogContext } from '@ark-ui/react/dialog'
|
||||||
|
import { ark } from '@ark-ui/react/factory'
|
||||||
|
import { type ComponentProps, forwardRef } from 'react'
|
||||||
|
import { createStyleContext, styled } from 'styled-system/jsx'
|
||||||
|
import { dialog } from 'styled-system/recipes'
|
||||||
|
|
||||||
|
const { withRootProvider, withContext } = createStyleContext(dialog)
|
||||||
|
|
||||||
|
export type RootProps = ComponentProps<typeof Root>
|
||||||
|
export const Root = withRootProvider(Dialog.Root, {
|
||||||
|
defaultProps: { unmountOnExit: true, lazyMount: true },
|
||||||
|
})
|
||||||
|
export const RootProvider = withRootProvider(Dialog.RootProvider, {
|
||||||
|
defaultProps: { unmountOnExit: true, lazyMount: true },
|
||||||
|
})
|
||||||
|
export const Backdrop = withContext(Dialog.Backdrop, 'backdrop')
|
||||||
|
export const CloseTrigger = withContext(Dialog.CloseTrigger, 'closeTrigger')
|
||||||
|
export const Content = withContext(Dialog.Content, 'content')
|
||||||
|
export const Description = withContext(Dialog.Description, 'description')
|
||||||
|
export const Positioner = withContext(Dialog.Positioner, 'positioner')
|
||||||
|
export const Title = withContext(Dialog.Title, 'title')
|
||||||
|
export const Trigger = withContext(Dialog.Trigger, 'trigger')
|
||||||
|
export const Body = withContext(ark.div, 'body')
|
||||||
|
export const Header = withContext(ark.div, 'header')
|
||||||
|
export const Footer = withContext(ark.div, 'footer')
|
||||||
|
|
||||||
|
const StyledButton = styled(ark.button)
|
||||||
|
|
||||||
|
export const ActionTrigger = forwardRef<HTMLButtonElement, ComponentProps<typeof StyledButton>>(
|
||||||
|
function ActionTrigger(props, ref) {
|
||||||
|
const dialog = useDialogContext()
|
||||||
|
return <StyledButton {...props} ref={ref} onClick={() => dialog.setOpen(false)} />
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
export { DialogContext as Context } from '@ark-ui/react/dialog'
|
||||||
17
src/components/ui/field.tsx
Normal file
17
src/components/ui/field.tsx
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
'use client'
|
||||||
|
import { Field } from '@ark-ui/react/field'
|
||||||
|
import type { ComponentProps } from 'react'
|
||||||
|
import { createStyleContext } from 'styled-system/jsx'
|
||||||
|
import { field } from 'styled-system/recipes'
|
||||||
|
|
||||||
|
const { withProvider, withContext } = createStyleContext(field)
|
||||||
|
|
||||||
|
export type RootProps = ComponentProps<typeof Root>
|
||||||
|
export const Root = withProvider(Field.Root, 'root')
|
||||||
|
export const RootProvider = withProvider(Field.RootProvider, 'root')
|
||||||
|
export const ErrorText = withContext(Field.ErrorText, 'errorText')
|
||||||
|
export const HelperText = withContext(Field.HelperText, 'helperText')
|
||||||
|
export const Label = withContext(Field.Label, 'label')
|
||||||
|
export const RequiredIndicator = withContext(Field.RequiredIndicator, 'requiredIndicator')
|
||||||
|
|
||||||
|
export { FieldContext as Context } from '@ark-ui/react/field'
|
||||||
7
src/components/ui/group.tsx
Normal file
7
src/components/ui/group.tsx
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
import { ark } from '@ark-ui/react'
|
||||||
|
import type { ComponentProps } from 'react'
|
||||||
|
import { styled } from 'styled-system/jsx'
|
||||||
|
import { group } from 'styled-system/recipes'
|
||||||
|
|
||||||
|
export type GroupProps = ComponentProps<typeof Group>
|
||||||
|
export const Group = styled(ark.div, group)
|
||||||
7
src/components/ui/input.tsx
Normal file
7
src/components/ui/input.tsx
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
import { Field } from '@ark-ui/react/field'
|
||||||
|
import type { ComponentProps } from 'react'
|
||||||
|
import { styled } from 'styled-system/jsx'
|
||||||
|
import { input } from 'styled-system/recipes'
|
||||||
|
|
||||||
|
export type InputProps = ComponentProps<typeof Input>
|
||||||
|
export const Input = styled(Field.Input, input)
|
||||||
69
src/components/ui/loader.tsx
Normal file
69
src/components/ui/loader.tsx
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
'use client'
|
||||||
|
import { forwardRef } from 'react'
|
||||||
|
import type { HTMLStyledProps } from 'styled-system/jsx'
|
||||||
|
import { AbsoluteCenter } from './absolute-center'
|
||||||
|
import { Span } from './span'
|
||||||
|
import { Spinner } from './spinner'
|
||||||
|
|
||||||
|
export interface LoaderProps extends HTMLStyledProps<'span'> {
|
||||||
|
/**
|
||||||
|
* Whether the loader is visible
|
||||||
|
* @default true
|
||||||
|
*/
|
||||||
|
visible?: boolean | undefined
|
||||||
|
/**
|
||||||
|
* The spinner to display when loading
|
||||||
|
*/
|
||||||
|
spinner?: React.ReactNode | undefined
|
||||||
|
/**
|
||||||
|
* The placement of the spinner
|
||||||
|
* @default "start"
|
||||||
|
*/
|
||||||
|
spinnerPlacement?: 'start' | 'end' | undefined
|
||||||
|
/**
|
||||||
|
* The text to display when loading
|
||||||
|
*/
|
||||||
|
text?: React.ReactNode | undefined
|
||||||
|
|
||||||
|
children?: React.ReactNode
|
||||||
|
}
|
||||||
|
|
||||||
|
export const Loader = forwardRef<HTMLSpanElement, LoaderProps>(function Loader(props, ref) {
|
||||||
|
const {
|
||||||
|
spinner = <Spinner size="inherit" borderWidth="0.125em" color="inherit" />,
|
||||||
|
spinnerPlacement = 'start',
|
||||||
|
children,
|
||||||
|
text,
|
||||||
|
visible = true,
|
||||||
|
...rest
|
||||||
|
} = props
|
||||||
|
|
||||||
|
if (!visible) return children
|
||||||
|
|
||||||
|
if (text) {
|
||||||
|
return (
|
||||||
|
<Span ref={ref} display="contents" {...rest}>
|
||||||
|
{spinnerPlacement === 'start' && spinner}
|
||||||
|
{text}
|
||||||
|
{spinnerPlacement === 'end' && spinner}
|
||||||
|
</Span>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (spinner) {
|
||||||
|
return (
|
||||||
|
<Span ref={ref} display="contents" {...rest}>
|
||||||
|
<AbsoluteCenter display="inline-flex">{spinner}</AbsoluteCenter>
|
||||||
|
<Span visibility="hidden" display="contents">
|
||||||
|
{children}
|
||||||
|
</Span>
|
||||||
|
</Span>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Span ref={ref} display="contents" {...rest}>
|
||||||
|
{children}
|
||||||
|
</Span>
|
||||||
|
)
|
||||||
|
})
|
||||||
50
src/components/ui/segment-group.tsx
Normal file
50
src/components/ui/segment-group.tsx
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
'use client'
|
||||||
|
import { SegmentGroup } from '@ark-ui/react/segment-group'
|
||||||
|
import { type ComponentProps, type ReactNode, useMemo } from 'react'
|
||||||
|
import { createStyleContext } from 'styled-system/jsx'
|
||||||
|
import { segmentGroup } from 'styled-system/recipes'
|
||||||
|
|
||||||
|
const { withProvider, withContext } = createStyleContext(segmentGroup)
|
||||||
|
|
||||||
|
export type RootProps = ComponentProps<typeof Root>
|
||||||
|
|
||||||
|
export const Root = withProvider(SegmentGroup.Root, 'root', {
|
||||||
|
defaultProps: { orientation: 'horizontal' },
|
||||||
|
forwardProps: ['orientation'],
|
||||||
|
})
|
||||||
|
export const RootProvider = withProvider(SegmentGroup.RootProvider, 'root')
|
||||||
|
export const Indicator = withContext(SegmentGroup.Indicator, 'indicator')
|
||||||
|
export const Item = withContext(SegmentGroup.Item, 'item')
|
||||||
|
export const ItemControl = withContext(SegmentGroup.ItemControl, 'itemControl')
|
||||||
|
export const ItemHiddenInput = SegmentGroup.ItemHiddenInput
|
||||||
|
export const ItemText = withContext(SegmentGroup.ItemText, 'itemText')
|
||||||
|
export const Label = withContext(SegmentGroup.Label, 'label')
|
||||||
|
|
||||||
|
export { SegmentGroupContext as Context } from '@ark-ui/react/segment-group'
|
||||||
|
|
||||||
|
interface Item {
|
||||||
|
value: string
|
||||||
|
label: ReactNode
|
||||||
|
disabled?: boolean | undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
type ItemProps = ComponentProps<typeof Item>
|
||||||
|
|
||||||
|
export interface ItemsProps extends Omit<ItemProps, 'value'> {
|
||||||
|
items: Array<string | Item>
|
||||||
|
}
|
||||||
|
|
||||||
|
export const Items = (props: ItemsProps) => {
|
||||||
|
const { items, ...itemProps } = props
|
||||||
|
const data = useMemo(() => normalize(items), [items])
|
||||||
|
|
||||||
|
return data.map((item) => (
|
||||||
|
<Item key={item.value} value={item.value} disabled={item.disabled} {...itemProps}>
|
||||||
|
<ItemText>{item.label}</ItemText>
|
||||||
|
<ItemHiddenInput />
|
||||||
|
</Item>
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
const normalize = (items: Array<string | Item>): Item[] =>
|
||||||
|
items.map((item) => (typeof item === 'string' ? { value: item, label: item } : item))
|
||||||
5
src/components/ui/span.tsx
Normal file
5
src/components/ui/span.tsx
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
import type { ComponentProps } from 'react'
|
||||||
|
import { styled } from 'styled-system/jsx'
|
||||||
|
|
||||||
|
export type SpanProps = ComponentProps<typeof Span>
|
||||||
|
export const Span = styled('span')
|
||||||
7
src/components/ui/spinner.tsx
Normal file
7
src/components/ui/spinner.tsx
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
import { ark } from '@ark-ui/react/factory'
|
||||||
|
import type { ComponentProps } from 'react'
|
||||||
|
import { styled } from 'styled-system/jsx'
|
||||||
|
import { spinner } from 'styled-system/recipes'
|
||||||
|
|
||||||
|
export type SpinnerProps = ComponentProps<typeof Spinner>
|
||||||
|
export const Spinner = styled(ark.span, spinner)
|
||||||
7
src/components/ui/textarea.tsx
Normal file
7
src/components/ui/textarea.tsx
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
import { Field } from '@ark-ui/react/field'
|
||||||
|
import type { ComponentProps } from 'react'
|
||||||
|
import { styled } from 'styled-system/jsx'
|
||||||
|
import { textarea } from 'styled-system/recipes'
|
||||||
|
|
||||||
|
export type TextareaProps = ComponentProps<typeof Textarea>
|
||||||
|
export const Textarea = styled(Field.Textarea, textarea)
|
||||||
183
src/main.jsx
Normal file
183
src/main.jsx
Normal file
@ -0,0 +1,183 @@
|
|||||||
|
import '@fontsource-variable/dm-sans'
|
||||||
|
import './styles.css'
|
||||||
|
import { StrictMode, useEffect, useRef, useState } from 'react'
|
||||||
|
import { createRoot } from 'react-dom/client'
|
||||||
|
import { ArrowUpRight, Building2, FolderOpen, LogIn, LogOut, Moon, Pencil, Plus, Sun, Trash2 } from 'lucide-react'
|
||||||
|
import { api } from './api'
|
||||||
|
import { Button } from './components/ui/button'
|
||||||
|
import * as Card from './components/ui/card'
|
||||||
|
import { LoginForm, PageForm } from './components/forms'
|
||||||
|
import { Brand, Choice, Modal, viewItems } from './components/shared'
|
||||||
|
import { ActionIcon, PageContent } from './components/page-content'
|
||||||
|
import { Editor } from './components/editor'
|
||||||
|
import { useColorMode } from './theme/use-color-mode'
|
||||||
|
|
||||||
|
function useResource(path) {
|
||||||
|
const [state, setState] = useState({ data: null, error: '' })
|
||||||
|
useEffect(() => {
|
||||||
|
let active = true
|
||||||
|
if (path) api(path).then((data) => {
|
||||||
|
if (active) setState({ data, error: '' })
|
||||||
|
}).catch((error) => {
|
||||||
|
if (active) setState({ data: null, error: error.message })
|
||||||
|
})
|
||||||
|
return () => { active = false }
|
||||||
|
}, [path])
|
||||||
|
return [state, (data) => setState({ data, error: '' })]
|
||||||
|
}
|
||||||
|
|
||||||
|
function DepartmentCard({ page, onDelete }) {
|
||||||
|
const href = '/' + page.slug
|
||||||
|
const icon = <span className="department-icon"><FolderOpen size={21} /></span>
|
||||||
|
if (!onDelete) return <Card.Root asChild className="department-card public-department-card">
|
||||||
|
<a href={href} aria-label={page.name}>
|
||||||
|
<Card.Header className="department-card-header">
|
||||||
|
{icon}<ArrowUpRight className="external-arrow" size={18} aria-hidden="true" />
|
||||||
|
</Card.Header>
|
||||||
|
<Card.Body className="department-card-body"><h2>{page.name}</h2><span className="path">{href}</span></Card.Body>
|
||||||
|
</a>
|
||||||
|
</Card.Root>
|
||||||
|
|
||||||
|
return <Card.Root className="department-card">
|
||||||
|
<Card.Header className="department-card-header">
|
||||||
|
{icon}
|
||||||
|
<ActionIcon label={`${page.name} löschen`} onClick={() => onDelete(page)}><Trash2 size={16} /></ActionIcon>
|
||||||
|
</Card.Header>
|
||||||
|
<Card.Body className="department-card-body"><h2>{page.name}</h2><a href={href} className="path">{href} <ArrowUpRight size={14} /></a></Card.Body>
|
||||||
|
<div className="department-footer">
|
||||||
|
<Button variant="outline" size="sm" asChild><a href={href + '?bearbeiten=1'}><Pencil size={15} /> Bearbeiten</a></Button>
|
||||||
|
<Button variant="plain" size="sm" asChild><a href={href} aria-label={`${page.name} öffnen`}>Öffnen <ArrowUpRight size={15} /></a></Button>
|
||||||
|
</div>
|
||||||
|
</Card.Root>
|
||||||
|
}
|
||||||
|
|
||||||
|
function Dashboard({ admin }) {
|
||||||
|
const [{ data: pages, error }, setPages] = useResource(admin ? '/admin/pages' : '/pages')
|
||||||
|
const [dialog, setDialog] = useState(null)
|
||||||
|
const close = () => setDialog(null)
|
||||||
|
function createButton() {
|
||||||
|
return <Button colorPalette="jade" onClick={() => setDialog('create')}><Plus size={18} /> Abteilung anlegen</Button>
|
||||||
|
}
|
||||||
|
return <main className="frame dashboard">
|
||||||
|
<div className="page-heading">
|
||||||
|
<div><h1>Abteilungen</h1>{admin && <p>Verwalte die öffentlichen Linksammlungen deiner Abteilungen.</p>}</div>
|
||||||
|
{admin && Boolean(pages?.length) && createButton()}
|
||||||
|
</div>
|
||||||
|
{error && <p className="feedback error" role="alert">{error}</p>}
|
||||||
|
{pages?.length === 0 && <Card.Root className="empty-state">
|
||||||
|
<div className="empty-icon"><Building2 size={28} strokeWidth={1.65} /></div>
|
||||||
|
<h2>Noch keine Abteilungen</h2>
|
||||||
|
{admin && <><p>Lege eine Abteilung an, um ihre Links und Widgets einzurichten.</p>{createButton()}</>}
|
||||||
|
</Card.Root>}
|
||||||
|
{Boolean(pages?.length) && <div className="department-grid">
|
||||||
|
{pages.map((page) => <DepartmentCard key={page.slug} page={page} onDelete={admin ? setDialog : undefined} />)}
|
||||||
|
</div>}
|
||||||
|
{dialog === 'create' && <PageForm close={close} save={async (data) => {
|
||||||
|
const page = await api('/pages', { method: 'POST', data })
|
||||||
|
window.location.assign('/' + page.slug + '?bearbeiten=1')
|
||||||
|
}} />}
|
||||||
|
{dialog && dialog !== 'create' && <Modal title="Abteilung löschen" submitLabel="Abteilung löschen" danger close={close}
|
||||||
|
description={`„${dialog.name}“ mit allen Links, Gruppen und Widgets endgültig löschen?`}
|
||||||
|
save={async () => {
|
||||||
|
await api('/pages/' + dialog.id, { method: 'DELETE' })
|
||||||
|
setPages(pages.filter((page) => page.id !== dialog.id))
|
||||||
|
}} />}
|
||||||
|
</main>
|
||||||
|
}
|
||||||
|
|
||||||
|
const hasContent = ({ layout }) => layout.loose.length > 0 || layout.blocks.length > 0
|
||||||
|
|
||||||
|
function Department({ page, setPage, admin, editing, setEditing, setDirty }) {
|
||||||
|
const [viewOverride, setViewOverride] = useState(null)
|
||||||
|
const view = viewOverride ?? page.view
|
||||||
|
const published = hasContent(page)
|
||||||
|
function edit(value) {
|
||||||
|
const url = '/' + page.slug + (value ? '?bearbeiten=1' : '')
|
||||||
|
window.history.replaceState(null, '', url)
|
||||||
|
setEditing(value)
|
||||||
|
}
|
||||||
|
function onSave(saved) {
|
||||||
|
if (saved.slug !== page.slug) window.history.replaceState(null, '', '/' + saved.slug + '?bearbeiten=1')
|
||||||
|
setPage(saved)
|
||||||
|
setViewOverride(null)
|
||||||
|
}
|
||||||
|
if (admin && editing) return <Editor initial={page} onSave={onSave} setDirty={setDirty} exit={() => edit(false)} />
|
||||||
|
if (!admin && !published) return null
|
||||||
|
return <main className="frame public-frame">
|
||||||
|
<div className="page-heading">
|
||||||
|
<div><span className="path">/{page.slug}</span><h1>{page.name}</h1></div>
|
||||||
|
<div className="actions">
|
||||||
|
{published && <Choice label="Ansicht" value={view} onChange={setViewOverride} items={viewItems} />}
|
||||||
|
{admin && published && <Button colorPalette="jade" onClick={() => edit(true)}><Pencil size={16} /> Seite bearbeiten</Button>}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{published && <PageContent layout={page.layout} view={view} />}
|
||||||
|
{!published && <Card.Root className="empty-state">
|
||||||
|
<div className="empty-icon"><FolderOpen size={28} /></div>
|
||||||
|
<h2>Diese Seite ist leer</h2>
|
||||||
|
<p>Füge im Bearbeitungsmodus Links, Gruppen oder Widgets hinzu.</p>
|
||||||
|
<Button colorPalette="jade" onClick={() => edit(true)}><Pencil size={16} /> Seite bearbeiten</Button>
|
||||||
|
</Card.Root>}
|
||||||
|
</main>
|
||||||
|
}
|
||||||
|
|
||||||
|
function App() {
|
||||||
|
const { dark, toggle } = useColorMode()
|
||||||
|
const slug = window.location.pathname.replace(/^\/|\/$/g, '')
|
||||||
|
const validSlug = /^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(slug)
|
||||||
|
const [session, setSession] = useResource('/session')
|
||||||
|
const [pageState, setPage] = useResource(validSlug ? '/pages/' + slug : null)
|
||||||
|
const [editing, setEditing] = useState(() => new URLSearchParams(window.location.search).has('bearbeiten'))
|
||||||
|
const [modal, setModal] = useState(null)
|
||||||
|
const [dirty, setDirty] = useState(false)
|
||||||
|
const [error, setError] = useState('')
|
||||||
|
const loginButton = useRef(null)
|
||||||
|
const admin = session.data?.admin ?? false
|
||||||
|
const page = pageState.data
|
||||||
|
const showBrand = !slug || admin || (page && hasContent(page))
|
||||||
|
useEffect(() => {
|
||||||
|
document.title = page ? `${page.name} · syncova-links` : 'syncova-links'
|
||||||
|
}, [page])
|
||||||
|
async function logout() {
|
||||||
|
setError('')
|
||||||
|
await api('/logout', { method: 'POST' })
|
||||||
|
setSession({ admin: false })
|
||||||
|
setEditing(false)
|
||||||
|
window.history.replaceState(null, '', window.location.pathname)
|
||||||
|
}
|
||||||
|
|
||||||
|
return <>
|
||||||
|
<header className={`topbar${showBrand ? ' topbar-surface' : ''}`}>
|
||||||
|
<div className="frame topbar-inner">
|
||||||
|
{showBrand && <Brand link={Boolean(slug)} />}
|
||||||
|
<div className="actions topbar-actions">
|
||||||
|
{showBrand && <Button className="theme-toggle" variant="plain" size="sm" aria-label="Dunkelmodus" aria-pressed={dark}
|
||||||
|
title={dark ? 'Hellmodus aktivieren' : 'Dunkelmodus aktivieren'} onClick={toggle}>
|
||||||
|
{dark ? <Sun size={18} aria-hidden="true" /> : <Moon size={18} aria-hidden="true" />}
|
||||||
|
</Button>}
|
||||||
|
{admin ? <>
|
||||||
|
{slug && <Button variant="plain" size="sm" asChild><a href="/"><Building2 size={17} /> Abteilungen</a></Button>}
|
||||||
|
<Button variant="outline" size="sm" onClick={() => {
|
||||||
|
if (dirty) setModal('logout')
|
||||||
|
else logout().catch((failure) => setError(failure.message))
|
||||||
|
}}><LogOut size={16} /> Abmelden</Button>
|
||||||
|
</> : session.data && <Button ref={loginButton} colorPalette="jade" size="sm" onClick={() => setModal('login')}><LogIn size={17} /> Anmelden</Button>}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
{(error || session.error) && <div className="frame"><p className="feedback error" role="alert">{error || session.error}</p></div>}
|
||||||
|
{slug ? page ? <Department {...{ page, setPage, admin, editing, setEditing, setDirty }} />
|
||||||
|
: (pageState.error || !validSlug) && <main className="frame not-found">
|
||||||
|
<h1>Abteilung nicht verfügbar</h1><p role="alert">{pageState.error || 'Dieser URL-Pfad ist ungültig.'}</p>
|
||||||
|
</main>
|
||||||
|
: <Dashboard key={admin ? 'admin' : 'public'} admin={admin} />}
|
||||||
|
{modal === 'login' && <LoginForm close={() => {
|
||||||
|
setModal(null)
|
||||||
|
requestAnimationFrame(() => loginButton.current?.focus())
|
||||||
|
}} onLogin={() => setSession({ admin: true })} />}
|
||||||
|
{modal === 'logout' && <Modal title="Abmelden" description="Beim Abmelden gehen ungespeicherte Änderungen verloren."
|
||||||
|
submitLabel="Abmelden" close={() => setModal(null)} save={logout} />}
|
||||||
|
</>
|
||||||
|
}
|
||||||
|
|
||||||
|
createRoot(document.getElementById('root')).render(<StrictMode><App /></StrictMode>)
|
||||||
193
src/styles.css
Normal file
193
src/styles.css
Normal file
@ -0,0 +1,193 @@
|
|||||||
|
@layer reset, base, tokens, recipes, utilities;
|
||||||
|
|
||||||
|
:root {
|
||||||
|
color-scheme: light;
|
||||||
|
--canvas: #f6f7f2;
|
||||||
|
--paper: #fff;
|
||||||
|
--ink: #142720;
|
||||||
|
--muted: #566760;
|
||||||
|
--line: #e0e7df;
|
||||||
|
--green: #176449;
|
||||||
|
--mint: #e8f3e9;
|
||||||
|
--soft: #f1f5ef;
|
||||||
|
--green-ink: #133f31;
|
||||||
|
--hover-surface: #eaf3e9;
|
||||||
|
--hover-line: #b6d3c0;
|
||||||
|
--selection: #c7e8d4;
|
||||||
|
--drop-highlight: #ccead6;
|
||||||
|
--drop-border: #6c9c84;
|
||||||
|
--error-bg: #fceaeb;
|
||||||
|
--error-ink: #852f31;
|
||||||
|
}
|
||||||
|
|
||||||
|
:root.dark {
|
||||||
|
color-scheme: dark;
|
||||||
|
--canvas: #101613;
|
||||||
|
--paper: #19211d;
|
||||||
|
--ink: #e7f0ea;
|
||||||
|
--muted: #afc0b6;
|
||||||
|
--line: #35443b;
|
||||||
|
--green: #84d6ad;
|
||||||
|
--mint: #233d2f;
|
||||||
|
--soft: #202a24;
|
||||||
|
--green-ink: #c6efda;
|
||||||
|
--hover-surface: #293a31;
|
||||||
|
--hover-line: #548367;
|
||||||
|
--selection: #295b43;
|
||||||
|
--drop-highlight: #2a503d;
|
||||||
|
--drop-border: #719c84;
|
||||||
|
--error-bg: #412429;
|
||||||
|
--error-ink: #ffb9bf;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
margin: 0;
|
||||||
|
min-width: 280px;
|
||||||
|
min-height: 100vh;
|
||||||
|
color: var(--ink);
|
||||||
|
background: var(--canvas);
|
||||||
|
font-family: 'DM Sans Variable', system-ui, sans-serif;
|
||||||
|
-webkit-font-smoothing: antialiased;
|
||||||
|
}
|
||||||
|
|
||||||
|
button { cursor: pointer; }
|
||||||
|
button:disabled { cursor: default; }
|
||||||
|
::selection { background: var(--selection); color: var(--ink); }
|
||||||
|
:focus-visible { outline: 2px solid var(--green); outline-offset: 3px; }
|
||||||
|
h1, h2, p { margin: 0; overflow-wrap: anywhere; }
|
||||||
|
h1 { font-size: clamp(2.45rem, 5.8vw, 4rem); line-height: 1.02; font-weight: 680; letter-spacing: -.066em; }
|
||||||
|
h2 { font-weight: 670; letter-spacing: -.026em; }
|
||||||
|
|
||||||
|
.frame { width: min(1088px, calc(100% - 56px)); margin-inline: auto; }
|
||||||
|
.topbar { min-height: 68px; }
|
||||||
|
.topbar-surface { background: var(--paper); border-bottom: 1px solid var(--line); }
|
||||||
|
.topbar-inner { min-height: 68px; display: flex; align-items: center; justify-content: space-between; gap: 14px; }
|
||||||
|
.topbar:not(.topbar-surface) .topbar-inner { width: calc(100% - 56px); }
|
||||||
|
.topbar-actions { margin-left: auto; justify-content: flex-end; }
|
||||||
|
.theme-toggle { width: 36px; padding-inline: 0; }
|
||||||
|
.brand { display: inline-flex; align-items: center; gap: 9px; font-size: 1.08rem; font-weight: 750; letter-spacing: -.045em; white-space: nowrap; }
|
||||||
|
.brand-mark { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 10px; background: var(--green-ink); color: var(--paper); }
|
||||||
|
.brand-mark svg { transform: rotate(-26deg); }
|
||||||
|
.brand-suffix { color: var(--green); font-weight: 560; }
|
||||||
|
.actions, .item-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
|
||||||
|
.item-actions { flex-wrap: nowrap; gap: 4px; }
|
||||||
|
.public-frame, .edit-frame, .dashboard, .not-found { padding-block: clamp(36px, 7vw, 78px) 80px; }
|
||||||
|
.page-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 19px; margin-bottom: 32px; }
|
||||||
|
.page-heading > div:first-child { min-width: 0; }
|
||||||
|
.page-heading p { margin-top: 13px; color: var(--muted); font-size: 1rem; }
|
||||||
|
.path { display: inline-flex; align-items: center; gap: 5px; color: var(--green); font: 500 .84rem ui-monospace, monospace; overflow-wrap: anywhere; }
|
||||||
|
.page-heading .path { margin-bottom: 11px; }
|
||||||
|
a.path:hover { text-decoration: underline; }
|
||||||
|
|
||||||
|
.choice { flex: none; max-width: 100%; }
|
||||||
|
.choice [data-part="item"] { cursor: pointer; }
|
||||||
|
.choice [data-part="item-text"] { display: inline-flex; align-items: center; gap: 6px; }
|
||||||
|
.choice [data-part="item"][data-state="checked"] { color: var(--green-ink); }
|
||||||
|
|
||||||
|
.department-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr)); gap: 15px; }
|
||||||
|
.department-card, .empty-state { background: var(--paper); border: 1px solid var(--line); border-radius: 18px; box-shadow: 0 2px 5px #153b2807; }
|
||||||
|
.department-card { padding: 18px 19px; gap: 17px; }
|
||||||
|
.public-department-card:hover { background: var(--hover-surface); border-color: var(--hover-line); }
|
||||||
|
.department-card-header { flex-direction: row; justify-content: space-between; align-items: start; padding: 0; }
|
||||||
|
.department-card-body { padding: 0; display: grid; gap: 5px; justify-items: start; }
|
||||||
|
.department-card h2 { font-size: 1.35rem; }
|
||||||
|
.department-footer { display: flex; gap: 5px; flex-wrap: wrap; }
|
||||||
|
.department-icon, .empty-icon, .section-icon, .link-icon { color: var(--green); background: var(--mint); display: grid; place-items: center; flex: none; }
|
||||||
|
.department-icon { width: 43px; height: 43px; border-radius: 12px; }
|
||||||
|
.empty-state { align-items: center; padding: clamp(34px, 7vw, 76px) 20px; gap: 10px; text-align: center; }
|
||||||
|
.empty-state .empty-icon { width: 59px; height: 59px; border-radius: 17px; margin-bottom: 3px; }
|
||||||
|
.empty-state h2 { font-size: 1.45rem; }
|
||||||
|
.empty-state p { color: var(--muted); }
|
||||||
|
.empty-state button { margin-top: 12px; }
|
||||||
|
|
||||||
|
.page-content { display: grid; gap: 18px; }
|
||||||
|
.group-panel { display: grid; gap: 13px; min-width: 0; padding: 15px; border: 1px solid var(--line); background: var(--paper); border-radius: 17px; }
|
||||||
|
.group-heading { display: flex; align-items: center; gap: 9px; }
|
||||||
|
.group-heading h2 { flex: 1; font-size: 1.11rem; min-width: 0; }
|
||||||
|
.section-icon { width: 34px; height: 34px; border-radius: 9px; }
|
||||||
|
.link-set { display: grid; gap: 6px; min-width: 0; }
|
||||||
|
.link-set.grid { grid-template-columns: repeat(auto-fill, minmax(min(100%, 232px), 1fr)); gap: 8px; }
|
||||||
|
.link-set.grid .link-position { height: 100%; }
|
||||||
|
.link-card { display: flex; flex-direction: row; align-items: center; gap: 11px; min-width: 0; padding: 10px 12px; background: var(--soft); color: var(--ink); border: 1px solid var(--line); border-radius: 11px; }
|
||||||
|
a.link-card:hover { border-color: var(--hover-line); background: var(--hover-surface); }
|
||||||
|
.grid .link-card { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-content: start; align-items: start; min-height: 106px; height: 100%; padding: 14px; }
|
||||||
|
.grid .link-card .link-icon { grid-area: 1 / 1; }
|
||||||
|
.grid .link-card .external-arrow { grid-area: 1 / 2; }
|
||||||
|
.grid .link-copy { grid-column: 1 / -1; }
|
||||||
|
.link-icon { background: var(--paper); border: 1px solid var(--line); width: 37px; height: 37px; border-radius: 9px; }
|
||||||
|
:root.dark .link-icon:has(img) { background: #767e79; }
|
||||||
|
.link-icon img { width: 23px; height: 23px; object-fit: contain; }
|
||||||
|
.link-copy { flex: 1; display: grid; gap: 2px; min-width: 0; overflow-wrap: anywhere; }
|
||||||
|
.link-copy strong { font-weight: 670; }
|
||||||
|
.link-copy small { color: var(--muted); font-size: .86rem; white-space: pre-wrap; }
|
||||||
|
.external-arrow { flex: none; color: var(--green); }
|
||||||
|
.editable-link { gap: 8px; }
|
||||||
|
.editing .link-position .drop-slot { margin-bottom: 6px; }
|
||||||
|
.empty-group { color: var(--muted); padding: 3px; font-size: .88rem; }
|
||||||
|
|
||||||
|
.widget { background: var(--paper); border: 1px solid var(--line); border-radius: 17px; overflow: hidden; }
|
||||||
|
.text-body { padding: 19px 22px; }
|
||||||
|
.text-body h2 { font-size: 1.2rem; }
|
||||||
|
.text-body h2 + p { margin-top: 7px; }
|
||||||
|
.text-body p { white-space: pre-wrap; color: var(--muted); }
|
||||||
|
.clock-widget { background: var(--mint); }
|
||||||
|
.clock-body { padding: 20px 23px 23px; display: flex; flex-direction: column; align-items: flex-start; gap: 7px; }
|
||||||
|
.clock-zone { display: inline-flex; align-items: center; gap: 7px; font-size: .88rem; color: var(--green-ink); overflow-wrap: anywhere; }
|
||||||
|
.clock-zone svg { flex: none; }
|
||||||
|
.clock-body time { color: var(--green-ink); line-height: 1.05; font-size: clamp(2.05rem, 5.5vw, 3.1rem); letter-spacing: -.055em; font-weight: 650; font-variant-numeric: tabular-nums; }
|
||||||
|
.widget-tools { display: flex; align-items: center; padding: 7px 10px; gap: 8px; background: var(--soft); border-bottom: 1px solid var(--line); }
|
||||||
|
.widget-tools span { flex: 1; font-size: .86rem; font-weight: 620; }
|
||||||
|
|
||||||
|
.edit-frame { padding-top: 43px; }
|
||||||
|
.edit-frame .page-heading { margin-bottom: 24px; }
|
||||||
|
.editor-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; padding: 9px; border: 1px solid var(--line); border-radius: 13px; background: var(--paper); }
|
||||||
|
.editor-message { min-height: 43px; display: flex; align-items: center; padding: 5px 1px; color: var(--muted); font-size: .86rem; }
|
||||||
|
.editor-message > span { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }
|
||||||
|
.layout-fieldset { display: block; border: 0; margin: 0; padding: 0; min-inline-size: 0; }
|
||||||
|
.grip { cursor: grab; color: var(--muted); flex: none; }
|
||||||
|
[data-moving] { opacity: .56; }
|
||||||
|
.drop-slot { display: grid; place-items: center; background: var(--mint); border: 1px dashed var(--drop-border); border-radius: 8px; min-height: 35px; }
|
||||||
|
.drop-slot [data-drop] { width: 100%; white-space: normal; height: auto; }
|
||||||
|
.page-content > div > .drop-slot { margin-bottom: 7px; }
|
||||||
|
.drop-slot[data-over], .drop-slot:focus-within { background: var(--drop-highlight); border-color: var(--green); }
|
||||||
|
.drop-slot[data-keyboard] [data-drop]:focus-visible { outline-offset: 2px; }
|
||||||
|
|
||||||
|
.dialog-backdrop { z-index: 1400; background: #10161380; backdrop-filter: blur(3px); }
|
||||||
|
.dialog-positioner { z-index: 1401; padding: 15px; overflow: auto; }
|
||||||
|
.dialog-panel { background: var(--paper); max-width: 482px; border-radius: 18px; box-shadow: 0 24px 84px #0006; }
|
||||||
|
.dialog-panel [data-part="title"] { font-size: 1.35rem; letter-spacing: -.026em; padding-right: 30px; }
|
||||||
|
.dialog-panel [data-part="description"] { color: var(--muted); }
|
||||||
|
.dialog-panel [data-part="close-trigger"] { top: 15px; right: 15px; }
|
||||||
|
.dialog-actions { flex-wrap: wrap; }
|
||||||
|
.form-stack { width: 100%; display: grid; gap: 14px; }
|
||||||
|
.control-stack { display: grid; gap: 7px; justify-items: start; }
|
||||||
|
.control-label { font-weight: 620; }
|
||||||
|
.icon-preview { width: 100%; display: flex; align-items: center; gap: 10px; min-width: 0; border: 1px solid var(--line); border-radius: 11px; padding: 9px; background: var(--soft); }
|
||||||
|
.icon-preview > div { flex: 1; min-width: 0; display: grid; }
|
||||||
|
.icon-preview small { color: var(--muted); overflow-wrap: anywhere; }
|
||||||
|
.feedback { display: flex; align-items: flex-start; gap: 6px; padding: 9px 12px; border-radius: 8px; background: var(--mint); color: var(--green-ink); font-size: .88rem; }
|
||||||
|
.feedback svg { flex: none; margin-top: 2px; }
|
||||||
|
.feedback.error { background: var(--error-bg); color: var(--error-ink); }
|
||||||
|
.frame > .feedback { margin-bottom: 14px; }
|
||||||
|
.not-found p { color: var(--muted); margin-top: 12px; }
|
||||||
|
|
||||||
|
@media (max-width: 660px) {
|
||||||
|
.frame, .topbar:not(.topbar-surface) .topbar-inner { width: calc(100% - 28px); }
|
||||||
|
.topbar, .topbar-inner { min-height: 60px; }
|
||||||
|
.page-heading { align-items: flex-start; flex-direction: column; gap: 15px; margin-bottom: 23px; }
|
||||||
|
.topbar-actions .button { padding-inline: 8px; }
|
||||||
|
.topbar-actions svg { display: none; }
|
||||||
|
.topbar-actions .theme-toggle svg { display: block; }
|
||||||
|
.group-panel { padding: 10px; }
|
||||||
|
.group-heading { gap: 5px; }
|
||||||
|
.edit-frame .group-heading > .section-icon { display: none; }
|
||||||
|
.link-set.grid { grid-template-columns: repeat(auto-fill, minmax(min(100%, 148px), 1fr)); }
|
||||||
|
.editable-link { padding-inline: 4px; gap: 5px; }
|
||||||
|
.editable-link .link-icon { width: 28px; height: 28px; }
|
||||||
|
.editable-link .link-icon > * { max-width: 18px; }
|
||||||
|
.editor-toolbar { flex-direction: column; align-items: flex-start; }
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (prefers-reduced-motion: reduce) {
|
||||||
|
*, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
|
||||||
|
}
|
||||||
21
src/theme/LICENSE.park-ui
Normal file
21
src/theme/LICENSE.park-ui
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2025 cschroeter
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
50
src/theme/animation-styles.ts
Normal file
50
src/theme/animation-styles.ts
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
import { defineAnimationStyles } from '@pandacss/dev'
|
||||||
|
|
||||||
|
export const animationStyles = defineAnimationStyles({
|
||||||
|
'slide-fade-in': {
|
||||||
|
value: {
|
||||||
|
transformOrigin: 'var(--transform-origin)',
|
||||||
|
'&[data-placement^=top]': {
|
||||||
|
animationName: 'slide-from-bottom, fade-in',
|
||||||
|
},
|
||||||
|
'&[data-placement^=bottom]': {
|
||||||
|
animationName: 'slide-from-top, fade-in',
|
||||||
|
},
|
||||||
|
'&[data-placement^=left]': {
|
||||||
|
animationName: 'slide-from-right, fade-in',
|
||||||
|
},
|
||||||
|
'&[data-placement^=right]': {
|
||||||
|
animationName: 'slide-from-left, fade-in',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
'slide-fade-out': {
|
||||||
|
value: {
|
||||||
|
transformOrigin: 'var(--transform-origin)',
|
||||||
|
'&[data-placement^=top]': {
|
||||||
|
animationName: 'slide-to-bottom, fade-out',
|
||||||
|
},
|
||||||
|
'&[data-placement^=bottom]': {
|
||||||
|
animationName: 'slide-to-top, fade-out',
|
||||||
|
},
|
||||||
|
'&[data-placement^=left]': {
|
||||||
|
animationName: 'slide-to-right, fade-out',
|
||||||
|
},
|
||||||
|
'&[data-placement^=right]': {
|
||||||
|
animationName: 'slide-to-left, fade-out',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
'scale-fade-in': {
|
||||||
|
value: {
|
||||||
|
transformOrigin: 'var(--transform-origin)',
|
||||||
|
animationName: 'scale-in, fade-in',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
'scale-fade-out': {
|
||||||
|
value: {
|
||||||
|
transformOrigin: 'var(--transform-origin)',
|
||||||
|
animationName: 'scale-out, fade-out',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
69
src/theme/colors/green.ts
Normal file
69
src/theme/colors/green.ts
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
import { defineSemanticTokens } from '@pandacss/dev'
|
||||||
|
|
||||||
|
export const green = defineSemanticTokens.colors({
|
||||||
|
'1': { value: { _light: '#fbfefc', _dark: '#0e1512' } },
|
||||||
|
'2': { value: { _light: '#f4fbf6', _dark: '#121b17' } },
|
||||||
|
'3': { value: { _light: '#e6f6eb', _dark: '#132d21' } },
|
||||||
|
'4': { value: { _light: '#d6f1df', _dark: '#113b29' } },
|
||||||
|
'5': { value: { _light: '#c4e8d1', _dark: '#174933' } },
|
||||||
|
'6': { value: { _light: '#adddc0', _dark: '#20573e' } },
|
||||||
|
'7': { value: { _light: '#8eceaa', _dark: '#28684a' } },
|
||||||
|
'8': { value: { _light: '#5bb98b', _dark: '#2f7c57' } },
|
||||||
|
'9': { value: { _light: '#30a46c', _dark: '#30a46c' } },
|
||||||
|
'10': { value: { _light: '#2b9a66', _dark: '#33b074' } },
|
||||||
|
'11': { value: { _light: '#218358', _dark: '#3dd68c' } },
|
||||||
|
'12': { value: { _light: '#193b2d', _dark: '#b1f1cb' } },
|
||||||
|
a1: { value: { _light: '#00c04004', _dark: '#00de4505' } },
|
||||||
|
a2: { value: { _light: '#00a32f0b', _dark: '#29f99d0b' } },
|
||||||
|
a3: { value: { _light: '#00a43319', _dark: '#22ff991e' } },
|
||||||
|
a4: { value: { _light: '#00a83829', _dark: '#11ff992d' } },
|
||||||
|
a5: { value: { _light: '#019c393b', _dark: '#2bffa23c' } },
|
||||||
|
a6: { value: { _light: '#00963c52', _dark: '#44ffaa4b' } },
|
||||||
|
a7: { value: { _light: '#00914071', _dark: '#50fdac5e' } },
|
||||||
|
a8: { value: { _light: '#00924ba4', _dark: '#54ffad73' } },
|
||||||
|
a9: { value: { _light: '#008f4acf', _dark: '#44ffa49e' } },
|
||||||
|
a10: { value: { _light: '#008647d4', _dark: '#43fea4ab' } },
|
||||||
|
a11: { value: { _light: '#00713fde', _dark: '#46fea5d4' } },
|
||||||
|
a12: { value: { _light: '#002616e6', _dark: '#bbffd7f0' } },
|
||||||
|
solid: {
|
||||||
|
bg: {
|
||||||
|
DEFAULT: { value: { _light: '{colors.green.9}', _dark: '{colors.green.9}' } },
|
||||||
|
hover: { value: { _light: '{colors.green.10}', _dark: '{colors.green.10}' } },
|
||||||
|
},
|
||||||
|
fg: { DEFAULT: { value: { _light: 'white', _dark: 'white' } } },
|
||||||
|
},
|
||||||
|
subtle: {
|
||||||
|
bg: {
|
||||||
|
DEFAULT: { value: { _light: '{colors.green.a3}', _dark: '{colors.green.a3}' } },
|
||||||
|
hover: { value: { _light: '{colors.green.a4}', _dark: '{colors.green.a4}' } },
|
||||||
|
active: { value: { _light: '{colors.green.a5}', _dark: '{colors.green.a5}' } },
|
||||||
|
},
|
||||||
|
fg: { DEFAULT: { value: { _light: '{colors.green.a11}', _dark: '{colors.green.a11}' } } },
|
||||||
|
},
|
||||||
|
surface: {
|
||||||
|
bg: {
|
||||||
|
DEFAULT: { value: { _light: '{colors.green.a2}', _dark: '{colors.green.a2}' } },
|
||||||
|
active: { value: { _light: '{colors.green.a3}', _dark: '{colors.green.a3}' } },
|
||||||
|
},
|
||||||
|
border: {
|
||||||
|
DEFAULT: { value: { _light: '{colors.green.a6}', _dark: '{colors.green.a6}' } },
|
||||||
|
hover: { value: { _light: '{colors.green.a7}', _dark: '{colors.green.a7}' } },
|
||||||
|
},
|
||||||
|
fg: { DEFAULT: { value: { _light: '{colors.green.a11}', _dark: '{colors.green.a11}' } } },
|
||||||
|
},
|
||||||
|
outline: {
|
||||||
|
bg: {
|
||||||
|
hover: { value: { _light: '{colors.green.a2}', _dark: '{colors.green.a2}' } },
|
||||||
|
active: { value: { _light: '{colors.green.a3}', _dark: '{colors.green.a3}' } },
|
||||||
|
},
|
||||||
|
border: { DEFAULT: { value: { _light: '{colors.green.a7}', _dark: '{colors.green.a7}' } } },
|
||||||
|
fg: { DEFAULT: { value: { _light: '{colors.green.a11}', _dark: '{colors.green.a11}' } } },
|
||||||
|
},
|
||||||
|
plain: {
|
||||||
|
bg: {
|
||||||
|
hover: { value: { _light: '{colors.green.a3}', _dark: '{colors.green.a3}' } },
|
||||||
|
active: { value: { _light: '{colors.green.a4}', _dark: '{colors.green.a4}' } },
|
||||||
|
},
|
||||||
|
fg: { DEFAULT: { value: { _light: '{colors.green.a11}', _dark: '{colors.green.a11}' } } },
|
||||||
|
},
|
||||||
|
})
|
||||||
69
src/theme/colors/jade.ts
Normal file
69
src/theme/colors/jade.ts
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
import { defineSemanticTokens } from '@pandacss/dev'
|
||||||
|
|
||||||
|
export const jade = defineSemanticTokens.colors({
|
||||||
|
'1': { value: { _light: '#fbfefd', _dark: '#0d1512' } },
|
||||||
|
'2': { value: { _light: '#f4fbf7', _dark: '#121c18' } },
|
||||||
|
'3': { value: { _light: '#e6f7ed', _dark: '#0f2e22' } },
|
||||||
|
'4': { value: { _light: '#d6f1e3', _dark: '#0b3b2c' } },
|
||||||
|
'5': { value: { _light: '#c3e9d7', _dark: '#114837' } },
|
||||||
|
'6': { value: { _light: '#acdec8', _dark: '#1b5745' } },
|
||||||
|
'7': { value: { _light: '#8bceb6', _dark: '#246854' } },
|
||||||
|
'8': { value: { _light: '#56ba9f', _dark: '#2a7e68' } },
|
||||||
|
'9': { value: { _light: '#29a383', _dark: '#29a383' } },
|
||||||
|
'10': { value: { _light: '#26997b', _dark: '#27b08b' } },
|
||||||
|
'11': { value: { _light: '#208368', _dark: '#1fd8a4' } },
|
||||||
|
'12': { value: { _light: '#1d3b31', _dark: '#adf0d4' } },
|
||||||
|
a1: { value: { _light: '#00c08004', _dark: '#00de4505' } },
|
||||||
|
a2: { value: { _light: '#00a3460b', _dark: '#27fba60c' } },
|
||||||
|
a3: { value: { _light: '#00ae4819', _dark: '#02f99920' } },
|
||||||
|
a4: { value: { _light: '#00a85129', _dark: '#00ffaa2d' } },
|
||||||
|
a5: { value: { _light: '#00a2553c', _dark: '#11ffb63b' } },
|
||||||
|
a6: { value: { _light: '#009a5753', _dark: '#34ffc24b' } },
|
||||||
|
a7: { value: { _light: '#00945f74', _dark: '#45fdc75e' } },
|
||||||
|
a8: { value: { _light: '#00976ea9', _dark: '#48ffcf75' } },
|
||||||
|
a9: { value: { _light: '#00916bd6', _dark: '#38feca9d' } },
|
||||||
|
a10: { value: { _light: '#008764d9', _dark: '#31fec7ab' } },
|
||||||
|
a11: { value: { _light: '#007152df', _dark: '#21fec0d6' } },
|
||||||
|
a12: { value: { _light: '#002217e2', _dark: '#b8ffe1ef' } },
|
||||||
|
solid: {
|
||||||
|
bg: {
|
||||||
|
DEFAULT: { value: { _light: '{colors.jade.9}', _dark: '{colors.jade.9}' } },
|
||||||
|
hover: { value: { _light: '{colors.jade.10}', _dark: '{colors.jade.10}' } },
|
||||||
|
},
|
||||||
|
fg: { DEFAULT: { value: { _light: 'white', _dark: 'white' } } },
|
||||||
|
},
|
||||||
|
subtle: {
|
||||||
|
bg: {
|
||||||
|
DEFAULT: { value: { _light: '{colors.jade.a3}', _dark: '{colors.jade.a3}' } },
|
||||||
|
hover: { value: { _light: '{colors.jade.a4}', _dark: '{colors.jade.a4}' } },
|
||||||
|
active: { value: { _light: '{colors.jade.a5}', _dark: '{colors.jade.a5}' } },
|
||||||
|
},
|
||||||
|
fg: { DEFAULT: { value: { _light: '{colors.jade.a11}', _dark: '{colors.jade.a11}' } } },
|
||||||
|
},
|
||||||
|
surface: {
|
||||||
|
bg: {
|
||||||
|
DEFAULT: { value: { _light: '{colors.jade.a2}', _dark: '{colors.jade.a2}' } },
|
||||||
|
active: { value: { _light: '{colors.jade.a3}', _dark: '{colors.jade.a3}' } },
|
||||||
|
},
|
||||||
|
border: {
|
||||||
|
DEFAULT: { value: { _light: '{colors.jade.a6}', _dark: '{colors.jade.a6}' } },
|
||||||
|
hover: { value: { _light: '{colors.jade.a7}', _dark: '{colors.jade.a7}' } },
|
||||||
|
},
|
||||||
|
fg: { DEFAULT: { value: { _light: '{colors.jade.a11}', _dark: '{colors.jade.a11}' } } },
|
||||||
|
},
|
||||||
|
outline: {
|
||||||
|
bg: {
|
||||||
|
hover: { value: { _light: '{colors.jade.a2}', _dark: '{colors.jade.a2}' } },
|
||||||
|
active: { value: { _light: '{colors.jade.a3}', _dark: '{colors.jade.a3}' } },
|
||||||
|
},
|
||||||
|
border: { DEFAULT: { value: { _light: '{colors.jade.a7}', _dark: '{colors.jade.a7}' } } },
|
||||||
|
fg: { DEFAULT: { value: { _light: '{colors.jade.a11}', _dark: '{colors.jade.a11}' } } },
|
||||||
|
},
|
||||||
|
plain: {
|
||||||
|
bg: {
|
||||||
|
hover: { value: { _light: '{colors.jade.a3}', _dark: '{colors.jade.a3}' } },
|
||||||
|
active: { value: { _light: '{colors.jade.a4}', _dark: '{colors.jade.a4}' } },
|
||||||
|
},
|
||||||
|
fg: { DEFAULT: { value: { _light: '{colors.jade.a11}', _dark: '{colors.jade.a11}' } } },
|
||||||
|
},
|
||||||
|
})
|
||||||
69
src/theme/colors/red.ts
Normal file
69
src/theme/colors/red.ts
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
import { defineSemanticTokens } from '@pandacss/dev'
|
||||||
|
|
||||||
|
export const red = defineSemanticTokens.colors({
|
||||||
|
'1': { value: { _light: '#fffcfc', _dark: '#191111' } },
|
||||||
|
'2': { value: { _light: '#fff7f7', _dark: '#201314' } },
|
||||||
|
'3': { value: { _light: '#feebec', _dark: '#3b1219' } },
|
||||||
|
'4': { value: { _light: '#ffdbdc', _dark: '#500f1c' } },
|
||||||
|
'5': { value: { _light: '#ffcdce', _dark: '#611623' } },
|
||||||
|
'6': { value: { _light: '#fdbdbe', _dark: '#72232d' } },
|
||||||
|
'7': { value: { _light: '#f4a9aa', _dark: '#8c333a' } },
|
||||||
|
'8': { value: { _light: '#eb8e90', _dark: '#b54548' } },
|
||||||
|
'9': { value: { _light: '#e5484d', _dark: '#e5484d' } },
|
||||||
|
'10': { value: { _light: '#dc3e42', _dark: '#ec5d5e' } },
|
||||||
|
'11': { value: { _light: '#ce2c31', _dark: '#ff9592' } },
|
||||||
|
'12': { value: { _light: '#641723', _dark: '#ffd1d9' } },
|
||||||
|
a1: { value: { _light: '#ff000003', _dark: '#f4121209' } },
|
||||||
|
a2: { value: { _light: '#ff000008', _dark: '#f22f3e11' } },
|
||||||
|
a3: { value: { _light: '#f3000d14', _dark: '#ff173f2d' } },
|
||||||
|
a4: { value: { _light: '#ff000824', _dark: '#fe0a3b44' } },
|
||||||
|
a5: { value: { _light: '#ff000632', _dark: '#ff204756' } },
|
||||||
|
a6: { value: { _light: '#f8000442', _dark: '#ff3e5668' } },
|
||||||
|
a7: { value: { _light: '#df000356', _dark: '#ff536184' } },
|
||||||
|
a8: { value: { _light: '#d2000571', _dark: '#ff5d61b0' } },
|
||||||
|
a9: { value: { _light: '#db0007b7', _dark: '#fe4e54e4' } },
|
||||||
|
a10: { value: { _light: '#d10005c1', _dark: '#ff6465eb' } },
|
||||||
|
a11: { value: { _light: '#c40006d3', _dark: '#ff9592' } },
|
||||||
|
a12: { value: { _light: '#55000de8', _dark: '#ffd1d9' } },
|
||||||
|
solid: {
|
||||||
|
bg: {
|
||||||
|
DEFAULT: { value: { _light: '{colors.red.9}', _dark: '{colors.red.9}' } },
|
||||||
|
hover: { value: { _light: '{colors.red.10}', _dark: '{colors.red.10}' } },
|
||||||
|
},
|
||||||
|
fg: { DEFAULT: { value: { _light: 'white', _dark: 'white' } } },
|
||||||
|
},
|
||||||
|
subtle: {
|
||||||
|
bg: {
|
||||||
|
DEFAULT: { value: { _light: '{colors.red.a3}', _dark: '{colors.red.a3}' } },
|
||||||
|
hover: { value: { _light: '{colors.red.a4}', _dark: '{colors.red.a4}' } },
|
||||||
|
active: { value: { _light: '{colors.red.a5}', _dark: '{colors.red.a5}' } },
|
||||||
|
},
|
||||||
|
fg: { DEFAULT: { value: { _light: '{colors.red.a11}', _dark: '{colors.red.a11}' } } },
|
||||||
|
},
|
||||||
|
surface: {
|
||||||
|
bg: {
|
||||||
|
DEFAULT: { value: { _light: '{colors.red.a2}', _dark: '{colors.red.a2}' } },
|
||||||
|
active: { value: { _light: '{colors.red.a3}', _dark: '{colors.red.a3}' } },
|
||||||
|
},
|
||||||
|
border: {
|
||||||
|
DEFAULT: { value: { _light: '{colors.red.a6}', _dark: '{colors.red.a6}' } },
|
||||||
|
hover: { value: { _light: '{colors.red.a7}', _dark: '{colors.red.a7}' } },
|
||||||
|
},
|
||||||
|
fg: { DEFAULT: { value: { _light: '{colors.red.a11}', _dark: '{colors.red.a11}' } } },
|
||||||
|
},
|
||||||
|
outline: {
|
||||||
|
bg: {
|
||||||
|
hover: { value: { _light: '{colors.red.a2}', _dark: '{colors.red.a2}' } },
|
||||||
|
active: { value: { _light: '{colors.red.a3}', _dark: '{colors.red.a3}' } },
|
||||||
|
},
|
||||||
|
border: { DEFAULT: { value: { _light: '{colors.red.a7}', _dark: '{colors.red.a7}' } } },
|
||||||
|
fg: { DEFAULT: { value: { _light: '{colors.red.a11}', _dark: '{colors.red.a11}' } } },
|
||||||
|
},
|
||||||
|
plain: {
|
||||||
|
bg: {
|
||||||
|
hover: { value: { _light: '{colors.red.a3}', _dark: '{colors.red.a3}' } },
|
||||||
|
active: { value: { _light: '{colors.red.a4}', _dark: '{colors.red.a4}' } },
|
||||||
|
},
|
||||||
|
fg: { DEFAULT: { value: { _light: '{colors.red.a11}', _dark: '{colors.red.a11}' } } },
|
||||||
|
},
|
||||||
|
})
|
||||||
70
src/theme/colors/sage.ts
Normal file
70
src/theme/colors/sage.ts
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
import { defineSemanticTokens } from '@pandacss/dev'
|
||||||
|
|
||||||
|
export const sage = defineSemanticTokens.colors({
|
||||||
|
'1': { value: { _light: '#fbfdfc', _dark: '#101211' } },
|
||||||
|
'2': { value: { _light: '#f7f9f8', _dark: '#171918' } },
|
||||||
|
'3': { value: { _light: '#eef1f0', _dark: '#202221' } },
|
||||||
|
'4': { value: { _light: '#e6e9e8', _dark: '#272a29' } },
|
||||||
|
'5': { value: { _light: '#dfe2e0', _dark: '#2e3130' } },
|
||||||
|
'6': { value: { _light: '#d7dad9', _dark: '#373b39' } },
|
||||||
|
'7': { value: { _light: '#cbcfcd', _dark: '#444947' } },
|
||||||
|
'8': { value: { _light: '#b8bcba', _dark: '#5b625f' } },
|
||||||
|
'9': { value: { _light: '#868e8b', _dark: '#63706b' } },
|
||||||
|
'10': { value: { _light: '#7c8481', _dark: '#717d79' } },
|
||||||
|
'11': { value: { _light: '#5f6563', _dark: '#adb5b2' } },
|
||||||
|
'12': { value: { _light: '#1a211e', _dark: '#eceeed' } },
|
||||||
|
a1: { value: { _light: '#00804004', _dark: '#00000000' } },
|
||||||
|
a2: { value: { _light: '#00402008', _dark: '#f0f2f108' } },
|
||||||
|
a3: { value: { _light: '#002d1e11', _dark: '#f3f5f412' } },
|
||||||
|
a4: { value: { _light: '#001f1519', _dark: '#f2fefd1a' } },
|
||||||
|
a5: { value: { _light: '#00180820', _dark: '#f1fbfa22' } },
|
||||||
|
a6: { value: { _light: '#00140d28', _dark: '#edfbf42d' } },
|
||||||
|
a7: { value: { _light: '#00140a34', _dark: '#edfcf73c' } },
|
||||||
|
a8: { value: { _light: '#000f0847', _dark: '#ebfdf657' } },
|
||||||
|
a9: { value: { _light: '#00110b79', _dark: '#dffdf266' } },
|
||||||
|
a10: { value: { _light: '#00100a83', _dark: '#e5fdf674' } },
|
||||||
|
a11: { value: { _light: '#000a07a0', _dark: '#f4fefbb0' } },
|
||||||
|
a12: { value: { _light: '#000805e5', _dark: '#fdfffeed' } },
|
||||||
|
solid: {
|
||||||
|
bg: {
|
||||||
|
DEFAULT: { value: { _light: '{colors.black}', _dark: '{colors.white}' } },
|
||||||
|
hover: { value: { _light: '{colors.gray.12}', _dark: '{colors.gray.12}' } },
|
||||||
|
},
|
||||||
|
fg: { DEFAULT: { value: { _light: '{colors.white}', _dark: '{colors.black}' } } },
|
||||||
|
},
|
||||||
|
subtle: {
|
||||||
|
bg: {
|
||||||
|
DEFAULT: { value: { _light: '{colors.gray.a3}', _dark: '{colors.gray.a3}' } },
|
||||||
|
hover: { value: { _light: '{colors.gray.a4}', _dark: '{colors.gray.a4}' } },
|
||||||
|
active: { value: { _light: '{colors.gray.a5}', _dark: '{colors.gray.a5}' } },
|
||||||
|
},
|
||||||
|
fg: { DEFAULT: { value: { _light: '{colors.gray.12}', _dark: '{colors.gray.12}' } } },
|
||||||
|
},
|
||||||
|
surface: {
|
||||||
|
bg: {
|
||||||
|
DEFAULT: { value: { _light: '{colors.white}', _dark: '{colors.gray.1}' } },
|
||||||
|
hover: { value: { _light: '{colors.gray.2}', _dark: '{colors.gray.2}' } },
|
||||||
|
active: { value: { _light: '{colors.gray.3}', _dark: '{colors.gray.3}' } },
|
||||||
|
},
|
||||||
|
border: {
|
||||||
|
DEFAULT: { value: { _light: '{colors.gray.6}', _dark: '{colors.gray.6}' } },
|
||||||
|
hover: { value: { _light: '{colors.gray.7}', _dark: '{colors.gray.7}' } },
|
||||||
|
},
|
||||||
|
fg: { DEFAULT: { value: { _light: '{colors.gray.12}', _dark: '{colors.gray.12}' } } },
|
||||||
|
},
|
||||||
|
outline: {
|
||||||
|
bg: {
|
||||||
|
hover: { value: { _light: '{colors.gray.a2}', _dark: '{colors.gray.a2}' } },
|
||||||
|
active: { value: { _light: '{colors.gray.a3}', _dark: '{colors.gray.a3}' } },
|
||||||
|
},
|
||||||
|
border: { DEFAULT: { value: { _light: '{colors.gray.6}', _dark: '{colors.gray.6}' } } },
|
||||||
|
fg: { DEFAULT: { value: { _light: '{colors.gray.12}', _dark: '{colors.gray.12}' } } },
|
||||||
|
},
|
||||||
|
plain: {
|
||||||
|
bg: {
|
||||||
|
hover: { value: { _light: '{colors.gray.a3}', _dark: '{colors.gray.a3}' } },
|
||||||
|
active: { value: { _light: '{colors.gray.a4}', _dark: '{colors.gray.a4}' } },
|
||||||
|
},
|
||||||
|
fg: { DEFAULT: { value: { _light: '{colors.gray.12}', _dark: '{colors.gray.12}' } } },
|
||||||
|
},
|
||||||
|
})
|
||||||
12
src/theme/conditions.ts
Normal file
12
src/theme/conditions.ts
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
export const conditions = {
|
||||||
|
extend: {
|
||||||
|
light: ':root:not(.dark) &',
|
||||||
|
invalid: '&:is(:user-invalid, [data-invalid], [aria-invalid=true])',
|
||||||
|
hover: '&:not(:disabled):hover',
|
||||||
|
active: '&:not(:disabled):active',
|
||||||
|
checked:
|
||||||
|
'&:is(:checked, [data-checked], [data-state=checked], [aria-checked=true], [data-state=indeterminate])',
|
||||||
|
on: '&:is([data-state=on])',
|
||||||
|
pinned: '&:is([data-pinned])',
|
||||||
|
},
|
||||||
|
} as const
|
||||||
17
src/theme/global-css.ts
Normal file
17
src/theme/global-css.ts
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
export const globalCss = {
|
||||||
|
extend: {
|
||||||
|
'*': {
|
||||||
|
'--global-color-border': 'colors.border',
|
||||||
|
'--global-color-placeholder': 'colors.fg.subtle',
|
||||||
|
'--global-color-selection': 'colors.colorPalette.subtle.bg',
|
||||||
|
'--global-color-focus-ring': 'colors.colorPalette.solid.bg',
|
||||||
|
},
|
||||||
|
html: {
|
||||||
|
colorPalette: 'gray',
|
||||||
|
},
|
||||||
|
body: {
|
||||||
|
background: 'canvas',
|
||||||
|
color: 'fg.default',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
125
src/theme/keyframes.ts
Normal file
125
src/theme/keyframes.ts
Normal file
@ -0,0 +1,125 @@
|
|||||||
|
import { defineKeyframes } from '@pandacss/dev'
|
||||||
|
|
||||||
|
export const keyframes = defineKeyframes({
|
||||||
|
// collapse
|
||||||
|
'expand-height': {
|
||||||
|
from: { height: '0' },
|
||||||
|
to: { height: 'var(--height)' },
|
||||||
|
},
|
||||||
|
'collapse-height': {
|
||||||
|
from: { height: 'var(--height)' },
|
||||||
|
to: { height: '0' },
|
||||||
|
},
|
||||||
|
'expand-width': {
|
||||||
|
from: { width: '0' },
|
||||||
|
to: { width: 'var(--width)' },
|
||||||
|
},
|
||||||
|
'collapse-width': {
|
||||||
|
from: { width: 'var(--width)' },
|
||||||
|
to: { width: '0' },
|
||||||
|
},
|
||||||
|
// fade
|
||||||
|
'fade-in': {
|
||||||
|
from: { opacity: '0' },
|
||||||
|
to: { opacity: '1' },
|
||||||
|
},
|
||||||
|
'fade-out': {
|
||||||
|
from: { opacity: '1' },
|
||||||
|
to: { opacity: '0' },
|
||||||
|
},
|
||||||
|
// slide from (full)
|
||||||
|
'slide-from-left-full': {
|
||||||
|
from: { translate: '-100% 0' },
|
||||||
|
to: { translate: '0 0' },
|
||||||
|
},
|
||||||
|
'slide-from-right-full': {
|
||||||
|
from: { translate: '100% 0' },
|
||||||
|
to: { translate: '0 0' },
|
||||||
|
},
|
||||||
|
'slide-from-top-full': {
|
||||||
|
from: { translate: '0 -100%' },
|
||||||
|
to: { translate: '0 0' },
|
||||||
|
},
|
||||||
|
'slide-from-bottom-full': {
|
||||||
|
from: { translate: '0 100%' },
|
||||||
|
to: { translate: '0 0' },
|
||||||
|
},
|
||||||
|
// slide to (full)
|
||||||
|
'slide-to-left-full': {
|
||||||
|
from: { translate: '0 0' },
|
||||||
|
to: { translate: '-100% 0' },
|
||||||
|
},
|
||||||
|
'slide-to-right-full': {
|
||||||
|
from: { translate: '0 0' },
|
||||||
|
to: { translate: '100% 0' },
|
||||||
|
},
|
||||||
|
'slide-to-top-full': {
|
||||||
|
from: { translate: '0 0' },
|
||||||
|
to: { translate: '0 -100%' },
|
||||||
|
},
|
||||||
|
'slide-to-bottom-full': {
|
||||||
|
from: { translate: '0 0' },
|
||||||
|
to: { translate: '0 100%' },
|
||||||
|
},
|
||||||
|
// slide from
|
||||||
|
'slide-from-top': {
|
||||||
|
'0%': { translate: '0 -0.5rem' },
|
||||||
|
to: { translate: '0' },
|
||||||
|
},
|
||||||
|
'slide-from-bottom': {
|
||||||
|
'0%': { translate: '0 0.5rem' },
|
||||||
|
to: { translate: '0' },
|
||||||
|
},
|
||||||
|
'slide-from-left': {
|
||||||
|
'0%': { translate: '-0.5rem 0' },
|
||||||
|
to: { translate: '0' },
|
||||||
|
},
|
||||||
|
'slide-from-right': {
|
||||||
|
'0%': { translate: '0.5rem 0' },
|
||||||
|
to: { translate: '0' },
|
||||||
|
},
|
||||||
|
// slide to
|
||||||
|
'slide-to-top': {
|
||||||
|
'0%': { translate: '0' },
|
||||||
|
to: { translate: '0 -0.5rem' },
|
||||||
|
},
|
||||||
|
'slide-to-bottom': {
|
||||||
|
'0%': { translate: '0' },
|
||||||
|
to: { translate: '0 0.5rem' },
|
||||||
|
},
|
||||||
|
'slide-to-left': {
|
||||||
|
'0%': { translate: '0' },
|
||||||
|
to: { translate: '-0.5rem 0' },
|
||||||
|
},
|
||||||
|
'slide-to-right': {
|
||||||
|
'0%': { translate: '0' },
|
||||||
|
to: { translate: '0.5rem 0' },
|
||||||
|
},
|
||||||
|
// scale
|
||||||
|
'scale-in': {
|
||||||
|
from: { scale: '0.95' },
|
||||||
|
to: { scale: '1' },
|
||||||
|
},
|
||||||
|
'scale-out': {
|
||||||
|
from: { scale: '1' },
|
||||||
|
to: { scale: '0.95' },
|
||||||
|
},
|
||||||
|
'bg-position': {
|
||||||
|
from: {
|
||||||
|
backgroundPosition: 'var(--animate-from, 1rem) 0',
|
||||||
|
},
|
||||||
|
to: {
|
||||||
|
backgroundPosition: 'var(--animate-to, 0) 0',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
position: {
|
||||||
|
from: {
|
||||||
|
insetInlineStart: 'var(--animate-from-x)',
|
||||||
|
insetBlockStart: 'var(--animate-from-y)',
|
||||||
|
},
|
||||||
|
to: {
|
||||||
|
insetInlineStart: 'var(--animate-to-x)',
|
||||||
|
insetBlockStart: 'var(--animate-to-y)',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
11
src/theme/layer-styles.ts
Normal file
11
src/theme/layer-styles.ts
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
import { defineLayerStyles } from '@pandacss/dev'
|
||||||
|
|
||||||
|
export const layerStyles = defineLayerStyles({
|
||||||
|
disabled: {
|
||||||
|
value: {
|
||||||
|
cursor: 'not-allowed',
|
||||||
|
opacity: '0.67',
|
||||||
|
filter: 'grayscale(100%)',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
37
src/theme/recipes/absolute-center.ts
Normal file
37
src/theme/recipes/absolute-center.ts
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
import { defineRecipe } from '@pandacss/dev'
|
||||||
|
|
||||||
|
export const absoluteCenter = defineRecipe({
|
||||||
|
className: 'absolute-center',
|
||||||
|
base: {
|
||||||
|
position: 'absolute',
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
},
|
||||||
|
defaultVariants: {
|
||||||
|
axis: 'both',
|
||||||
|
},
|
||||||
|
variants: {
|
||||||
|
axis: {
|
||||||
|
horizontal: {
|
||||||
|
insetStart: '50%',
|
||||||
|
translate: '-50%',
|
||||||
|
_rtl: {
|
||||||
|
translate: '50%',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
vertical: {
|
||||||
|
top: '50%',
|
||||||
|
translate: '0 -50%',
|
||||||
|
},
|
||||||
|
both: {
|
||||||
|
insetStart: '50%',
|
||||||
|
top: '50%',
|
||||||
|
translate: '-50% -50%',
|
||||||
|
_rtl: {
|
||||||
|
translate: '50% -50%',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
110
src/theme/recipes/button.ts
Normal file
110
src/theme/recipes/button.ts
Normal file
@ -0,0 +1,110 @@
|
|||||||
|
import { defineRecipe } from '@pandacss/dev'
|
||||||
|
|
||||||
|
export const button = defineRecipe({
|
||||||
|
className: 'button',
|
||||||
|
jsx: ['Button', 'IconButton', 'CloseButton', 'ButtonGroup'],
|
||||||
|
base: {
|
||||||
|
alignItems: 'center',
|
||||||
|
appearance: 'none',
|
||||||
|
borderRadius: 'l2',
|
||||||
|
cursor: 'pointer',
|
||||||
|
display: 'inline-flex',
|
||||||
|
flexShrink: '0',
|
||||||
|
fontWeight: 'semibold',
|
||||||
|
gap: '2',
|
||||||
|
isolation: 'isolate',
|
||||||
|
justifyContent: 'center',
|
||||||
|
outline: '0',
|
||||||
|
position: 'relative',
|
||||||
|
transition: 'colors',
|
||||||
|
transitionProperty: 'background-color, border-color, color, box-shadow',
|
||||||
|
userSelect: 'none',
|
||||||
|
verticalAlign: 'middle',
|
||||||
|
whiteSpace: 'nowrap',
|
||||||
|
_icon: {
|
||||||
|
flexShrink: '0',
|
||||||
|
},
|
||||||
|
_disabled: {
|
||||||
|
layerStyle: 'disabled',
|
||||||
|
},
|
||||||
|
focusVisibleRing: 'outside',
|
||||||
|
},
|
||||||
|
defaultVariants: {
|
||||||
|
variant: 'solid',
|
||||||
|
size: 'md',
|
||||||
|
},
|
||||||
|
variants: {
|
||||||
|
variant: {
|
||||||
|
solid: {
|
||||||
|
bg: 'colorPalette.solid.bg',
|
||||||
|
color: 'colorPalette.solid.fg',
|
||||||
|
_hover: {
|
||||||
|
bg: 'colorPalette.solid.bg.hover',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
surface: {
|
||||||
|
bg: 'colorPalette.surface.bg',
|
||||||
|
borderWidth: '1px',
|
||||||
|
borderColor: 'colorPalette.surface.border',
|
||||||
|
color: 'colorPalette.surface.fg',
|
||||||
|
_hover: {
|
||||||
|
borderColor: 'colorPalette.surface.border.hover',
|
||||||
|
},
|
||||||
|
_active: {
|
||||||
|
bg: 'colorPalette.surface.bg.active',
|
||||||
|
},
|
||||||
|
_on: {
|
||||||
|
bg: 'colorPalette.surface.bg.active',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
subtle: {
|
||||||
|
bg: 'colorPalette.subtle.bg',
|
||||||
|
color: 'colorPalette.subtle.fg',
|
||||||
|
_hover: {
|
||||||
|
bg: 'colorPalette.subtle.bg.hover',
|
||||||
|
},
|
||||||
|
_active: {
|
||||||
|
bg: 'colorPalette.subtle.bg.active',
|
||||||
|
},
|
||||||
|
_on: {
|
||||||
|
bg: 'colorPalette.subtle.bg.active',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
outline: {
|
||||||
|
borderWidth: '1px',
|
||||||
|
borderColor: 'colorPalette.outline.border',
|
||||||
|
color: 'colorPalette.outline.fg',
|
||||||
|
_hover: {
|
||||||
|
bg: 'colorPalette.outline.bg.hover',
|
||||||
|
},
|
||||||
|
_active: {
|
||||||
|
bg: 'colorPalette.outline.bg.active',
|
||||||
|
},
|
||||||
|
_on: {
|
||||||
|
bg: 'colorPalette.outline.bg.active',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
plain: {
|
||||||
|
color: 'colorPalette.plain.fg',
|
||||||
|
_hover: {
|
||||||
|
bg: 'colorPalette.plain.bg.hover',
|
||||||
|
},
|
||||||
|
_active: {
|
||||||
|
bg: 'colorPalette.plain.bg.active',
|
||||||
|
},
|
||||||
|
_on: {
|
||||||
|
bg: 'colorPalette.plain.bg.active',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
size: {
|
||||||
|
'2xs': { h: '6', minW: '6', textStyle: 'xs', px: '2', _icon: { boxSize: '3.5' } },
|
||||||
|
xs: { h: '8', minW: '8', textStyle: 'sm', px: '2.5', _icon: { boxSize: '4' } },
|
||||||
|
sm: { h: '9', minW: '9', textStyle: 'sm', px: '3', _icon: { boxSize: '4' } },
|
||||||
|
md: { h: '10', minW: '10', textStyle: 'sm', px: '3.5', _icon: { boxSize: '5' } },
|
||||||
|
lg: { h: '11', minW: '11', textStyle: 'md', px: '4', _icon: { boxSize: '5' } },
|
||||||
|
xl: { h: '12', minW: '12', textStyle: 'md', px: '4.5', _icon: { boxSize: '5.5' } },
|
||||||
|
'2xl': { h: '16', minW: '16', textStyle: 'xl', px: '6', _icon: { boxSize: '6' } },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
68
src/theme/recipes/card.ts
Normal file
68
src/theme/recipes/card.ts
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
import { defineSlotRecipe } from '@pandacss/dev'
|
||||||
|
|
||||||
|
export const card = defineSlotRecipe({
|
||||||
|
className: 'card',
|
||||||
|
slots: ['root', 'header', 'body', 'footer', 'title', 'description'],
|
||||||
|
base: {
|
||||||
|
root: {
|
||||||
|
borderRadius: 'l3',
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'column',
|
||||||
|
overflow: 'hidden',
|
||||||
|
position: 'relative',
|
||||||
|
},
|
||||||
|
header: {
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'column',
|
||||||
|
gap: '1',
|
||||||
|
p: '6',
|
||||||
|
},
|
||||||
|
body: {
|
||||||
|
display: 'flex',
|
||||||
|
flex: '1',
|
||||||
|
flexDirection: 'column',
|
||||||
|
pb: '6',
|
||||||
|
px: '6',
|
||||||
|
},
|
||||||
|
footer: {
|
||||||
|
display: 'flex',
|
||||||
|
justifyContent: 'flex-end',
|
||||||
|
gap: '3',
|
||||||
|
pb: '6',
|
||||||
|
pt: '2',
|
||||||
|
px: '6',
|
||||||
|
},
|
||||||
|
title: {
|
||||||
|
textStyle: 'lg',
|
||||||
|
fontWeight: 'semibold',
|
||||||
|
},
|
||||||
|
description: {
|
||||||
|
color: 'fg.muted',
|
||||||
|
textStyle: 'sm',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
defaultVariants: {
|
||||||
|
variant: 'outline',
|
||||||
|
},
|
||||||
|
variants: {
|
||||||
|
variant: {
|
||||||
|
elevated: {
|
||||||
|
root: {
|
||||||
|
bg: 'gray.surface.bg',
|
||||||
|
boxShadow: 'lg',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
outline: {
|
||||||
|
root: {
|
||||||
|
bg: 'gray.surface.bg',
|
||||||
|
borderWidth: '1px',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
subtle: {
|
||||||
|
root: {
|
||||||
|
bg: 'gray.subtle.bg',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
210
src/theme/recipes/dialog.ts
Normal file
210
src/theme/recipes/dialog.ts
Normal file
@ -0,0 +1,210 @@
|
|||||||
|
import { dialogAnatomy } from '@ark-ui/react/anatomy'
|
||||||
|
import { defineSlotRecipe } from '@pandacss/dev'
|
||||||
|
|
||||||
|
export const dialog = defineSlotRecipe({
|
||||||
|
className: 'dialog',
|
||||||
|
slots: dialogAnatomy.extendWith('header', 'body', 'footer').keys(),
|
||||||
|
base: {
|
||||||
|
backdrop: {
|
||||||
|
background: 'black.a7',
|
||||||
|
height: '100dvh',
|
||||||
|
left: '0',
|
||||||
|
position: 'fixed',
|
||||||
|
top: '0',
|
||||||
|
width: '100dvw',
|
||||||
|
zIndex: 'var(--z-index)',
|
||||||
|
_open: {
|
||||||
|
animationName: 'fade-in',
|
||||||
|
animationTimingFunction: 'emphasized-in',
|
||||||
|
animationDuration: 'normal',
|
||||||
|
},
|
||||||
|
_closed: {
|
||||||
|
animationName: 'fade-out',
|
||||||
|
animationTimingFunction: 'emphasized-out',
|
||||||
|
animationDuration: 'fast',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
positioner: {
|
||||||
|
'--dialog-z-index': 'zIndex.modal',
|
||||||
|
display: 'flex',
|
||||||
|
height: '100dvh',
|
||||||
|
justifyContent: 'center',
|
||||||
|
left: 0,
|
||||||
|
overscrollBehaviorY: 'none',
|
||||||
|
position: 'fixed',
|
||||||
|
top: 0,
|
||||||
|
width: '100dvw',
|
||||||
|
zIndex: 'calc(var(--dialog-z-index) + var(--layer-index, 0))',
|
||||||
|
},
|
||||||
|
|
||||||
|
title: {
|
||||||
|
fontWeight: 'semibold',
|
||||||
|
textStyle: 'lg',
|
||||||
|
},
|
||||||
|
description: {
|
||||||
|
color: 'fg.muted',
|
||||||
|
textStyle: 'sm',
|
||||||
|
},
|
||||||
|
closeTrigger: {
|
||||||
|
pos: 'absolute',
|
||||||
|
top: '3',
|
||||||
|
insetEnd: '3',
|
||||||
|
},
|
||||||
|
content: {
|
||||||
|
'--dialog-z-index': 'zIndex.modal',
|
||||||
|
bg: 'gray.surface.bg',
|
||||||
|
borderRadius: 'l3',
|
||||||
|
boxShadow: 'lg',
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'column',
|
||||||
|
my: 'var(--dialog-margin, var(--dialog-base-margin))',
|
||||||
|
outline: 0,
|
||||||
|
position: 'relative',
|
||||||
|
textStyle: 'sm',
|
||||||
|
width: '100%',
|
||||||
|
zIndex: 'calc(var(--dialog-z-index) + var(--layer-index, 0))',
|
||||||
|
py: { base: '4', md: '6' },
|
||||||
|
gap: { base: '4', md: '6' },
|
||||||
|
_open: {
|
||||||
|
animationDuration: 'slowest',
|
||||||
|
},
|
||||||
|
_closed: {
|
||||||
|
animationDuration: 'normal',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
header: {
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'column',
|
||||||
|
gap: '0.5',
|
||||||
|
px: { base: '4', md: '6' },
|
||||||
|
flex: '0',
|
||||||
|
},
|
||||||
|
body: {
|
||||||
|
display: 'flex',
|
||||||
|
flex: '1',
|
||||||
|
flexDirection: 'column',
|
||||||
|
alignItems: 'flex-start',
|
||||||
|
px: { base: '4', md: '6' },
|
||||||
|
},
|
||||||
|
footer: {
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'flex-end',
|
||||||
|
flex: '0',
|
||||||
|
gap: '3',
|
||||||
|
px: { base: '4', md: '6' },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
defaultVariants: {
|
||||||
|
size: 'md',
|
||||||
|
scrollBehavior: 'outside',
|
||||||
|
placement: 'center',
|
||||||
|
motionPreset: 'scale',
|
||||||
|
},
|
||||||
|
variants: {
|
||||||
|
motionPreset: {
|
||||||
|
scale: {
|
||||||
|
content: {
|
||||||
|
_open: { animationName: 'scale-in, fade-in' },
|
||||||
|
_closed: { animationName: 'scale-out, fade-out' },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
'slide-in-bottom': {
|
||||||
|
content: {
|
||||||
|
_open: { animationName: 'slide-from-bottom, fade-in' },
|
||||||
|
_closed: { animationName: 'slide-to-bottom, fade-out' },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
'slide-in-top': {
|
||||||
|
content: {
|
||||||
|
_open: { animationName: 'slide-from-top, fade-in' },
|
||||||
|
_closed: { animationName: 'slide-to-top, fade-out' },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
'slide-in-left': {
|
||||||
|
content: {
|
||||||
|
_open: { animationName: 'slide-from-left, fade-in' },
|
||||||
|
_closed: { animationName: 'slide-to-left, fade-out' },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
'slide-in-right': {
|
||||||
|
content: {
|
||||||
|
_open: { animationName: 'slide-from-right, fade-in' },
|
||||||
|
_closed: { animationName: 'slide-to-right, fade-out' },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
none: {},
|
||||||
|
},
|
||||||
|
size: {
|
||||||
|
xs: { content: { maxW: 'xs' } },
|
||||||
|
sm: { content: { maxW: 'sm' } },
|
||||||
|
md: { content: { maxW: 'md' } },
|
||||||
|
lg: { content: { maxW: 'lg' } },
|
||||||
|
xl: { content: { maxW: 'xl' } },
|
||||||
|
cover: {
|
||||||
|
positioner: { padding: '8' },
|
||||||
|
content: {
|
||||||
|
width: '100%',
|
||||||
|
height: '100%',
|
||||||
|
'--dialog-margin': '0',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
full: {
|
||||||
|
content: {
|
||||||
|
maxW: '100dvw',
|
||||||
|
minH: '100dvh',
|
||||||
|
'--dialog-margin': '0',
|
||||||
|
borderRadius: '0',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
placement: {
|
||||||
|
center: {
|
||||||
|
positioner: {
|
||||||
|
alignItems: 'center',
|
||||||
|
},
|
||||||
|
content: {
|
||||||
|
'--dialog-base-margin': 'auto',
|
||||||
|
mx: 'auto',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
top: {
|
||||||
|
positioner: {
|
||||||
|
alignItems: 'flex-start',
|
||||||
|
},
|
||||||
|
content: {
|
||||||
|
'--dialog-base-margin': 'spacing.16',
|
||||||
|
mx: 'auto',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
bottom: {
|
||||||
|
positioner: {
|
||||||
|
alignItems: 'flex-end',
|
||||||
|
},
|
||||||
|
content: {
|
||||||
|
'--dialog-base-margin': 'spacing.16',
|
||||||
|
mx: 'auto',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
scrollBehavior: {
|
||||||
|
inside: {
|
||||||
|
positioner: {
|
||||||
|
overflow: 'hidden',
|
||||||
|
},
|
||||||
|
content: {
|
||||||
|
maxH: 'calc(100% - 7.5rem)',
|
||||||
|
},
|
||||||
|
body: {
|
||||||
|
overflow: 'auto',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
outside: {
|
||||||
|
positioner: {
|
||||||
|
overflow: 'auto',
|
||||||
|
pointerEvents: 'auto',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
40
src/theme/recipes/field.ts
Normal file
40
src/theme/recipes/field.ts
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
import { fieldAnatomy } from '@ark-ui/react/anatomy'
|
||||||
|
import { defineSlotRecipe } from '@pandacss/dev'
|
||||||
|
|
||||||
|
export const field = defineSlotRecipe({
|
||||||
|
className: 'field',
|
||||||
|
slots: fieldAnatomy.keys(),
|
||||||
|
base: {
|
||||||
|
root: {
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'column',
|
||||||
|
gap: '1.5',
|
||||||
|
},
|
||||||
|
label: {
|
||||||
|
alignItems: 'center',
|
||||||
|
color: 'fg.default',
|
||||||
|
display: 'flex',
|
||||||
|
gap: '0.5',
|
||||||
|
textAlign: 'start',
|
||||||
|
userSelect: 'none',
|
||||||
|
textStyle: 'label',
|
||||||
|
_disabled: {
|
||||||
|
layerStyle: 'disabled',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
requiredIndicator: {
|
||||||
|
color: 'colorPalette.solid',
|
||||||
|
},
|
||||||
|
helperText: {
|
||||||
|
color: 'fg.muted',
|
||||||
|
textStyle: 'sm',
|
||||||
|
_disabled: {
|
||||||
|
layerStyle: 'disabled',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
errorText: {
|
||||||
|
color: 'error',
|
||||||
|
textStyle: 'sm',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
77
src/theme/recipes/group.ts
Normal file
77
src/theme/recipes/group.ts
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
import { defineRecipe } from '@pandacss/dev'
|
||||||
|
|
||||||
|
export const group = defineRecipe({
|
||||||
|
className: 'group',
|
||||||
|
base: {
|
||||||
|
display: 'inline-flex',
|
||||||
|
position: 'relative',
|
||||||
|
gap: '2',
|
||||||
|
'& > *': {
|
||||||
|
_focusVisible: {
|
||||||
|
zIndex: 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
defaultVariants: {
|
||||||
|
orientation: 'horizontal',
|
||||||
|
},
|
||||||
|
variants: {
|
||||||
|
orientation: {
|
||||||
|
horizontal: {
|
||||||
|
flexDirection: 'row',
|
||||||
|
},
|
||||||
|
vertical: {
|
||||||
|
flexDirection: 'column',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
attached: {
|
||||||
|
true: {
|
||||||
|
gap: '0',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
grow: {
|
||||||
|
true: {
|
||||||
|
display: 'flex',
|
||||||
|
'& > *': {
|
||||||
|
flex: 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
compoundVariants: [
|
||||||
|
{
|
||||||
|
orientation: 'horizontal',
|
||||||
|
attached: true,
|
||||||
|
css: {
|
||||||
|
'& > *:first-child': {
|
||||||
|
borderEndRadius: '0',
|
||||||
|
marginEnd: '-1px',
|
||||||
|
},
|
||||||
|
'& > *:last-child': {
|
||||||
|
borderStartRadius: '0',
|
||||||
|
},
|
||||||
|
'& > *:not(:first-child):not(:last-child)': {
|
||||||
|
borderRadius: '0',
|
||||||
|
marginEnd: '-1px',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
orientation: 'vertical',
|
||||||
|
attached: true,
|
||||||
|
css: {
|
||||||
|
'& > *:first-child': {
|
||||||
|
borderBottomRadius: '0',
|
||||||
|
marginBottom: '-1px',
|
||||||
|
},
|
||||||
|
'& > *:last-child': {
|
||||||
|
borderTopRadius: '0',
|
||||||
|
},
|
||||||
|
'& > *:not(:first-child):not(:last-child)': {
|
||||||
|
borderRadius: '0',
|
||||||
|
marginBottom: '-1px',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})
|
||||||
13
src/theme/recipes/index.ts
Normal file
13
src/theme/recipes/index.ts
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
import { absoluteCenter } from './absolute-center'
|
||||||
|
import { button } from './button'
|
||||||
|
import { card } from './card'
|
||||||
|
import { dialog } from './dialog'
|
||||||
|
import { field } from './field'
|
||||||
|
import { group } from './group'
|
||||||
|
import { input } from './input'
|
||||||
|
import { segmentGroup } from './segment-group'
|
||||||
|
import { spinner } from './spinner'
|
||||||
|
import { textarea } from './textarea'
|
||||||
|
|
||||||
|
export const recipes = { absoluteCenter, button, group, input, spinner, textarea }
|
||||||
|
export const slotRecipes = { card, dialog, field, segmentGroup }
|
||||||
89
src/theme/recipes/input.ts
Normal file
89
src/theme/recipes/input.ts
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
import type { RecipeConfig } from '@pandacss/dev'
|
||||||
|
|
||||||
|
export const input = {
|
||||||
|
className: 'input',
|
||||||
|
jsx: ['Input', 'Field.Input'],
|
||||||
|
base: {
|
||||||
|
appearance: 'none',
|
||||||
|
borderRadius: 'l2',
|
||||||
|
height: 'var(--input-height)',
|
||||||
|
minHeight: 'var(--input-height)',
|
||||||
|
minW: 'var(--input-height)',
|
||||||
|
outline: '0',
|
||||||
|
position: 'relative',
|
||||||
|
textAlign: 'start',
|
||||||
|
transition: 'colors',
|
||||||
|
width: '100%',
|
||||||
|
_disabled: {
|
||||||
|
layerStyle: 'disabled',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
defaultVariants: {
|
||||||
|
size: 'md',
|
||||||
|
variant: 'outline',
|
||||||
|
},
|
||||||
|
variants: {
|
||||||
|
variant: {
|
||||||
|
outline: {
|
||||||
|
borderWidth: '1px',
|
||||||
|
borderColor: 'gray.outline.border',
|
||||||
|
focusVisibleRing: 'inside',
|
||||||
|
_invalid: {
|
||||||
|
focusRingColor: 'error',
|
||||||
|
borderColor: 'error',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
surface: {
|
||||||
|
bg: 'gray.surface.bg',
|
||||||
|
borderWidth: '1px',
|
||||||
|
borderColor: 'gray.surface.border',
|
||||||
|
focusVisibleRing: 'inside',
|
||||||
|
|
||||||
|
_invalid: {
|
||||||
|
focusRingColor: 'error',
|
||||||
|
borderColor: 'error',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
subtle: {
|
||||||
|
borderWidth: '1px',
|
||||||
|
borderColor: 'transparent',
|
||||||
|
bg: 'gray.subtle.bg',
|
||||||
|
color: 'gray.subtle.fg',
|
||||||
|
focusVisibleRing: 'inside',
|
||||||
|
|
||||||
|
_invalid: {
|
||||||
|
focusRingColor: 'error',
|
||||||
|
borderColor: 'error',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
flushed: {
|
||||||
|
borderBottomWidth: '1px',
|
||||||
|
borderBottomColor: 'gray.outline.border',
|
||||||
|
borderRadius: '0',
|
||||||
|
color: 'fg.default',
|
||||||
|
px: '0',
|
||||||
|
_invalid: {
|
||||||
|
borderColor: 'error',
|
||||||
|
},
|
||||||
|
_focus: {
|
||||||
|
borderColor: 'colorPalette.solid.bg',
|
||||||
|
boxShadowColor: 'colorPalette.solid.bg',
|
||||||
|
boxShadow: '0 1px 0 0 var(--shadow-color)',
|
||||||
|
_invalid: {
|
||||||
|
borderColor: 'error',
|
||||||
|
boxShadowColor: 'error',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
size: {
|
||||||
|
'2xs': { textStyle: 'xs', px: '1.5', '--input-height': 'sizes.7' },
|
||||||
|
xs: { textStyle: 'sm', px: '2', '--input-height': 'sizes.8' },
|
||||||
|
sm: { textStyle: 'sm', px: '2.5', '--input-height': 'sizes.9' },
|
||||||
|
md: { textStyle: 'md', px: '3', '--input-height': 'sizes.10' },
|
||||||
|
lg: { textStyle: 'md', px: '3.5', '--input-height': 'sizes.11' },
|
||||||
|
xl: { textStyle: 'lg', px: '4', '--input-height': 'sizes.12' },
|
||||||
|
'2xl': { textStyle: '3xl', px: '4.5', '--input-height': 'sizes.16' },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
} satisfies RecipeConfig
|
||||||
111
src/theme/recipes/segment-group.ts
Normal file
111
src/theme/recipes/segment-group.ts
Normal file
@ -0,0 +1,111 @@
|
|||||||
|
import { segmentGroupAnatomy } from '@ark-ui/react/anatomy'
|
||||||
|
import { defineSlotRecipe } from '@pandacss/dev'
|
||||||
|
|
||||||
|
export const segmentGroup = defineSlotRecipe({
|
||||||
|
className: 'segment-group',
|
||||||
|
slots: segmentGroupAnatomy.keys(),
|
||||||
|
base: {
|
||||||
|
root: {
|
||||||
|
bg: {
|
||||||
|
_light: 'gray.2',
|
||||||
|
_dark: 'gray.1',
|
||||||
|
},
|
||||||
|
borderRadius: 'l3',
|
||||||
|
boxShadow: 'inset 0 0 0px 1px var(--shadow-color)',
|
||||||
|
boxShadowColor: 'border',
|
||||||
|
display: 'inline-flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
isolation: 'isolate',
|
||||||
|
pos: 'relative',
|
||||||
|
_vertical: {
|
||||||
|
flexDirection: 'column',
|
||||||
|
alignItems: 'stretch',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
item: {
|
||||||
|
alignItems: 'center',
|
||||||
|
borderRadius: 'l3',
|
||||||
|
display: 'inline-flex',
|
||||||
|
flexShrink: '0',
|
||||||
|
fontWeight: 'medium',
|
||||||
|
gap: '2',
|
||||||
|
justifyContent: 'center',
|
||||||
|
position: 'relative',
|
||||||
|
userSelect: 'none',
|
||||||
|
_disabled: {
|
||||||
|
opacity: '0.5',
|
||||||
|
},
|
||||||
|
'&:has(input:focus-visible)': {
|
||||||
|
focusVisibleRing: 'outside',
|
||||||
|
},
|
||||||
|
|
||||||
|
_before: {
|
||||||
|
content: '""',
|
||||||
|
position: 'absolute',
|
||||||
|
bg: 'gray.surface.border',
|
||||||
|
transition: 'opacity 0.2s',
|
||||||
|
},
|
||||||
|
|
||||||
|
_horizontal: {
|
||||||
|
_before: {
|
||||||
|
insetInlineStart: '0',
|
||||||
|
insetBlock: '1.5',
|
||||||
|
width: '1px',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
_vertical: {
|
||||||
|
_before: {
|
||||||
|
insetBlockStart: '0',
|
||||||
|
insetInline: '1.5',
|
||||||
|
height: '1px',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
'& + &[data-state=checked], &[data-state=checked] + &, &:first-of-type': {
|
||||||
|
_before: {
|
||||||
|
opacity: '0',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
indicator: {
|
||||||
|
bg: {
|
||||||
|
_light: 'white',
|
||||||
|
_dark: 'gray.2',
|
||||||
|
},
|
||||||
|
borderWidth: '1px',
|
||||||
|
borderColor: 'gray.surface.border',
|
||||||
|
borderRadius: 'l3',
|
||||||
|
height: 'var(--height)',
|
||||||
|
pos: 'absolute',
|
||||||
|
width: 'var(--width)',
|
||||||
|
zIndex: -1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
variants: {
|
||||||
|
size: {
|
||||||
|
xs: { item: { h: '8', minW: '8', textStyle: 'sm', px: '2.5', _icon: { boxSize: '4' } } },
|
||||||
|
sm: { item: { h: '9', minW: '9', textStyle: 'sm', px: '3', _icon: { boxSize: '4' } } },
|
||||||
|
md: { item: { h: '10', minW: '10', textStyle: 'sm', px: '3.5', _icon: { boxSize: '5' } } },
|
||||||
|
lg: { item: { h: '11', minW: '11', textStyle: 'md', px: '4', _icon: { boxSize: '5' } } },
|
||||||
|
xl: { item: { h: '12', minW: '12', textStyle: 'md', px: '4.5', _icon: { boxSize: '5.5' } } },
|
||||||
|
},
|
||||||
|
fitted: {
|
||||||
|
true: {
|
||||||
|
root: {
|
||||||
|
display: 'flex',
|
||||||
|
},
|
||||||
|
item: {
|
||||||
|
flex: '1',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
defaultVariants: {
|
||||||
|
size: 'md',
|
||||||
|
},
|
||||||
|
})
|
||||||
33
src/theme/recipes/spinner.ts
Normal file
33
src/theme/recipes/spinner.ts
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
import { defineRecipe } from '@pandacss/dev'
|
||||||
|
|
||||||
|
export const spinner = defineRecipe({
|
||||||
|
className: 'spinner',
|
||||||
|
base: {
|
||||||
|
'--spinner-track-color': 'transparent',
|
||||||
|
animation: 'spin',
|
||||||
|
animationDuration: 'slowest',
|
||||||
|
borderBottomColor: 'var(--spinner-track-color)',
|
||||||
|
borderColor: 'currentColor',
|
||||||
|
borderInlineStartColor: 'var(--spinner-track-color)',
|
||||||
|
borderRadius: 'full',
|
||||||
|
borderStyle: 'solid',
|
||||||
|
borderWidth: '2px',
|
||||||
|
display: 'inline-block',
|
||||||
|
height: 'var(--spinner-size)',
|
||||||
|
width: 'var(--spinner-size)',
|
||||||
|
},
|
||||||
|
defaultVariants: {
|
||||||
|
size: 'md',
|
||||||
|
},
|
||||||
|
variants: {
|
||||||
|
size: {
|
||||||
|
inherit: { '--spinner-size': '1em' },
|
||||||
|
xs: { '--spinner-size': 'sizes.3' },
|
||||||
|
sm: { '--spinner-size': 'sizes.4' },
|
||||||
|
md: { '--spinner-size': 'sizes.5' },
|
||||||
|
lg: { '--spinner-size': 'sizes.6' },
|
||||||
|
xl: { '--spinner-size': 'sizes.7' },
|
||||||
|
'2xl': { '--spinner-size': 'sizes.8' },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
82
src/theme/recipes/textarea.ts
Normal file
82
src/theme/recipes/textarea.ts
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
import { defineRecipe } from '@pandacss/dev'
|
||||||
|
|
||||||
|
export const textarea = defineRecipe({
|
||||||
|
className: 'textarea',
|
||||||
|
base: {
|
||||||
|
appearance: 'none',
|
||||||
|
borderRadius: 'l2',
|
||||||
|
minWidth: '0',
|
||||||
|
outline: '0',
|
||||||
|
position: 'relative',
|
||||||
|
transition: 'colors',
|
||||||
|
transitionProperty: 'box-shadow, border-color',
|
||||||
|
width: '100%',
|
||||||
|
_disabled: {
|
||||||
|
layerStyle: 'disabled',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
defaultVariants: {
|
||||||
|
size: 'md',
|
||||||
|
variant: 'surface',
|
||||||
|
},
|
||||||
|
variants: {
|
||||||
|
variant: {
|
||||||
|
outline: {
|
||||||
|
borderWidth: '1px',
|
||||||
|
borderColor: 'gray.outline.border',
|
||||||
|
focusVisibleRing: 'inside',
|
||||||
|
_invalid: {
|
||||||
|
borderColor: 'error',
|
||||||
|
focusRingColor: 'error',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
surface: {
|
||||||
|
bg: 'gray.surface.bg',
|
||||||
|
borderWidth: '1px',
|
||||||
|
borderColor: 'gray.surface.border',
|
||||||
|
focusVisibleRing: 'inside',
|
||||||
|
_invalid: {
|
||||||
|
borderColor: 'error',
|
||||||
|
focusRingColor: 'error',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
subtle: {
|
||||||
|
borderWidth: '1px',
|
||||||
|
borderColor: 'transparent',
|
||||||
|
bg: 'gray.subtle.bg',
|
||||||
|
color: 'gray.subtle.fg',
|
||||||
|
focusVisibleRing: 'inside',
|
||||||
|
_invalid: {
|
||||||
|
borderColor: 'error',
|
||||||
|
focusRingColor: 'error',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
flushed: {
|
||||||
|
borderBottomWidth: '1px',
|
||||||
|
borderBottomColor: 'gray.outline.border',
|
||||||
|
borderRadius: '0',
|
||||||
|
color: 'fg.default',
|
||||||
|
px: '0',
|
||||||
|
_invalid: {
|
||||||
|
borderColor: 'error',
|
||||||
|
},
|
||||||
|
_focus: {
|
||||||
|
borderColor: 'colorPalette.solid.bg',
|
||||||
|
boxShadowColor: 'colorPalette.solid.bg',
|
||||||
|
boxShadow: '0 1px 0 0 var(--shadow-color)',
|
||||||
|
_invalid: {
|
||||||
|
borderColor: 'error',
|
||||||
|
boxShadowColor: 'error',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
size: {
|
||||||
|
xs: { textStyle: 'sm', px: '2', py: '5px', scrollPaddingBottom: '5px' },
|
||||||
|
sm: { textStyle: 'sm', px: '2.5', py: '7px', scrollPaddingBottom: '7px' },
|
||||||
|
md: { textStyle: 'md', px: '3', py: '7px', scrollPaddingBottom: '7px' },
|
||||||
|
lg: { textStyle: 'md', px: '3.5', py: '9px', scrollPaddingBottom: '9px' },
|
||||||
|
xl: { textStyle: 'lg', px: '4', py: '9px', scrollPaddingBottom: '9px' },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
17
src/theme/text-styles.ts
Normal file
17
src/theme/text-styles.ts
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import { defineTextStyles } from '@pandacss/dev'
|
||||||
|
|
||||||
|
export const textStyles = defineTextStyles({
|
||||||
|
xs: { value: { fontSize: 'xs', lineHeight: '1.125rem' } },
|
||||||
|
sm: { value: { fontSize: 'sm', lineHeight: '1.25rem' } },
|
||||||
|
md: { value: { fontSize: 'md', lineHeight: '1.5rem' } },
|
||||||
|
lg: { value: { fontSize: 'lg', lineHeight: '1.75rem' } },
|
||||||
|
xl: { value: { fontSize: 'xl', lineHeight: '1.875rem' } },
|
||||||
|
'2xl': { value: { fontSize: '2xl', lineHeight: '2rem' } },
|
||||||
|
'3xl': { value: { fontSize: '3xl', lineHeight: '2.375rem' } },
|
||||||
|
'4xl': { value: { fontSize: '4xl', lineHeight: '2.75rem', letterSpacing: '-0.02em' } },
|
||||||
|
'5xl': { value: { fontSize: '5xl', lineHeight: '3.75rem', letterSpacing: '-0.02em' } },
|
||||||
|
'6xl': { value: { fontSize: '6xl', lineHeight: '4.5rem', letterSpacing: '-0.02em' } },
|
||||||
|
'7xl': { value: { fontSize: '7xl', lineHeight: '5.75rem', letterSpacing: '-0.02em' } },
|
||||||
|
|
||||||
|
label: { value: { fontSize: 'sm', lineHeight: '1.25rem', fontWeight: 'medium' } },
|
||||||
|
})
|
||||||
35
src/theme/tokens/colors.ts
Normal file
35
src/theme/tokens/colors.ts
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
import { defineTokens } from '@pandacss/dev'
|
||||||
|
|
||||||
|
const black = defineTokens.colors({
|
||||||
|
DEFAULT: { value: '#000000' },
|
||||||
|
a1: { value: 'rgba(0, 0, 0, 0.05)' },
|
||||||
|
a2: { value: 'rgba(0, 0, 0, 0.1)' },
|
||||||
|
a3: { value: 'rgba(0, 0, 0, 0.15)' },
|
||||||
|
a4: { value: 'rgba(0, 0, 0, 0.2)' },
|
||||||
|
a5: { value: 'rgba(0, 0, 0, 0.3)' },
|
||||||
|
a6: { value: 'rgba(0, 0, 0, 0.4)' },
|
||||||
|
a7: { value: 'rgba(0, 0, 0, 0.5)' },
|
||||||
|
a8: { value: 'rgba(0, 0, 0, 0.6)' },
|
||||||
|
a9: { value: 'rgba(0, 0, 0, 0.7)' },
|
||||||
|
a10: { value: 'rgba(0, 0, 0, 0.8)' },
|
||||||
|
a11: { value: 'rgba(0, 0, 0, 0.9)' },
|
||||||
|
a12: { value: 'rgba(0, 0, 0, 0.95)' },
|
||||||
|
})
|
||||||
|
|
||||||
|
const white = defineTokens.colors({
|
||||||
|
DEFAULT: { value: '#ffffff' },
|
||||||
|
a1: { value: 'rgba(255, 255, 255, 0.05)' },
|
||||||
|
a2: { value: 'rgba(255, 255, 255, 0.1)' },
|
||||||
|
a3: { value: 'rgba(255, 255, 255, 0.15)' },
|
||||||
|
a4: { value: 'rgba(255, 255, 255, 0.2)' },
|
||||||
|
a5: { value: 'rgba(255, 255, 255, 0.3)' },
|
||||||
|
a6: { value: 'rgba(255, 255, 255, 0.4)' },
|
||||||
|
a7: { value: 'rgba(255, 255, 255, 0.5)' },
|
||||||
|
a8: { value: 'rgba(255, 255, 255, 0.6)' },
|
||||||
|
a9: { value: 'rgba(255, 255, 255, 0.7)' },
|
||||||
|
a10: { value: 'rgba(255, 255, 255, 0.8)' },
|
||||||
|
a11: { value: 'rgba(255, 255, 255, 0.9)' },
|
||||||
|
a12: { value: 'rgba(255, 255, 255, 0.95)' },
|
||||||
|
})
|
||||||
|
|
||||||
|
export const colors = { black, white }
|
||||||
11
src/theme/tokens/durations.ts
Normal file
11
src/theme/tokens/durations.ts
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
import { defineTokens } from '@pandacss/dev'
|
||||||
|
|
||||||
|
export const durations = defineTokens.durations({
|
||||||
|
fastest: { value: '50ms' },
|
||||||
|
faster: { value: '100ms' },
|
||||||
|
fast: { value: '150ms' },
|
||||||
|
normal: { value: '200ms' },
|
||||||
|
slow: { value: '250ms' },
|
||||||
|
slower: { value: '300ms' },
|
||||||
|
slowest: { value: '400ms' },
|
||||||
|
})
|
||||||
46
src/theme/tokens/shadows.ts
Normal file
46
src/theme/tokens/shadows.ts
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
import { defineSemanticTokens } from '@pandacss/dev'
|
||||||
|
|
||||||
|
export const shadows = defineSemanticTokens.shadows({
|
||||||
|
xs: {
|
||||||
|
value: {
|
||||||
|
_light: '0px 1px 2px {colors.gray.a6}, 0px 0px 1px {colors.gray.a7}',
|
||||||
|
_dark: '0px 1px 1px {colors.black.a8}, 0px 0px 1px inset {colors.gray.a8}',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
sm: {
|
||||||
|
value: {
|
||||||
|
_light: '0px 2px 4px {colors.gray.a4}, 0px 0px 1px {colors.gray.a4}',
|
||||||
|
_dark: '0px 2px 4px {colors.black.a8}, 0px 0px 1px inset {colors.gray.a8}',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
md: {
|
||||||
|
value: {
|
||||||
|
_light: '0px 4px 8px {colors.gray.a4}, 0px 0px 1px {colors.gray.a4}',
|
||||||
|
_dark: '0px 4px 8px {colors.black.a8}, 0px 0px 1px inset {colors.gray.a8}',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
lg: {
|
||||||
|
value: {
|
||||||
|
_light: '0px 8px 16px {colors.gray.a4}, 0px 0px 1px {colors.gray.a4}',
|
||||||
|
_dark: '0px 8px 16px {colors.black.a8}, 0px 0px 1px inset {colors.gray.a8}',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
xl: {
|
||||||
|
value: {
|
||||||
|
_light: '0px 16px 24px {colors.gray.a4}, 0px 0px 1px {colors.gray.a4}',
|
||||||
|
_dark: '0px 16px 24px {colors.black.a8}, 0px 0px 1px inset {colors.gray.a8}',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
'2xl': {
|
||||||
|
value: {
|
||||||
|
_light: '0px 24px 40px {colors.gray.a4}, 0px 0px 1px {colors.gray.a4}',
|
||||||
|
_dark: '0px 24px 40px {colors.black.a8}, 0px 0px 1px inset {colors.gray.a8}',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
inset: {
|
||||||
|
value: {
|
||||||
|
_light: 'inset 8px 0 12px -8px {colors.gray.a4}',
|
||||||
|
_dark: 'inset 8px 0 12px -8px {colors.black.a6}',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
40
src/theme/tokens/z-index.ts
Normal file
40
src/theme/tokens/z-index.ts
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
import { defineTokens } from '@pandacss/dev'
|
||||||
|
|
||||||
|
export const zIndex = defineTokens.zIndex({
|
||||||
|
hide: {
|
||||||
|
value: -1,
|
||||||
|
},
|
||||||
|
base: {
|
||||||
|
value: 0,
|
||||||
|
},
|
||||||
|
docked: {
|
||||||
|
value: 10,
|
||||||
|
},
|
||||||
|
dropdown: {
|
||||||
|
value: 1000,
|
||||||
|
},
|
||||||
|
sticky: {
|
||||||
|
value: 1100,
|
||||||
|
},
|
||||||
|
banner: {
|
||||||
|
value: 1200,
|
||||||
|
},
|
||||||
|
overlay: {
|
||||||
|
value: 1300,
|
||||||
|
},
|
||||||
|
modal: {
|
||||||
|
value: 1400,
|
||||||
|
},
|
||||||
|
popover: {
|
||||||
|
value: 1500,
|
||||||
|
},
|
||||||
|
skipLink: {
|
||||||
|
value: 1600,
|
||||||
|
},
|
||||||
|
toast: {
|
||||||
|
value: 1700,
|
||||||
|
},
|
||||||
|
tooltip: {
|
||||||
|
value: 1800,
|
||||||
|
},
|
||||||
|
})
|
||||||
51
src/theme/use-color-mode.js
Normal file
51
src/theme/use-color-mode.js
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
import { useEffect, useLayoutEffect, useState } from 'react'
|
||||||
|
|
||||||
|
const key = 'syncova-color-mode'
|
||||||
|
const system = window.matchMedia('(prefers-color-scheme: dark)')
|
||||||
|
|
||||||
|
function savedMode() {
|
||||||
|
try {
|
||||||
|
const mode = window.localStorage.getItem(key)
|
||||||
|
if (mode === 'dark' || mode === 'light') return mode
|
||||||
|
} catch {
|
||||||
|
// The theme can still be changed when browser storage is unavailable.
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useColorMode() {
|
||||||
|
const [preference, setPreference] = useState(savedMode)
|
||||||
|
const [systemDark, setSystemDark] = useState(() => system.matches)
|
||||||
|
const dark = preference === null ? systemDark : preference === 'dark'
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const syncSystem = () => setSystemDark(system.matches)
|
||||||
|
const syncPreference = (event) => {
|
||||||
|
if (event.key === key || event.key === null) setPreference(savedMode())
|
||||||
|
}
|
||||||
|
system.addEventListener('change', syncSystem)
|
||||||
|
window.addEventListener('storage', syncPreference)
|
||||||
|
syncSystem()
|
||||||
|
return () => {
|
||||||
|
system.removeEventListener('change', syncSystem)
|
||||||
|
window.removeEventListener('storage', syncPreference)
|
||||||
|
}
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
useLayoutEffect(() => {
|
||||||
|
document.documentElement.classList.toggle('dark', dark)
|
||||||
|
document.querySelector('meta[name="theme-color"]').content = getComputedStyle(document.body).backgroundColor
|
||||||
|
}, [dark])
|
||||||
|
|
||||||
|
function toggle() {
|
||||||
|
const next = dark ? 'light' : 'dark'
|
||||||
|
setPreference(next)
|
||||||
|
try {
|
||||||
|
window.localStorage.setItem(key, next)
|
||||||
|
} catch {
|
||||||
|
// State keeps the selection active for the current page.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return { dark, toggle }
|
||||||
|
}
|
||||||
267
tests/acceptance.spec.js
Normal file
267
tests/acceptance.spec.js
Normal file
@ -0,0 +1,267 @@
|
|||||||
|
import { promisify } from 'node:util'
|
||||||
|
import { execFile } from 'node:child_process'
|
||||||
|
import { expect, test } from '@playwright/test'
|
||||||
|
import sharp from 'sharp'
|
||||||
|
|
||||||
|
const exec = promisify(execFile)
|
||||||
|
const password = process.env.SYNCOVA_TEST_PASSWORD
|
||||||
|
const project = process.env.SYNCOVA_TEST_PROJECT
|
||||||
|
const baseURL = process.env.SYNCOVA_TEST_URL
|
||||||
|
const envFile = process.env.SYNCOVA_TEST_ENV
|
||||||
|
const writeHeaders = { 'X-Syncova-Request': '1' }
|
||||||
|
|
||||||
|
test('Frischer Docker-Start, Verwaltung und persistente öffentliche Ansicht', async ({ page, browser, request }, info) => {
|
||||||
|
if (!/^syncova-test-[a-f0-9]{10}$/.test(project ?? '') || !password || !baseURL || !envFile) {
|
||||||
|
throw new Error('Bitte über npm run test:e2e starten.')
|
||||||
|
}
|
||||||
|
const guest = await browser.newContext({ baseURL, colorScheme: 'light', viewport: { width: 390, height: 844 } })
|
||||||
|
const publicPage = await guest.newPage()
|
||||||
|
const dialog = page.getByRole('dialog')
|
||||||
|
const button = (name) => page.getByRole('button', { name, exact: true })
|
||||||
|
const apply = () => dialog.getByRole('button', { name: 'Übernehmen', exact: true }).click()
|
||||||
|
|
||||||
|
async function createDepartment(name) {
|
||||||
|
await button('Abteilung anlegen').click()
|
||||||
|
await dialog.getByLabel('Name', { exact: true }).fill(name)
|
||||||
|
await dialog.getByRole('button', { name: 'Abteilung anlegen', exact: true }).click()
|
||||||
|
await expect(page.getByRole('heading', { name, exact: true })).toBeVisible()
|
||||||
|
}
|
||||||
|
async function checkEmpty(slug) {
|
||||||
|
await publicPage.goto('/' + slug + '?bearbeiten=1')
|
||||||
|
await expect(publicPage.locator('body')).toHaveText('Anmelden')
|
||||||
|
await expect(publicPage.getByRole('button', { name: 'Anmelden' })).toBeVisible()
|
||||||
|
}
|
||||||
|
async function group(name) {
|
||||||
|
await button('Gruppe').click()
|
||||||
|
await dialog.getByLabel('Gruppenname').fill(name)
|
||||||
|
await apply()
|
||||||
|
}
|
||||||
|
async function link(groupName, title, url) {
|
||||||
|
await button(`Link hinzufügen · ${groupName}`).click()
|
||||||
|
await dialog.getByLabel('Titel', { exact: true }).fill(title)
|
||||||
|
await dialog.getByLabel('URL', { exact: true }).fill(url)
|
||||||
|
}
|
||||||
|
async function isLoaded(image) {
|
||||||
|
await expect(image).toBeVisible()
|
||||||
|
await expect.poll(() => image.evaluate((element) => element.complete && element.naturalWidth > 0)).toBe(true)
|
||||||
|
}
|
||||||
|
async function denyWrites(id) {
|
||||||
|
for (const [method, path] of [
|
||||||
|
['POST', '/api/pages'], ['PUT', '/api/pages/' + id], ['DELETE', '/api/pages/' + id],
|
||||||
|
['POST', '/api/icons/upload'], ['POST', '/api/icons/favicon'],
|
||||||
|
]) {
|
||||||
|
expect((await request.fetch(path, { method, headers: writeHeaders, data: {} })).status()).toBe(401)
|
||||||
|
}
|
||||||
|
expect((await request.get('/api/admin/pages')).status()).toBe(401)
|
||||||
|
}
|
||||||
|
async function publicLayout(view) {
|
||||||
|
const selected = publicPage.getByRole('radio', { name: view, exact: true })
|
||||||
|
await expect(selected).toBeChecked()
|
||||||
|
await expect(publicPage.getByRole('radiogroup', { name: 'Ansicht' })).toHaveCSS('border-radius', '12px')
|
||||||
|
expect(await publicPage.locator('body').evaluate((body) => body.scrollWidth <= window.innerWidth)).toBe(true)
|
||||||
|
await expect(publicPage.locator('.page-content > *').locator('h2, .clock-zone')).toHaveText([
|
||||||
|
'Europe/Berlin', 'Werkzeuge', 'Dokumentation', 'Hinweise', 'UTC',
|
||||||
|
])
|
||||||
|
await expect(publicPage.getByRole('region', { name: 'Dokumentation' }).getByRole('link'))
|
||||||
|
.toHaveText(['Lokales Portal', 'Handbuch', 'Python'])
|
||||||
|
await expect(publicPage.getByText('Zugänge für den Arbeitsalltag.')).toBeVisible()
|
||||||
|
await expect(publicPage.locator('time')).toHaveCount(2)
|
||||||
|
for (const title of ['Handbuch', 'Python']) await isLoaded(publicPage.getByRole('link', { name: title }).locator('img'))
|
||||||
|
await expect(publicPage.getByRole('link', { name: 'Lokales Portal' }).locator('img')).toHaveCount(0)
|
||||||
|
await expect(publicPage.locator('[data-grip], [data-drop]')).toHaveCount(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
await test.step('Systemeinstellung und manuelle Moduswahl', async () => {
|
||||||
|
await page.emulateMedia({ colorScheme: 'dark' })
|
||||||
|
await page.goto('/')
|
||||||
|
await expect(page.locator('body')).toHaveCSS('background-color', 'rgb(16, 22, 19)')
|
||||||
|
await page.emulateMedia({ colorScheme: 'light' })
|
||||||
|
await expect(page.locator('body')).toHaveCSS('background-color', 'rgb(246, 247, 242)')
|
||||||
|
await button('Dunkelmodus').press('Space')
|
||||||
|
await page.reload()
|
||||||
|
await expect(button('Dunkelmodus')).toHaveAttribute('aria-pressed', 'true')
|
||||||
|
await expect(page.locator('body')).toHaveCSS('background-color', 'rgb(16, 22, 19)')
|
||||||
|
})
|
||||||
|
|
||||||
|
await test.step('Öffentliche Startseite, Anmeldung und zwei leere Abteilungen', async () => {
|
||||||
|
await page.goto('/')
|
||||||
|
await expect(page.getByRole('heading', { name: 'Abteilungen', exact: true })).toBeVisible()
|
||||||
|
await expect(page.getByText('Noch keine Abteilungen')).toBeVisible()
|
||||||
|
await expect(button('Abteilung anlegen')).toHaveCount(0)
|
||||||
|
await button('Anmelden').click()
|
||||||
|
await expect(dialog).toHaveCSS('background-color', 'rgb(25, 33, 29)')
|
||||||
|
if (process.env.SYNCOVA_CAPTURE) await page.screenshot({ path: info.outputPath('anmeldung.png'), animations: 'disabled' })
|
||||||
|
await dialog.getByLabel('Benutzername').fill('abnahme')
|
||||||
|
await dialog.getByLabel('Passwort').fill(password)
|
||||||
|
await dialog.getByRole('button', { name: 'Anmelden', exact: true }).click()
|
||||||
|
await expect(button('Abteilung anlegen')).toBeVisible()
|
||||||
|
const cookies = await page.context().cookies()
|
||||||
|
expect(cookies).toEqual(expect.arrayContaining([expect.objectContaining({ name: 'syncova_session', httpOnly: true, sameSite: 'Strict' })]))
|
||||||
|
await createDepartment('IT')
|
||||||
|
await checkEmpty('it')
|
||||||
|
await page.getByRole('link', { name: 'Abteilungen', exact: true }).click()
|
||||||
|
await createDepartment('Personal')
|
||||||
|
await checkEmpty('personal')
|
||||||
|
await publicPage.goto('/')
|
||||||
|
await expect(publicPage.getByRole('link', { name: 'IT', exact: true })).toHaveAttribute('href', '/it')
|
||||||
|
await expect(publicPage.getByRole('button', { name: /anlegen|löschen/i })).toHaveCount(0)
|
||||||
|
await expect(publicPage.getByRole('link', { name: 'Bearbeiten', exact: true })).toHaveCount(0)
|
||||||
|
await publicPage.getByRole('link', { name: 'Personal', exact: true }).click()
|
||||||
|
await expect(publicPage).toHaveURL(/\/personal$/)
|
||||||
|
await expect(publicPage.locator('body')).toHaveText('Anmelden')
|
||||||
|
await page.getByRole('link', { name: 'Abteilungen', exact: true }).click()
|
||||||
|
await expect(page.getByRole('heading', { name: 'Personal', exact: true })).toBeVisible()
|
||||||
|
if (process.env.SYNCOVA_CAPTURE) await page.screenshot({ path: info.outputPath('abteilungen.png') })
|
||||||
|
await page.locator('.department-card').filter({ has: page.getByRole('heading', { name: 'IT', exact: true }) })
|
||||||
|
.getByRole('link', { name: 'Bearbeiten' }).click()
|
||||||
|
await expect(page.locator('.editor-toolbar')).toHaveCSS('background-color', 'rgb(25, 33, 29)')
|
||||||
|
await button('Dunkelmodus').click()
|
||||||
|
await expect(page.locator('body')).toHaveCSS('background-color', 'rgb(246, 247, 242)')
|
||||||
|
})
|
||||||
|
|
||||||
|
await test.step('Gruppen, Links, Icon-Vorschauen und Widgets bearbeiten', async () => {
|
||||||
|
await group('Werkzeuge')
|
||||||
|
await group('Dokumentation')
|
||||||
|
await link('Werkzeuge', 'Handbuch', 'https://example.com/handbuch')
|
||||||
|
const png = await sharp({
|
||||||
|
create: { width: 24, height: 24, channels: 4, background: '#176449' },
|
||||||
|
}).png().toBuffer()
|
||||||
|
await dialog.locator('input[type="file"]').setInputFiles({ name: 'icon.png', mimeType: 'image/png', buffer: png })
|
||||||
|
await isLoaded(dialog.getByRole('img', { name: 'Icon-Vorschau' }))
|
||||||
|
const stagedUrl = await dialog.getByRole('img', { name: 'Icon-Vorschau' }).getAttribute('src')
|
||||||
|
expect((await request.get(stagedUrl)).status()).toBe(404)
|
||||||
|
await apply()
|
||||||
|
|
||||||
|
await link('Dokumentation', 'Python', 'https://www.python.org/')
|
||||||
|
await dialog.getByRole('button', { name: 'Favicon abrufen' }).click()
|
||||||
|
await isLoaded(dialog.getByRole('img', { name: 'Icon-Vorschau' }))
|
||||||
|
await apply()
|
||||||
|
|
||||||
|
await link('Dokumentation', 'Lokales Portal', 'http://127.0.0.1:3000/')
|
||||||
|
await dialog.getByRole('button', { name: 'Favicon abrufen' }).click()
|
||||||
|
await expect(dialog.getByRole('status')).toContainText('Kein verwendbares Favicon')
|
||||||
|
await expect(dialog.getByText('Standard-Icon', { exact: true })).toBeVisible()
|
||||||
|
await apply()
|
||||||
|
|
||||||
|
await button('Text-Widget').click()
|
||||||
|
await dialog.getByLabel('Überschrift (optional)', { exact: true }).fill('Hinweise')
|
||||||
|
await dialog.getByLabel('Text', { exact: true }).fill('Zugänge für den Arbeitsalltag.')
|
||||||
|
await apply()
|
||||||
|
await button('Uhrzeit-Widget').click()
|
||||||
|
await apply()
|
||||||
|
await button('Uhrzeit-Widget').click()
|
||||||
|
await dialog.getByLabel('Zeitzone', { exact: true }).fill('UTC')
|
||||||
|
await dialog.getByText('12 Stunden', { exact: true }).click()
|
||||||
|
await apply()
|
||||||
|
await expect(page.locator('time').last()).toHaveText(/(?:AM|PM)/i)
|
||||||
|
await checkEmpty('it')
|
||||||
|
})
|
||||||
|
|
||||||
|
await test.step('Drag-and-drop und Tastatur, Standardansicht und Speichern', async () => {
|
||||||
|
const grip = button('Handbuch verschieben')
|
||||||
|
const box = await grip.boundingBox()
|
||||||
|
await page.mouse.move(box.x + box.width / 2, box.y + box.height / 2)
|
||||||
|
await page.mouse.down()
|
||||||
|
await page.mouse.move(box.x + box.width / 2 + 14, box.y + box.height / 2 + 4, { steps: 5 })
|
||||||
|
const drop = button('Dokumentation · Vor Python ablegen')
|
||||||
|
await expect(drop).toBeVisible()
|
||||||
|
await drop.scrollIntoViewIfNeeded()
|
||||||
|
const target = await drop.boundingBox()
|
||||||
|
await page.mouse.move(target.x + target.width / 2, target.y + target.height / 2, { steps: 10 })
|
||||||
|
await page.mouse.move(target.x + target.width / 2 + 1, target.y + target.height / 2)
|
||||||
|
await expect(drop.locator('..')).toHaveAttribute('data-over', 'true')
|
||||||
|
await page.mouse.up()
|
||||||
|
await expect(page.getByRole('region', { name: 'Werkzeuge' }).getByText('Handbuch')).toHaveCount(0)
|
||||||
|
await expect(page.getByRole('region', { name: 'Dokumentation' }).getByText('Handbuch')).toBeVisible()
|
||||||
|
await button('Lokales Portal verschieben').focus()
|
||||||
|
await page.keyboard.press('Enter')
|
||||||
|
const beforeHandbuch = button('Dokumentation · Vor Handbuch ablegen')
|
||||||
|
await page.keyboard.press('ArrowDown')
|
||||||
|
await page.keyboard.press('ArrowDown')
|
||||||
|
await expect(beforeHandbuch).toBeFocused()
|
||||||
|
await page.keyboard.press('Enter')
|
||||||
|
await button('Uhrzeit · Europe/Berlin verschieben').focus()
|
||||||
|
await page.keyboard.press('Space')
|
||||||
|
await expect(button('Vor Werkzeuge ablegen')).toBeFocused()
|
||||||
|
await page.keyboard.press('Space')
|
||||||
|
await button('Seiteneinstellungen').click()
|
||||||
|
await dialog.getByText('Kacheln', { exact: true }).click()
|
||||||
|
await apply()
|
||||||
|
await button('Seite speichern').click()
|
||||||
|
await expect(page.getByText('Seite gespeichert.')).toBeVisible()
|
||||||
|
await expect(button('Seite speichern')).toBeDisabled()
|
||||||
|
expect((await page.request.post('/api/pages', { data: { name: 'Falsch', slug: 'falsch', view: 'list' } })).status()).toBe(403)
|
||||||
|
if (process.env.SYNCOVA_CAPTURE) await page.screenshot({ path: info.outputPath('bearbeitung.png'), fullPage: true })
|
||||||
|
})
|
||||||
|
|
||||||
|
const id = (await (await request.get('/api/pages/it')).json()).id
|
||||||
|
await test.step('Veröffentlichung, Ansichtswechsel, Abmeldung und Zugriffsschutz', async () => {
|
||||||
|
await publicPage.goto('/it')
|
||||||
|
await publicLayout('Kacheln')
|
||||||
|
const guestMode = publicPage.getByRole('button', { name: 'Dunkelmodus', exact: true })
|
||||||
|
await guestMode.click()
|
||||||
|
await expect(guestMode.locator('svg')).toBeVisible()
|
||||||
|
await expect(publicPage.locator('.choice [data-part="indicator"]')).toHaveCSS('background-color', 'rgb(23, 25, 24)')
|
||||||
|
await expect(publicPage.locator('.clock-widget').first()).toHaveCSS('background-color', 'rgb(35, 61, 47)')
|
||||||
|
if (process.env.SYNCOVA_CAPTURE) await publicPage.screenshot({ path: info.outputPath('kacheln.png'), fullPage: true })
|
||||||
|
const previous = await publicPage.locator('time').first().textContent()
|
||||||
|
await expect(publicPage.locator('time').first()).not.toHaveText(previous)
|
||||||
|
await publicPage.getByText('Liste', { exact: true }).click()
|
||||||
|
await publicLayout('Liste')
|
||||||
|
if (process.env.SYNCOVA_CAPTURE) await publicPage.screenshot({ path: info.outputPath('mobil.png'), fullPage: true })
|
||||||
|
await button('Abmelden').click()
|
||||||
|
await expect(button('Anmelden')).toBeVisible()
|
||||||
|
expect((await page.context().cookies()).some(({ name }) => name === 'syncova_session')).toBe(false)
|
||||||
|
await denyWrites(id)
|
||||||
|
})
|
||||||
|
|
||||||
|
await test.step('Neustart aus demselben Volume', async () => {
|
||||||
|
await exec('docker', ['compose', '--env-file', envFile, '-p', project, '-f', 'compose.yaml', 'restart', 'links'], { timeout: 25_000 })
|
||||||
|
await expect.poll(async () => (await fetch(baseURL + '/healthz').catch(() => null))?.status).toBe(200)
|
||||||
|
await publicPage.goto('/it')
|
||||||
|
await publicLayout('Kacheln')
|
||||||
|
await checkEmpty('personal')
|
||||||
|
await denyWrites(id)
|
||||||
|
})
|
||||||
|
|
||||||
|
await test.step('Abteilung und Gruppe umbenennen, Gruppe und Abteilung löschen', async () => {
|
||||||
|
await page.goto('/personal')
|
||||||
|
await button('Anmelden').click()
|
||||||
|
await dialog.getByLabel('Benutzername').fill('abnahme')
|
||||||
|
await dialog.getByLabel('Passwort').fill(password)
|
||||||
|
await dialog.getByRole('button', { name: 'Anmelden', exact: true }).click()
|
||||||
|
await button('Seite bearbeiten').click()
|
||||||
|
await button('Seiteneinstellungen').click()
|
||||||
|
await dialog.getByLabel('Name', { exact: true }).fill('Personalservice')
|
||||||
|
await dialog.getByLabel('URL-Pfad', { exact: true }).fill('personalservice')
|
||||||
|
await apply()
|
||||||
|
await button('Seite speichern').click()
|
||||||
|
await expect(page).toHaveURL(/\/personalservice\?bearbeiten=1$/)
|
||||||
|
expect((await request.get('/api/pages/personal')).status()).toBe(404)
|
||||||
|
await checkEmpty('personalservice')
|
||||||
|
await publicPage.goto('/')
|
||||||
|
await expect(publicPage.getByRole('link', { name: 'Personalservice', exact: true })).toHaveAttribute('href', '/personalservice')
|
||||||
|
await expect(publicPage.getByRole('link', { name: 'Personal', exact: true })).toHaveCount(0)
|
||||||
|
|
||||||
|
await group('Anträge')
|
||||||
|
await button('Anträge bearbeiten').click()
|
||||||
|
await dialog.getByLabel('Gruppenname').fill('Formulare')
|
||||||
|
await apply()
|
||||||
|
await link('Formulare', 'Urlaubsantrag', 'https://example.com/urlaub')
|
||||||
|
await apply()
|
||||||
|
await button('Formulare löschen').click()
|
||||||
|
await dialog.getByRole('button', { name: 'Entfernen', exact: true }).click()
|
||||||
|
await expect(page.getByRole('region', { name: 'Ungruppierte Links' }).getByText('Urlaubsantrag')).toBeVisible()
|
||||||
|
await button('Seite speichern').click()
|
||||||
|
await expect(page.getByText('Seite gespeichert.')).toBeVisible()
|
||||||
|
await page.getByRole('link', { name: 'Abteilungen', exact: true }).click()
|
||||||
|
await button('Personalservice löschen').click()
|
||||||
|
await dialog.getByRole('button', { name: 'Abteilung löschen', exact: true }).click()
|
||||||
|
await expect(page.getByRole('heading', { name: 'Personalservice', exact: true })).toHaveCount(0)
|
||||||
|
expect((await request.get('/api/pages/personalservice')).status()).toBe(404)
|
||||||
|
await publicPage.goto('/')
|
||||||
|
await expect(publicPage.getByRole('link', { name: 'IT', exact: true })).toBeVisible()
|
||||||
|
await expect(publicPage.locator('.department-card')).toHaveCount(1)
|
||||||
|
})
|
||||||
|
await guest.close()
|
||||||
|
})
|
||||||
11
tsconfig.json
Normal file
11
tsconfig.json
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"baseUrl": ".",
|
||||||
|
"target": "ES2022",
|
||||||
|
"module": "ESNext",
|
||||||
|
"moduleResolution": "Bundler",
|
||||||
|
"jsx": "react-jsx",
|
||||||
|
"paths": { "@/*": ["./src/*"], "styled-system/*": ["./styled-system/*"] }
|
||||||
|
},
|
||||||
|
"include": ["src", "panda.config.ts"]
|
||||||
|
}
|
||||||
13
vite.config.js
Normal file
13
vite.config.js
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
import { defineConfig } from 'vite'
|
||||||
|
import react from '@vitejs/plugin-react'
|
||||||
|
import { fileURLToPath } from 'node:url'
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
plugins: [react()],
|
||||||
|
resolve: {
|
||||||
|
alias: {
|
||||||
|
'@': fileURLToPath(new URL('./src', import.meta.url)),
|
||||||
|
'styled-system': fileURLToPath(new URL('./styled-system', import.meta.url)),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
Loading…
Reference in New Issue
Block a user