version
This commit is contained in:
@@ -48,6 +48,7 @@ export function initEditor() {
|
||||
let dialogCancelBound = false;
|
||||
let suppressDirty = false;
|
||||
let suppressTimer = null;
|
||||
let baselineReady = false;
|
||||
|
||||
const ok = (m) => toast(m, true);
|
||||
const err = (m) => toast(m, false);
|
||||
@@ -198,6 +199,7 @@ export function initEditor() {
|
||||
const fields = extractContentFields(payload);
|
||||
savedSnapshot = buildSnapshot(fields);
|
||||
clearDirty();
|
||||
baselineReady = true;
|
||||
}
|
||||
|
||||
async function syncSnapshotFromEditor() {
|
||||
@@ -206,9 +208,11 @@ export function initEditor() {
|
||||
if (!currentSnapshot) return;
|
||||
savedSnapshot = currentSnapshot;
|
||||
clearDirty();
|
||||
baselineReady = true;
|
||||
}
|
||||
|
||||
function scheduleSnapshotSync(delay = 600) {
|
||||
baselineReady = false;
|
||||
beginSuppressDirty();
|
||||
setTimeout(() => {
|
||||
syncSnapshotFromEditor().catch(() => {});
|
||||
@@ -216,6 +220,7 @@ export function initEditor() {
|
||||
}
|
||||
|
||||
async function hasUnsavedChanges() {
|
||||
if (!baselineReady) return false;
|
||||
if (suppressDirty) return false;
|
||||
if (!savedSnapshot) return false;
|
||||
const currentSnapshot = await buildCurrentSnapshot();
|
||||
@@ -304,6 +309,7 @@ export function initEditor() {
|
||||
}
|
||||
|
||||
async function applyVersionPayload(payload) {
|
||||
baselineReady = false;
|
||||
beginSuppressDirty();
|
||||
const data = extractContentFields(payload);
|
||||
const targetType = data.editorType === 'craftjs' ? 'craftjs' : 'grapesjs';
|
||||
@@ -338,6 +344,7 @@ export function initEditor() {
|
||||
}
|
||||
|
||||
async function loadLatestContentFromServer() {
|
||||
baselineReady = false;
|
||||
beginSuppressDirty();
|
||||
const res = await apiAction('content.get', { method: 'GET', data: { id: current.id, section_id: current.section.id } });
|
||||
await applyVersionPayload(res || {});
|
||||
|
||||
Reference in New Issue
Block a user