Add generic per-field text styling (font/size/color), starting with home sections
Adds a new text_styles table keyed by field_key ("{table}.{slugOrId}.{column}")
so any individual text field anywhere in the dashboard can get its own
font-family/font-size/color override, without a dedicated column per field.
App\Support\TextStyleFields is a server-side registry of which table/column/
permission combinations are valid, so TextStyleController::update() can't be
used to write styling for a field outside the caller's own permission domain,
and typos can't create permanently orphaned rows. Resetting all three values
deletes the row entirely rather than leaving it null, so the table only ever
holds fields an admin actually customized.
Font-size reuses the same "curated list, mirrored PHP+JS constant" approach
already used for font-family (App\Support\Fonts / fontOptions.js) - a free px
input on dozens of independently-edited fields with no design review step is
the most likely way to end up with an accidentally 4px or 400px heading.
New reusable pieces: TextStyleWidget.jsx (a self-contained font/size/color
toolbar with a live preview, used next to any field by passing its
field_key) and TextStylesContext.jsx + useTextStyle() hook (bulk-fetches all
styles once per page load in PublicLayout.jsx, same pattern as
SiteSettingsContext). This first phase wires both into the home-section
eyebrow/title/button-label fields (the ones from the screenshot that started
this) as a proven pilot; the registry is designed so extending it to the
remaining ~15 admin pages is just adding entries and wiring the widget/hook,
no new architecture.
Verified locally via direct PHP invocation: migration creates the table,
registry validation accepts only known table/slug-or-id/column
combinations and rejects the rest, upsert/reset round-trips correctly, and
a second migration run doesn't re-touch anything.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
parent
c17eee49cd
commit
260cd0700e
19 changed files with 737 additions and 343 deletions
|
|
@ -9,6 +9,7 @@ import CookieConsentBanner from './CookieConsentBanner.jsx';
|
|||
import GoogleAnalytics from './GoogleAnalytics.jsx';
|
||||
import { MaintenanceProvider } from '../context/MaintenanceContext.jsx';
|
||||
import { SiteSettingsProvider } from '../context/SiteSettingsContext.jsx';
|
||||
import { TextStylesProvider } from '../context/TextStylesContext.jsx';
|
||||
import { LanguageProvider } from '../context/LanguageContext.jsx';
|
||||
import { useAuth } from '../context/AuthContext.jsx';
|
||||
import { api } from '../api/client.js';
|
||||
|
|
@ -58,12 +59,14 @@ const LEGAL_PATHS = ['/impressum', '/datenschutz', '/agb'];
|
|||
export default function PublicLayout() {
|
||||
const [status, setStatus] = useState(null);
|
||||
const [siteSettings, setSiteSettings] = useState(DEFAULT_SITE_SETTINGS);
|
||||
const [textStyles, setTextStyles] = useState({});
|
||||
const { loading: authLoading, hasPermission } = useAuth();
|
||||
const location = useLocation();
|
||||
|
||||
useEffect(() => {
|
||||
api.get('/maintenance').then(setStatus).catch(() => setStatus(FALLBACK_STATUS));
|
||||
api.get('/site-settings').then(setSiteSettings).catch(() => {});
|
||||
api.get('/text-styles').then(setTextStyles).catch(() => {});
|
||||
}, []);
|
||||
|
||||
// Globale Schriftart als CSS-Variable auf <html> - tailwind.config.js definiert font-sans
|
||||
|
|
@ -96,6 +99,7 @@ export default function PublicLayout() {
|
|||
<LanguageProvider>
|
||||
<MaintenanceProvider value={{ ...status, bypass }}>
|
||||
<SiteSettingsProvider value={siteSettings}>
|
||||
<TextStylesProvider value={textStyles}>
|
||||
<div className="page-texture flex min-h-screen flex-col text-neutral-900 dark:text-neutral-100">
|
||||
{bypass && status.global.enabled && <MaintenanceBypassBanner />}
|
||||
<ScrollProgress />
|
||||
|
|
@ -107,6 +111,7 @@ export default function PublicLayout() {
|
|||
<CookieConsentBanner />
|
||||
<GoogleAnalytics />
|
||||
</div>
|
||||
</TextStylesProvider>
|
||||
</SiteSettingsProvider>
|
||||
</MaintenanceProvider>
|
||||
</LanguageProvider>
|
||||
|
|
|
|||
93
hifi-src/src/components/TextStyleWidget.jsx
Normal file
93
hifi-src/src/components/TextStyleWidget.jsx
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
import { useEffect, useState } from 'react';
|
||||
import { api } from '../api/client.js';
|
||||
import { FONT_OPTIONS } from '../utils/fontOptions.js';
|
||||
import { FONT_SIZE_OPTIONS } from '../utils/fontSizeOptions.js';
|
||||
|
||||
const EMPTY = { font_family: '', font_size: '', color: '' };
|
||||
|
||||
/**
|
||||
* Kleine, in sich geschlossene Werkzeugleiste fuer Schriftart/-groesse/Farbe eines einzelnen
|
||||
* Textfelds - laedt und speichert eigenstaendig gegen /text-styles, ohne dass die umgebende
|
||||
* Seite den Stil-Zustand selbst verwalten muss. fieldKey identifiziert das Feld eindeutig
|
||||
* (siehe App\Support\TextStyleFields fuer gueltige Kombinationen).
|
||||
*/
|
||||
export default function TextStyleWidget({ fieldKey, previewText = 'Beispieltext', label = 'Stil' }) {
|
||||
const [style, setStyle] = useState(EMPTY);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState('');
|
||||
|
||||
useEffect(() => {
|
||||
setLoading(true);
|
||||
api
|
||||
.get(`/text-styles/one?key=${encodeURIComponent(fieldKey)}`)
|
||||
.then((res) => setStyle({
|
||||
font_family: res.font_family || '',
|
||||
font_size: res.font_size || '',
|
||||
color: res.color || '',
|
||||
}))
|
||||
.catch(() => setStyle(EMPTY))
|
||||
.finally(() => setLoading(false));
|
||||
}, [fieldKey]);
|
||||
|
||||
const save = async (next) => {
|
||||
setStyle(next);
|
||||
setError('');
|
||||
try {
|
||||
await api.put('/text-styles', { field_key: fieldKey, ...next });
|
||||
} catch (err) {
|
||||
setError(err.message);
|
||||
}
|
||||
};
|
||||
|
||||
if (loading) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const previewStyle = {
|
||||
fontFamily: style.font_family || undefined,
|
||||
fontSize: style.font_size || undefined,
|
||||
color: style.color || undefined,
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="mt-1.5 flex flex-wrap items-center gap-2 rounded-md border border-neutral-200 bg-neutral-50 p-2 dark:border-neutral-700 dark:bg-neutral-800/50">
|
||||
<span className="text-xs font-medium uppercase tracking-wide text-neutral-400">{label}</span>
|
||||
<select
|
||||
value={style.font_family}
|
||||
onChange={(e) => save({ ...style, font_family: e.target.value })}
|
||||
className="rounded-md border border-neutral-300 bg-white px-2 py-1 text-xs dark:border-neutral-700 dark:bg-neutral-900"
|
||||
>
|
||||
{FONT_OPTIONS.map((f) => (
|
||||
<option key={f.label} value={f.value}>{f.label}</option>
|
||||
))}
|
||||
</select>
|
||||
<select
|
||||
value={style.font_size}
|
||||
onChange={(e) => save({ ...style, font_size: e.target.value })}
|
||||
className="rounded-md border border-neutral-300 bg-white px-2 py-1 text-xs dark:border-neutral-700 dark:bg-neutral-900"
|
||||
>
|
||||
{FONT_SIZE_OPTIONS.map((f) => (
|
||||
<option key={f.label} value={f.value}>{f.label}</option>
|
||||
))}
|
||||
</select>
|
||||
<input
|
||||
type="color"
|
||||
value={style.color || '#000000'}
|
||||
onChange={(e) => save({ ...style, color: e.target.value })}
|
||||
className="h-7 w-9 cursor-pointer rounded border border-neutral-300 bg-white p-0.5 dark:border-neutral-700 dark:bg-neutral-900"
|
||||
title="Textfarbe"
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => save(EMPTY)}
|
||||
className="rounded-md border border-neutral-300 px-2 py-1 text-xs text-neutral-500 hover:bg-neutral-100 dark:border-neutral-700 dark:text-neutral-400 dark:hover:bg-neutral-700"
|
||||
>
|
||||
Zurücksetzen
|
||||
</button>
|
||||
<span className="ml-1 rounded px-2 py-1 text-sm" style={previewStyle}>
|
||||
{previewText}
|
||||
</span>
|
||||
{error && <span className="text-xs text-red-600">{error}</span>}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
21
hifi-src/src/context/TextStylesContext.jsx
Normal file
21
hifi-src/src/context/TextStylesContext.jsx
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
import { createContext, useContext } from 'react';
|
||||
|
||||
// Ein einzelner Bulk-Request laedt alle text_styles-Zeilen (siehe PublicLayout.jsx), damit nicht
|
||||
// jede einzelne Textkomponente einen eigenen Request braucht. Leeres Objekt = noch keine
|
||||
// Overrides gesetzt, wie beim ersten Laden oder auf frisch installierten Seiten.
|
||||
const TextStylesContext = createContext({});
|
||||
|
||||
export const TextStylesProvider = TextStylesContext.Provider;
|
||||
|
||||
/** Liefert {fontFamily, fontSize, color} (nur die tatsaechlich gesetzten Werte) zum
|
||||
* Hineinspreaden in ein style-Objekt, oder {} wenn fuer dieses Feld nichts hinterlegt ist. */
|
||||
export function useTextStyle(fieldKey) {
|
||||
const styles = useContext(TextStylesContext);
|
||||
const entry = styles[fieldKey];
|
||||
if (!entry) return {};
|
||||
const result = {};
|
||||
if (entry.font_family) result.fontFamily = entry.font_family;
|
||||
if (entry.font_size) result.fontSize = entry.font_size;
|
||||
if (entry.color) result.color = entry.color;
|
||||
return result;
|
||||
}
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
import { useEffect, useRef, useState } from 'react';
|
||||
import { api } from '../../api/client.js';
|
||||
import RichTextEditor from '../../components/RichTextEditor.jsx';
|
||||
import TextStyleWidget from '../../components/TextStyleWidget.jsx';
|
||||
import { dragAnchorStyle } from '../../utils/dragAnchorPosition.js';
|
||||
import { FONT_OPTIONS } from '../../utils/fontOptions.js';
|
||||
|
||||
|
|
@ -290,6 +291,10 @@ export default function HomeSections() {
|
|||
onChange={(e) => update(`eyebrow_${activeLang}`, e.target.value)}
|
||||
className="w-full rounded-md border border-neutral-300 bg-white px-3 py-2 text-sm dark:border-neutral-700 dark:bg-neutral-900"
|
||||
/>
|
||||
<TextStyleWidget
|
||||
fieldKey={`home_sections.${activeSlug}.eyebrow`}
|
||||
previewText={active[`eyebrow_${activeLang}`] || 'Beispieltext'}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label className="mb-1 block text-sm font-medium text-neutral-700 dark:text-neutral-300">Überschrift</label>
|
||||
|
|
@ -298,6 +303,10 @@ export default function HomeSections() {
|
|||
onChange={(e) => update(`title_${activeLang}`, e.target.value)}
|
||||
className="w-full rounded-md border border-neutral-300 bg-white px-3 py-2 text-sm dark:border-neutral-700 dark:bg-neutral-900"
|
||||
/>
|
||||
<TextStyleWidget
|
||||
fieldKey={`home_sections.${activeSlug}.title`}
|
||||
previewText={active[`title_${activeLang}`] || 'Beispieltext'}
|
||||
/>
|
||||
</div>
|
||||
<RichTextEditor
|
||||
label="Text"
|
||||
|
|
@ -314,6 +323,10 @@ export default function HomeSections() {
|
|||
onChange={(e) => update(`button_label_${activeLang}`, e.target.value)}
|
||||
className="w-full rounded-md border border-neutral-300 bg-white px-3 py-2 text-sm dark:border-neutral-700 dark:bg-neutral-900"
|
||||
/>
|
||||
<TextStyleWidget
|
||||
fieldKey={`home_sections.${activeSlug}.button_label`}
|
||||
previewText={active[`button_label_${activeLang}`] || 'Beispieltext'}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label className="mb-1 block text-sm font-medium text-neutral-700 dark:text-neutral-300">
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import Accordion from '../../components/Accordion.jsx';
|
|||
import StarRating from '../../components/StarRating.jsx';
|
||||
import TestimonialSlider from '../../components/TestimonialSlider.jsx';
|
||||
import { useSiteSettings } from '../../context/SiteSettingsContext.jsx';
|
||||
import { useTextStyle } from '../../context/TextStylesContext.jsx';
|
||||
import { useLanguage } from '../../context/LanguageContext.jsx';
|
||||
import { dragAnchorStyle } from '../../utils/dragAnchorPosition.js';
|
||||
import defaultHeroImage from '../../assets/photos/gallery-dash2.webp';
|
||||
|
|
@ -35,17 +36,17 @@ const EMPTY_SECTION = {
|
|||
|
||||
/** Rendert nur, wenn sowohl Beschriftung als auch Ziel gesetzt sind - interne Ziele (mit "/")
|
||||
* bleiben in der SPA, alles andere oeffnet extern in einem neuen Tab. */
|
||||
function SectionButton({ label, url, className }) {
|
||||
function SectionButton({ label, url, className, style }) {
|
||||
if (!label || !url) return null;
|
||||
if (url.startsWith('/')) {
|
||||
return (
|
||||
<Link to={url} className={className}>
|
||||
<Link to={url} className={className} style={style}>
|
||||
{label}
|
||||
</Link>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<a href={url} target="_blank" rel="noopener noreferrer" className={className}>
|
||||
<a href={url} target="_blank" rel="noopener noreferrer" className={className} style={style}>
|
||||
{label}
|
||||
</a>
|
||||
);
|
||||
|
|
@ -92,6 +93,25 @@ export default function Home() {
|
|||
};
|
||||
};
|
||||
|
||||
// Pro-Feld-Stil (Schriftart/-groesse/Farbe je Vorspann/Überschrift/Button-Text), zusaetzlich
|
||||
// zur bestehenden Schriftart pro ganzer Sektion (section(slug).fontFamily) - siehe
|
||||
// TextStylesContext.jsx. Feste Anzahl Aufrufe (6 Sektionen x bis zu 3 Felder), keine Schleife,
|
||||
// da React Hooks nicht bedingt/dynamisch aufgerufen werden duerfen.
|
||||
const heroEyebrowStyle = useTextStyle('home_sections.hero.eyebrow');
|
||||
const heroTitleStyle = useTextStyle('home_sections.hero.title');
|
||||
const youtubeEyebrowStyle = useTextStyle('home_sections.youtube.eyebrow');
|
||||
const youtubeTitleStyle = useTextStyle('home_sections.youtube.title');
|
||||
const youtubeButtonStyle = useTextStyle('home_sections.youtube.button_label');
|
||||
const craftEyebrowStyle = useTextStyle('home_sections.craft.eyebrow');
|
||||
const craftTitleStyle = useTextStyle('home_sections.craft.title');
|
||||
const adviceEyebrowStyle = useTextStyle('home_sections.advice.eyebrow');
|
||||
const adviceTitleStyle = useTextStyle('home_sections.advice.title');
|
||||
const insightsEyebrowStyle = useTextStyle('home_sections.insights.eyebrow');
|
||||
const insightsTitleStyle = useTextStyle('home_sections.insights.title');
|
||||
const moreEyebrowStyle = useTextStyle('home_sections.more.eyebrow');
|
||||
const moreTitleStyle = useTextStyle('home_sections.more.title');
|
||||
const moreButtonStyle = useTextStyle('home_sections.more.button_label');
|
||||
|
||||
useEffect(() => {
|
||||
api.get('/home-sections').then(setHomeSections).catch(() => {});
|
||||
}, []);
|
||||
|
|
@ -221,11 +241,11 @@ export default function Home() {
|
|||
transition={{ duration: 0.7, ease: 'easeOut' }}
|
||||
>
|
||||
{section('hero').eyebrow && (
|
||||
<p className="mb-3 text-sm font-semibold uppercase tracking-wide text-brand-400">
|
||||
<p className="mb-3 text-sm font-semibold uppercase tracking-wide text-brand-400" style={heroEyebrowStyle}>
|
||||
{section('hero').eyebrow}
|
||||
</p>
|
||||
)}
|
||||
<h1 className="text-3xl font-extrabold tracking-tight text-white sm:text-5xl">
|
||||
<h1 className="text-3xl font-extrabold tracking-tight text-white sm:text-5xl" style={heroTitleStyle}>
|
||||
{section('hero').title}
|
||||
</h1>
|
||||
<div
|
||||
|
|
@ -303,11 +323,11 @@ export default function Home() {
|
|||
>
|
||||
<Reveal>
|
||||
{section('youtube').eyebrow && (
|
||||
<p className="mb-4 text-xs font-semibold uppercase tracking-[0.2em] text-neutral-200 sm:text-sm">
|
||||
<p className="mb-4 text-xs font-semibold uppercase tracking-[0.2em] text-neutral-200 sm:text-sm" style={youtubeEyebrowStyle}>
|
||||
{section('youtube').eyebrow}
|
||||
</p>
|
||||
)}
|
||||
<h2 className="text-3xl font-bold uppercase tracking-wide text-white sm:text-5xl">
|
||||
<h2 className="text-3xl font-bold uppercase tracking-wide text-white sm:text-5xl" style={youtubeTitleStyle}>
|
||||
{section('youtube').title}
|
||||
</h2>
|
||||
<div
|
||||
|
|
@ -318,6 +338,7 @@ export default function Home() {
|
|||
label={section('youtube').buttonLabel}
|
||||
url={section('youtube').buttonUrl}
|
||||
className="mt-8 inline-flex items-center justify-center rounded-full bg-white px-8 py-3 text-xs font-bold uppercase tracking-wide text-neutral-900 transition hover:-translate-y-0.5 hover:bg-neutral-100"
|
||||
style={youtubeButtonStyle}
|
||||
/>
|
||||
</Reveal>
|
||||
</div>
|
||||
|
|
@ -338,9 +359,9 @@ export default function Home() {
|
|||
</Reveal>
|
||||
<Reveal direction="right" index={1} className={ALIGN_TEXT[section('craft').align]} style={{ fontFamily: section('craft').fontFamily }}>
|
||||
{section('craft').eyebrow && (
|
||||
<p className="mb-2 text-sm font-semibold uppercase tracking-wide text-brand-600 dark:text-brand-400">{section('craft').eyebrow}</p>
|
||||
<p className="mb-2 text-sm font-semibold uppercase tracking-wide text-brand-600 dark:text-brand-400" style={craftEyebrowStyle}>{section('craft').eyebrow}</p>
|
||||
)}
|
||||
<h2 className="mb-3 text-2xl font-bold text-neutral-900 dark:text-white">{section('craft').title}</h2>
|
||||
<h2 className="mb-3 text-2xl font-bold text-neutral-900 dark:text-white" style={craftTitleStyle}>{section('craft').title}</h2>
|
||||
<div
|
||||
className="legal-content text-neutral-600 dark:text-neutral-300"
|
||||
dangerouslySetInnerHTML={{ __html: section('craft').bodyHtml }}
|
||||
|
|
@ -351,9 +372,9 @@ export default function Home() {
|
|||
<div className="grid items-center gap-8 md:grid-cols-2">
|
||||
<Reveal direction="left" className={`order-2 md:order-1 ${ALIGN_TEXT[section('advice').align]}`} style={{ fontFamily: section('advice').fontFamily }}>
|
||||
{section('advice').eyebrow && (
|
||||
<p className="mb-2 text-sm font-semibold uppercase tracking-wide text-brand-600 dark:text-brand-400">{section('advice').eyebrow}</p>
|
||||
<p className="mb-2 text-sm font-semibold uppercase tracking-wide text-brand-600 dark:text-brand-400" style={adviceEyebrowStyle}>{section('advice').eyebrow}</p>
|
||||
)}
|
||||
<h2 className="mb-3 text-2xl font-bold text-neutral-900 dark:text-white">{section('advice').title}</h2>
|
||||
<h2 className="mb-3 text-2xl font-bold text-neutral-900 dark:text-white" style={adviceTitleStyle}>{section('advice').title}</h2>
|
||||
<div
|
||||
className="legal-content text-neutral-600 dark:text-neutral-300"
|
||||
dangerouslySetInnerHTML={{ __html: section('advice').bodyHtml }}
|
||||
|
|
@ -376,9 +397,9 @@ export default function Home() {
|
|||
<section className="mx-auto max-w-6xl px-4 py-16 sm:px-6">
|
||||
<Reveal className={`mb-8 ${ALIGN_TEXT[section('insights').align]}`} style={{ fontFamily: section('insights').fontFamily }}>
|
||||
{section('insights').eyebrow && (
|
||||
<p className="mb-2 text-sm font-semibold uppercase tracking-wide text-brand-600 dark:text-brand-400">{section('insights').eyebrow}</p>
|
||||
<p className="mb-2 text-sm font-semibold uppercase tracking-wide text-brand-600 dark:text-brand-400" style={insightsEyebrowStyle}>{section('insights').eyebrow}</p>
|
||||
)}
|
||||
<h2 className="text-2xl font-bold text-neutral-900 dark:text-white">{section('insights').title}</h2>
|
||||
<h2 className="text-2xl font-bold text-neutral-900 dark:text-white" style={insightsTitleStyle}>{section('insights').title}</h2>
|
||||
<div
|
||||
className="legal-content mt-2 text-neutral-600 dark:text-neutral-300"
|
||||
dangerouslySetInnerHTML={{ __html: section('insights').bodyHtml }}
|
||||
|
|
@ -444,9 +465,9 @@ export default function Home() {
|
|||
style={{ fontFamily: section('more').fontFamily }}
|
||||
>
|
||||
{section('more').eyebrow && (
|
||||
<p className="mb-2 text-sm font-semibold uppercase tracking-wide text-brand-600 dark:text-brand-400">{section('more').eyebrow}</p>
|
||||
<p className="mb-2 text-sm font-semibold uppercase tracking-wide text-brand-600 dark:text-brand-400" style={moreEyebrowStyle}>{section('more').eyebrow}</p>
|
||||
)}
|
||||
<h2 className="mb-3 text-2xl font-bold text-neutral-900 dark:text-white">{section('more').title}</h2>
|
||||
<h2 className="mb-3 text-2xl font-bold text-neutral-900 dark:text-white" style={moreTitleStyle}>{section('more').title}</h2>
|
||||
<div
|
||||
className={`legal-content mb-8 max-w-2xl text-neutral-600 dark:text-neutral-300 ${ALIGN_MARGIN_X[section('more').align]}`}
|
||||
dangerouslySetInnerHTML={{ __html: section('more').bodyHtml }}
|
||||
|
|
@ -455,6 +476,7 @@ export default function Home() {
|
|||
label={section('more').buttonLabel}
|
||||
url={section('more').buttonUrl}
|
||||
className="inline-block rounded-md border border-neutral-300 px-6 py-3 text-sm font-semibold text-neutral-700 transition hover:-translate-y-0.5 hover:bg-neutral-100 dark:border-neutral-700 dark:text-neutral-200 dark:hover:bg-neutral-800"
|
||||
style={moreButtonStyle}
|
||||
/>
|
||||
</Reveal>
|
||||
</div>
|
||||
|
|
|
|||
13
hifi-src/src/utils/fontSizeOptions.js
Normal file
13
hifi-src/src/utils/fontSizeOptions.js
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
// Kuratierte Groessen-Liste statt freiem px-Wert - verhindert, dass ein Textfeld versehentlich
|
||||
// auf eine kaputte Groesse gestellt wird. Muss zu hifi/api/src/Support/FontSizes.php passen.
|
||||
export const FONT_SIZE_OPTIONS = [
|
||||
{ label: 'Standard', value: '' },
|
||||
{ label: 'S (14px)', value: '14px' },
|
||||
{ label: 'M (16px)', value: '16px' },
|
||||
{ label: 'L (18px)', value: '18px' },
|
||||
{ label: 'XL (20px)', value: '20px' },
|
||||
{ label: 'XXL (24px)', value: '24px' },
|
||||
{ label: 'XXXL (28px)', value: '28px' },
|
||||
{ label: 'Groß (36px)', value: '36px' },
|
||||
{ label: 'Riesig (48px)', value: '48px' },
|
||||
];
|
||||
17
hifi/api/database/migration_text_styles.sql
Normal file
17
hifi/api/database/migration_text_styles.sql
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
USE hifi_shop;
|
||||
|
||||
-- Generischer Stil (Schriftart/-groesse/Farbe) pro einzelnem Textfeld irgendwo im Dashboard,
|
||||
-- statt eigener Spalten pro Tabelle/Feld. field_key identifiziert das Feld eindeutig (Format
|
||||
-- "{tabelle}.{slugOderId}.{spalte}"), serverseitig validiert gegen TextStyleFields::TABLES.
|
||||
-- Additiv, nichts wird geloescht.
|
||||
-- Hinweis: Auf der Live-Seite reicht stattdessen ein Klick auf "Datenbankstruktur aktualisieren"
|
||||
-- unter Admin-Panel -> Einstellungen -> Datenbank.
|
||||
|
||||
CREATE TABLE IF NOT EXISTS text_styles (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
field_key VARCHAR(190) NOT NULL UNIQUE,
|
||||
font_family VARCHAR(255) NULL,
|
||||
font_size VARCHAR(20) NULL,
|
||||
color VARCHAR(20) NULL,
|
||||
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
||||
) ENGINE=InnoDB;
|
||||
|
|
@ -143,6 +143,15 @@ CREATE TABLE partners (
|
|||
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
||||
) ENGINE=InnoDB;
|
||||
|
||||
CREATE TABLE text_styles (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
field_key VARCHAR(190) NOT NULL UNIQUE,
|
||||
font_family VARCHAR(255) NULL,
|
||||
font_size VARCHAR(20) NULL,
|
||||
color VARCHAR(20) NULL,
|
||||
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
||||
) ENGINE=InnoDB;
|
||||
|
||||
CREATE TABLE car_models (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
brand_id INT NOT NULL,
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ use App\Controllers\ServiceController;
|
|||
use App\Controllers\SettingsController;
|
||||
use App\Controllers\SetupController;
|
||||
use App\Controllers\SiteSettingsController;
|
||||
use App\Controllers\TextStyleController;
|
||||
use App\Controllers\TwoFactorController;
|
||||
use App\Controllers\UpdateController;
|
||||
use App\Controllers\UploadController;
|
||||
|
|
@ -174,6 +175,12 @@ $router->post('/partners', $perm('content.manage', fn($p) => PartnerController::
|
|||
$router->put('/partners/{id}', $perm('content.manage', fn($p) => PartnerController::update($p)));
|
||||
$router->delete('/partners/{id}', $perm('content.manage', fn($p) => PartnerController::destroy($p)));
|
||||
|
||||
// Kein $perm(...) hier - TextStyleController::update() prueft die Berechtigung selbst pro
|
||||
// field_key, da ein einzelner Endpunkt Felder aus vielen verschiedenen Bereichen bedient.
|
||||
$router->get('/text-styles', fn($p) => TextStyleController::index());
|
||||
$router->get('/text-styles/one', fn($p) => TextStyleController::show());
|
||||
$router->put('/text-styles', $admin(fn($p) => TextStyleController::update()));
|
||||
|
||||
// Nur der zuletzt gecachte Stand - kein Live-Aufruf bei Google pro Seitenbesuch
|
||||
// (Aktualisierung laeuft ausschliesslich ueber refresh_google_reviews.php).
|
||||
$router->get('/google-reviews', fn($p) => GoogleReviewsController::publicReviews());
|
||||
|
|
|
|||
111
hifi/api/src/Controllers/TextStyleController.php
Normal file
111
hifi/api/src/Controllers/TextStyleController.php
Normal file
|
|
@ -0,0 +1,111 @@
|
|||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Config\Database;
|
||||
use App\Middleware\AuthMiddleware;
|
||||
use App\Support\Fonts;
|
||||
use App\Support\FontSizes;
|
||||
use App\Support\Http;
|
||||
use App\Support\TextStyleFields;
|
||||
|
||||
/**
|
||||
* Generischer Stil (Schriftart/-groesse/Farbe) fuer jedes einzelne Textfeld im Dashboard - siehe
|
||||
* App\Support\TextStyleFields fuer die Registry, die festlegt, welche field_key-Kombinationen
|
||||
* gueltig sind. Lesen ist oeffentlich (wie /home-sections), Schreiben prueft die Berechtigung
|
||||
* der jeweiligen Tabelle aus der Registry - nicht pauschal ueber die Router-Klammer, da ein
|
||||
* einzelner Endpunkt hier Felder aus vielen verschiedenen Berechtigungsbereichen bedient.
|
||||
*/
|
||||
class TextStyleController
|
||||
{
|
||||
/** Alle Zeilen auf einmal - fuer die oeffentliche Seite (ein Request statt vieler). */
|
||||
public static function index(): void
|
||||
{
|
||||
$stmt = Database::connection()->query('SELECT field_key, font_family, font_size, color FROM text_styles');
|
||||
$result = [];
|
||||
foreach ($stmt->fetchAll() as $row) {
|
||||
$result[$row['field_key']] = [
|
||||
'font_family' => $row['font_family'],
|
||||
'font_size' => $row['font_size'],
|
||||
'color' => $row['color'],
|
||||
];
|
||||
}
|
||||
// Leeres Array wuerde als JSON "[]" statt "{}" serialisiert werden (PHP kann bei einem
|
||||
// leeren Array nicht zwischen Liste und Objekt unterscheiden) - das Frontend erwartet
|
||||
// aber immer ein Objekt, das sich per field_key indizieren laesst.
|
||||
Http::send($result ?: (object) []);
|
||||
}
|
||||
|
||||
/** Eine einzelne Zeile - fuer den initialen Ladezustand eines Admin-Widgets. */
|
||||
public static function show(): void
|
||||
{
|
||||
$key = trim($_GET['key'] ?? '');
|
||||
$stmt = Database::connection()->prepare(
|
||||
'SELECT font_family, font_size, color FROM text_styles WHERE field_key = ?'
|
||||
);
|
||||
$stmt->execute([$key]);
|
||||
$row = $stmt->fetch();
|
||||
Http::send($row ?: (object) []);
|
||||
}
|
||||
|
||||
public static function update(): void
|
||||
{
|
||||
$body = Http::jsonBody();
|
||||
$fieldKey = trim($body['field_key'] ?? '');
|
||||
|
||||
if (!preg_match('/^([a-z_]+)\.([a-zA-Z0-9_-]+)\.([a-z_]+)$/', $fieldKey, $m)) {
|
||||
Http::error('Ungültiger field_key', 422);
|
||||
}
|
||||
[, $table, $middle, $column] = $m;
|
||||
|
||||
$entry = TextStyleFields::TABLES[$table] ?? null;
|
||||
if (!$entry || !in_array($column, $entry['columns'], true)) {
|
||||
Http::error('Unbekanntes Feld', 422);
|
||||
}
|
||||
|
||||
$valid = match ($entry['key_type']) {
|
||||
'slug' => in_array($middle, $entry['slugs'], true),
|
||||
'id' => ctype_digit($middle),
|
||||
'singleton' => $middle === '1',
|
||||
default => false,
|
||||
};
|
||||
if (!$valid) {
|
||||
Http::error('Ungültiger field_key', 422);
|
||||
}
|
||||
|
||||
// Erst nachdem field_key als strukturell gueltig erkannt wurde die passende
|
||||
// Berechtigung pruefen - verhindert, dass z.B. ein Admin mit nur services.manage
|
||||
// Stile fuer brands.* schreiben kann (jede Tabelle hat ihre eigene Berechtigung).
|
||||
AuthMiddleware::requirePermission($entry['permission']);
|
||||
|
||||
$fontFamily = (string) ($body['font_family'] ?? '');
|
||||
if (!in_array($fontFamily, Fonts::VALUES, true)) {
|
||||
$fontFamily = '';
|
||||
}
|
||||
$fontSize = (string) ($body['font_size'] ?? '');
|
||||
if (!in_array($fontSize, FontSizes::VALUES, true)) {
|
||||
$fontSize = '';
|
||||
}
|
||||
$color = trim((string) ($body['color'] ?? ''));
|
||||
if ($color !== '' && !preg_match('/^#[0-9a-fA-F]{6}$/', $color)) {
|
||||
$color = '';
|
||||
}
|
||||
|
||||
$db = Database::connection();
|
||||
|
||||
// Kein Override mehr gesetzt ("Zurücksetzen") - Zeile komplett entfernen statt drei
|
||||
// NULL-Spalten stehen zu lassen, damit die Tabelle nicht mit toten Zeilen waechst.
|
||||
if ($fontFamily === '' && $fontSize === '' && $color === '') {
|
||||
$db->prepare('DELETE FROM text_styles WHERE field_key = ?')->execute([$fieldKey]);
|
||||
Http::send(['ok' => true]);
|
||||
}
|
||||
|
||||
$stmt = $db->prepare(
|
||||
'INSERT INTO text_styles (field_key, font_family, font_size, color) VALUES (?, ?, ?, ?)
|
||||
ON DUPLICATE KEY UPDATE font_family = VALUES(font_family), font_size = VALUES(font_size), color = VALUES(color)'
|
||||
);
|
||||
$stmt->execute([$fieldKey, $fontFamily ?: null, $fontSize ?: null, $color ?: null]);
|
||||
|
||||
Http::send(['ok' => true]);
|
||||
}
|
||||
}
|
||||
13
hifi/api/src/Support/FontSizes.php
Normal file
13
hifi/api/src/Support/FontSizes.php
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
namespace App\Support;
|
||||
|
||||
/**
|
||||
* Kuratierte Groessen-Liste statt freiem px-Wert - verhindert, dass ein Textfeld versehentlich
|
||||
* auf eine kaputte Groesse (z.B. 4px oder 400px) gestellt wird. Muss zu
|
||||
* hifi-src/src/utils/fontSizeOptions.js (FONT_SIZE_OPTIONS) passen.
|
||||
*/
|
||||
class FontSizes
|
||||
{
|
||||
public const VALUES = ['', '14px', '16px', '18px', '20px', '24px', '28px', '36px', '48px'];
|
||||
}
|
||||
|
|
@ -169,6 +169,20 @@ class Schema
|
|||
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
||||
) ENGINE=InnoDB",
|
||||
|
||||
// Generischer Stil (Schriftart/-groesse/Farbe) pro einzelnem Textfeld irgendwo im
|
||||
// Dashboard, statt eigener Spalten pro Tabelle/Feld - field_key identifiziert das Feld
|
||||
// eindeutig (Format "{tabelle}.{slugOderId}.{spalte}", siehe TextStyleFields::TABLES,
|
||||
// das serverseitig validiert welche Kombinationen erlaubt sind). VARCHAR(190) statt 255,
|
||||
// damit der UNIQUE-Index unter dem utf8mb4-Limit bleibt.
|
||||
'text_styles' => "CREATE TABLE text_styles (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
field_key VARCHAR(190) NOT NULL UNIQUE,
|
||||
font_family VARCHAR(255) NULL,
|
||||
font_size VARCHAR(20) NULL,
|
||||
color VARCHAR(20) NULL,
|
||||
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
||||
) ENGINE=InnoDB",
|
||||
|
||||
'car_models' => "CREATE TABLE car_models (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
brand_id INT NOT NULL,
|
||||
|
|
@ -449,6 +463,14 @@ class Schema
|
|||
'created_at' => 'DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP',
|
||||
'updated_at' => 'DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP',
|
||||
],
|
||||
'text_styles' => [
|
||||
'id' => 'INT AUTO_INCREMENT PRIMARY KEY',
|
||||
'field_key' => 'VARCHAR(190) NOT NULL',
|
||||
'font_family' => 'VARCHAR(255) NULL',
|
||||
'font_size' => 'VARCHAR(20) NULL',
|
||||
'color' => 'VARCHAR(20) NULL',
|
||||
'updated_at' => 'DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP',
|
||||
],
|
||||
'car_models' => [
|
||||
'id' => 'INT AUTO_INCREMENT PRIMARY KEY',
|
||||
'brand_id' => 'INT NOT NULL',
|
||||
|
|
|
|||
19
hifi/api/src/Support/TextStyleCleanup.php
Normal file
19
hifi/api/src/Support/TextStyleCleanup.php
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
namespace App\Support;
|
||||
|
||||
use App\Config\Database;
|
||||
|
||||
/**
|
||||
* Raeumt verwaiste text_styles-Zeilen auf, wenn die zugehoerige Entitaet geloescht wird (offene
|
||||
* Tabellen wie faqs/services/brands - bei festen Tabellen wie home_sections/legal_pages gibt es
|
||||
* keine Loeschfunktion, dort nicht noetig).
|
||||
*/
|
||||
class TextStyleCleanup
|
||||
{
|
||||
public static function forgetEntity(string $table, string $id): void
|
||||
{
|
||||
$stmt = Database::connection()->prepare('DELETE FROM text_styles WHERE field_key LIKE ?');
|
||||
$stmt->execute(["$table.$id.%"]);
|
||||
}
|
||||
}
|
||||
29
hifi/api/src/Support/TextStyleFields.php
Normal file
29
hifi/api/src/Support/TextStyleFields.php
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
namespace App\Support;
|
||||
|
||||
use App\Controllers\HomeSectionController;
|
||||
|
||||
/**
|
||||
* Registry, die serverseitig festlegt, welche field_key-Kombinationen fuer text_styles gueltig
|
||||
* sind - verhindert, dass ein field_key blind vom Client akzeptiert wird (sonst koennte z.B. ein
|
||||
* Admin mit nur services.manage Stile fuer brands.* schreiben, oder ein Tippfehler wuerde eine
|
||||
* dauerhaft verwaiste Zeile erzeugen). Jede Tabelle bekommt hier einen Eintrag:
|
||||
* - key_type 'slug': mittleres Key-Segment muss in der gegebenen slugs-Liste stehen
|
||||
* (feste Zeilenanzahl, z.B. home_sections/legal_pages).
|
||||
* - key_type 'id': mittleres Segment muss numerisch sein (offene Tabelle, echte Zeilen-ID).
|
||||
* - key_type 'singleton': mittleres Segment muss literal "1" sein (app_settings).
|
||||
* Weitere Tabellen werden einfach als weitere Eintraege ergaenzt (siehe Roadmap-Plan), ohne dass
|
||||
* TextStyleController selbst angepasst werden muss.
|
||||
*/
|
||||
class TextStyleFields
|
||||
{
|
||||
public const TABLES = [
|
||||
'home_sections' => [
|
||||
'key_type' => 'slug',
|
||||
'slugs' => HomeSectionController::ALLOWED_SLUGS,
|
||||
'columns' => ['eyebrow', 'title', 'button_label'],
|
||||
'permission' => 'content.manage',
|
||||
],
|
||||
];
|
||||
}
|
||||
325
hifi/assets/index-Bcw7aoHB.js
Normal file
325
hifi/assets/index-Bcw7aoHB.js
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
1
hifi/assets/index-fn7vJl0-.css
Normal file
1
hifi/assets/index-fn7vJl0-.css
Normal file
File diff suppressed because one or more lines are too long
|
|
@ -43,9 +43,9 @@
|
|||
"sameAs": ["https://www.youtube.com/@hifiplanet2812"]
|
||||
}
|
||||
</script>
|
||||
<script type="module" crossorigin src="/assets/index-D5DdJjJZ.js"></script>
|
||||
<script type="module" crossorigin src="/assets/index-Bcw7aoHB.js"></script>
|
||||
<link rel="modulepreload" crossorigin href="/assets/lucide-icons-Cg2IxtAO.js">
|
||||
<link rel="stylesheet" crossorigin href="/assets/index-CV-knTge.css">
|
||||
<link rel="stylesheet" crossorigin href="/assets/index-fn7vJl0-.css">
|
||||
</head>
|
||||
<body class="bg-white text-slate-900 dark:bg-slate-950 dark:text-slate-100">
|
||||
<div id="root"></div>
|
||||
|
|
|
|||
Loading…
Reference in a new issue