This commit is contained in:
2026-02-05 00:37:32 +01:00
parent e8a4967296
commit a8e606a27f
2 changed files with 49 additions and 42 deletions

View File

@@ -1 +1 @@
1.2.54 1.2.55

View File

@@ -480,19 +480,23 @@
return; return;
} }
// Kein aktives Sync mehr vor dem Speichern, nur Logging // Minimaler Sync vor dem Speichern + Logging (nur echte Text-Components)
try { try {
const doc = editor.Canvas && editor.Canvas.getDocument ? editor.Canvas.getDocument() : null; const doc = editor.Canvas && editor.Canvas.getDocument ? editor.Canvas.getDocument() : null;
const active = doc && doc.activeElement; const active = doc && doc.activeElement;
const selectionNode = doc && doc.getSelection ? (doc.getSelection().focusNode || doc.getSelection().anchorNode) : null; const selectionNode = doc && doc.getSelection ? (doc.getSelection().focusNode || doc.getSelection().anchorNode) : null;
const selectionEl = selectionNode ? (selectionNode.nodeType === 1 ? selectionNode : selectionNode.parentElement) : null; const selectionEl = selectionNode ? (selectionNode.nodeType === 1 ? selectionNode : selectionNode.parentElement) : null;
const selected = editor.getSelected && editor.getSelected(); const selected = editor.getSelected && editor.getSelected();
<<<<<<< ours const win = doc && doc.defaultView;
const lastEl = win && win.__bridgeLastEditableEl;
const lastCompId = win && win.__bridgeLastEditableCompId;
let syncResult = null; let syncResult = null;
let syncReason = 'no-editable-selection'; let syncReason = 'no-editable-selection';
const syncFromElement = (comp, el, reason) => { const syncFromElement = (comp, el, reason) => {
if (!comp || !comp.set || !el) return false; if (!comp || !comp.set || !el) return false;
const type = comp.get ? comp.get('type') : null;
if (type && type !== 'text' && type !== 'textnode') return false;
const html = el.innerHTML || ''; const html = el.innerHTML || '';
const before = typeof comp.get === 'function' ? (comp.get('content') || '') : ''; const before = typeof comp.get === 'function' ? (comp.get('content') || '') : '';
if (html.trim() || !String(before || '').trim()) { if (html.trim() || !String(before || '').trim()) {
@@ -510,40 +514,11 @@
return false; return false;
}; };
<<<<<<< ours // 1) Selection im DOM (bevorzugt)
<<<<<<< ours
<<<<<<< ours
// 1) Selection im DOM suchen (bevorzugt)
=======
=======
>>>>>>> theirs
// 1) Bevorzugt: ausgewähltes Component-Element aus der View
if (selected) {
const selEl = (selected.getEl && selected.getEl()) || (selected.view && selected.view.el);
if (selEl && (selEl.isContentEditable || (selEl.getAttribute && selEl.getAttribute('contenteditable') === 'true'))) {
syncFromElement(selected, selEl, 'selected:view');
}
<<<<<<< ours
}
// 2) Fallback: Selection im DOM suchen
>>>>>>> theirs
=======
// 1) Wenn ein ContentEditable aktiv ist, Blur auslösen, damit GrapesJS den Model-Content übernimmt
if (active && (active.isContentEditable || (active.getAttribute && active.getAttribute('contenteditable') === 'true'))) {
try {
active.dispatchEvent(new Event('blur', { bubbles: true }));
syncReason = 'blur:dispatched';
} catch {}
=======
>>>>>>> theirs
}
// 2) Fallback: Selection im DOM suchen
>>>>>>> theirs
if (!syncResult && doc && selectionEl && (selectionEl.isContentEditable || (selectionEl.getAttribute && selectionEl.getAttribute('contenteditable') === 'true'))) { if (!syncResult && doc && selectionEl && (selectionEl.isContentEditable || (selectionEl.getAttribute && selectionEl.getAttribute('contenteditable') === 'true'))) {
const root = (selectionEl.closest && selectionEl.closest('[data-gjs-type="text"]')) || selectionEl; const root = selectionEl.closest ? selectionEl.closest('[data-gjs-type="text"]') : null;
const id = root && root.getAttribute ? root.getAttribute('id') : null; if (root) {
const id = root.getAttribute ? root.getAttribute('id') : null;
const wrapper = editor.getWrapper && editor.getWrapper(); const wrapper = editor.getWrapper && editor.getWrapper();
if (id && wrapper && wrapper.find) { if (id && wrapper && wrapper.find) {
const found = wrapper.find(`#${id}`); const found = wrapper.find(`#${id}`);
@@ -551,11 +526,41 @@
syncFromElement(comp, root, 'selection:root'); syncFromElement(comp, root, 'selection:root');
} }
} }
}
// 2) zuletzt fokussiertes Element
if (!syncResult && lastEl && (lastEl.isContentEditable || (lastEl.getAttribute && lastEl.getAttribute('contenteditable') === 'true'))) {
const root = lastEl.closest ? lastEl.closest('[data-gjs-type="text"]') : null;
if (root) {
const id = root.getAttribute ? root.getAttribute('id') : null;
const wrapper = editor.getWrapper && editor.getWrapper();
if (id && wrapper && wrapper.find) {
const found = wrapper.find(`#${id}`);
const comp = found && found[0];
syncFromElement(comp, root, 'last:element');
}
}
}
if (!syncResult && lastCompId) {
const wrapper = editor.getWrapper && editor.getWrapper();
if (wrapper && wrapper.find) {
const found = wrapper.find(`#${lastCompId}`);
const comp = found && found[0];
const el = comp && comp.view && comp.view.el;
if (el && (el.isContentEditable || (el.getAttribute && el.getAttribute('contenteditable') === 'true'))) {
syncFromElement(comp, el, 'last:compId');
}
}
}
// 3) Fallback: ausgewähltes Component-Element
if (!syncResult && selected) {
const selEl = (selected.getEl && selected.getEl()) || (selected.view && selected.view.el);
if (selEl && (selEl.isContentEditable || (selEl.getAttribute && selEl.getAttribute('contenteditable') === 'true'))) {
syncFromElement(selected, selEl, 'selected:view');
}
}
=======
>>>>>>> theirs
writeDebugLog({ writeDebugLog({
event: 'save:sync:skipped', event: 'save:sync:minimal',
entityId: CURRENT_ENTITY_ID, entityId: CURRENT_ENTITY_ID,
sectionId: SECTION_ID || null, sectionId: SECTION_ID || null,
active: active ? { active: active ? {
@@ -571,6 +576,8 @@
type: selected.get ? selected.get('type') : null, type: selected.get ? selected.get('type') : null,
contentLen: selected.get ? String(selected.get('content') || '').length : 0, contentLen: selected.get ? String(selected.get('content') || '').length : 0,
} : null, } : null,
syncResult,
syncReason,
editorHtmlLen: (editor.getHtml && String(editor.getHtml() || '').length) || 0, editorHtmlLen: (editor.getHtml && String(editor.getHtml() || '').length) || 0,
editorHtmlPreview: (editor.getHtml && String(editor.getHtml() || '').slice(0, 300)) || '', editorHtmlPreview: (editor.getHtml && String(editor.getHtml() || '').slice(0, 300)) || '',
}); });