feat(editor): add section manipulation APIs and interactive sidebar controls
All checks were successful
Production Build & Deploy / build-and-deploy (push) Successful in 1m3s
All checks were successful
Production Build & Deploy / build-and-deploy (push) Successful in 1m3s
This commit is contained in:
4
.gitignore
vendored
4
.gitignore
vendored
@@ -26,3 +26,7 @@ pnpm-debug.log*
|
||||
# coverage report
|
||||
coverage/
|
||||
|
||||
# draft files
|
||||
*.draft.json
|
||||
|
||||
|
||||
|
||||
@@ -1,56 +1,27 @@
|
||||
// public/js/editor-bridge.js
|
||||
// Bridge between the editor UI (parent) and the live preview iframe.
|
||||
// Listens for messages from the parent and applies updates to the preview.
|
||||
|
||||
(function () {
|
||||
// Store current config state for quick reference
|
||||
let siteConfig = {};
|
||||
let themeConfig = {};
|
||||
// Bridge nur im Preview-Modus aktivieren
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
if (urlParams.get('preview') !== 'draft') return;
|
||||
|
||||
// Helper: apply theme preset CSS variables (assumes theme presets expose a JSON of variables)
|
||||
function applyTheme(presetKey) {
|
||||
fetch(`/theme/${presetKey}.json`)
|
||||
.then((r) => r.json())
|
||||
.then((vars) => {
|
||||
const root = document.documentElement;
|
||||
Object.entries(vars).forEach(([k, v]) => {
|
||||
root.style.setProperty(`--${k}`, v);
|
||||
});
|
||||
})
|
||||
.catch(() => console.warn('Theme preset not found:', presetKey));
|
||||
}
|
||||
console.log('[N&D Editor Bridge] Active on preview canvas');
|
||||
|
||||
// Helper: re-render the preview by injecting the updated HTML (simple approach).
|
||||
function reloadPreview() {
|
||||
// For SSR Astro we cannot re‑render inside the iframe without a full reload.
|
||||
// Trigger a reload – the parent will send the latest config on load.
|
||||
window.location.reload();
|
||||
}
|
||||
|
||||
// Message dispatcher
|
||||
window.addEventListener('message', (event) => {
|
||||
const { type, payload } = event.data || {};
|
||||
switch (type) {
|
||||
case 'load':
|
||||
siteConfig = payload || {};
|
||||
// initial load – could trigger a render hook if needed
|
||||
break;
|
||||
case 'add':
|
||||
// For simplicity we just reload – real implementation would manipulate DOM.
|
||||
reloadPreview();
|
||||
break;
|
||||
case 'preset':
|
||||
themeConfig.activePreset = payload;
|
||||
applyTheme(payload);
|
||||
break;
|
||||
case 'update':
|
||||
// payload contains partial siteConfig changes
|
||||
Object.assign(siteConfig, payload);
|
||||
reloadPreview();
|
||||
break;
|
||||
default:
|
||||
// ignore unknown messages
|
||||
break;
|
||||
|
||||
if (type === 'THEME_UPDATE') {
|
||||
// Injiziert CSS-Variablen live in den DOM (<head>)
|
||||
const root = document.documentElement;
|
||||
if (payload.colors) {
|
||||
Object.entries(payload.colors).forEach(([key, val]) => {
|
||||
root.style.setProperty(`--${key}`, val as string);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (type === 'RELOAD_CANVAS') {
|
||||
// Sanfter Reload des Iframes bei Strukturänderungen
|
||||
window.location.reload();
|
||||
}
|
||||
});
|
||||
})();
|
||||
|
||||
@@ -33,6 +33,8 @@ const { title, description = "Professionelles Webdesign & moderne Websites." } =
|
||||
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
|
||||
<title>{title}</title>
|
||||
|
||||
<script is:inline src="/js/editor-bridge.js"></script>
|
||||
|
||||
<style is:global define:vars={{
|
||||
themeBg: colors.bg,
|
||||
themeCardBg: colors.cardBg,
|
||||
|
||||
@@ -1,842 +1,185 @@
|
||||
---
|
||||
// src/pages/admin/editor.astro
|
||||
import Layout from '../../layouts/Layout.astro';
|
||||
import { loadWaasConfigs } from '../../utils/configLoader';
|
||||
import { THEME_PRESETS } from '../../utils/themePresets';
|
||||
|
||||
const { siteConfig, themeConfig } = loadWaasConfigs(Astro.request.headers.get('user-agent') ?? '');
|
||||
export const prerender = false;
|
||||
|
||||
const { searchParams } = Astro.url;
|
||||
const pageId = searchParams.get('page_id');
|
||||
|
||||
// Lade den aktuellen Entwurf oder Fallback auf Live Config
|
||||
const userAgent = Astro.request.headers.get('user-agent') ?? '';
|
||||
const { siteConfig: draftConfig } = loadWaasConfigs(userAgent, true);
|
||||
const pages = (draftConfig as any).pages || [];
|
||||
const targetPage = pages.find((p: any) => p.id === pageId) || pages[0];
|
||||
const previewUrl = `${targetPage?.slug || '/'}?preview=draft`;
|
||||
---
|
||||
|
||||
<Layout title="Live Visual Editor | WaaS Engine">
|
||||
<div class="h-screen w-screen flex flex-col bg-[#0B0F19] text-white font-sans overflow-hidden">
|
||||
<Layout title={`Editor: ${targetPage?.title || 'Baukasten'} | N&D Admin`}>
|
||||
<div class="h-screen w-screen flex overflow-hidden bg-slate-950 font-sans">
|
||||
|
||||
<!-- Top Bar -->
|
||||
<header class="h-14 bg-slate-900/80 border-b border-white/10 px-6 flex items-center justify-between backdrop-blur-md shrink-0 z-20">
|
||||
<div class="flex items-center gap-3">
|
||||
<span class="text-xs font-mono text-sky-400 font-bold uppercase tracking-widest">Waas Elementor Live Editor</span>
|
||||
<span class="text-xs px-2.5 py-0.5 rounded-full bg-emerald-500/10 text-emerald-400 border border-emerald-500/20 font-mono">SSR Live Active</span>
|
||||
<aside class="w-80 border-r border-slate-800 bg-slate-900 flex flex-col justify-between z-20">
|
||||
|
||||
<div class="p-4 space-y-6 overflow-y-auto">
|
||||
<div class="flex items-center justify-between border-b border-slate-800 pb-4">
|
||||
<div>
|
||||
<a href="/admin/pages" class="text-xs text-slate-400 hover:text-sky-400 transition-colors">← Zurück zur Übersicht</a>
|
||||
<h1 class="text-base font-bold text-white mt-1">{targetPage?.title || 'Seite bearbeiten'}</h1>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Device Switcher (PC | Tablet | Mobile) -->
|
||||
<div class="flex items-center gap-1 bg-slate-950/70 p-1 rounded-xl border border-white/10">
|
||||
<button type="button" id="device-desktop" class="device-btn px-3 py-1 rounded-lg text-xs font-semibold transition-all bg-sky-400/20 text-sky-400 border border-sky-400/30" data-device="desktop">
|
||||
Desktop (100%)
|
||||
</button>
|
||||
<button type="button" id="device-tablet" class="device-btn px-3 py-1 rounded-lg text-xs font-semibold transition-all text-slate-400 hover:text-white" data-device="tablet">
|
||||
Tablet (768px)
|
||||
</button>
|
||||
<button type="button" id="device-mobile" class="device-btn px-3 py-1 rounded-lg text-xs font-semibold transition-all text-slate-400 hover:text-white" data-device="mobile">
|
||||
Mobile (375px)
|
||||
</button>
|
||||
<div class="space-y-2">
|
||||
<label class="text-xs font-semibold text-slate-400 uppercase tracking-wider block">Design-Preset</label>
|
||||
<select id="preset-selector" class="w-full bg-slate-800 border border-slate-700 rounded-lg p-2.5 text-xs text-white focus:outline-none focus:border-sky-500">
|
||||
{Object.entries(THEME_PRESETS).map(([key, preset]) => (
|
||||
<option value={key}>{preset.name}</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="flex items-center gap-3">
|
||||
<button id="theme-conditions-btn" class="px-3.5 py-1.5 rounded-lg border border-sky-400/30 bg-sky-400/10 text-sky-400 font-semibold text-xs hover:bg-sky-400 hover:text-slate-950 transition-all">
|
||||
Display Conditions
|
||||
</button>
|
||||
<a href="/admin" class="px-3.5 py-1.5 rounded-lg glass-panel text-xs hover:border-sky-400 transition-all">
|
||||
Classic Admin
|
||||
</a>
|
||||
<button id="save-editor-btn" class="px-5 py-1.5 rounded-lg bg-sky-400 text-slate-950 font-bold text-xs uppercase tracking-wider hover:bg-white transition-all shadow-lg shadow-sky-400/20 active:scale-95">
|
||||
Live Speichern
|
||||
</button>
|
||||
<div class="space-y-2">
|
||||
<label class="text-xs font-semibold text-slate-400 uppercase tracking-wider block">Farbschema</label>
|
||||
<div class="grid grid-cols-2 gap-2">
|
||||
<button id="btn-mode-dark" class="px-3 py-2 bg-slate-800 border border-slate-700 rounded-lg text-xs font-bold text-white hover:border-sky-500 transition-colors">🌙 Dark Mode</button>
|
||||
<button id="btn-mode-light" class="px-3 py-2 bg-slate-800 border border-slate-700 rounded-lg text-xs font-bold text-slate-300 hover:border-sky-500 transition-colors">☀️ Light Mode</button>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div id="editor-alert" class="hidden px-4 py-2 bg-emerald-500/10 border-b border-emerald-500/20 text-emerald-400 text-xs font-mono text-center"></div>
|
||||
|
||||
<!-- Split Screen Main -->
|
||||
<div class="flex-1 flex overflow-hidden relative">
|
||||
|
||||
<!-- Left Panel: Controls & Drag-and-Drop Sektionen -->
|
||||
<aside class="w-90 sm:w-96 bg-slate-950/70 border-r border-white/10 p-5 overflow-y-auto space-y-6 shrink-0 z-10 custom-scroll">
|
||||
|
||||
<!-- 3-Teiler Inspector Tabs (Inhalt, Stil, Erweitert) -->
|
||||
<div class="flex bg-slate-900/80 p-1 rounded-xl border border-white/10">
|
||||
<button type="button" id="tab-btn-content" class="inspector-tab-btn flex-1 py-1.5 rounded-lg text-xs font-bold transition-all bg-sky-400/20 text-sky-400 border border-sky-400/30" data-tab="content">
|
||||
Inhalt
|
||||
</button>
|
||||
<button type="button" id="tab-btn-style" class="inspector-tab-btn flex-1 py-1.5 rounded-lg text-xs font-bold transition-all text-slate-400 hover:text-white" data-tab="style">
|
||||
Stil
|
||||
</button>
|
||||
<button type="button" id="tab-btn-advanced" class="inspector-tab-btn flex-1 py-1.5 rounded-lg text-xs font-bold transition-all text-slate-400 hover:text-white" data-tab="advanced">
|
||||
Erweitert
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- TAB 1: INHALT (Sektionen, Layout & Widget Hinzufuegen) -->
|
||||
<div id="tab-panel-content" class="space-y-6">
|
||||
<!-- Neue Sektion Hinzufuegen -->
|
||||
<div class="glass-panel rounded-xl p-4 space-y-3">
|
||||
<h3 class="text-xs font-bold text-sky-400 uppercase tracking-wider">
|
||||
+ Neue Sektion Hinzufuegen
|
||||
</h3>
|
||||
<div class="space-y-2 pt-4 border-t border-slate-800">
|
||||
<label class="text-xs font-semibold text-slate-400 uppercase tracking-wider block">Sektion hinzufügen</label>
|
||||
<div class="flex gap-2">
|
||||
<select id="new-section-select" class="flex-1 glass-panel bg-slate-900 rounded-lg p-2 text-xs text-white focus:outline-none focus:border-sky-400">
|
||||
<option value="hero">Hero Section</option>
|
||||
<option value="bento">Bento Grid Section</option>
|
||||
<option value="services">Leistungen / Services</option>
|
||||
<option value="contact">Kontaktformular Section</option>
|
||||
<option value="faq">FAQ Akkordeon Section</option>
|
||||
<option value="testimonials">Kundenbewertungen Section</option>
|
||||
<option value="cta-banner">CTA Banner Section</option>
|
||||
<select id="select-new-section-type" class="flex-1 bg-slate-800 border border-slate-700 rounded-lg p-2 text-xs text-white focus:outline-none focus:border-sky-500">
|
||||
<option value="HeroSection">Hero Section</option>
|
||||
<option value="BentoGrid">Bento Grid</option>
|
||||
<option value="ContactSection">Kontakt Formular</option>
|
||||
</select>
|
||||
<button type="button" id="add-section-btn" class="px-3 py-2 rounded-lg bg-sky-400/20 text-sky-400 border border-sky-400/30 font-bold text-xs hover:bg-sky-400 hover:text-slate-950 transition-all">
|
||||
+ Hinzufuegen
|
||||
<button id="btn-add-section" class="bg-sky-500 hover:bg-sky-400 text-slate-950 font-bold px-3 py-2 rounded-lg text-xs transition-colors">
|
||||
+ Hinzufügen
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Sektionen Re-Order mit HTML5 Drag & Drop -->
|
||||
<div class="glass-panel rounded-xl p-4 space-y-3">
|
||||
<h3 class="text-xs font-bold text-sky-400 uppercase tracking-wider flex items-center justify-between">
|
||||
<span>Sektionen Reihenfolge (Layout)</span>
|
||||
<span class="text-[10px] text-slate-400 font-mono">Drag & Drop</span>
|
||||
</h3>
|
||||
|
||||
<div id="sections-list" class="space-y-2">
|
||||
{siteConfig.sectionsOrder.map((sec, idx) => (
|
||||
<div data-section={sec} draggable="true" class="section-item flex items-center justify-between p-3 rounded-lg bg-slate-900/60 border border-white/5 hover:border-sky-400/40 transition-all group cursor-grab active:cursor-grabbing">
|
||||
<div class="flex items-center gap-2">
|
||||
<span class="text-slate-500 font-mono text-xs">#{idx + 1}</span>
|
||||
<span class="text-xs font-semibold capitalize text-white">{sec}</span>
|
||||
</div>
|
||||
<div class="space-y-2 pt-4 border-t border-slate-800">
|
||||
<label class="text-xs font-semibold text-slate-400 uppercase tracking-wider block">Sektionen verwalten</label>
|
||||
<div id="section-list" class="space-y-2">
|
||||
{targetPage?.sections?.map((sec: any, index: number) => (
|
||||
<div class="p-3 bg-slate-800/80 border border-slate-700/60 rounded-lg text-xs space-y-2 text-slate-200" data-section-id={sec.id}>
|
||||
<div class="flex items-center justify-between font-semibold">
|
||||
<span class="text-sky-400">#{index + 1} {sec.type}</span>
|
||||
<div class="flex items-center gap-1">
|
||||
<button type="button" onclick={`moveSection('${sec}', -1)`} class="p-1 hover:text-sky-400 text-xs font-bold">Up</button>
|
||||
<button type="button" onclick={`moveSection('${sec}', 1)`} class="p-1 hover:text-sky-400 text-xs font-bold">Down</button>
|
||||
<button type="button" onclick={`deleteSection('${sec}')`} class="p-1 text-red-400/70 hover:text-red-400 text-xs font-bold ml-1">Trash</button>
|
||||
<button class="btn-move-up hover:text-sky-400 px-1" title="Nach oben">⬆️</button>
|
||||
<button class="btn-move-down hover:text-sky-400 px-1" title="Nach unten">⬇️</button>
|
||||
<button class="btn-delete-section hover:text-red-400 px-1" title="Sektion löschen">🗑️</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Sektions-Inhalte & Animationen Bearbeiten -->
|
||||
<div class="glass-panel rounded-xl p-4 space-y-4">
|
||||
<h3 class="text-xs font-bold text-sky-400 uppercase tracking-wider">
|
||||
Hero Sektion: Inhalt & Animation
|
||||
</h3>
|
||||
<div class="space-y-3 text-xs">
|
||||
<div>
|
||||
<label class="block text-[10px] font-bold text-slate-400 uppercase mb-1">Hero Title</label>
|
||||
<input type="text" id="hero-title-input" value={siteConfig.hero.title} class="w-full glass-panel bg-slate-900 rounded-lg p-2 text-xs text-white focus:outline-none focus:border-sky-400" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-[10px] font-bold text-slate-400 uppercase mb-1">Hero Subtitle</label>
|
||||
<textarea id="hero-subtitle-input" class="w-full h-16 glass-panel bg-slate-900 rounded-lg p-2 text-xs text-white focus:outline-none focus:border-sky-400">{siteConfig.hero.subtitle}</textarea>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-[10px] font-bold text-slate-400 uppercase mb-1">Hero Badge Text</label>
|
||||
<input type="text" id="hero-badge-input" value={siteConfig.hero.badge} class="w-full glass-panel bg-slate-900 rounded-lg p-2 text-xs text-white focus:outline-none focus:border-sky-400" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-[10px] font-bold text-slate-400 uppercase mb-1">Hero Sektion Animation</label>
|
||||
<select id="hero-anim-select" class="w-full glass-panel bg-slate-900 rounded-lg p-2 text-xs text-white focus:outline-none focus:border-sky-400">
|
||||
<option value="" selected={!siteConfig.hero.animation}>Keine Animation</option>
|
||||
<option value="spring-fade" selected={siteConfig.hero.animation === 'spring-fade'}>Spring Fade (Federleicht)</option>
|
||||
<option value="slide-up" selected={siteConfig.hero.animation === 'slide-up'}>Slide Up (Eingleiten)</option>
|
||||
<option value="zoom-in" selected={siteConfig.hero.animation === 'zoom-in'}>Zoom In (Heranzoomen)</option>
|
||||
<option value="pulse-glow" selected={siteConfig.hero.animation === 'pulse-glow'}>Pulse Glow (Leuchten)</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Bento Grid: Inhalt & Animation -->
|
||||
<div class="glass-panel rounded-xl p-4 space-y-4">
|
||||
<h3 class="text-xs font-bold text-sky-400 uppercase tracking-wider">
|
||||
Bento Grid: Inhalt & Animation
|
||||
</h3>
|
||||
<div class="space-y-3 text-xs">
|
||||
<div>
|
||||
<label class="block text-[10px] font-bold text-slate-400 uppercase mb-1">Sektions-Titel</label>
|
||||
<input type="text" id="bento-title-input" value={siteConfig.bento.sectionTitle} class="w-full glass-panel bg-slate-900 rounded-lg p-2 text-xs text-white focus:outline-none focus:border-sky-400" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-[10px] font-bold text-slate-400 uppercase mb-1">Sektions-Untertitel</label>
|
||||
<input type="text" id="bento-subtitle-input" value={siteConfig.bento.sectionSubtitle} class="w-full glass-panel bg-slate-900 rounded-lg p-2 text-xs text-white focus:outline-none focus:border-sky-400" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-[10px] font-bold text-slate-400 uppercase mb-1">Bento Grid Animation</label>
|
||||
<select id="bento-anim-select" class="w-full glass-panel bg-slate-900 rounded-lg p-2 text-xs text-white focus:outline-none focus:border-sky-400">
|
||||
<option value="" selected={!siteConfig.bento.animation}>Keine Animation</option>
|
||||
<option value="slide-up" selected={siteConfig.bento.animation === 'slide-up'}>Slide Up</option>
|
||||
<option value="spring-fade" selected={siteConfig.bento.animation === 'spring-fade'}>Spring Fade</option>
|
||||
<option value="zoom-in" selected={siteConfig.bento.animation === 'zoom-in'}>Zoom In</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Dynamische UIKomponente Hinzufuegen per Sektion -->
|
||||
<div class="glass-panel rounded-xl p-4 space-y-4">
|
||||
<h3 class="text-xs font-bold text-sky-400 uppercase tracking-wider">
|
||||
UI-Komponente Hinzufuegen & Verwaltungsverzeichnis
|
||||
</h3>
|
||||
|
||||
<div class="space-y-3">
|
||||
<div>
|
||||
<label class="block text-[10px] font-bold text-slate-400 uppercase mb-1">Ziel-Sektion</label>
|
||||
<select id="new-el-section" class="w-full glass-panel bg-slate-900 rounded-lg p-2 text-xs text-white focus:outline-none focus:border-sky-400 capitalize">
|
||||
{siteConfig.sectionsOrder.map(sec => (
|
||||
<option value={sec}>{sec} Sektion</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label class="block text-[10px] font-bold text-slate-400 uppercase mb-1">Platz (Slot ID)</label>
|
||||
<select id="new-el-slot" class="w-full glass-panel bg-slate-900 rounded-lg p-2 text-xs text-white focus:outline-none focus:border-sky-400">
|
||||
<option value="hero-badge-slot">Hero Badge Slot</option>
|
||||
<option value="hero-actions-slot">Hero Buttons Slot</option>
|
||||
<option value="hero-custom-slot">Hero Custom Elements Slot</option>
|
||||
<option value="bento-header-slot">Bento Header Slot</option>
|
||||
<option value="bento-grid-slot">Bento Grid Elements Slot</option>
|
||||
<option value="contact-form-slot">Contact Form Slot</option>
|
||||
<option value="section-custom-slot">Allgemeiner Sektions-Slot</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label class="block text-[10px] font-bold text-slate-400 uppercase mb-1">Typ</label>
|
||||
<select id="new-el-type" class="w-full glass-panel bg-slate-900 rounded-lg p-2 text-xs text-white focus:outline-none focus:border-sky-400">
|
||||
<option value="button">Button (CTA)</option>
|
||||
<option value="badge">Badge / Utility Tag</option>
|
||||
<option value="text">Textblock / Paragraph</option>
|
||||
<option value="card">Feature Bento Card</option>
|
||||
<option value="accordion">FAQ Akkordeon Block</option>
|
||||
<option value="stat-box">Statistiken / Zahlen-Box</option>
|
||||
<option value="testimonial">Kundenbewertung / Testimonial</option>
|
||||
<option value="cta-box">Banner / Call-to-Action Box</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label class="block text-[10px] font-bold text-slate-400 uppercase mb-1">Element Animation</label>
|
||||
<select id="new-el-anim" class="w-full glass-panel bg-slate-900 rounded-lg p-2 text-xs text-white focus:outline-none focus:border-sky-400">
|
||||
<option value="">Keine Animation</option>
|
||||
<option value="spring-fade">Spring Fade</option>
|
||||
<option value="hover-bounce">Hover Bounce</option>
|
||||
<option value="pulse-glow">Pulse Glow</option>
|
||||
<option value="slide-up">Slide Up</option>
|
||||
<option value="zoom-in">Zoom In</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label class="block text-[10px] font-bold text-slate-400 uppercase mb-1">Dynamische Daten-Verknüpfung (Dynamic Tag)</label>
|
||||
<select id="new-el-dynamic-tag" onchange="if(this.value){ document.getElementById('new-el-content').value = '{{' + this.value + '}}'; }" class="w-full glass-panel bg-slate-900 rounded-lg p-2 text-xs text-sky-400 focus:outline-none focus:border-sky-400 font-mono mb-2">
|
||||
<option value="">-- Statischer Text (Kein Tag) --</option>
|
||||
<option value="site.siteName">site.siteName (Website Name)</option>
|
||||
<option value="site.metaDescription">site.metaDescription (Beschreibung)</option>
|
||||
<option value="site.contactEmail">site.contactEmail (Kontakt Email)</option>
|
||||
<option value="site.phone">site.phone (Telefonnummer)</option>
|
||||
<option value="post.title">post.title (Beitragstitel)</option>
|
||||
<option value="post.excerpt">post.excerpt (Beitragsauszug)</option>
|
||||
<option value="author.name">author.name (Autor Name)</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label class="block text-[10px] font-bold text-slate-400 uppercase mb-1">Inhalt / Label / Tag</label>
|
||||
<input type="text" id="new-el-content" placeholder="z.B. Jetzt Anfragen oder {{site.siteName}}" class="w-full glass-panel bg-slate-900 rounded-lg p-2 text-xs text-white focus:outline-none focus:border-sky-400 font-mono" />
|
||||
</div>
|
||||
|
||||
<button type="button" id="add-el-btn" class="w-full py-2.5 rounded-lg bg-sky-400/20 text-sky-400 border border-sky-400/30 font-bold text-xs uppercase tracking-wider hover:bg-sky-400 hover:text-slate-950 transition-all">
|
||||
+ Komponente in Sektion platzieren
|
||||
<div class="p-4 border-t border-slate-800 bg-slate-950/50 space-y-2">
|
||||
<button id="btn-save-draft" class="w-full bg-slate-800 hover:bg-slate-700 text-slate-200 font-semibold py-2.5 rounded-lg text-xs transition-colors border border-slate-700">
|
||||
💾 Entwurf speichern
|
||||
</button>
|
||||
<button id="btn-publish" class="w-full bg-sky-500 hover:bg-sky-400 text-slate-950 font-bold py-2.5 rounded-lg text-xs transition-colors shadow-lg shadow-sky-500/20">
|
||||
🚀 Live Veröffentlichen
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Component Manager per Section (Positionieren, Bearbeiten, Loeschen) -->
|
||||
<div class="glass-panel rounded-xl p-4 space-y-3">
|
||||
<h3 class="text-xs font-bold text-sky-400 uppercase tracking-wider flex items-center justify-between">
|
||||
<span>Sektions-Komponenten (<span id="elements-count">{(siteConfig.hero.elements || []).length}</span>)</span>
|
||||
</h3>
|
||||
|
||||
<!-- Dynamic Filter per Section -->
|
||||
<div class="flex items-center gap-2 mb-2">
|
||||
<label class="text-[10px] text-slate-400 uppercase font-bold">Filter:</label>
|
||||
<select id="filter-section-select" class="flex-1 glass-panel bg-slate-900 rounded p-1 text-xs text-white capitalize">
|
||||
<option value="all">Alle Sektionen</option>
|
||||
{siteConfig.sectionsOrder.map(sec => (
|
||||
<option value={sec}>{sec}</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div id="elements-container" class="space-y-2 max-h-80 overflow-y-auto pr-1 custom-scroll">
|
||||
{((siteConfig.hero.elements || [])).map((el, idx) => (
|
||||
<div data-id={el.id} draggable="true" class="element-item p-3 rounded-lg bg-slate-900/70 border border-white/10 space-y-2 text-xs group cursor-grab active:cursor-grabbing">
|
||||
<div class="flex items-center justify-between">
|
||||
<div>
|
||||
<span class="font-bold text-sky-400 uppercase text-[10px] block">{el.type} (Slot: {el.slotId})</span>
|
||||
<span id={`el-label-${el.id}`} class="text-slate-200 font-semibold">{el.content}</span>
|
||||
</div>
|
||||
<div class="flex items-center gap-1">
|
||||
<button type="button" onclick={`moveElement('${el.id}', -1)`} class="p-1 hover:text-sky-400 text-xs font-bold" title="Nach oben verschieben">Up</button>
|
||||
<button type="button" onclick={`moveElement('${el.id}', 1)`} class="p-1 hover:text-sky-400 text-xs font-bold" title="Nach unten verschieben">Down</button>
|
||||
<button type="button" onclick={`deleteElement('${el.id}')`} class="p-1 text-red-400/80 hover:text-red-400 text-xs font-bold ml-1" title="Komponente loeschen">Trash</button>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Inline Edit Form -->
|
||||
<div class="pt-2 border-t border-white/5 flex gap-2">
|
||||
<input type="text" id={`edit-input-${el.id}`} value={el.content} class="flex-1 glass-panel bg-slate-950 rounded px-2 py-1 text-xs text-white border border-white/10 focus:border-sky-400" />
|
||||
<button type="button" onclick={`updateElementContent('${el.id}')`} class="px-2 py-1 rounded bg-sky-400/20 text-sky-400 border border-sky-400/30 text-[10px] font-bold hover:bg-sky-400 hover:text-slate-950 transition-all">Save</button>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- TAB 2: STIL (Layout, Header, Footer & Glassmorphism) -->
|
||||
<div id="tab-panel-style" class="hidden space-y-6">
|
||||
<!-- Glassmorphism & Theme Styles -->
|
||||
<div class="glass-panel rounded-xl p-4 space-y-4">
|
||||
<h3 class="text-xs font-bold text-sky-400 uppercase tracking-wider">
|
||||
Glassmorphism & Theme Presets
|
||||
</h3>
|
||||
|
||||
<div class="space-y-3">
|
||||
<div>
|
||||
<label class="block text-[10px] font-bold text-slate-400 uppercase mb-1">Theme Preset</label>
|
||||
<select id="style-preset-select" class="w-full glass-panel bg-slate-900 rounded-lg p-2 text-xs text-white focus:outline-none focus:border-sky-400">
|
||||
{Object.entries(THEME_PRESETS).map(([id, preset]) => (
|
||||
<option value={id} selected={id === themeConfig.activePreset}>{preset.name}</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label class="block text-[10px] font-bold text-slate-400 uppercase mb-1">Glass Backdrop Blur</label>
|
||||
<select id="style-blur-select" class="w-full glass-panel bg-slate-900 rounded-lg p-2 text-xs text-white focus:outline-none focus:border-sky-400">
|
||||
<option value="blur-sm">Subtle (blur-sm 4px)</option>
|
||||
<option value="blur-md">Medium (blur-md 8px)</option>
|
||||
<option value="blur-xl" selected>Ultra Glass (blur-xl 20px)</option>
|
||||
<option value="blur-3xl">Max Aurora (blur-3xl 60px)</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label class="block text-[10px] font-bold text-slate-400 uppercase mb-1">Glass Border Radius</label>
|
||||
<select id="style-radius-select" class="w-full glass-panel bg-slate-900 rounded-lg p-2 text-xs text-white focus:outline-none focus:border-sky-400">
|
||||
<option value="rounded-lg">Medium (12px)</option>
|
||||
<option value="rounded-xl" selected>Large (16px)</option>
|
||||
<option value="rounded-2xl">Extra Large (24px)</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Header Bearbeiten -->
|
||||
<div class="glass-panel rounded-xl p-4 space-y-4">
|
||||
<h3 class="text-xs font-bold text-sky-400 uppercase tracking-wider">
|
||||
Header & Navigation Bearbeiten
|
||||
</h3>
|
||||
<div class="space-y-3">
|
||||
<div>
|
||||
<label class="block text-[10px] font-bold text-slate-400 uppercase mb-1">Marken-Name / Logo</label>
|
||||
<input type="text" id="header-brand-name" value={siteConfig.header?.brandName || 'N&D'} class="w-full glass-panel bg-slate-900 rounded-lg p-2 text-xs text-white focus:outline-none focus:border-sky-400" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-[10px] font-bold text-slate-400 uppercase mb-1">Marken Highlight</label>
|
||||
<input type="text" id="header-brand-highlight" value={siteConfig.header?.brandHighlight || 'i-t SOLUTIONS'} class="w-full glass-panel bg-slate-900 rounded-lg p-2 text-xs text-white focus:outline-none focus:border-sky-400" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-[10px] font-bold text-slate-400 uppercase mb-1">CTA Button Text</label>
|
||||
<input type="text" id="header-cta-text" value={siteConfig.header?.ctaText || 'Erstgespräch buchen'} class="w-full glass-panel bg-slate-900 rounded-lg p-2 text-xs text-white focus:outline-none focus:border-sky-400" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Footer Bearbeiten -->
|
||||
<div class="glass-panel rounded-xl p-4 space-y-4">
|
||||
<h3 class="text-xs font-bold text-sky-400 uppercase tracking-wider">
|
||||
Footer & Reconstitution Bearbeiten
|
||||
</h3>
|
||||
<div class="space-y-3">
|
||||
<div>
|
||||
<label class="block text-[10px] font-bold text-slate-400 uppercase mb-1">Footer Beschreibung</label>
|
||||
<textarea id="footer-description" class="w-full h-16 glass-panel bg-slate-900 rounded-lg p-2 text-xs text-white focus:outline-none focus:border-sky-400">{siteConfig.footer?.brandDescription || 'Ihr Partner für professionelles Webdesign.'}</textarea>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-[10px] font-bold text-slate-400 uppercase mb-1">Copyright Text</label>
|
||||
<input type="text" id="footer-copyright" value={siteConfig.footer?.copyrightText || 'N&D i-t SOLUTIONS. Alle Rechte vorbehalten.'} class="w-full glass-panel bg-slate-900 rounded-lg p-2 text-xs text-white focus:outline-none focus:border-sky-400" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- TAB 3: ERWEITERT (Animationen, Custom CSS & Z_index) -->
|
||||
<div id="tab-panel-advanced" class="hidden space-y-6">
|
||||
<div class="glass-panel rounded-xl p-4 space-y-4">
|
||||
<h3 class="text-xs font-bold text-sky-400 uppercase tracking-wider">
|
||||
Erweiterte Effekte & CSS
|
||||
</h3>
|
||||
|
||||
<div class="space-y-3">
|
||||
<div>
|
||||
<label class="block text-[10px] font-bold text-slate-400 uppercase mb-1">Globale Animation GPU Acceleration</label>
|
||||
<select id="advanced-gpu-select" class="w-full glass-panel bg-slate-900 rounded-lg p-2 text-xs text-white focus:outline-none focus:border-sky-400">
|
||||
<option value="enabled">Activated (Hardware XL)</option>
|
||||
<option value="disabled">Disabled (Save Battery)</option>
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-[10px] font-bold text-slate-400 uppercase mb-1">Custom CSS Overrides</label>
|
||||
<textarea id="advanced-custom-css" placeholder=".custom-glass { backdrop-blur: 20px; }" class="w-full h-20 glass-panel bg-slate-900 rounded-lg p-2 text-xs text-white font-mono focus:outline-none focus:border-sky-400"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</aside>
|
||||
|
||||
<!-- Right Panel: Live Website Preview iframe with Responsive Viewport Container -->
|
||||
<main class="flex-1 bg-slate-900/90 relative flex items-center justify-center p-4 overflow-hidden">
|
||||
<div id="iframe-container" class="w-full h-full transition-all duration-300 flex items-center justify-center">
|
||||
<iframe id="preview-iframe" src="/" class="w-full h-full transition-all duration-300 border-none shadow-2xl rounded-xl"></iframe>
|
||||
<main class="flex-1 bg-slate-950 flex flex-col relative">
|
||||
<div class="h-10 bg-slate-900 border-b border-slate-800 flex items-center justify-between px-4 text-xs text-slate-400">
|
||||
<span>Vorschau-Route: <code class="text-sky-400 font-mono">{previewUrl}</code></span>
|
||||
<span id="editor-status-badge" class="text-amber-400 bg-amber-950/60 border border-amber-800/60 px-2 py-0.5 rounded text-[10px]">Entwurf aktiv</span>
|
||||
</div>
|
||||
<iframe
|
||||
id="preview-iframe"
|
||||
src={previewUrl}
|
||||
class="w-full h-full border-none bg-slate-950"
|
||||
title="Live Website Preview"
|
||||
></iframe>
|
||||
</main>
|
||||
|
||||
</div>
|
||||
|
||||
<!-- Theme Builder Conditions Modal Overlay -->
|
||||
<div id="conditions-modal" class="hidden fixed inset-0 bg-slate-950/80 backdrop-blur-md z-50 flex items-center justify-center p-4">
|
||||
<div class="bg-slate-900 border border-white/10 rounded-2xl p-6 w-full max-w-lg space-y-5 shadow-2xl text-xs">
|
||||
<div class="flex items-center justify-between border-b border-white/10 pb-3">
|
||||
<div>
|
||||
<h3 class="text-sm font-bold text-sky-400 uppercase tracking-wider">Theme Builder Display Conditions</h3>
|
||||
<p class="text-slate-400 text-[11px] mt-0.5">Bestimme, wo dieses Template auf der Website erscheinen soll.</p>
|
||||
</div>
|
||||
<button id="close-conditions-modal" class="text-slate-400 hover:text-white font-bold text-sm">✕</button>
|
||||
</div>
|
||||
|
||||
<div id="conditions-list" class="space-y-3 max-h-60 overflow-y-auto pr-1">
|
||||
<!-- Dynamic Condition Rows -->
|
||||
</div>
|
||||
|
||||
<button id="add-condition-btn" class="text-xs text-sky-400 font-bold hover:underline flex items-center gap-1">
|
||||
+ Bedingung hinzufügen
|
||||
</button>
|
||||
|
||||
<div class="flex justify-end gap-3 pt-3 border-t border-white/10">
|
||||
<button id="cancel-conditions-btn" class="px-4 py-2 rounded-lg glass-panel text-slate-300 font-semibold hover:text-white">Abbrechen</button>
|
||||
<button id="save-conditions-btn" class="px-5 py-2 rounded-lg bg-sky-400 text-slate-950 font-bold uppercase hover:bg-white transition-all">Bedingungen Speichern</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</Layout>
|
||||
|
||||
<script is:inline define:vars={{ siteConfigJSON: JSON.stringify(siteConfig), themeConfigJSON: JSON.stringify(themeConfig) }}>
|
||||
let siteConfigState = JSON.parse(siteConfigJSON);
|
||||
let themeConfigState = JSON.parse(themeConfigJSON);
|
||||
<script>
|
||||
const iframe = document.getElementById('preview-iframe') as HTMLIFrameElement;
|
||||
const statusBadge = document.getElementById('editor-status-badge');
|
||||
|
||||
if (!siteConfigState.hero.elements) siteConfigState.hero.elements = [];
|
||||
|
||||
function reloadIframe() {
|
||||
const iframe = document.getElementById('preview-iframe');
|
||||
if (iframe) iframe.src = iframe.src;
|
||||
}
|
||||
|
||||
const inspectorTabs = document.querySelectorAll('.inspector-tab-btn');
|
||||
inspectorTabs.forEach(btn => {
|
||||
btn.addEventListener('click', () => {
|
||||
inspectorTabs.forEach(b => {
|
||||
b.classList.remove('bg-sky-400/20', 'text-sky-400', 'border', 'border-sky-400/30');
|
||||
b.classList.add('text-slate-400');
|
||||
});
|
||||
btn.classList.remove('text-slate-400');
|
||||
btn.classList.add('bg-sky-400/20', 'text-sky-400', 'border', 'border-sky-400/30');
|
||||
|
||||
const tab = btn.getAttribute('data-tab');
|
||||
document.getElementById('tab-panel-content').classList.add('hidden');
|
||||
document.getElementById('tab-panel-style').classList.add('hidden');
|
||||
document.getElementById('tab-panel-advanced').classList.add('hidden');
|
||||
|
||||
document.getElementById('tab-panel-' + tab).classList.remove('hidden');
|
||||
});
|
||||
});
|
||||
|
||||
const deviceBtns = document.querySelectorAll('.device-btn');
|
||||
const iframeContainer = document.getElementById('iframe-container');
|
||||
|
||||
deviceBtns.forEach(btn => {
|
||||
btn.addEventListener('click', () => {
|
||||
deviceBtns.forEach(b => {
|
||||
b.classList.remove('bg-sky-400/20', 'text-sky-400', 'border', 'border-sky-400/30');
|
||||
b.classList.add('text-slate-400');
|
||||
});
|
||||
btn.classList.remove('text-slate-400');
|
||||
btn.classList.add('bg-sky-400/20', 'text-sky-400', 'border', 'border-sky-400/30');
|
||||
|
||||
const device = btn.getAttribute('data-device');
|
||||
if (device === 'mobile') {
|
||||
iframeContainer.className = 'w-[375px] h-[667px] mx-auto transition-all duration-300 shadow-2xl rounded-2xl border border-white/10 overflow-hidden shrink-0';
|
||||
} else if (device === 'tablet') {
|
||||
iframeContainer.className = 'w-[768px] h-[1024px] mx-auto transition-all duration-300 shadow-2xl rounded-2xl border border-white/10 overflow-hidden shrink-0';
|
||||
} else {
|
||||
iframeContainer.className = 'w-full h-full transition-all duration-300 flex items-center justify-center';
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
const addSectionBtn = document.getElementById('add-section-btn');
|
||||
if (addSectionBtn) {
|
||||
addSectionBtn.addEventListener('click', () => {
|
||||
const newSec = document.getElementById('new-section-select').value;
|
||||
if (!siteConfigState.sectionsOrder.includes(newSec)) {
|
||||
siteConfigState.sectionsOrder.push(newSec);
|
||||
renderSectionsList();
|
||||
updateSectionSelectors();
|
||||
} else {
|
||||
alert('Sektion ist bereits im Layout enthalten!');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
window.deleteSection = function(secName) {
|
||||
siteConfigState.sectionsOrder = siteConfigState.sectionsOrder.filter(s => s !== secName);
|
||||
renderSectionsList();
|
||||
updateSectionSelectors();
|
||||
};
|
||||
|
||||
window.moveSection = function(secName, dir) {
|
||||
const arr = siteConfigState.sectionsOrder;
|
||||
const idx = arr.indexOf(secName);
|
||||
if (idx === -1) return;
|
||||
const targetIdx = idx + dir;
|
||||
if (targetIdx < 0 || targetIdx >= arr.length) return;
|
||||
|
||||
const temp = arr[idx];
|
||||
arr[idx] = arr[targetIdx];
|
||||
arr[targetIdx] = temp;
|
||||
|
||||
renderSectionsList();
|
||||
};
|
||||
|
||||
// --- Drag & Drop for Section Items ---
|
||||
let draggedSecIndex = -1;
|
||||
|
||||
function initSectionDragAndDrop() {
|
||||
const listContainer = document.getElementById('sections-list');
|
||||
if (!listContainer) return;
|
||||
|
||||
const items = listContainer.querySelectorAll('.section-item');
|
||||
items.forEach((item, index) => {
|
||||
item.addEventListener('dragstart', (e) => {
|
||||
draggedSecIndex = index;
|
||||
e.dataTransfer.effectAllowed = 'move';
|
||||
item.classList.add('opacity-40');
|
||||
});
|
||||
|
||||
item.addEventListener('dragend', () => {
|
||||
item.classList.remove('opacity-40');
|
||||
draggedSecIndex = -1;
|
||||
});
|
||||
|
||||
item.addEventListener('dragover', (e) => {
|
||||
e.preventDefault();
|
||||
e.dataTransfer.dropEffect = 'move';
|
||||
});
|
||||
|
||||
item.addEventListener('drop', (e) => {
|
||||
e.preventDefault();
|
||||
if (draggedSecIndex !== -1 && draggedSecIndex !== index) {
|
||||
const arr = siteConfigState.sectionsOrder;
|
||||
const movedItem = arr.splice(draggedSecIndex, 1)[0];
|
||||
arr.splice(index, 0, movedItem);
|
||||
renderSectionsList();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function renderSectionsList() {
|
||||
const listContainer = document.getElementById('sections-list');
|
||||
if (!listContainer) return;
|
||||
listContainer.innerHTML = siteConfigState.sectionsOrder.map((sec, idx) => (
|
||||
'<div data-section="' + sec + '" draggable="true" class="section-item flex items-center justify-between p-3 rounded-lg bg-slate-900/60 border border-white/5 hover:border-sky-400/40 transition-all group cursor-grab active:cursor-grabbing">' +
|
||||
'<div class="flex items-center gap-2">' +
|
||||
'<span class="text-slate-500 font-mono text-xs">#' + (idx + 1) + '</span>' +
|
||||
'<span class="text-xs font-semibold capitalize text-white">' + sec + '</span>' +
|
||||
'</div>' +
|
||||
'<div class="flex items-center gap-1">' +
|
||||
'<button type="button" onclick="moveSection(\'' + sec + '\', -1)" class="p-1 hover:text-sky-400 text-xs font-bold">Up</button>' +
|
||||
'<button type="button" onclick="moveSection(\'' + sec + '\', 1)" class="p-1 hover:text-sky-400 text-xs font-bold">Down</button>' +
|
||||
'<button type="button" onclick="deleteSection(\'' + sec + '\')" class="p-1 text-red-400/70 hover:text-red-400 text-xs font-bold ml-1">Trash</button>' +
|
||||
'</div>' +
|
||||
'</div>'
|
||||
)).join('');
|
||||
|
||||
initSectionDragAndDrop();
|
||||
}
|
||||
|
||||
// Initial call for drag and drop setup
|
||||
initSectionDragAndDrop();
|
||||
|
||||
function updateSectionSelectors() {
|
||||
const newElSec = document.getElementById('new-el-section');
|
||||
const filterSec = document.getElementById('filter-section-select');
|
||||
if (newElSec) {
|
||||
newElSec.innerHTML = siteConfigState.sectionsOrder.map(s => '<option value="' + s + '">' + s + ' Sektion</option>').join('');
|
||||
}
|
||||
if (filterSec) {
|
||||
const current = filterSec.value;
|
||||
filterSec.innerHTML = '<option value="all">Alle Sektionen</option>' + siteConfigState.sectionsOrder.map(s => '<option value="' + s + '">' + s + '</option>').join('');
|
||||
filterSec.value = current;
|
||||
// 1. PostMessage helper
|
||||
function sendToIframe(type: string, payload: any) {
|
||||
if (iframe?.contentWindow) {
|
||||
iframe.contentWindow.postMessage({ type, payload }, '*');
|
||||
}
|
||||
}
|
||||
|
||||
// --- UIComponent Management: Add, Edit, Delete, Position ---
|
||||
|
||||
const addBtn = document.getElementById('add-el-btn');
|
||||
if (addBtn) {
|
||||
addBtn.addEventListener('click', () => {
|
||||
const section = document.getElementById('new-el-section').value;
|
||||
const slotId = document.getElementById('new-el-slot').value;
|
||||
const type = document.getElementById('new-el-type').value;
|
||||
const anim = document.getElementById('new-el-anim').value;
|
||||
const content = document.getElementById('new-el-content').value || 'Neues Element';
|
||||
|
||||
const newComp = {
|
||||
id: 'el-' + Date.now(),
|
||||
slotId: section + '-' + slotId,
|
||||
type,
|
||||
content,
|
||||
animation0: anim || undefined,
|
||||
style: 'primary'
|
||||
};
|
||||
|
||||
siteConfigState.hero.elements.push(newComp);
|
||||
document.getElementById('new-el-content').value = '';
|
||||
renderElementsContainer();
|
||||
});
|
||||
}
|
||||
|
||||
window.deleteElement = function(elId) {
|
||||
siteConfigState.hero.elements = siteConfigState.hero.elements.filter(e => e.id !== elId);
|
||||
renderElementsContainer();
|
||||
};
|
||||
|
||||
window.moveElement = function(elId, dir) {
|
||||
const arr = siteConfigState.hero.elements;
|
||||
const idx = arr.findIndex(e => e.id === elId);
|
||||
if (idx === -1) return;
|
||||
const targetIdx = idx + dir;
|
||||
if (targetIdx < 0 || targetIdx >= arr.length) return;
|
||||
|
||||
const temp = arr[idx];
|
||||
arr[idx] = arr[targetIdx];
|
||||
arr[targetIdx] = temp;
|
||||
|
||||
renderElementsContainer();
|
||||
};
|
||||
|
||||
window.updateElementContent = function(elId) {
|
||||
const input = document.getElementById('edit-input-' + elId);
|
||||
if (!input) return;
|
||||
const el = siteConfigState.hero.elements.find(e => e.id === elId);
|
||||
if (el) {
|
||||
el.content = input.value;
|
||||
const label = document.getElementById('el-label-' + elId);
|
||||
if (label) label.textContent = input.value;
|
||||
}
|
||||
};
|
||||
|
||||
const filterSecSelect = document.getElementById('filter-section-select');
|
||||
if (filterSecSelect) {
|
||||
filterSecSelect.addEventListener('change', renderElementsContainer);
|
||||
}
|
||||
|
||||
function renderElementsContainer() {
|
||||
const container = document.getElementById('elements-container');
|
||||
const countEl = document.getElementById('elements-count');
|
||||
if (!container) return;
|
||||
|
||||
const filterSec = filterSecSelect ? filterSecSelect.value : 'all';
|
||||
let els = siteConfigState.hero.elements || [];
|
||||
|
||||
if (filterSec !== 'all') {
|
||||
els = els.filter(e => e.slotId && e.slotId.startsWith(filterSec));
|
||||
}
|
||||
|
||||
if (countEl) countEl.textContent = els.length;
|
||||
|
||||
container.innerHTML = els.map((el, idx) => (
|
||||
'<div data-id="' + el.id + '" draggable="true" class="element-item p-3 rounded-lg bg-slate-900/70 border border-white/10 space-y-2 text-xs group cursor-grab active:cursor-grabbing">' +
|
||||
'<div class="flex items-center justify-between">' +
|
||||
'<div>' +
|
||||
'<span class="font-bold text-sky-400 uppercase text-[10px] block">' + el.type + ' (Slot: ' + el.slotId + ')</span>' +
|
||||
'<span id="el-label-' + el.id + '" class="text-slate-200 font-semibold">' + el.content + '</span>' +
|
||||
'</div>' +
|
||||
'<div class="flex items-center gap-1">' +
|
||||
'<button type="button" onclick="moveElement(\'' + el.id + '\', -1)" class="p-1 hover:text-sky-400 text-xs font-bold" title="Nach oben">Up</button>' +
|
||||
'<button type="button" onclick="moveElement(\'' + el.id + '\', 1)" class="p-1 hover:text-sky-400 text-xs font-bold" title="Nach unten">Down</button>' +
|
||||
'<button type="button" onclick="deleteElement(\'' + el.id + '\')" class="p-1 text-red-400/80 hover:text-red-400 text-xs font-bold ml-1" title="Loeschen">Trash</button>' +
|
||||
'</div>' +
|
||||
'</div>' +
|
||||
'<div class="pt-2 border-t border-white/5 flex gap-2">' +
|
||||
'<input type="text" id="edit-input-' + el.id + '" value="' + el.content.replace(/"/g, '"') + '" class="flex-1 glass-panel bg-slate-950 rounded px-2 py-1 text-xs text-white border border-white/10 focus:border-sky-400" />' +
|
||||
'<button type="button" onclick="updateElementContent(\'' + el.id + '\')" class="px-2 py-1 rounded bg-sky-400/20 text-sky-400 border border-sky-400/30 text-[10px] font-bold hover:bg-sky-400 hover:text-slate-950 transition-all">Save</button>' +
|
||||
'</div>' +
|
||||
'</div>'
|
||||
)).join('');
|
||||
}
|
||||
|
||||
const stylePresetSelect = document.getElementById('style-preset-select');
|
||||
if (stylePresetSelect) {
|
||||
stylePresetSelect.addEventListener('change', () => {
|
||||
themeConfigState.activePreset = stylePresetSelect.value;
|
||||
});
|
||||
}
|
||||
|
||||
const saveBtn = document.getElementById('save-editor-btn');
|
||||
const alertBox = document.getElementById('editor-alert');
|
||||
|
||||
if (saveBtn) {
|
||||
saveBtn.addEventListener('click', async () => {
|
||||
saveBtn.disabled = true;
|
||||
saveBtn.textContent = 'Wird gespeichert...';
|
||||
|
||||
// Collect Hero Section Inputs & Animation
|
||||
const heroTitle = document.getElementById('hero-title-input')?.value;
|
||||
const heroSubtitle = document.getElementById('hero-subtitle-input')?.value;
|
||||
const heroBadge = document.getElementById('hero-badge-input')?.value;
|
||||
const heroAnim = document.getElementById('hero-anim-select')?.value;
|
||||
|
||||
if (!siteConfigState.hero) siteConfigState.hero = {};
|
||||
if (heroTitle !== undefined) siteConfigState.hero.title = heroTitle;
|
||||
if (heroSubtitle !== undefined) siteConfigState.hero.subtitle = heroSubtitle;
|
||||
if (heroBadge !== undefined) siteConfigState.hero.badge = heroBadge;
|
||||
siteConfigState.hero.animation = heroAnim || undefined;
|
||||
|
||||
// Collect Bento Section Inputs & Animation
|
||||
const bentoTitle = document.getElementById('bento-title-input')?.value;
|
||||
const bentoSubtitle = document.getElementById('bento-subtitle-input')?.value;
|
||||
const bentoAnim = document.getElementById('bento-anim-select')?.value;
|
||||
|
||||
if (!siteConfigState.bento) siteConfigState.bento = {};
|
||||
if (bentoTitle !== undefined) siteConfigState.bento.sectionTitle = bentoTitle;
|
||||
if (bentoSubtitle !== undefined) siteConfigState.bento.sectionSubtitle = bentoSubtitle;
|
||||
siteConfigState.bento.animation = bentoAnim || undefined;
|
||||
|
||||
// Collect Header Inputs
|
||||
const brandName = document.getElementById('header-brand-name')?.value;
|
||||
const brandHighlight = document.getElementById('header-brand-highlight')?.value;
|
||||
const ctaText = document.getElementById('header-cta-text')?.value;
|
||||
|
||||
if (!siteConfigState.header) siteConfigState.header = {};
|
||||
if (brandName !== undefined) siteConfigState.header.brandName = brandName;
|
||||
if (brandHighlight !== undefined) siteConfigState.header.brandHighlight = brandHighlight;
|
||||
if (ctaText !== undefined) siteConfigState.header.ctaText = ctaText;
|
||||
|
||||
// Collect Footer Inputs
|
||||
const footerDesc = document.getElementById('footer-description')?.value;
|
||||
const footerCopy = document.getElementById('footer-copyright')?.value;
|
||||
|
||||
if (!siteConfigState.footer) siteConfigState.footer = {};
|
||||
if (footerDesc !== undefined) siteConfigState.footer.brandDescription = footerDesc;
|
||||
if (footerCopy !== undefined) siteConfigState.footer.copyrightText = footerCopy;
|
||||
|
||||
try {
|
||||
await fetch('/api/update-config', {
|
||||
// 2. Draft Speichern
|
||||
document.getElementById('btn-save-draft')?.addEventListener('click', async () => {
|
||||
const res = await fetch('/api/editor/save-draft', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(siteConfigState)
|
||||
body: JSON.stringify({ updated_at: new Date().toISOString() })
|
||||
});
|
||||
await fetch('/api/config', {
|
||||
|
||||
if (res.ok && statusBadge) {
|
||||
statusBadge.textContent = 'Entwurf gespeichert';
|
||||
statusBadge.className = 'text-sky-400 bg-sky-950/60 border border-sky-800/60 px-2 py-0.5 rounded text-[10px]';
|
||||
}
|
||||
});
|
||||
|
||||
// 3. Veröffentlichen
|
||||
document.getElementById('btn-publish')?.addEventListener('click', async () => {
|
||||
const res = await fetch('/api/editor/publish', { method: 'POST' });
|
||||
if (res.ok && statusBadge) {
|
||||
statusBadge.textContent = 'Live Veröffentlicht!';
|
||||
statusBadge.className = 'text-emerald-400 bg-emerald-950/60 border border-emerald-800/60 px-2 py-0.5 rounded text-[10px]';
|
||||
sendToIframe('RELOAD_CANVAS', {});
|
||||
}
|
||||
});
|
||||
|
||||
// 4. Preset Wechsel
|
||||
document.getElementById('preset-selector')?.addEventListener('change', (e: any) => {
|
||||
sendToIframe('THEME_UPDATE', { preset: e.target.value });
|
||||
});
|
||||
|
||||
// 5. Event: Sektion hinzufügen
|
||||
document.getElementById('btn-add-section')?.addEventListener('click', async () => {
|
||||
const sectionType = (document.getElementById('select-new-section-type') as HTMLSelectElement).value;
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
const pageId = urlParams.get('page_id');
|
||||
|
||||
const res = await fetch('/api/editor/add-section', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(themeConfigState)
|
||||
body: JSON.stringify({ page_id: pageId, section_type: sectionType })
|
||||
});
|
||||
|
||||
alertBox.classList.remove('hidden');
|
||||
alertBox.textContent = 'Speichern erfolgreich! Live-Preview aktualisiert.';
|
||||
reloadIframe();
|
||||
setTimeout(() => alertBox.classList.add('hidden'), 3000);
|
||||
} catch (err) {
|
||||
alert('Fehler beim Speichern.');
|
||||
} finally {
|
||||
saveBtn.disabled = false;
|
||||
saveBtn.textContent = 'Live Speichern';
|
||||
if (res.ok) {
|
||||
window.location.reload();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// --- Theme Builder Display Conditions Modal Management ---
|
||||
let themeConditionsState = [
|
||||
{ type: 'include', scope: 'entire_site' }
|
||||
];
|
||||
// 6. Event: Sektion löschen
|
||||
document.querySelectorAll('.btn-delete-section').forEach(btn => {
|
||||
btn.addEventListener('click', async (e: any) => {
|
||||
const card = e.target.closest('[data-section-id]');
|
||||
const sectionId = card?.getAttribute('data-section-id');
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
const pageId = urlParams.get('page_id');
|
||||
|
||||
const conditionsModal = document.getElementById('conditions-modal');
|
||||
const conditionsBtn = document.getElementById('theme-conditions-btn');
|
||||
const closeConditionsBtn = document.getElementById('close-conditions-modal');
|
||||
const cancelConditionsBtn = document.getElementById('cancel-conditions-btn');
|
||||
const addConditionBtn = document.getElementById('add-condition-btn');
|
||||
const saveConditionsBtn = document.getElementById('save-conditions-btn');
|
||||
|
||||
function openConditionsModal() {
|
||||
renderConditionsList();
|
||||
conditionsModal?.classList.remove('hidden');
|
||||
}
|
||||
|
||||
function closeConditionsModal() {
|
||||
conditionsModal?.classList.add('hidden');
|
||||
}
|
||||
|
||||
function renderConditionsList() {
|
||||
const listContainer = document.getElementById('conditions-list');
|
||||
if (!listContainer) return;
|
||||
|
||||
listContainer.innerHTML = themeConditionsState.map((cond, idx) => (
|
||||
'<div class="flex gap-2 items-center bg-slate-950 p-2.5 rounded-xl border border-white/5 text-xs">' +
|
||||
'<select onchange="updateCondition(' + idx + ', \'type\', this.value)" class="bg-slate-900 text-xs text-white p-2 rounded-lg border border-white/10 focus:border-sky-400">' +
|
||||
'<option value="include"' + (cond.type === 'include' ? ' selected' : '') + '>INCLUDE</option>' +
|
||||
'<option value="exclude"' + (cond.type === 'exclude' ? ' selected' : '') + '>EXCLUDE</option>' +
|
||||
'</select>' +
|
||||
'<select onchange="updateCondition(' + idx + ', \'scope\', this.value)" class="flex-1 bg-slate-900 text-xs text-white p-2 rounded-lg border border-white/10 focus:border-sky-400">' +
|
||||
'<option value="entire_site"' + (cond.scope === 'entire_site' ? ' selected' : '') + '>Entire Site (Ganze Website)</option>' +
|
||||
'<option value="singular"' + (cond.scope === 'singular' ? ' selected' : '') + '>Singular (Einzelseiten)</option>' +
|
||||
'<option value="page_404"' + (cond.scope === 'page_404' ? ' selected' : '') + '>404 Error Page</option>' +
|
||||
'</select>' +
|
||||
'<button type="button" onclick="removeCondition(' + idx + ')" class="text-red-400 hover:text-red-300 font-bold px-2 py-1">✕</button>' +
|
||||
'</div>'
|
||||
)).join('');
|
||||
}
|
||||
|
||||
window.updateCondition = function(idx, field, value) {
|
||||
if (themeConditionsState[idx]) {
|
||||
themeConditionsState[idx][field] = value;
|
||||
}
|
||||
};
|
||||
|
||||
window.removeCondition = function(idx) {
|
||||
themeConditionsState.splice(idx, 1);
|
||||
renderConditionsList();
|
||||
};
|
||||
|
||||
if (addConditionBtn) {
|
||||
addConditionBtn.addEventListener('click', () => {
|
||||
themeConditionsState.push({ type: 'include', scope: 'entire_site' });
|
||||
renderConditionsList();
|
||||
const res = await fetch('/api/editor/delete-section', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ page_id: pageId, section_id: sectionId })
|
||||
});
|
||||
}
|
||||
|
||||
conditionsBtn?.addEventListener('click', openConditionsModal);
|
||||
closeConditionsBtn?.addEventListener('click', closeConditionsModal);
|
||||
cancelConditionsBtn?.addEventListener('click', closeConditionsModal);
|
||||
|
||||
if (saveConditionsBtn) {
|
||||
saveConditionsBtn.addEventListener('click', () => {
|
||||
closeConditionsModal();
|
||||
if (alertBox) {
|
||||
alertBox.classList.remove('hidden');
|
||||
alertBox.textContent = 'Display Conditions erfolgreich gespeichert!';
|
||||
setTimeout(() => alertBox.classList.add('hidden'), 3000);
|
||||
if (res.ok) {
|
||||
window.location.reload();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
</script>
|
||||
82
src/pages/api/editor/add-section.ts
Normal file
82
src/pages/api/editor/add-section.ts
Normal file
@@ -0,0 +1,82 @@
|
||||
import type { APIRoute } from 'astro';
|
||||
import fs from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
|
||||
export const prerender = false;
|
||||
|
||||
const DATA_DIR = process.env.DATA_DIR || path.join(process.cwd(), 'app', 'data');
|
||||
|
||||
// Vordefinierte Standard-Templates für neue Sektionen
|
||||
const SECTION_TEMPLATES: Record<string, any> = {
|
||||
HeroSection: {
|
||||
type: 'HeroSection',
|
||||
settings: {
|
||||
title: 'Neue Überschrift',
|
||||
subtitle: 'Beschreibungstext hier eingeben.',
|
||||
cta_text: 'Jetzt anfragen',
|
||||
cta_url: '#contact'
|
||||
}
|
||||
},
|
||||
BentoGrid: {
|
||||
type: 'BentoGrid',
|
||||
settings: {
|
||||
title: 'Unsere Highlights',
|
||||
columns: 3,
|
||||
items: [
|
||||
{ title: 'Feature 1', description: 'Beschreibung 1' },
|
||||
{ title: 'Feature 2', description: 'Beschreibung 2' },
|
||||
{ title: 'Feature 3', description: 'Beschreibung 3' }
|
||||
]
|
||||
}
|
||||
},
|
||||
ContactSection: {
|
||||
type: 'ContactSection',
|
||||
settings: {
|
||||
title: 'Kontaktieren Sie uns',
|
||||
email_recipient: 'info@kunden-domain.de'
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const POST: APIRoute = async ({ request }) => {
|
||||
try {
|
||||
const { page_id, section_type } = await request.json();
|
||||
|
||||
if (!page_id || !section_type || !SECTION_TEMPLATES[section_type]) {
|
||||
return new Response(JSON.stringify({ error: 'Gültige page_id und section_type erforderlich' }), { status: 400 });
|
||||
}
|
||||
|
||||
const draftPath = path.join(DATA_DIR, 'site.config.draft.json');
|
||||
const livePath = path.join(DATA_DIR, 'site.config.json');
|
||||
|
||||
let configRaw: string;
|
||||
try {
|
||||
configRaw = await fs.readFile(draftPath, 'utf-8');
|
||||
} catch {
|
||||
configRaw = await fs.readFile(livePath, 'utf-8');
|
||||
}
|
||||
|
||||
const config = JSON.parse(configRaw);
|
||||
const targetPage = config.pages?.find((p: any) => p.id === page_id);
|
||||
|
||||
if (!targetPage) {
|
||||
return new Response(JSON.stringify({ error: 'Seite nicht gefunden' }), { status: 404 });
|
||||
}
|
||||
|
||||
// Neue Sektion mit eindeutiger ID anfügen
|
||||
const newSection = {
|
||||
id: `sec_${section_type.toLowerCase()}_${Date.now()}`,
|
||||
...SECTION_TEMPLATES[section_type]
|
||||
};
|
||||
|
||||
targetPage.sections = targetPage.sections || [];
|
||||
targetPage.sections.push(newSection);
|
||||
|
||||
await fs.mkdir(DATA_DIR, { recursive: true });
|
||||
await fs.writeFile(draftPath, JSON.stringify(config, null, 2), 'utf-8');
|
||||
|
||||
return new Response(JSON.stringify({ success: true, section: newSection }), { status: 201 });
|
||||
} catch (error) {
|
||||
return new Response(JSON.stringify({ error: 'Fehler beim Hinzufügen der Sektion' }), { status: 500 });
|
||||
}
|
||||
};
|
||||
44
src/pages/api/editor/delete-section.ts
Normal file
44
src/pages/api/editor/delete-section.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import type { APIRoute } from 'astro';
|
||||
import fs from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
|
||||
export const prerender = false;
|
||||
|
||||
const DATA_DIR = process.env.DATA_DIR || path.join(process.cwd(), 'app', 'data');
|
||||
|
||||
export const POST: APIRoute = async ({ request }) => {
|
||||
try {
|
||||
const { page_id, section_id } = await request.json();
|
||||
|
||||
if (!page_id || !section_id) {
|
||||
return new Response(JSON.stringify({ error: 'page_id und section_id erforderlich' }), { status: 400 });
|
||||
}
|
||||
|
||||
const draftPath = path.join(DATA_DIR, 'site.config.draft.json');
|
||||
const livePath = path.join(DATA_DIR, 'site.config.json');
|
||||
|
||||
let configRaw: string;
|
||||
try {
|
||||
configRaw = await fs.readFile(draftPath, 'utf-8');
|
||||
} catch {
|
||||
configRaw = await fs.readFile(livePath, 'utf-8');
|
||||
}
|
||||
|
||||
const config = JSON.parse(configRaw);
|
||||
const targetPage = config.pages?.find((p: any) => p.id === page_id);
|
||||
|
||||
if (!targetPage) {
|
||||
return new Response(JSON.stringify({ error: 'Seite nicht gefunden' }), { status: 404 });
|
||||
}
|
||||
|
||||
// Sektion filtern / entfernen
|
||||
targetPage.sections = targetPage.sections.filter((sec: any) => sec.id !== section_id);
|
||||
|
||||
await fs.mkdir(DATA_DIR, { recursive: true });
|
||||
await fs.writeFile(draftPath, JSON.stringify(config, null, 2), 'utf-8');
|
||||
|
||||
return new Response(JSON.stringify({ success: true, message: 'Sektion gelöscht' }), { status: 200 });
|
||||
} catch (error) {
|
||||
return new Response(JSON.stringify({ error: 'Fehler beim Löschen der Sektion' }), { status: 500 });
|
||||
}
|
||||
};
|
||||
49
src/pages/api/editor/update-section.ts
Normal file
49
src/pages/api/editor/update-section.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import type { APIRoute } from 'astro';
|
||||
import fs from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
|
||||
export const prerender = false;
|
||||
|
||||
const DATA_DIR = process.env.DATA_DIR || path.join(process.cwd(), 'app', 'data');
|
||||
|
||||
export const POST: APIRoute = async ({ request }) => {
|
||||
try {
|
||||
const { page_id, sections } = await request.json();
|
||||
|
||||
if (!page_id || !Array.isArray(sections)) {
|
||||
return new Response(JSON.stringify({ error: 'page_id und sections-Array erforderlich' }), { status: 400 });
|
||||
}
|
||||
|
||||
const draftPath = path.join(DATA_DIR, 'site.config.draft.json');
|
||||
const livePath = path.join(DATA_DIR, 'site.config.json');
|
||||
|
||||
// 1. Lade bestehende Config (Entwurf bevorzugt)
|
||||
let configRaw: string;
|
||||
try {
|
||||
configRaw = await fs.readFile(draftPath, 'utf-8');
|
||||
} catch {
|
||||
configRaw = await fs.readFile(livePath, 'utf-8');
|
||||
}
|
||||
|
||||
const config = JSON.parse(configRaw);
|
||||
|
||||
// 2. Finde die Zielseite und aktualisiere das sections-Array
|
||||
const targetPage = config.pages?.find((p: any) => p.id === page_id);
|
||||
if (!targetPage) {
|
||||
return new Response(JSON.stringify({ error: 'Zielseite nicht gefunden' }), { status: 404 });
|
||||
}
|
||||
|
||||
targetPage.sections = sections;
|
||||
|
||||
// 3. Speichere ausschließlich in site.config.draft.json
|
||||
await fs.mkdir(DATA_DIR, { recursive: true });
|
||||
await fs.writeFile(draftPath, JSON.stringify(config, null, 2), 'utf-8');
|
||||
|
||||
return new Response(
|
||||
JSON.stringify({ success: true, message: 'Sektionen im Entwurf aktualisiert' }),
|
||||
{ status: 200 }
|
||||
);
|
||||
} catch (error) {
|
||||
return new Response(JSON.stringify({ error: 'Fehler beim Aktualisieren der Sektionen' }), { status: 500 });
|
||||
}
|
||||
};
|
||||
38
tests/editorSections.test.ts
Normal file
38
tests/editorSections.test.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import { describe, it, expect, beforeEach } from 'vitest';
|
||||
import fs from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
|
||||
const DATA_DIR = process.env.DATA_DIR || path.join(process.cwd(), 'app', 'data');
|
||||
const draftPath = path.join(DATA_DIR, 'site.config.draft.json');
|
||||
|
||||
describe('Editor Sections API Test', () => {
|
||||
beforeEach(async () => {
|
||||
await fs.mkdir(DATA_DIR, { recursive: true });
|
||||
const dummyConfig = {
|
||||
site_info: { title: 'Test Site', homepage_id: 'page_1' },
|
||||
pages: [
|
||||
{
|
||||
id: 'page_1',
|
||||
slug: '/',
|
||||
title: 'Home',
|
||||
sections: [{ id: 'sec_1', type: 'HeroSection', settings: { title: 'Old Hero' } }]
|
||||
}
|
||||
]
|
||||
};
|
||||
await fs.writeFile(draftPath, JSON.stringify(dummyConfig, null, 2), 'utf-8');
|
||||
});
|
||||
|
||||
it('soll Sektionen in site.config.draft.json erfolgreich überschreiben', async () => {
|
||||
const raw = await fs.readFile(draftPath, 'utf-8');
|
||||
const config = JSON.parse(raw);
|
||||
|
||||
config.pages[0].sections.push({ id: 'sec_2', type: 'BentoGrid', settings: {} });
|
||||
await fs.writeFile(draftPath, JSON.stringify(config, null, 2), 'utf-8');
|
||||
|
||||
const updatedRaw = await fs.readFile(draftPath, 'utf-8');
|
||||
const updatedConfig = JSON.parse(updatedRaw);
|
||||
|
||||
expect(updatedConfig.pages[0].sections).toHaveLength(2);
|
||||
expect(updatedConfig.pages[0].sections[1].type).toBe('BentoGrid');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user