|
|
|
|
@@ -87,7 +87,9 @@ function overflowMeldung(overflow?: PreviewOverflow[]) {
|
|
|
|
|
export default function Textmenge() {
|
|
|
|
|
const [formate, setFormate] = useState<Format[]>([]);
|
|
|
|
|
const [settings, setSettings] = useState<PublicSettings | null>(null);
|
|
|
|
|
const [format, setFormat] = useState('a4');
|
|
|
|
|
// Format wird über Familie (A4/A5/A6/DIN lang) + optionale Ausrichtung (hoch/quer) gewählt.
|
|
|
|
|
const [familie, setFamilie] = useState('');
|
|
|
|
|
const [ausrichtung, setAusrichtung] = useState('');
|
|
|
|
|
const [font, setFont] = useState('tilda');
|
|
|
|
|
const [realistic, setRealistic] = useState(true);
|
|
|
|
|
const [text, setText] = useState('');
|
|
|
|
|
@@ -99,15 +101,45 @@ export default function Textmenge() {
|
|
|
|
|
const [gross, setGross] = useState(false);
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
fetchCheckFormats()
|
|
|
|
|
.then((f) => {
|
|
|
|
|
setFormate(f);
|
|
|
|
|
setFormat(f.find((x) => x.key === 'a4')?.key ?? f[0]?.key ?? 'a4');
|
|
|
|
|
})
|
|
|
|
|
.catch(() => {});
|
|
|
|
|
fetchCheckFormats().then(setFormate).catch(() => {});
|
|
|
|
|
fetchSettings().then(setSettings).catch(() => {});
|
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
// Formate zu Familien gruppieren (gleiche family = ein Eintrag mit Ausrichtungen).
|
|
|
|
|
// Formate ohne family bilden je einen eigenen Eintrag (Label = Name).
|
|
|
|
|
const familien = useMemo(() => {
|
|
|
|
|
const map = new Map<string, Format[]>();
|
|
|
|
|
for (const f of formate) {
|
|
|
|
|
const label = (f.family && f.family.trim()) || f.name;
|
|
|
|
|
if (!map.has(label)) map.set(label, []);
|
|
|
|
|
map.get(label)!.push(f);
|
|
|
|
|
}
|
|
|
|
|
return [...map.entries()].map(([label, items]) => ({ label, items }));
|
|
|
|
|
}, [formate]);
|
|
|
|
|
|
|
|
|
|
// Aktuelle Familie + verfügbare Ausrichtungen + effektiv gewähltes Format.
|
|
|
|
|
const aktuelleFamilie = familien.find((fm) => fm.label === familie) ?? familien[0] ?? null;
|
|
|
|
|
const ausrichtungen = (aktuelleFamilie?.items ?? []).filter((f) => f.orientation);
|
|
|
|
|
const hatAusrichtung = ausrichtungen.length > 1;
|
|
|
|
|
const gewaehltesFormat = aktuelleFamilie
|
|
|
|
|
? (hatAusrichtung
|
|
|
|
|
? (aktuelleFamilie.items.find((f) => f.orientation === ausrichtung) ?? aktuelleFamilie.items[0])
|
|
|
|
|
: aktuelleFamilie.items[0])
|
|
|
|
|
: null;
|
|
|
|
|
const formatKey = gewaehltesFormat?.key ?? 'a4';
|
|
|
|
|
|
|
|
|
|
// Standardauswahl setzen / reparieren, wenn Formate geladen sind oder sich die Familie ändert.
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (!familien.length) return;
|
|
|
|
|
const gueltig = familien.some((fm) => fm.label === familie);
|
|
|
|
|
if (!gueltig) {
|
|
|
|
|
const start = familien.find((fm) => fm.items.some((f) => f.key === 'a4')) ?? familien[0];
|
|
|
|
|
setFamilie(start.label);
|
|
|
|
|
const ori = start.items.filter((f) => f.orientation);
|
|
|
|
|
setAusrichtung(ori.length > 1 ? (ori[0].orientation ?? '') : '');
|
|
|
|
|
}
|
|
|
|
|
}, [familien, familie]);
|
|
|
|
|
|
|
|
|
|
// Escape schließt die Großansicht.
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (!gross) return;
|
|
|
|
|
@@ -142,7 +174,7 @@ export default function Textmenge() {
|
|
|
|
|
setDoc(null);
|
|
|
|
|
setFehler(null);
|
|
|
|
|
setGross(false);
|
|
|
|
|
}, [text, font, format, realistic]);
|
|
|
|
|
}, [text, font, formatKey, realistic]);
|
|
|
|
|
|
|
|
|
|
async function generieren() {
|
|
|
|
|
if (!text.trim() || laedt) return;
|
|
|
|
|
@@ -153,7 +185,7 @@ export default function Textmenge() {
|
|
|
|
|
client_id: clientId(),
|
|
|
|
|
text,
|
|
|
|
|
font,
|
|
|
|
|
format,
|
|
|
|
|
format: formatKey,
|
|
|
|
|
realistic,
|
|
|
|
|
entries: [{}],
|
|
|
|
|
});
|
|
|
|
|
@@ -185,13 +217,34 @@ export default function Textmenge() {
|
|
|
|
|
<div style={{ display: 'flex', gap: 16, flexWrap: 'wrap' }}>
|
|
|
|
|
<label className="sk-field" style={{ flex: '1 1 200px' }}>
|
|
|
|
|
<span className="sk-label">Format</span>
|
|
|
|
|
<select className="sk-input" value={format} onChange={(e) => setFormat(e.target.value)}>
|
|
|
|
|
{formate.length === 0 && <option value="a4">A4</option>}
|
|
|
|
|
{formate.map((f) => (
|
|
|
|
|
<option key={f.key} value={f.key}>{f.name}</option>
|
|
|
|
|
<select
|
|
|
|
|
className="sk-input"
|
|
|
|
|
value={aktuelleFamilie?.label ?? ''}
|
|
|
|
|
onChange={(e) => {
|
|
|
|
|
setFamilie(e.target.value);
|
|
|
|
|
const fam = familien.find((fm) => fm.label === e.target.value);
|
|
|
|
|
const ori = (fam?.items ?? []).filter((f) => f.orientation);
|
|
|
|
|
setAusrichtung(ori.length > 1 ? (ori[0].orientation ?? '') : '');
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{familien.length === 0 && <option value="">A4</option>}
|
|
|
|
|
{familien.map((fm) => (
|
|
|
|
|
<option key={fm.label} value={fm.label}>{fm.label}</option>
|
|
|
|
|
))}
|
|
|
|
|
</select>
|
|
|
|
|
</label>
|
|
|
|
|
{hatAusrichtung && (
|
|
|
|
|
<label className="sk-field" style={{ flex: '1 1 200px' }}>
|
|
|
|
|
<span className="sk-label">Ausrichtung</span>
|
|
|
|
|
<select className="sk-input" value={ausrichtung} onChange={(e) => setAusrichtung(e.target.value)}>
|
|
|
|
|
{ausrichtungen.map((f) => (
|
|
|
|
|
<option key={f.key} value={f.orientation ?? ''}>
|
|
|
|
|
{f.orientation === 'hoch' ? 'Hochformat' : f.orientation === 'quer' ? 'Querformat' : f.name}
|
|
|
|
|
</option>
|
|
|
|
|
))}
|
|
|
|
|
</select>
|
|
|
|
|
</label>
|
|
|
|
|
)}
|
|
|
|
|
<label className="sk-field" style={{ flex: '1 1 200px' }}>
|
|
|
|
|
<span className="sk-label">Schriftart</span>
|
|
|
|
|
<select className="sk-input" value={font} onChange={(e) => setFont(e.target.value)}>
|
|
|
|
|
|