Phase 6: KI-Prompt-Generator
Neues Modul js/ai/promptBuilder.js: reine Funktion buildPrompt(), deckt alle 10 Pflichtpunkte aus anforderung.md explizit ab (Region+Radius, Kategorien, Alter, wichtige Eigenschaften, Anzahl Ergebnisse, keine erfundenen Informationen, unsichere Angaben kennzeichnen, ausschliesslich gueltiges JSON, genaue Koordinaten, direkte Importierbarkeit) und bettet das exakte JSON-Zielschema aus anforderung.md unveraendert ein. UI (js/ui/promptGenerator.js): Modal mit allen Eingabefeldern aus der Anforderung (Region, Radius, Kategorien, Altersgruppe, Indoor/Outdoor, Kostenrahmen, max. Ergebnisse, besondere Anforderungen als Checkboxen + Freitext, Ausgabesprache), Live-Vorschau des generierten Prompts, Copy-to-Clipboard mit execCommand-Fallback (js/utils/clipboard.js) und Speichern als Textdatei (js/utils/download.js). Neuer Toolbar-Button oeffnet den Generator. JSON-Import der KI-Antwort ist bewusst nicht Teil dieser Phase, sondern folgt in Phase 7. docs/plan.md entsprechend fortgeschrieben.
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
// Zwischenablage-Utility für den KI-Prompt-Generator (Phase 6). Nutzt primär
|
||||
// die moderne Clipboard API, fällt aber auf das ältere
|
||||
// document.execCommand('copy') zurück, falls navigator.clipboard nicht
|
||||
// verfügbar ist oder der Aufruf fehlschlägt (z.B. weil manche Browser die
|
||||
// Clipboard API unter file:// einschränken).
|
||||
|
||||
(function () {
|
||||
/** Kopiert per unsichtbarem <textarea> + execCommand('copy'). Gibt boolean zurück. */
|
||||
function copyViaExecCommand(text) {
|
||||
const textarea = document.createElement('textarea');
|
||||
textarea.value = text;
|
||||
// Unsichtbar, aber im Layout-Fluss vorhanden, damit select() zuverlässig funktioniert.
|
||||
textarea.style.position = 'fixed';
|
||||
textarea.style.top = '-1000px';
|
||||
textarea.style.left = '-1000px';
|
||||
textarea.setAttribute('readonly', '');
|
||||
document.body.appendChild(textarea);
|
||||
textarea.select();
|
||||
textarea.setSelectionRange(0, textarea.value.length);
|
||||
|
||||
let success = false;
|
||||
try {
|
||||
success = document.execCommand('copy');
|
||||
} catch (err) {
|
||||
success = false;
|
||||
}
|
||||
|
||||
document.body.removeChild(textarea);
|
||||
return success;
|
||||
}
|
||||
|
||||
/**
|
||||
* Kopiert einen Text in die Zwischenablage.
|
||||
* @param {string} text
|
||||
* @returns {Promise<boolean>} true, wenn das Kopieren erfolgreich war.
|
||||
*/
|
||||
async function copyToClipboard(text) {
|
||||
if (navigator.clipboard && typeof navigator.clipboard.writeText === 'function') {
|
||||
try {
|
||||
await navigator.clipboard.writeText(text);
|
||||
return true;
|
||||
} catch (err) {
|
||||
// Fällt unten auf den execCommand-Fallback zurück (z.B. Berechtigung
|
||||
// verweigert oder API unter file:// eingeschränkt).
|
||||
}
|
||||
}
|
||||
|
||||
return copyViaExecCommand(text);
|
||||
}
|
||||
|
||||
EventMap.utils.copyToClipboard = copyToClipboard;
|
||||
})();
|
||||
Reference in New Issue
Block a user