asdasd
This commit is contained in:
@@ -46,6 +46,8 @@ export function initEditor() {
|
|||||||
let isDirty = false;
|
let isDirty = false;
|
||||||
let dirtyCleanup = null;
|
let dirtyCleanup = null;
|
||||||
let dialogCancelBound = false;
|
let dialogCancelBound = false;
|
||||||
|
let suppressDirty = false;
|
||||||
|
let suppressTimer = null;
|
||||||
|
|
||||||
const ok = (m) => toast(m, true);
|
const ok = (m) => toast(m, true);
|
||||||
const err = (m) => toast(m, false);
|
const err = (m) => toast(m, false);
|
||||||
@@ -120,6 +122,7 @@ export function initEditor() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function markDirty() {
|
function markDirty() {
|
||||||
|
if (suppressDirty) return;
|
||||||
isDirty = true;
|
isDirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,6 +130,15 @@ export function initEditor() {
|
|||||||
isDirty = false;
|
isDirty = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function beginSuppressDirty(ms = 800) {
|
||||||
|
suppressDirty = true;
|
||||||
|
if (suppressTimer) clearTimeout(suppressTimer);
|
||||||
|
suppressTimer = setTimeout(() => {
|
||||||
|
suppressDirty = false;
|
||||||
|
suppressTimer = null;
|
||||||
|
}, ms);
|
||||||
|
}
|
||||||
|
|
||||||
function attachGjsDirtyTracker(editor) {
|
function attachGjsDirtyTracker(editor) {
|
||||||
if (!editor || typeof editor.on !== 'function') return () => {};
|
if (!editor || typeof editor.on !== 'function') return () => {};
|
||||||
const onUpdate = () => markDirty();
|
const onUpdate = () => markDirty();
|
||||||
@@ -182,6 +194,7 @@ export function initEditor() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function setSavedSnapshotFromData(payload) {
|
function setSavedSnapshotFromData(payload) {
|
||||||
|
beginSuppressDirty();
|
||||||
const fields = extractContentFields(payload);
|
const fields = extractContentFields(payload);
|
||||||
savedSnapshot = buildSnapshot(fields);
|
savedSnapshot = buildSnapshot(fields);
|
||||||
clearDirty();
|
clearDirty();
|
||||||
@@ -275,6 +288,7 @@ export function initEditor() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function applyVersionPayload(payload) {
|
async function applyVersionPayload(payload) {
|
||||||
|
beginSuppressDirty();
|
||||||
const data = extractContentFields(payload);
|
const data = extractContentFields(payload);
|
||||||
const targetType = data.editorType === 'craftjs' ? 'craftjs' : 'grapesjs';
|
const targetType = data.editorType === 'craftjs' ? 'craftjs' : 'grapesjs';
|
||||||
setEditorType(targetType);
|
setEditorType(targetType);
|
||||||
@@ -305,6 +319,7 @@ export function initEditor() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function loadLatestContentFromServer() {
|
async function loadLatestContentFromServer() {
|
||||||
|
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 || {});
|
||||||
}
|
}
|
||||||
@@ -594,6 +609,7 @@ export function initEditor() {
|
|||||||
setEditorType(editorType);
|
setEditorType(editorType);
|
||||||
if (editorType === 'craftjs') {
|
if (editorType === 'craftjs') {
|
||||||
const craftHtml = extractCraftHtml(craftJson, fresh);
|
const craftHtml = extractCraftHtml(craftJson, fresh);
|
||||||
|
beginSuppressDirty();
|
||||||
craftEditor?.setContent(craftHtml, craftJson);
|
craftEditor?.setContent(craftHtml, craftJson);
|
||||||
if (dirtyCleanup) dirtyCleanup();
|
if (dirtyCleanup) dirtyCleanup();
|
||||||
dirtyCleanup = attachCraftDirtyTracker();
|
dirtyCleanup = attachCraftDirtyTracker();
|
||||||
@@ -691,6 +707,7 @@ export function initEditor() {
|
|||||||
waitForEditor(6000)
|
waitForEditor(6000)
|
||||||
.then((ed) => {
|
.then((ed) => {
|
||||||
if (dirtyCleanup) dirtyCleanup();
|
if (dirtyCleanup) dirtyCleanup();
|
||||||
|
beginSuppressDirty();
|
||||||
dirtyCleanup = attachGjsDirtyTracker(ed);
|
dirtyCleanup = attachGjsDirtyTracker(ed);
|
||||||
})
|
})
|
||||||
.catch(() => {});
|
.catch(() => {});
|
||||||
|
|||||||
Reference in New Issue
Block a user