import { createContext, useContext } from 'react'; import { FONT_OPTIONS } from '../utils/fontOptions.js'; // Vom Admin selbst hochgeladene Schriftarten (siehe CustomFontController) - ein Request pro // Seitenaufruf (siehe PublicLayout.jsx/AdminLayout.jsx), von dort ueber Context verteilt statt // dass jede einzelne Schriftart-Auswahl (RichTextEditor, TextStyleWidget, ...) selbst laedt. // refresh() laedt neu, ohne die ganze Seite neu zu laden - nach Hochladen/Loeschen einer // Schriftart in WebsiteSettings.jsx, damit alle Schriftart-Auswahlen sofort den neuen Stand // zeigen (auch auf derselben Seite), nicht erst nach Navigation/Reload. const CustomFontsContext = createContext({ fonts: [], refresh: () => {} }); export const CustomFontsProvider = CustomFontsContext.Provider; /** Die rohe Liste der hochgeladenen Schriftarten ({id, name, font_family, file_path}). */ export function useCustomFonts() { return useContext(CustomFontsContext).fonts; } /** Laedt die Liste neu - nach Hochladen/Loeschen einer eigenen Schriftart aufrufen. */ export function useCustomFontsRefresh() { return useContext(CustomFontsContext).refresh; } /** FONT_OPTIONS ergaenzt um die hochgeladenen Schriftarten - fuer jede Schriftart-Auswahl im * Dashboard, damit eigene Schriftarten dort ueberall gleichermassen zur Wahl stehen. */ export function useFontOptionsWithCustom() { const customFonts = useCustomFonts(); return [ ...FONT_OPTIONS, ...customFonts.map((f) => ({ label: f.name, value: f.font_family })), ]; }