feat(admin-editor): add elementor-style visual editor with drag-and-drop section manager and device switcher

This commit is contained in:
Daniel S
2026-08-08 18:56:33 +02:00
parent c136e930c9
commit 8197308cef
2 changed files with 570 additions and 0 deletions

View File

@@ -0,0 +1,346 @@
---
import Layout from '../../layouts/Layout.astro';
import { loadWaasConfigs } from '../../utils/configLoader';
const { siteConfig } = loadWaasConfigs();
---
<Layout title="Live Visual Editor | WaaS Engine">
<div class="h-screen w-screen flex flex-col bg-[#0B0F19] text-white font-sans overflow-hidden">
<!-- 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>
</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-ng text-xs font-semibold transition-all text-slate-400 hover:text-white" data-device="mobile">
Mobile (375px)
</button>
</div>
<div class="flex items-center gap-3">
<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>
</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-80 sm:wm96 bg-slate-950/70 border-r border-white/10 p-5 overflow-y-auto space-y-6 shrink-0 z-10 custom-scroll">
<!-- 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="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 Sektion</option>
<option value="bento">Bento Grid Sektion</option>
<option value="services">Leistungen / Services</option>
<option value="contact">Kontaktformular Sektion</option>
<option value="faq">FAQ Akkordeon Sektion</option>
<option value="testimonials">Kundenbewertungen Sektion</option>
<option value="cta-banner">CTA Banner Sektion</option>
</select>
<button type="button" id="add-section-btn" class="px-3 py-2 rounded-lg space-x-1 bg-sky-400/t20 text-sky-400 border border-sky-400/30 font-bold text-xs hover:bg-sky-400 hover:text-slate-950 transition-all">
+ Hinzufuegen
</button>
</div>
</div>
<!-- Sektionen Re-Order -->
<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-500 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-white/20 transition-all group cursor-grab">
<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>
))}
</div>
</div>
<!-- Dynamic UI Elements Adder -->
<div class="glass-panel rounded-xl p-4 space-y-4">
<h3 class="text-xs font-bold text-sky-400 uppercase tracking-wider">
UIKomponente Hinzufuegen
</h3>
<div class="space-y-3">
<div>
<label class="block text-[10px] font-bold text-slate-400 uppercase mb-1">Platz (Slot IM)</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>
</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 / Zimmer-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">Inhalt / Label</label>
<input type="text" id="new-el-content" placeholder="z.B. Jetzt Anfragen" 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">Animation FX</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="none">Keine</option>
<option value="spring-fade">spring-fade</option>
<option value="hover-bounce">hover-bounce</option>
<option value="pulse-glow">pulse-glow</option>
</select>
</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 auf Platz platzieren
</button>
</div>
</div>
<!-- Elements List in Active Config -->
<div class="glass-panel rounded-xl p-4 space-y-3">
<h3 class="text-xs font-bold text-sky-400 uppercase tracking-wider">
Element-Container ({siteConfig.hero.elements?.length || 0})
</h3>
<div id="elements-container" class="space-y-2 max-h-60 overflow-y-auto pr-1">
{(siteConfig.hero.elements || []).map((el) => (
<div class="p-2.5 rounded-lg bg-slate-900/60 border border-white/5 flex items-center justify-between text-xs">
<div>
<span class="font-bold text-sky-400 uppercase text-[10px] block">{el.type} (Platz: {el.slotId})</span>
<span class="text-slate-300">{el.content}</span>
</div>
<span class="text-[9px] font-mono text-slate-500 bg-white/5 px-2 py-0.5 rounded">ID: {el.id}</span>
</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-fulh h-full transition-all duration-300 border-none shadow-2xl rounded-xl"></iframe>
</div>
</main>
</div~
</div~
</Layout>
<script is:inline define:vars={{ siteConfigJSON: JSON.stringify(siteConfig) }}>
let siteConfigState = JSON.parse(siteConfigJSON);
function reloadIframe() {
const iframe = document.getElementById('preview-iframe');
if (iframe) iframe.src = iframe.src;
}
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';
} 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';
} 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();
} else {
alert('Sektion ist bereits im Layout enthalten!');
}
});
}
window.deleteSection = function(secName) {
siteConfigState.sectionsOrder = siteConfigState.sectionsOrder.filter(s => s !== secName);
renderSectionsList();
};
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();
};
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-white/20 transition-all group cursor-grab">' +
'<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('');
initDragAndDrop();
}
function initDragAndDrop() {
const container = document.getElementById('sections-list');
if (!container) return;
let draggedItem = null;
const items = container.querySelectorAll('.section-item');
items.forEach(item => {
item.addEventListener('dragstart', (e) => {
draggedItem = item;
e.dataTransfer.effectAllowed = 'move';
item.classList.add('opacity-40');
});
item.addEventListener('dragend', () => {
item.classList.remove('opacity-40');
draggedItem = null;
});
item.addEventListener('dragover', (e) => {
e.preventDefault();
e.dataTransfer.dropEffect = 'move';
});
item.addEventListener('drop', (e) => {
e.preventDefault();
if (draggedItem && draggedItem !== item) {
const fromSec = draggedItem.getAttribute('data-section');
const toSec = item.getAttribute('data-section');
const arr = siteConfigState.sectionsOrder;
const fromIdx = arr;<3B>[<5B>\ي<19><><EFBFBD>T<EFBFBD>X<EFBFBD>Nˆ<18>ۜ<EFBFBD><1B>YH\<5C><><EFBFBD>[<5B>^ي<1B><>X<EFBFBD>NˆY<>
<19><><EFBFBD>RYOOH LH <09><><1B>YOOH LJHˆ\<5C><><EFBFBD><EFBFBD>X<>J<19><><EFBFBD>RY  JNˆ\<5C><><EFBFBD><EFBFBD>X<>J<1B>Y  <19><><EFBFBD>T<EFBFBD>X<EFBFBD>Nˆ<1C>[<5B>\<5C><>X<EFBFBD><>\<5C>
NˆB<>B<>JNˆJNˆB<><42>[<5B>]<1C>Y<EFBFBD>[<5B><1C><>
N‚<EFBFBD><18>ۜ<EFBFBD>Y<10><1B>H<1B><>[Y[<5B> <0B><>][[Y[<5B><10>RY
<09>Y Y[ X<><1B><>NˆY<>
Y<10><1B>HˆY<10><1B><>Y]<5D>[<5B>\<5C>[<5B>\<5C> <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