adsad
This commit is contained in:
@@ -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(() => {});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user