From 1b503f8db86ca42aca9436ec1c4e01c5e21e1ca3 Mon Sep 17 00:00:00 2001 From: Lars Gebhardt-Kusche Date: Wed, 21 Jan 2026 00:31:04 +0100 Subject: [PATCH] adsad --- public/assets/js/ui-editor.js | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/public/assets/js/ui-editor.js b/public/assets/js/ui-editor.js index 2df41cf..f86c58f 100644 --- a/public/assets/js/ui-editor.js +++ b/public/assets/js/ui-editor.js @@ -189,7 +189,7 @@ export function initEditor() { craftJson: '', }); } catch { - return buildSnapshot({ editorType: currentEditorType, html: '', json: '', craftJson: '' }); + return null; } } @@ -200,10 +200,25 @@ export function initEditor() { clearDirty(); } + async function syncSnapshotFromEditor() { + beginSuppressDirty(); + const currentSnapshot = await buildCurrentSnapshot(); + if (!currentSnapshot) return; + savedSnapshot = currentSnapshot; + clearDirty(); + } + + function scheduleSnapshotSync(delay = 600) { + beginSuppressDirty(); + setTimeout(() => { + syncSnapshotFromEditor().catch(() => {}); + }, delay); + } + async function hasUnsavedChanges() { - if (isDirty) return true; if (!savedSnapshot) return false; const currentSnapshot = await buildCurrentSnapshot(); + if (!currentSnapshot) return false; return currentSnapshot !== savedSnapshot; } @@ -297,6 +312,7 @@ export function initEditor() { setSavedSnapshotFromData(payload); if (dirtyCleanup) dirtyCleanup(); dirtyCleanup = attachCraftDirtyTracker(); + scheduleSnapshotSync(300); return; } const editor = await waitForEditor(3000); @@ -308,6 +324,7 @@ export function initEditor() { setSavedSnapshotFromData(payload); if (dirtyCleanup) dirtyCleanup(); dirtyCleanup = attachGjsDirtyTracker(editor); + scheduleSnapshotSync(300); return; } catch {} } @@ -316,12 +333,14 @@ export function initEditor() { setSavedSnapshotFromData(payload); if (dirtyCleanup) dirtyCleanup(); dirtyCleanup = attachGjsDirtyTracker(editor); + scheduleSnapshotSync(300); } async function loadLatestContentFromServer() { beginSuppressDirty(); const res = await apiAction('content.get', { method: 'GET', data: { id: current.id, section_id: current.section.id } }); await applyVersionPayload(res || {}); + scheduleSnapshotSync(300); }   function writeHtmlToFrame(html) { @@ -607,12 +626,14 @@ export function initEditor() { editorType = editorType === 'craftjs' ? 'craftjs' : 'grapesjs'; setSavedSnapshotFromData({ html: fresh, content: jsonState, editor_type: editorType, craft_json: craftJson }); setEditorType(editorType); + scheduleSnapshotSync(1200); if (editorType === 'craftjs') { const craftHtml = extractCraftHtml(craftJson, fresh); beginSuppressDirty(); craftEditor?.setContent(craftHtml, craftJson); if (dirtyCleanup) dirtyCleanup(); dirtyCleanup = attachCraftDirtyTracker(); + scheduleSnapshotSync(300); hideVeil(); if (dlg && typeof dlg.showModal === 'function') dlg.showModal(); if (!looksCraftSerialized(craftJson) && craftEditor?.serializeFromHtml) { @@ -709,6 +730,7 @@ export function initEditor() { if (dirtyCleanup) dirtyCleanup(); beginSuppressDirty(); dirtyCleanup = attachGjsDirtyTracker(ed); + scheduleSnapshotSync(1200); }) .catch(() => {}); }