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