adsad
This commit is contained in:
@@ -189,7 +189,7 @@ export function initEditor() {
|
|||||||
craftJson: '',
|
craftJson: '',
|
||||||
});
|
});
|
||||||
} catch {
|
} catch {
|
||||||
return buildSnapshot({ editorType: currentEditorType, html: '', json: '', craftJson: '' });
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -200,10 +200,25 @@ export function initEditor() {
|
|||||||
clearDirty();
|
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() {
|
async function hasUnsavedChanges() {
|
||||||
if (isDirty) return true;
|
|
||||||
if (!savedSnapshot) return false;
|
if (!savedSnapshot) return false;
|
||||||
const currentSnapshot = await buildCurrentSnapshot();
|
const currentSnapshot = await buildCurrentSnapshot();
|
||||||
|
if (!currentSnapshot) return false;
|
||||||
return currentSnapshot !== savedSnapshot;
|
return currentSnapshot !== savedSnapshot;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -297,6 +312,7 @@ export function initEditor() {
|
|||||||
setSavedSnapshotFromData(payload);
|
setSavedSnapshotFromData(payload);
|
||||||
if (dirtyCleanup) dirtyCleanup();
|
if (dirtyCleanup) dirtyCleanup();
|
||||||
dirtyCleanup = attachCraftDirtyTracker();
|
dirtyCleanup = attachCraftDirtyTracker();
|
||||||
|
scheduleSnapshotSync(300);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const editor = await waitForEditor(3000);
|
const editor = await waitForEditor(3000);
|
||||||
@@ -308,6 +324,7 @@ export function initEditor() {
|
|||||||
setSavedSnapshotFromData(payload);
|
setSavedSnapshotFromData(payload);
|
||||||
if (dirtyCleanup) dirtyCleanup();
|
if (dirtyCleanup) dirtyCleanup();
|
||||||
dirtyCleanup = attachGjsDirtyTracker(editor);
|
dirtyCleanup = attachGjsDirtyTracker(editor);
|
||||||
|
scheduleSnapshotSync(300);
|
||||||
return;
|
return;
|
||||||
} catch {}
|
} catch {}
|
||||||
}
|
}
|
||||||
@@ -316,12 +333,14 @@ export function initEditor() {
|
|||||||
setSavedSnapshotFromData(payload);
|
setSavedSnapshotFromData(payload);
|
||||||
if (dirtyCleanup) dirtyCleanup();
|
if (dirtyCleanup) dirtyCleanup();
|
||||||
dirtyCleanup = attachGjsDirtyTracker(editor);
|
dirtyCleanup = attachGjsDirtyTracker(editor);
|
||||||
|
scheduleSnapshotSync(300);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loadLatestContentFromServer() {
|
async function loadLatestContentFromServer() {
|
||||||
beginSuppressDirty();
|
beginSuppressDirty();
|
||||||
const res = await apiAction('content.get', { method: 'GET', data: { id: current.id, section_id: current.section.id } });
|
const res = await apiAction('content.get', { method: 'GET', data: { id: current.id, section_id: current.section.id } });
|
||||||
await applyVersionPayload(res || {});
|
await applyVersionPayload(res || {});
|
||||||
|
scheduleSnapshotSync(300);
|
||||||
}
|
}
|
||||||
|
|
||||||
function writeHtmlToFrame(html) {
|
function writeHtmlToFrame(html) {
|
||||||
@@ -607,12 +626,14 @@ export function initEditor() {
|
|||||||
editorType = editorType === 'craftjs' ? 'craftjs' : 'grapesjs';
|
editorType = editorType === 'craftjs' ? 'craftjs' : 'grapesjs';
|
||||||
setSavedSnapshotFromData({ html: fresh, content: jsonState, editor_type: editorType, craft_json: craftJson });
|
setSavedSnapshotFromData({ html: fresh, content: jsonState, editor_type: editorType, craft_json: craftJson });
|
||||||
setEditorType(editorType);
|
setEditorType(editorType);
|
||||||
|
scheduleSnapshotSync(1200);
|
||||||
if (editorType === 'craftjs') {
|
if (editorType === 'craftjs') {
|
||||||
const craftHtml = extractCraftHtml(craftJson, fresh);
|
const craftHtml = extractCraftHtml(craftJson, fresh);
|
||||||
beginSuppressDirty();
|
beginSuppressDirty();
|
||||||
craftEditor?.setContent(craftHtml, craftJson);
|
craftEditor?.setContent(craftHtml, craftJson);
|
||||||
if (dirtyCleanup) dirtyCleanup();
|
if (dirtyCleanup) dirtyCleanup();
|
||||||
dirtyCleanup = attachCraftDirtyTracker();
|
dirtyCleanup = attachCraftDirtyTracker();
|
||||||
|
scheduleSnapshotSync(300);
|
||||||
hideVeil();
|
hideVeil();
|
||||||
if (dlg && typeof dlg.showModal === 'function') dlg.showModal();
|
if (dlg && typeof dlg.showModal === 'function') dlg.showModal();
|
||||||
if (!looksCraftSerialized(craftJson) && craftEditor?.serializeFromHtml) {
|
if (!looksCraftSerialized(craftJson) && craftEditor?.serializeFromHtml) {
|
||||||
@@ -709,6 +730,7 @@ export function initEditor() {
|
|||||||
if (dirtyCleanup) dirtyCleanup();
|
if (dirtyCleanup) dirtyCleanup();
|
||||||
beginSuppressDirty();
|
beginSuppressDirty();
|
||||||
dirtyCleanup = attachGjsDirtyTracker(ed);
|
dirtyCleanup = attachGjsDirtyTracker(ed);
|
||||||
|
scheduleSnapshotSync(1200);
|
||||||
})
|
})
|
||||||
.catch(() => {});
|
.catch(() => {});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user