From a3767b1c0f032d48f016324949d7738fa24b66c9 Mon Sep 17 00:00:00 2001 From: Maaxxs <61059039+MaaxxsDev@users.noreply.github.com> Date: Thu, 10 Sep 2026 03:15:53 +0200 Subject: [PATCH] Extend text styling to brand/model names and package text, add bold bullets Rolls the generic text_styles mechanism out to three more areas (Phase 3/4 of the earlier text-styling plan): brands.name, car_models.name, packages.description and packages.price_text. Registry entries reuse each table's existing manage permission (brands.manage/models.manage/ packages.manage). Widgets are gated on an existing row (editingId in Brands.jsx/Models.jsx, row.existing in Packages.jsx's batch editor), since a newly-created row has no id yet to key a style on. Added fieldStyle()/useTextStylesMap() to TextStylesContext.jsx alongside the existing useTextStyle() - brand/model lists are open-ended, so styling each one from inside a .map() can't call a hook per item (rules of hooks); fieldStyle() does a plain lookup against the already-loaded styles map instead. pkg.name stays unstyled (it's chosen from a fixed tier list, not free text). Deleting a brand cascades to its models and their packages in the database, so BrandController/ModelController::destroy() now collect the cascaded ids first and clean up their text_styles rows too (mirroring how they already do this for orphaned uploaded images); SettingsController's catalog reset endpoints get the same cleanup in bulk. Separately: package descriptions can now mark individual bullet points bold. Packages.jsx gained a "Fett" button that wraps the current textarea selection in **markers** (one line per bullet is unchanged); the public ModelPage.jsx renders those through a new BoldText.jsx component that turns **text** into via a plain regex - no dangerouslySetInnerHTML, since the only possible output is a tag. Product-name bullets (scraped from the linked shop, not admin-authored) are unaffected. Verified locally: registry rejects packages.name (not free text) and a non-numeric id, and deleting a test brand correctly cascades text_styles cleanup through its model and package. Co-Authored-By: Claude Sonnet 5 --- hifi-src/src/components/BoldText.jsx | 11 + hifi-src/src/context/TextStylesContext.jsx | 23 +- hifi-src/src/pages/admin/Brands.jsx | 2 + hifi-src/src/pages/admin/Models.jsx | 2 + hifi-src/src/pages/admin/Packages.jsx | 50 ++- hifi-src/src/pages/public/BrandPage.jsx | 9 +- hifi-src/src/pages/public/ModelPage.jsx | 27 +- hifi-src/src/pages/public/VehicleSelect.jsx | 4 +- hifi/api/src/Controllers/BrandController.php | 30 +- hifi/api/src/Controllers/ModelController.php | 12 + .../api/src/Controllers/PackageController.php | 5 +- .../src/Controllers/SettingsController.php | 10 + hifi/api/src/Support/TextStyleFields.php | 15 + hifi/assets/index-D4_C7pxq.js | 325 ------------------ hifi/assets/index-kZ4ovh9r.js | 325 ++++++++++++++++++ hifi/index.html | 2 +- 16 files changed, 503 insertions(+), 349 deletions(-) create mode 100644 hifi-src/src/components/BoldText.jsx delete mode 100644 hifi/assets/index-D4_C7pxq.js create mode 100644 hifi/assets/index-kZ4ovh9r.js diff --git a/hifi-src/src/components/BoldText.jsx b/hifi-src/src/components/BoldText.jsx new file mode 100644 index 0000000..9129f7d --- /dev/null +++ b/hifi-src/src/components/BoldText.jsx @@ -0,0 +1,11 @@ +// Sehr eingeschraenkte, bewusst nicht-HTML-basierte Formatierung fuer Stichpunkte, die sonst +// reiner Text sind (z.B. Paket-Beschreibungen) - **markierter Text** wird fett dargestellt. +// Kein dangerouslySetInnerHTML noetig: der Regex kann nur erzeugen, nichts anderes. +export default function BoldText({ text }) { + if (!text) return null; + const parts = text.split(/(\*\*[^*]+\*\*)/g); + return parts.map((part, i) => { + const match = part.match(/^\*\*([^*]+)\*\*$/); + return match ? {match[1]} : {part}; + }); +} diff --git a/hifi-src/src/context/TextStylesContext.jsx b/hifi-src/src/context/TextStylesContext.jsx index f7ce789..c8c2ed9 100644 --- a/hifi-src/src/context/TextStylesContext.jsx +++ b/hifi-src/src/context/TextStylesContext.jsx @@ -7,10 +7,11 @@ 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); +/** {fontFamily, fontSize, color} (nur die tatsaechlich gesetzten Werte) aus einer bereits + * geladenen Styles-Map fuer einen bestimmten Key - als eigene, NICHT-Hook-Funktion nutzbar + * innerhalb einer .map()-Schleife (z.B. eine Liste von Marken/Modellen mit wechselnder Anzahl), + * wo ein Hook-Aufruf pro Element gegen die Rules of Hooks verstossen wuerde. */ +export function fieldStyle(styles, fieldKey) { const entry = styles[fieldKey]; if (!entry) return {}; const result = {}; @@ -19,3 +20,17 @@ export function useTextStyle(fieldKey) { if (entry.color) result.color = entry.color; return result; } + +/** Liefert {fontFamily, fontSize, color} fuer einen einzelnen, zur Build-Zeit bekannten Key + * (z.B. eine feste Startseiten-Sektion) - Komfort-Wrapper um fieldStyle() fuer den haeufigen + * Fall "genau ein Feld an einer festen Stelle im Markup". */ +export function useTextStyle(fieldKey) { + const styles = useContext(TextStylesContext); + return fieldStyle(styles, fieldKey); +} + +/** Die komplette geladene Styles-Map - fuer Stellen, die mehrere/dynamisch viele Keys pruefen + * muessen (siehe fieldStyle() oben). */ +export function useTextStylesMap() { + return useContext(TextStylesContext); +} diff --git a/hifi-src/src/pages/admin/Brands.jsx b/hifi-src/src/pages/admin/Brands.jsx index 5e0cbcd..9e5e2a5 100644 --- a/hifi-src/src/pages/admin/Brands.jsx +++ b/hifi-src/src/pages/admin/Brands.jsx @@ -2,6 +2,7 @@ import { useEffect, useState } from 'react'; import { Link } from 'react-router-dom'; import { api } from '../../api/client.js'; import ImageUploadField from '../../components/ImageUploadField.jsx'; +import TextStyleWidget from '../../components/TextStyleWidget.jsx'; const emptyForm = { name: '', image_path: '', sort_order: 0 }; @@ -103,6 +104,7 @@ export default function Brands() { onChange={(e) => setForm({ ...form, name: 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" /> + {editingId && } setForm({ ...form, name: 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" /> + {editingId && } { + const el = descriptionRefs.current.get(rowKey); + if (!el) return; + const { selectionStart: start, selectionEnd: end, value } = el; + if (start === end) return; + const selected = value.slice(start, end); + const isBold = selected.startsWith('**') && selected.endsWith('**') && selected.length >= 4; + const replacement = isBold ? selected.slice(2, -2) : `**${selected}**`; + const next = value.slice(0, start) + replacement + value.slice(end); + updateRowForm(rowKey, { description: next }); + requestAnimationFrame(() => { + el.focus(); + const cursor = start + replacement.length; + el.setSelectionRange(cursor, cursor); + }); + }; const load = async () => { const [pkgs, mdls] = await Promise.all([api.get('/packages'), api.get('/models')]); @@ -506,15 +529,32 @@ export default function Packages() {

- Jede Zeile erscheint als eigener Stichpunkt zusammen mit den Bauteilen. + Jede Zeile erscheint als eigener Stichpunkt zusammen mit den Bauteilen. Text markieren und + "Fett" klicken, um nur diese Stelle hervorzuheben.

+
+ +