fix(editor): enable design preset saving, section moving up/down and modal content editing
This commit is contained in:
@@ -169,15 +169,81 @@ const previewUrl = `${targetPage?.slug || '/'}?preview=draft`;
|
||||
});
|
||||
|
||||
// 4. Preset Wechsel
|
||||
document.getElementById('preset-selector')?.addEventListener('change', (e: any) => {
|
||||
sendToIframe('THEME_UPDATE', { preset: e.target.value });
|
||||
document.getElementById('preset-selector')?.addEventListener('change', async (e: any) => {
|
||||
const presetKey = e.target.value;
|
||||
sendToIframe('THEME_UPDATE', { preset: presetKey });
|
||||
|
||||
// Speichere Preset in theme.config.json
|
||||
await fetch('/api/config', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ themeConfig: { activePreset: presetKey } })
|
||||
});
|
||||
});
|
||||
|
||||
// Helper zum Verschieben & Speichern der Sektionen-Reihenfolge
|
||||
async function updateSectionsOrder(newSections: any[]) {
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
const pageId = urlParams.get('page_id') || 'page_home';
|
||||
|
||||
const res = await fetch('/api/editor/update-section', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ page_id: pageId, sections: newSections })
|
||||
});
|
||||
|
||||
if (res.ok) {
|
||||
window.location.reload();
|
||||
}
|
||||
}
|
||||
|
||||
function getSectionsFromDOM() {
|
||||
const list: any[] = [];
|
||||
document.querySelectorAll('#section-list > div').forEach(card => {
|
||||
const id = card.getAttribute('data-section-id');
|
||||
const type = card.getAttribute('data-section-type');
|
||||
const settings = JSON.parse(card.getAttribute('data-settings') || '{}');
|
||||
list.push({ id, type, settings });
|
||||
});
|
||||
return list;
|
||||
}
|
||||
|
||||
// Event: Sektion nach oben / unten verschieben
|
||||
document.querySelectorAll('.btn-move-up').forEach(btn => {
|
||||
btn.addEventListener('click', async (e: any) => {
|
||||
const sections = getSectionsFromDOM();
|
||||
const card = e.target.closest('[data-section-id]');
|
||||
const sectionId = card.getAttribute('data-section-id');
|
||||
const index = sections.findIndex(s => s.id === sectionId);
|
||||
if (index > 0) {
|
||||
const temp = sections[index];
|
||||
sections[index] = sections[index - 1];
|
||||
sections[index - 1] = temp;
|
||||
await updateSectionsOrder(sections);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
document.querySelectorAll('.btn-move-down').forEach(btn => {
|
||||
btn.addEventListener('click', async (e: any) => {
|
||||
const sections = getSectionsFromDOM();
|
||||
const card = e.target.closest('[data-section-id]');
|
||||
const sectionId = card.getAttribute('data-section-id');
|
||||
const index = sections.findIndex(s => s.id === sectionId);
|
||||
if (index >= 0 && index < sections.length - 1) {
|
||||
const temp = sections[index];
|
||||
sections[index] = sections[index + 1];
|
||||
sections[index + 1] = temp;
|
||||
await updateSectionsOrder(sections);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// 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 pageId = urlParams.get('page_id') || 'page_home';
|
||||
|
||||
const res = await fetch('/api/editor/add-section', {
|
||||
method: 'POST',
|
||||
@@ -196,7 +262,7 @@ const previewUrl = `${targetPage?.slug || '/'}?preview=draft`;
|
||||
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 pageId = urlParams.get('page_id') || 'page_home';
|
||||
|
||||
const res = await fetch('/api/editor/delete-section', {
|
||||
method: 'POST',
|
||||
@@ -259,7 +325,7 @@ const previewUrl = `${targetPage?.slug || '/'}?preview=draft`;
|
||||
formData.forEach((val, key) => { settings[key] = val; });
|
||||
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
const pageId = urlParams.get('page_id');
|
||||
const pageId = urlParams.get('page_id') || 'page_home';
|
||||
|
||||
const res = await fetch('/api/editor/update-section-settings', {
|
||||
method: 'POST',
|
||||
@@ -269,9 +335,8 @@ const previewUrl = `${targetPage?.slug || '/'}?preview=draft`;
|
||||
|
||||
if (res.ok) {
|
||||
editModal?.close();
|
||||
// Schicke Live-Reload Signal an Iframe Bridge
|
||||
const iframeElement = document.getElementById('preview-iframe') as HTMLIFrameElement;
|
||||
iframeElement?.contentWindow?.postMessage({ type: 'RELOAD_CANVAS' }, '*');
|
||||
window.location.reload();
|
||||
}
|
||||
});
|
||||
|
||||
</script>
|
||||
Reference in New Issue
Block a user